/* =========================================================================
   BENTO DEV — Developer Hub Stylesheet
   Matches BENTO IDE design system (purple primary, white surfaces)
   ========================================================================= */

/* --- Design Tokens ------------------------------------------------------ */
:root {
  --tesa-primary: #7239ea;
  --tesa-primary-hover: #5f2bc7;
  --tesa-primary-light: #e3d6ff;
  --tesa-primary-subtle: #f5f0ff;
  --tesa-blue: #3c54a4;
  --tesa-red: #e9292a;
  --tesa-navy: #231f20;

  --color-success: #50cd89;
  --color-success-hover: #43b578;
  --color-info: #009ef7;
  --color-info-hover: #0085d1;
  --color-warning: #ffc700;
  --color-danger: #f1416c;
  --color-danger-hover: #d9365d;

  --bg-body: #f5f8fa;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f3f5;
  --bg-code: #1e1e2d;
  --bg-terminal: #1a1a2e;

  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --text-inverse: #f9fafb;
  --text-code: #d4d4d4;

  --border-color: #e5e7eb;
  --border-hover: #d1d5db;
  --border-focus: var(--tesa-primary);

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);

  --header-height: 54px;
  --toolbar-height: 40px;
  --statusbar-height: 26px;

  --border-radius: 8px;
  --border-radius-sm: 6px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Consolas', monospace;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base ------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-body);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--tesa-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* --- Scrollbar ---------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* --- Splash Screen ------------------------------------------------------ */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #fff;
  transition: opacity 0.5s ease-out;
}
#splash.fade-out { opacity: 0; pointer-events: none; }

#splash .logo-text {
  font-size: 2.4rem; font-weight: 800; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--tesa-primary), var(--color-info));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
#splash .subtitle { font-size: 0.9rem; color: var(--text-tertiary); margin-top: 8px; letter-spacing: 1px; }
#splash .spinner {
  margin-top: 32px; width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--tesa-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================================================= */
/* HEADER                                                                    */
/* ========================================================================= */
#header {
  height: var(--header-height);
  background: linear-gradient(135deg, #4a0e0e 0%, #6b1a1a 40%, #7c2020 100%);
  border-bottom: 1px solid rgba(139, 45, 45, 0.5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(74, 14, 14, 0.3);
  flex-shrink: 0;
  color: rgba(255, 255, 255, 0.95);
}

.header-left,
.header-center,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Logo */
.logo { display: flex; align-items: center; gap: 8px; }

.logo-text {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.logo-circles {
  color: #f4a6a6;
  font-weight: 700;
}

.logo-subtitle {
  font-size: 0.72rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.6);
  white-space: nowrap;
}

/* View Toggle */
.view-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--border-radius-sm);
  padding: 2px;
  gap: 2px;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.view-btn:hover {
  color: #fff;
}

.view-btn.active {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.view-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Board Selector (Header) */
.board-selector {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}
.board-selector:focus {
  border-color: var(--tesa-primary);
  box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.1);
}

/* Header Badge */
.header-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 10px;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  white-space: nowrap;
}

/* ========================================================================= */
/* TOOLBAR                                                                   */
/* ========================================================================= */
#toolbar {
  height: var(--toolbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
}

/* ========================================================================= */
/* BUTTONS                                                                   */
/* ========================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--border-radius-sm);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover { filter: brightness(0.95); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.btn-primary {
  background: var(--tesa-primary);
  color: white;
  box-shadow: 0 1px 2px rgba(114, 57, 234, 0.3);
}
.btn-primary:hover { background: var(--tesa-primary-hover); }

.btn-success {
  background: var(--color-success);
  color: white;
  box-shadow: 0 1px 2px rgba(80, 205, 137, 0.3);
}
.btn-success:hover { background: var(--color-success-hover); }

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-outline {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border-color);
}
.btn-outline:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

/* ========================================================================= */
/* MAIN LAYOUT                                                               */
/* ========================================================================= */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* --- Panels ------------------------------------------------------------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-title svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.panel-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
}

/* --- Editor Panel (Left) ------------------------------------------------ */
#editorPanel {
  flex: 1;
  min-width: 200px;
}

/* Editor body: flex row containing file tree + Monaco */
.editor-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* File Tree Sidebar */
.file-tree {
  width: 200px;
  min-width: 140px;
  max-width: 320px;
  background: var(--bg-code);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.file-tree-header {
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.file-tree-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1;
}

.file-tree-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-code);
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tree-list li:hover {
  background: rgba(255, 255, 255, 0.06);
}

.file-tree-list li.active {
  background: rgba(114, 57, 234, 0.25);
  color: #fff;
}

.file-tree-list li .file-icon {
  flex-shrink: 0;
  font-size: 13px;
  opacity: 0.7;
}

/* Nested file tree (GitHub-live) */
.file-tree-group {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-tree-children {
  list-style: none;
  padding: 0;
  margin: 0;
}

.file-tree-children.collapsed {
  display: none;
}

.file-tree-dir {
  cursor: pointer;
  color: rgba(255, 255, 255, 0.7);
  user-select: none;
  font-size: 11px;
  padding: 3px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tree-dir:hover {
  background: rgba(255, 255, 255, 0.06);
}

.dir-arrow {
  display: inline-block;
  width: 14px;
  font-size: 8px;
  text-align: center;
  transition: transform 0.15s ease;
}

/* File tree ↔ Monaco resize handle */
.file-tree-resize {
  width: 4px;
  background: transparent;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.file-tree-resize:hover,
.file-tree-resize.active {
  background: var(--tesa-primary);
}

/* Monaco Editor Container */
.monaco-container {
  flex: 1;
  overflow: hidden;
  background: var(--bg-code);
  position: relative;
  min-width: 0;
}

.monaco-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-tertiary);
  font-size: 13px;
  gap: 8px;
  text-align: center;
  padding: 24px;
}

.monaco-placeholder-icon {
  font-size: 2.5rem;
  opacity: 0.4;
}

.monaco-placeholder-hint {
  font-size: 11px;
  opacity: 0.6;
}

/* --- Resize Handle (Horizontal) ----------------------------------------- */
.resize-handle {
  width: 5px;
  background: var(--border-color);
  cursor: col-resize;
  transition: background var(--transition);
  position: relative;
  flex-shrink: 0;
}

.resize-handle:hover,
.resize-handle.active {
  background: var(--tesa-primary);
}

.resize-dots {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 24px;
  opacity: 0;
  transition: opacity var(--transition);
  /* 3 dots via box-shadow */
  background: #fff;
  border-radius: 1px;
  box-shadow: 0 -8px 0 #fff, 0 8px 0 #fff;
}

.resize-handle:hover .resize-dots {
  opacity: 0.8;
}

/* --- Flowchart Panel (Right) -------------------------------------------- */
#flowchartPanel {
  flex: 4;
  min-width: 200px;
  background: var(--bg-code);
  color: var(--text-code);
}

#flowchartPanel .panel-header {
  background: var(--bg-terminal);
  border-bottom-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
}

#flowchartPanel .panel-title {
  color: rgba(255, 255, 255, 0.85);
}

#flowchartPanel .panel-title svg {
  fill: rgba(255, 255, 255, 0.85);
}

#flowchartPanel .flowchart-zoom-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
}

#flowchartPanel .flowchart-zoom-btn:hover {
  background: var(--tesa-primary);
  color: #fff;
  border-color: var(--tesa-primary);
}

#flowchartPanel .flowchart-ctrl-divider {
  background: rgba(255, 255, 255, 0.12);
}

#flowchartPanel .panel-badge {
  color: rgba(255, 255, 255, 0.5);
}

.flowchart-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s ease;
}

.flowchart-close-btn:hover {
  color: #fff;
}

.flowchart-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.flowchart-zoom-btn {
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--border-radius-sm);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background var(--transition), color var(--transition);
}

.flowchart-zoom-btn:hover {
  background: var(--tesa-primary);
  color: #fff;
  border-color: var(--tesa-primary);
}

.flowchart-ctrl-divider {
  display: inline-block;
  width: 1px;
  height: 16px;
  background: var(--border-color);
  margin: 0 4px;
}

.flowchart-fn-btn {
  font-size: 10px;
  background: var(--bg-muted);
  border: 1px solid #4ade80;
  color: #4ade80;
}

.flowchart-fn-btn:hover {
  background: #2d4a3e;
  color: #a7f3d0;
  border-color: #4ade80;
}

.flowchart-export-btn {
  font-size: 10px;
  letter-spacing: 0.04em;
}

.flowchart-svg-wrap {
  flex: 1;
  overflow: auto;
  background: var(--bg-code);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
}

.flowchart-svg-wrap svg {
  max-width: 100%;
}

.flowchart-empty,
.flowchart-error {
  color: var(--text-tertiary);
  font-size: 13px;
  text-align: center;
  padding: 40px;
  align-self: center;
}
.flowchart-error { color: var(--color-danger); }

/* ========================================================================= */
/* STATUS BAR                                                                */
/* ========================================================================= */
#statusBar {
  height: var(--statusbar-height);
  background: linear-gradient(90deg, #4a0e0e 0%, #6b1a1a 100%);
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  gap: 16px;
  flex-shrink: 0;
}

/* Hide PSoC Edge board info + example count from footer */
#statusBar .status-left { display: none; }

.status-left,
.status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-left { flex: 1; }
.status-right { flex-shrink: 0; }

.status-item {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.status-item svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.status-divider {
  width: 1px;
  height: 14px;
  background: rgba(255, 255, 255, 0.25);
}

/* ========================================================================= */
/* WELCOME MODAL OVERLAY                                                     */
/* ========================================================================= */
.welcome-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.welcome-modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.welcome-card {
  position: relative;
  background: var(--bg-surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 92%;
  max-width: 700px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 32px;
  animation: welcomeFadeIn 0.4s ease-out;
}

.welcome-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  z-index: 1;
  transition: all var(--transition);
}

.welcome-close:hover {
  background: var(--color-danger);
  color: white;
  transform: scale(1.1);
}

@keyframes welcomeFadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes welcomeCardIn {
  from { opacity: 0; transform: scale(0.95) translateY(-20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.welcome-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.welcome-logo {
  width: 40px;
  height: 40px;
  background: var(--tesa-primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.welcome-logo svg {
  width: 22px;
  height: 22px;
  fill: white;
}

.welcome-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.2;
}

.welcome-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 2px 0 0;
}

/* Welcome Features Grid */
.welcome-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.welcome-feature {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--bg-muted);
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
  transition: all var(--transition);
}

.welcome-feature:hover {
  border-color: var(--tesa-primary);
  background: var(--tesa-primary-subtle);
}

.welcome-feature-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.welcome-feature-text h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.welcome-feature-text p {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Welcome Quick Links */
.welcome-links {
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: 8px;
}

.welcome-links-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.welcome-links-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.welcome-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-muted);
  border-radius: var(--border-radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.welcome-link:hover {
  background: var(--tesa-primary-subtle);
  color: var(--tesa-primary);
  border-color: var(--tesa-primary-light);
  text-decoration: none;
}

.welcome-link svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.welcome-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

/* ========================================================================= */
/* LANDING EXPLORER (inline full-page, shown before any example is opened)   */
/* ========================================================================= */
.landing-explorer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-body);
}

.landing-explorer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 0;
  flex-shrink: 0;
}

.landing-explorer-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.landing-explorer-title svg {
  width: 20px;
  height: 20px;
  fill: var(--tesa-primary);
}

.landing-explorer-toolbar {
  padding: 12px 24px;
  flex-shrink: 0;
}

.landing-explorer .examples-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
}

/* ========================================================================= */
/* EXAMPLES OVERLAY                                                          */
/* ========================================================================= */
.examples-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.examples-container {
  background: var(--bg-surface);
  border-radius: 16px;
  width: 94%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: welcomeCardIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.examples-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.examples-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.examples-header-left svg {
  width: 18px;
  height: 18px;
  fill: var(--tesa-primary);
}

.examples-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.examples-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
}

/* Filters Toolbar */
.examples-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.examples-filter-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.examples-filter-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

.filter-divider {
  width: 1px;
  height: 16px;
  background: var(--border-color);
  margin: 0 4px;
}

.examples-chip {
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
  transition: all var(--transition);
}

.examples-chip:hover {
  border-color: var(--tesa-primary);
  color: var(--tesa-primary);
  background: var(--tesa-primary-subtle);
}

.examples-chip.active {
  background: var(--tesa-primary);
  color: white;
  border-color: var(--tesa-primary);
}

/* Search */
.examples-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.examples-search-input {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 12px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}

.examples-search-input:focus {
  border-color: var(--tesa-primary);
  box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.1);
}

.examples-search-input::placeholder {
  color: var(--text-tertiary);
}

/* Card Grid */
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  padding: 16px 20px;
  flex: 1;
  overflow-y: auto;
}

/* Example Card — Product Card Style */
.example-card {
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  min-height: 220px;
  overflow: hidden;
}

.example-card:hover {
  border-color: var(--tesa-primary);
  box-shadow: 0 6px 20px rgba(114, 57, 234, 0.15);
  transform: translateY(-3px);
}

/* Thumbnail area — shows image or domain icon placeholder */
.example-card-thumb {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.example-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Domain icon placeholder when no thumbnail */
.example-card-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  opacity: 0.6;
}

/* Gradient backgrounds per domain */
.thumb-bg-embedded    { background: linear-gradient(135deg, #1a237e 0%, #283593 100%); }
.thumb-bg-security    { background: linear-gradient(135deg, #b71c1c 0%, #c62828 100%); }
.thumb-bg-integrations{ background: linear-gradient(135deg, #004d40 0%, #00695c 100%); }
.thumb-bg-realtime    { background: linear-gradient(135deg, #e65100 0%, #f57c00 100%); }
.thumb-bg-analytics   { background: linear-gradient(135deg, #4a148c 0%, #6a1b9a 100%); }
.thumb-bg-identity    { background: linear-gradient(135deg, #0d47a1 0%, #1565c0 100%); }
.thumb-bg-sensors     { background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 100%); }
.thumb-bg-gpio        { background: linear-gradient(135deg, #33691e 0%, #558b2f 100%); }
.thumb-bg-dashboards  { background: linear-gradient(135deg, #0277bd 0%, #0288d1 100%); }
.thumb-bg-ui          { background: linear-gradient(135deg, #6a1b9a 0%, #8e24aa 100%); }
.thumb-bg-game        { background: linear-gradient(135deg, #ad1457 0%, #c2185b 100%); }
.thumb-bg-system      { background: linear-gradient(135deg, #37474f 0%, #455a64 100%); }
.thumb-bg-automation  { background: linear-gradient(135deg, #bf360c 0%, #d84315 100%); }
.thumb-bg-applications{ background: linear-gradient(135deg, #1565c0 0%, #1976d2 100%); }
.thumb-bg-default     { background: linear-gradient(135deg, #424242 0%, #616161 100%); }

/* Badges overlaid on thumbnail */
.example-card-badges {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.example-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.example-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.example-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px 0;
  line-height: 1.35;
}

.example-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

/* Fallback text when no description */
.example-card-desc:empty::after {
  content: "Click to preview this example";
  font-style: italic;
  opacity: 0.5;
}

.example-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.example-card-tags {
  font-size: 10px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Difficulty Badges */
.difficulty-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.difficulty-badge.beginner,
.difficulty-badge[data-level="beginner"] {
  background: #d1fae5;
  color: #065f46;
}

.difficulty-badge.intermediate,
.difficulty-badge[data-level="intermediate"] {
  background: #fef3c7;
  color: #92400e;
}

.difficulty-badge.advanced,
.difficulty-badge[data-level="advanced"] {
  background: #fee2e2;
  color: #991b1b;
}

.repo-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: rgba(99, 102, 241, 0.12);
  color: #6366f1;
  margin-left: auto;
}

.example-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-count {
  font-size: 10px;
  font-weight: 500;
  color: var(--tesa-primary);
  opacity: 0.8;
}

.domain-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: capitalize;
}

/* ── View Mode Toggle ── */
.examples-view-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  overflow: hidden;
  margin-left: auto;
  flex-shrink: 0;
}

.examples-view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
}

.examples-view-btn + .examples-view-btn {
  border-left: 1px solid var(--border-color);
}

.examples-view-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.examples-view-btn:hover {
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.examples-view-btn.active {
  background: var(--tesa-primary);
  color: #fff;
}

/* ── List View ── */
.examples-grid[data-view="list"] {
  grid-template-columns: 1fr;
  gap: 4px;
}

.examples-grid[data-view="list"] .example-card {
  flex-direction: row;
  align-items: stretch;
  min-height: auto;
  border-radius: var(--border-radius-sm);
  overflow: visible;
}

.examples-grid[data-view="list"] .example-card:hover {
  transform: none;
  box-shadow: 0 2px 8px rgba(114, 57, 234, 0.12);
}

.examples-grid[data-view="list"] .example-card-thumb {
  width: 56px;
  min-height: 56px;
  height: auto;
  flex-shrink: 0;
}

.examples-grid[data-view="list"] .example-card-thumb-placeholder {
  font-size: 22px;
  border-radius: var(--border-radius-sm) 0 0 var(--border-radius-sm);
}

.examples-grid[data-view="list"] .example-card-thumb img {
  border-radius: var(--border-radius-sm) 0 0 var(--border-radius-sm);
}

.examples-grid[data-view="list"] .example-card-badges {
  display: none;
}

.examples-grid[data-view="list"] .example-card-body {
  padding: 6px 14px;
  flex: 1;
  min-width: 0;
  justify-content: center;
}

.examples-grid[data-view="list"] .example-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.examples-grid[data-view="list"] .example-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  -webkit-line-clamp: unset;
  -webkit-box-orient: unset;
}

.examples-grid[data-view="list"] .example-card-footer {
  display: none;
}

/* List view: show inline badges (hidden in grid/small-grid) */
.example-card-list-badges {
  display: none;
}

.examples-grid[data-view="list"] .example-card-list-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
}

/* ── Responsive overrides for view modes ── */
@media (max-width: 640px) {
  .examples-grid[data-view="list"] .example-card-desc {
    display: none;
  }
  .examples-view-toggle {
    display: none;
  }
}

/* Empty state in grid */
.examples-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  color: var(--text-tertiary);
}

.examples-empty-icon {
  font-size: 2rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* ========================================================================= */
/* EXAMPLE PREVIEW MODAL                                                     */
/* ========================================================================= */
.example-preview {
  position: fixed;
  inset: 0;
  z-index: 950;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-card {
  background: var(--bg-surface);
  border-radius: 16px;
  width: 90%;
  max-width: 800px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: welcomeCardIn 0.25s ease-out;
  overflow: hidden;
}

.preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.preview-meta { flex: 1; }

.preview-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.preview-description {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 8px;
  line-height: 1.5;
}

.preview-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}

.preview-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(114, 57, 234, 0.08);
  color: var(--tesa-primary);
  font-weight: 500;
}

.preview-apis {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.preview-apis-label {
  font-weight: 600;
  color: var(--text-tertiary);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.preview-api {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-code);
  color: var(--text-code);
}

.preview-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* README Markdown Content */
.readme-content {
  padding: 20px 24px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-primary);
  min-height: 200px;
}

.readme-loading {
  color: var(--text-tertiary);
  text-align: center;
  padding: 40px;
}

.readme-content h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.readme-content h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 20px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.readme-content h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 6px;
}

.readme-content h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 4px;
}

.readme-content p {
  margin: 8px 0;
}

.readme-content ul,
.readme-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.readme-content li {
  margin: 4px 0;
}

.readme-content code {
  background: var(--bg-muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--tesa-primary);
}

.readme-content pre {
  background: var(--bg-code);
  border-radius: var(--border-radius-sm);
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
}

.readme-content pre code {
  background: none;
  padding: 0;
  color: var(--text-code);
  font-size: 12px;
  line-height: 1.6;
}

.readme-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
}

.readme-content th,
.readme-content td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
}

.readme-content th {
  background: var(--bg-muted);
  font-weight: 600;
}

.readme-content blockquote {
  border-left: 3px solid var(--tesa-primary);
  margin: 10px 0;
  padding: 8px 16px;
  background: var(--tesa-primary-subtle);
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
  color: var(--text-secondary);
}

.readme-content a {
  color: var(--tesa-primary);
}

.readme-content img {
  max-width: 100%;
  border-radius: var(--border-radius-sm);
  margin: 8px 0;
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* ========================================================================= */
/* HELP PANEL (Slide-out from Right)                                         */
/* ========================================================================= */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 840;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.help-overlay.open {
  opacity: 1;
  visibility: visible;
}

.help-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 850;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.help-panel.open {
  transform: translateX(0);
}

.help-resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s ease;
}

.help-resize-handle:hover,
.help-resize-handle.active {
  background: var(--tesa-primary);
  opacity: 0.5;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.help-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.help-title svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.help-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all var(--transition);
}

.help-close:hover {
  background: var(--color-danger);
  color: white;
}

.help-search {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.help-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 12px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}

.help-search input:focus {
  border-color: var(--tesa-primary);
  box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.1);
}

.help-search input::placeholder {
  color: var(--text-tertiary);
}

.help-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
}

/* API Module Styles (inside Help panel) */
.api-module {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.api-module-header {
  padding: 10px 14px;
  background: var(--bg-muted);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background var(--transition);
}

.api-module-header:hover { background: var(--border-color); }

.api-module-body {
  padding: 10px 14px;
  display: none;
}

.api-module.open .api-module-body { display: block; }

.api-fn {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}
.api-fn:last-child { border-bottom: none; }

.api-fn-sig {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--tesa-primary);
  font-weight: 500;
}

.api-fn-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ========================================================================= */
/* ANIMATIONS                                                                */
/* ========================================================================= */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ========================================================================= */
/* EDITOR LOADING MODAL                                                      */
/* ========================================================================= */
.editor-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.editor-loading-overlay.hidden { display: none; }

.editor-loading-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 36px 48px;
  text-align: center;
  min-width: 340px;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.editor-loading-icon {
  color: var(--tesa-primary);
  margin-bottom: 16px;
  animation: editorLoadingPulse 1.5s ease-in-out infinite;
}

@keyframes editorLoadingPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

.editor-loading-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.editor-loading-status {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  min-height: 18px;
}

.editor-loading-bar-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.editor-loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--tesa-primary), #a855f7);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.editor-loading-percent {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ========================================================================= */
/* RESPONSIVE                                                                */
/* ========================================================================= */
@media (max-width: 768px) {
  .header-center { display: none; }
  .logo-subtitle { display: none; }

  #main { flex-direction: column; }
  .resize-handle { display: none; }
  #editorPanel, #flowchartPanel { flex: 1; min-width: 0; }
  .file-tree, .file-tree-resize { display: none; }

  .examples-container { width: 98%; max-height: 95vh; }
  .examples-grid { grid-template-columns: 1fr; }
  .examples-filter-row { flex-direction: column; gap: 8px; }

  .preview-card { width: 98%; max-height: 90vh; }

  .welcome-card { width: 96%; }
  .welcome-features { grid-template-columns: 1fr; }

  .help-panel { width: 100%; }
}
