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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d2e;
  --surface2:  #252840;
  --border:    #2e3150;
  --accent:    #6366f1;
  --accent-h:  #818cf8;
  --success:   #22c55e;
  --warning:   #f59e0b;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --radius:    8px;
  --font:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', 'Fira Code', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.navbar-brand {
  font-size: 18px; font-weight: 700; color: var(--accent);
  letter-spacing: -0.5px;
}
.navbar-brand span { color: var(--text-muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
.navbar-right { display: flex; align-items: center; gap: 16px; }
.user-email { color: var(--text-muted); font-size: 13px; }

/* ── Tabs ──────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 0 24px; height: 46px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab {
  padding: 6px 16px; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; color: var(--text-muted);
  transition: all 0.15s; border: none; background: none;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active { color: var(--accent); background: rgba(99,102,241,0.12); font-weight: 500; }

/* ── Main content area ─────────────────────────────────────────────────────── */
.main { flex: 1; overflow: hidden; display: flex; }
.panel { flex: 1; overflow-y: auto; padding: 24px; display: none; }
.panel.active { display: block; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 14px;
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--accent); }
.form-input.mono { font-family: var(--mono); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Script list ────────────────────────────────────────────────────────────── */
.script-list { display: grid; gap: 12px; }
.script-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; align-items: flex-start; justify-content: space-between;
  cursor: pointer; transition: border-color 0.15s;
}
.script-item:hover { border-color: var(--accent); }
.script-item-info {}
.script-name { font-weight: 600; font-size: 14px; }
.script-keyword {
  display: inline-block; margin-top: 4px;
  padding: 2px 8px; border-radius: 4px;
  background: rgba(99,102,241,0.15); color: var(--accent);
  font-family: var(--mono); font-size: 12px;
}
.script-desc { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.script-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Script editor panel ─────────────────────────────────────────────────────── */
.editor-layout { display: flex; gap: 16px; height: calc(100vh - 120px); }
.editor-sidebar { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.editor-main { flex: 1; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.editor-container {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; min-height: 300px;
}
.ai-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.ai-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ai-title::before { content: "✦"; color: var(--accent); }

/* ── Logs ───────────────────────────────────────────────────────────────────── */
.log-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.log-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-partial { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-error { background: rgba(239,68,68,0.15); color: var(--danger); }
.log-meta { font-size: 12px; color: var(--text-muted); }
.log-results { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.log-result { font-size: 12px; font-family: var(--mono); padding: 4px 8px; border-radius: 4px; background: var(--bg); }
.log-result.ok { border-left: 2px solid var(--success); }
.log-result.fail { border-left: 2px solid var(--danger); }

/* ── API key panel ───────────────────────────────────────────────────────────── */
.apikey-status {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 16px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.disconnected { background: var(--text-muted); }

/* ── Auth modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px; width: 400px; max-width: 95vw;
}
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.modal-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.modal-tabs { display: flex; gap: 8px; margin-bottom: 24px; }
.modal-tab {
  flex: 1; padding: 8px; text-align: center; border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); color: var(--text-muted);
  background: var(--bg);
}
.modal-tab.active { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,0.1); }
.modal-error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; display: flex;
  flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
  font-size: 13px; min-width: 200px; box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slide-in 0.2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Misc helpers ────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.font-mono { font-family: var(--mono); }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--text-muted);
}
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 13px; margin-bottom: 20px; }

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