/* Script Doctor — shared design tokens + chrome components.
   Every page links this file instead of redeclaring the same tokens/topbar/
   footer/button rules. Page-unique widgets (hero, stage panels, modals,
   accordions) stay in that page's own <style> block, consuming these tokens.

   Fonts are NOT @import-ed here (slower) — every page's <head> loads them via
   <link>: Space Grotesk (headings/numbers), IBM Plex Sans (body), IBM Plex
   Mono (scene numbers, %, timestamps). */

:root {
  --blue: #2f15f4;
  --purple: #8a2dfb;
  --gold: #daa520;
  --gold-dim: rgba(218, 165, 32, 0.6);
  --teal: #2fbf9b;
  --red: #e0556b;
  --black: #000000;
}

body.dark-mode {
  --bg: #08080b;
  --surface: #0c0c11;
  --card: #101017;
  --card-grad: linear-gradient(160deg, #101017, #0c0c11);
  --border: rgba(255, 255, 255, 0.07);
  --border-soft: rgba(255, 255, 255, 0.05);
  --text: #f2f2f5;
  --subtext: #8a8a96;
  --subtext-dim: #5f5f6b;
  --input-bg: #101016;
  --input-border: rgba(255, 255, 255, 0.08);
  --input-text: #e7e7ec;
  --input-placeholder: #55556a;
  --headline-color: var(--gold);
  --sub-color: #ffffff;
  --toggle-text: var(--gold);
  --accent-text: #8ea0ff;
  --sidebar-grad: linear-gradient(180deg, #0c0c11, #0a0a0e);
  --hero-grad-start: var(--blue);
  --hero-grad-end: var(--purple);
}

body.light-mode {
  --bg: #f6f6fa;
  --surface: #ffffff;
  --card: #ffffff;
  --card-grad: linear-gradient(160deg, #ffffff, #f7f7fb);
  --border: #e3e3ea;
  --border-soft: #ececf1;
  --text: #0a0a12;
  --subtext: #55555f;
  --subtext-dim: #8a8a96;
  --input-bg: #ffffff;
  --input-border: #d7d7e0;
  --input-text: #0a0a12;
  --input-placeholder: #9a9aa8;
  --headline-color: var(--blue);
  --sub-color: #0a0a12;
  --toggle-text: var(--blue);
  --accent-text: var(--blue);
  --sidebar-grad: linear-gradient(180deg, #ffffff, #f7f7fb);
  --hero-grad-start: #e8e4ff;
  --hero-grad-end: #ffffff;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}

body.dark-mode {
  background:
    radial-gradient(1200px 600px at 78% -8%, rgba(138, 45, 251, 0.10), transparent 60%),
    radial-gradient(900px 500px at -6% 4%, rgba(47, 21, 244, 0.12), transparent 55%),
    var(--bg);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

h1, h2, h3, .mono-num, .sd-heading {
  font-family: 'Space Grotesk', sans-serif;
}

.sd-mono {
  font-family: 'IBM Plex Mono', monospace;
}

@keyframes sd-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.82); } }

/* ── App shell: sidebar + main column ── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex: 0 0 252px;
  background: var(--sidebar-grad);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: background 0.3s, border-color 0.3s;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 22px;
}
.sidebar-logo-badge {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 12px;
  background: linear-gradient(150deg, #f5f5f7, #dfe0e6);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(47, 21, 244, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.sidebar-logo-badge img { width: 32px; height: 32px; object-fit: contain; display: block; }
.sidebar-logo-text { line-height: 1.1; }
.sidebar-logo-text .name {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 15px;
  letter-spacing: 0.06em; color: var(--text);
}
.sidebar-logo-text .brand {
  font-size: 10px; letter-spacing: 0.14em; color: var(--gold); font-weight: 600; margin-top: 3px;
}

.sidebar-section-label {
  padding: 2px 12px; font-size: 10px; letter-spacing: 0.16em; color: var(--subtext-dim);
  font-weight: 600; margin: 6px 8px 8px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; }
.sidebar-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: var(--subtext); font-size: 14px; font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav-item:hover { background: var(--input-bg); color: var(--text); }
.sidebar-nav-item.active {
  color: var(--text); font-weight: 600;
  background: linear-gradient(90deg, rgba(47, 21, 244, 0.22), rgba(47, 21, 244, 0.04));
  box-shadow: inset 3px 0 0 var(--accent-text);
}
.sidebar-nav-icon { width: 18px; height: 18px; flex: 0 0 18px; display: flex; align-items: center; justify-content: center; }

.sidebar-footer { margin-top: auto; padding: 16px 14px; }

/* ── Main column / topbar ── */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 18px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { flex: 1; min-width: 0; }
.topbar-left h1 { margin: 0; font-weight: 700; font-size: 22px; letter-spacing: -0.01em; display: inline; }
.topbar-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-left p, .topbar-subtitle { font-size: 13px; color: var(--subtext); margin-top: 3px; font-weight: 400; }

.synced-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--teal);
  background: rgba(47, 191, 155, 0.12); border: 1px solid rgba(47, 191, 155, 0.3);
  padding: 3px 9px; border-radius: 20px;
}
.synced-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); animation: sd-pulse 1.8s ease-in-out infinite; }

.topbar-search {
  display: flex; align-items: center; gap: 9px;
  background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: 10px; padding: 9px 12px; width: 260px;
}
.topbar-search svg { flex: 0 0 auto; color: var(--subtext-dim); }
.topbar-search input {
  background: transparent; border: 0; outline: 0; color: var(--input-text);
  font-family: 'IBM Plex Sans', sans-serif; font-size: 13px; width: 100%;
}
.topbar-search input::placeholder { color: var(--input-placeholder); }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.new-script-btn {
  font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; font-size: 13.5px;
  color: #fff; background: linear-gradient(90deg, var(--blue), var(--purple));
  border: none; border-radius: 10px; padding: 0 18px; height: 40px;
  cursor: pointer; white-space: nowrap; transition: box-shadow 0.2s;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 18px rgba(47, 21, 244, 0.4);
}
.new-script-btn:hover { box-shadow: 0 0 22px rgba(218, 165, 32, 0.45); }
.new-script-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.toggle-btn {
  font-family: 'IBM Plex Sans', sans-serif; font-size: 12.5px; font-weight: 600;
  color: var(--toggle-text); background: transparent; border: 1px solid var(--toggle-text);
  border-radius: 999px; padding: 7px 14px; cursor: pointer;
  transition: background 0.2s, color 0.2s; white-space: nowrap;
}
.toggle-btn:hover { background: var(--toggle-text); color: var(--bg); }

.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--input-border); background: var(--input-bg); cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--subtext);
}
.icon-btn .badge-dot {
  position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 2px var(--input-bg);
}

/* ── Stat cards ── */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
  background: var(--card-grad); border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 18px 16px; position: relative; overflow: hidden;
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--stat-accent, linear-gradient(90deg, var(--blue), var(--purple)));
}
.stat-card-top { display: flex; align-items: center; justify-content: space-between; }
.stat-card .label { font-size: 12.5px; color: var(--subtext); font-weight: 500; }
.stat-card-icon {
  width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
}
.stat-card .value {
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 32px;
  letter-spacing: -0.02em; margin-top: 12px; line-height: 1; color: var(--text);
}
.stat-card .context { font-size: 12px; margin-top: 8px; font-weight: 500; }

/* ── Section card (table wrappers, panels) ── */
.sd-section {
  background: var(--card-grad); border: 1px solid var(--border); border-radius: 16px; overflow: hidden;
}
.sd-section-header {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 14px; gap: 12px; flex-wrap: wrap;
}
.sd-section-header h2 { margin: 0; font-weight: 600; font-size: 16px; color: var(--text); }
.sd-section-header .sub { font-size: 12.5px; color: var(--subtext); margin-top: 2px; font-weight: 400; }
.sd-section-header .view-all { font-size: 12.5px; color: var(--accent-text); text-decoration: none; font-weight: 600; }
.sd-section-header .view-all:hover { text-decoration: underline; }

/* ── Grid table (used by Script Board / Scripts list) ── */
.sd-grid-head {
  display: grid; gap: 14px; padding: 10px 22px;
  font-size: 10.5px; letter-spacing: 0.09em; color: var(--subtext-dim); font-weight: 600;
  text-transform: uppercase;
  border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft);
}
.sd-grid-row {
  display: grid; gap: 14px; align-items: center; padding: 15px 22px;
  border-bottom: 1px solid var(--border-soft); cursor: pointer; transition: background 0.15s;
}
.sd-grid-row:hover { background: var(--input-bg); }
.sd-grid-row:last-child { border-bottom: none; }

.sd-poster {
  width: 34px; height: 44px; flex: 0 0 34px; border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  display: flex; align-items: flex-end; padding: 5px;
}
.sd-poster span { font-family: 'IBM Plex Mono', monospace; font-size: 8px; color: rgba(255, 255, 255, 0.85); font-weight: 600; }

.sd-title-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.sd-title-cell .title { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sd-title-cell .logline { font-size: 11.5px; color: var(--subtext-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sd-progress-cell { display: flex; align-items: center; gap: 10px; }
.sd-progress-track { flex: 1; height: 7px; border-radius: 6px; background: var(--input-border); overflow: hidden; }
.sd-progress-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--blue), var(--purple)); }
.sd-progress-pct { font-family: 'IBM Plex Mono', monospace; font-size: 12px; color: var(--text); width: 34px; text-align: right; }

.sd-status-pill {
  justify-self: start; font-size: 11.5px; font-weight: 600; padding: 4px 10px;
  border-radius: 20px; white-space: nowrap; border: 1px solid transparent;
}
.sd-status-pill.draft { color: var(--subtext-dim); background: rgba(154, 154, 164, 0.1); border-color: rgba(154, 154, 164, 0.26); }
.sd-status-pill.in-progress { color: #b7c1ff; background: rgba(91, 116, 255, 0.13); border-color: rgba(91, 116, 255, 0.32); }
.sd-status-pill.complete { color: #5fd9bd; background: rgba(47, 191, 155, 0.13); border-color: rgba(47, 191, 155, 0.32); }

.sd-updated-cell { color: var(--subtext-dim); font-size: 12px; }

/* ── Element chips (cast/locations/wardrobe/vehicles) ── */
.sd-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500;
  padding: 3px 8px 3px 7px; border-radius: 6px; border: 1px solid transparent;
}
.sd-chip .dot { width: 6px; height: 6px; border-radius: 2px; }

/* ── Empty state ── */
.sd-empty-state { text-align: center; padding: 64px 20px; }
.sd-empty-state h3 { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.sd-empty-state p { font-size: 0.85rem; color: var(--subtext); font-weight: 400; margin-bottom: 20px; }

/* ── Footer ── */
footer {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
footer a { color: inherit; text-decoration: none; }
footer a:hover { color: var(--gold); }
body.dark-mode footer img, body.dark-mode .home-logo img, body.dark-mode .sidebar-logo img {
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.5));
}
.footer-center, .footer-right { font-size: 0.76rem; font-weight: 400; opacity: 0.75; color: var(--text); }

/* ── Simple top nav (marketing / centered-card pages without a sidebar) ── */
.home-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.home-logo img { display: block; }
.home-nav a { font-weight: 600; font-size: 0.85rem; color: var(--gold); text-decoration: none; letter-spacing: 0.02em; }
.home-nav a:hover { text-decoration: underline; }
.home-topbar-actions { display: flex; align-items: center; gap: 14px; }

@media (max-width: 900px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; height: auto; flex-direction: row; align-items: center; overflow-x: auto; position: static; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .topbar, .stat-row { padding-left: 16px; padding-right: 16px; }
}
