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

  :root {
    --bg:           #0f1117;
    --bg-surface:   #1a1d27;
    --bg-elevated:  #21253a;
    --bg-hover:     #2a2f45;
    --border:       #2e3350;
    --border-light: #3a4060;
    --accent:       #6c63ff;
    --accent-hover: #7d75ff;
    --accent-dim:   rgba(108, 99, 255, 0.15);
    --success:      #22c55e;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --text-primary: #e8eaf6;
    --text-secondary:#9aa0c0;
    --text-muted:   #5a6080;
    --sidebar-w:    260px;
    --radius:       10px;
    --shadow:       0 4px 24px rgba(0,0,0,0.4);
    --transition:   0.18s ease;
    --font:         'Inter', system-ui, -apple-system, sans-serif;
   --mono:         'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  }

  html, body { height: 100%; overflow: hidden; }

  body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
  }

  /* ── Layout ───────────────────────────────────────────────── */
  .app {
    display: flex;
    height: 100vh;
    overflow: hidden;
  }

  /* ── Sidebar ──────────────────────────────────────────────── */
  .sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
  }

  .sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
  }

  .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
  }

  .logo svg {
    width: 22px;
    height: 22px;
    color: var(--accent);
    flex-shrink: 0;
  }

  /* ── Nav ──────────────────────────────────────────────────── */
  .sidebar-nav {
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid var(--border);
  }

  .nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
    width: 100%;
  }

  .nav-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }

  .nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  .nav-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
  }

  /* ── Sidebar Actions ──────────────────────────────────────── */
  .sidebar-actions {
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid var(--border);
  }

  .action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), opacity var(--transition);
    width: 100%;
  }

  .action-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  .action-btn:active { transform: scale(0.97); }
  .action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

  .action-btn.primary {
    background: var(--accent);
    color: #fff;
  }
  .action-btn.primary:hover:not(:disabled) { background: var(--accent-hover); }

  .action-btn.secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
  }
  .action-btn.secondary:hover:not(:disabled) { background: var(--bg-hover); }
/* ── Sidebar Sections ─────────────────────────────────────── */
.sidebar-section {
   padding: 12px 16px;
   border-bottom: 1px solid var(--border);
}
.section-header {
   display: flex;
   align-items: center;
   gap: 8px;
   font-size: 11px;
   font-weight: 600;
   text-transform: uppercase;
   letter-spacing: 0.5px;
   color: var(--text-muted);
   margin-bottom: 10px;
}
.section-header svg {
   width: 14px;
   height: 14px;
}
/* ── Session Info ──────────────────────────────────────────── */
.session-info {
   display: flex;
   flex-direction: column;
   gap: 8px;
}
.session-id {
   font-family: var(--mono);
   font-size: 11px;
   color: var(--text-secondary);
   background: var(--bg-elevated);
   padding: 6px 10px;
   border-radius: var(--radius-sm);
   border: 1px solid var(--border);
   overflow: hidden;
   text-overflow: ellipsis;
   white-space: nowrap;
}
.session-links {
   display: flex;
   flex-direction: column;
   gap: 4px;
}
.session-monitor-link {
   display: flex;
   align-items: center;
   gap: 6px;
   font-size: 12px;
   color: var(--accent);
   text-decoration: none;
   padding: 4px 0;
   transition: color var(--transition);
}
.session-monitor-link:hover {
   color: var(--accent-hover);
}
.session-monitor-link svg {
   width: 12px;
   height: 12px;
}
/* ── Task List ─────────────────────────────────────────────── */
.task-list {
   display: flex;
   flex-direction: column;
   gap: 4px;
   max-height: 150px;
   overflow-y: auto;
}
.task-empty {
   font-size: 12px;
   color: var(--text-muted);
   font-style: italic;
}
.task-item {
   display: flex;
   align-items: center;
   gap: 8px;
   padding: 6px 8px;
   background: var(--bg-elevated);
   border-radius: var(--radius-sm);
   font-size: 12px;
}
.task-status {
   width: 16px;
   text-align: center;
   font-weight: 600;
}
.task-item.success .task-status { color: var(--success); }
.task-item.running .task-status { color: var(--accent); animation: pulse 1s infinite; }
.task-item.error .task-status { color: var(--danger); }
.task-item.pending .task-status { color: var(--text-muted); }
@keyframes pulse {
   0%, 100% { opacity: 1; }
   50% { opacity: 0.5; }
}
.task-name {
   flex: 1;
   overflow: hidden;
   text-overflow: ellipsis;
   white-space: nowrap;
   color: var(--text-secondary);
}
.task-link {
   font-size: 11px;
   color: var(--accent);
   text-decoration: none;
}
.task-link:hover {
   text-decoration: underline;
}


  /* ── Status Bar ───────────────────────────────────────────── */
  .sidebar-status {
    padding: 12px 16px;
    margin-top: auto;
    font-size: 12px;
    color: var(--text-muted);
  }

  .status-idle,
  .status-working,
  .status-success,
  .status-error {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .status-idle svg,
  .status-working svg,
  .status-success svg,
  .status-error svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
  }

  .status-success { color: var(--success); }
  .status-error   { color: var(--danger); }
  .status-working { color: var(--accent); }

  /* ── Main ─────────────────────────────────────────────────── */
  .main {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-width: 0;
  }

  /* ── Editor Panel ─────────────────────────────────────────── */
  .editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 280px;
    overflow: hidden;
  }

  .tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
  }

  .tab-content.active {
    display: flex;
  }

  .editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
  }

  .editor-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
  }

  .file-label {
    font-size: 11px;
   font-family: var(--mono);
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
  }

  .editor-body {
    flex: 1;
    overflow: hidden;
    display: flex;
  }

  .editor {
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--bg);
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    padding: 20px;
   font-family: var(--mono);
    font-size: 13px;
    line-height: 1.7;
    caret-color: var(--accent);
  }

  .editor::placeholder { color: var(--text-muted); }
/* ── Settings Tab ─────────────────────────────────────────── */
.settings-body {
   padding: 24px;
   overflow-y: auto;
   height: 100%;
}
.settings-section {
   margin-bottom: 32px;
}
.settings-section h3 {
   font-size: 15px;
   font-weight: 600;
   color: var(--text-primary);
   margin-bottom: 8px;
}
.settings-description {
   font-size: 13px;
   color: var(--text-secondary);
   margin-bottom: 20px;
   line-height: 1.5;
}
.setting-group {
   margin-bottom: 20px;
}
.setting-group label {
   display: block;
   font-size: 13px;
   font-weight: 500;
   color: var(--text-primary);
   margin-bottom: 6px;
}
.setting-hint {
   display: block;
   font-size: 11px;
   color: var(--text-muted);
   margin-top: 4px;
}
.model-select {
   width: 100%;
   padding: 10px 12px;
   background: var(--bg-elevated);
   border: 1px solid var(--border);
   border-radius: var(--radius-sm);
   color: var(--text-primary);
   font-size: 13px;
   font-family: var(--font);
   cursor: pointer;
   transition: border-color var(--transition);
}
.model-select:hover {
   border-color: var(--border-light);
}
.model-select:focus {
   outline: none;
   border-color: var(--accent);
}
.model-select option {
   background: var(--bg-surface);
   color: var(--text-primary);
}
.model-select optgroup {
   font-weight: 600;
   color: var(--text-secondary);
}
/* ── Usage Stats ───────────────────────────────────────────── */
.usage-stats {
   background: var(--bg-elevated);
   border: 1px solid var(--border);
   border-radius: var(--radius-sm);
   padding: 16px;
   margin-bottom: 12px;
}
.usage-row {
   display: flex;
   justify-content: space-between;
   align-items: center;
   padding: 8px 0;
   border-bottom: 1px solid var(--border);
}
.usage-row:last-child {
   border-bottom: none;
}
.usage-row.total {
   margin-top: 8px;
   padding-top: 12px;
   border-top: 1px solid var(--border-light);
   border-bottom: none;
}
.usage-label {
   font-size: 13px;
   color: var(--text-secondary);
}
.usage-value {
   font-size: 13px;
   font-family: var(--mono);
   color: var(--text-primary);
   font-weight: 500;
}
.usage-row.total .usage-label,
.usage-row.total .usage-value {
   font-weight: 600;
   color: var(--accent);
}
.refresh-usage-btn {
   display: flex;
   align-items: center;
   justify-content: center;
   gap: 8px;
   width: 100%;
   padding: 10px 16px;
   background: var(--bg-elevated);
   border: 1px solid var(--border);
   border-radius: var(--radius-sm);
   color: var(--text-secondary);
   font-size: 13px;
   cursor: pointer;
   transition: background var(--transition), color var(--transition);
}
.refresh-usage-btn:hover {
   background: var(--bg-hover);
   color: var(--text-primary);
}
.refresh-usage-btn svg {
   width: 14px;
   height: 14px;
}


  /* ── Divider ──────────────────────────────────────────────── */
  .divider {
    width: 5px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background var(--transition);
    position: relative;
  }

  .divider:hover,
  .divider.dragging {
    background: var(--accent);
  }

  /* ── Preview Panel ────────────────────────────────────────── */
  .preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 280px;
    overflow: hidden;
    background: var(--bg-surface);
  }

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

  .preview-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
  }

  .preview-controls {
    display: flex;
    gap: 6px;
  }

  .icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
  }

  .icon-btn svg { width: 14px; height: 14px; }

  .icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  .preview-body {
    flex: 1;
    overflow: hidden;
    position: relative;
  }

  .preview-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
  }

  .preview-empty svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
  }

  .preview-empty p {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
  }

  .preview-empty span {
    font-size: 13px;
    max-width: 260px;
    line-height: 1.6;
  }

  .preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
  }

  /* ── Loading Overlay ──────────────────────────────────────── */
  .loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
  }

  .loading-overlay.hidden { display: none; }

  .loading-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
  }

  .loading-card p {
    color: var(--text-secondary);
    font-size: 14px;
  }

.loading-card .session-link {
   display: flex;
   align-items: center;
   gap: 8px;
   margin-top: 8px;
   padding: 8px 16px;
   background: var(--accent-dim);
   border: 1px solid var(--accent);
   border-radius: var(--radius-sm);
   color: var(--accent);
   font-size: 13px;
   text-decoration: none;
   transition: background var(--transition);
}

.loading-card .session-link:hover {
   background: rgba(108, 99, 255, 0.25);
    color: var(--accent-hover);
}

.loading-card .session-link svg {
   width: 14px;
   height: 14px;
}

.loading-card .session-link.hidden {
   display: none;
}


  .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── Toast ────────────────────────────────────────────────── */
  .toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
  }

  .toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 13px;
    color: var(--text-primary);
    animation: slideIn 0.2s ease;
    max-width: 320px;
  }

  .toast svg { width: 16px; height: 16px; flex-shrink: 0; }
  .toast.success { border-color: var(--success); }
  .toast.success svg { color: var(--success); }
  .toast.error   { border-color: var(--danger); }
  .toast.error svg { color: var(--danger); }
  .toast.info    { border-color: var(--accent); }
  .toast.info svg { color: var(--accent); }

  @keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
  }

  /* ── Utilities ────────────────────────────────────────────── */
  .hidden { display: none !important; }

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