/* Aiellogic design system. Loaded last: it owns colour, surfaces, type and
   the shared components. Legacy stylesheets keep layout only.

   Rules: one background, one elevated surface, 1px borders, one solid accent
   (primary actions and active states only), radius 6/8px, spacing 4/8/16/24/32/48,
   150ms functional transitions, no blur, gradients, glows or looping motion. */

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f4f4f3;          /* subtle fill: inputs, table headers, skeletons */
  --border: #e5e7eb;
  --text: #111827;
  --text-2: #4b5563;             /* secondary text, 7:1 on --bg */
  --text-3: #6b7280;
  --accent: #1f7a4c;             /* primary actions + active states only */
  --accent-text: #ffffff;
  --accent-weak: #ecf5f0;        /* active nav background */
  --danger: #b42318;
  --warning: #b54708;
  --focus: #1f7a4c;
  --r-sm: 6px;
  --r: 8px;
  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px; --s6: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --t: 150ms ease;

  /* legacy variables, remapped */
  --paper: var(--bg); --white: var(--surface); --ink: var(--text); --muted: var(--text-2);
  --line: var(--border); --green: var(--accent); --shadow: none; --accent-legacy: var(--accent);
}
.dark {
  --bg: #09090b;
  --surface: #18181b;
  --surface-2: #1f1f23;
  --border: #27272a;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #8b8b94;
  --accent: #3fae6f;
  --accent-text: #08130c;
  --accent-weak: #13261b;
  --danger: #f97066;
  --warning: #fdb022;
  --focus: #3fae6f;
  --paper: var(--bg); --white: var(--surface); --ink: var(--text); --muted: var(--text-2); --line: var(--border); --green: var(--accent);
}

/* ---------- base ---------- */
html, body { background: var(--bg); color: var(--text); }
body, .dark { font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, .pagehead h1, .hero h1, .section h2, .brand { letter-spacing: -0.02em; color: var(--text); }
h1, .pagehead h1 { font-weight: 650; }
.hero h1 span { color: var(--text-2); }
p, .muted, .small, .section-intro, .pagehead p, .hero p { color: var(--text-2); }
.eyebrow, .num, .side-label, th {
  color: var(--text-3); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; font-size: 12px;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mono, .metric b, .large, td, .float strong, [class*="kpi"], [class*="metric"] b, time, output { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); }
::selection { background: var(--accent-weak); }

/* ---------- icons (Lucide, see icons.js) ---------- */
.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-20 { width: 20px; height: 20px; }

/* ---------- buttons ---------- */
button, .btn {
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  padding: var(--s2) var(--s3); font-size: 14px; font-weight: 550; gap: var(--s2);
  transition: background-color var(--t), border-color var(--t), color var(--t);
  transform: none !important;
}
button:hover, .btn:hover { background: var(--surface-2); border-color: var(--border); }
.primary, button.primary, .btn.primary {
  background: var(--accent) !important; border-color: var(--accent) !important; color: var(--accent-text) !important;
}
.primary:hover { filter: brightness(0.95); }
.quiet { background: transparent; border-color: transparent; }
.quiet:hover { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- surfaces ---------- */
.panel, .metric, .sim, #demo .sim, .glass, .float, .hero-art, dialog,
.twin-stage, .twin-quick, .twin-transport, .twin-advanced, .company-explainer-bottom, .company-leadership-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); color: var(--text);
}
.panel { padding: var(--s4); }
.metric { padding: var(--s3); border-radius: var(--r); }
.metric b { font-weight: 600; letter-spacing: -0.02em; }
.metric small { color: var(--text-3); }
.sim, #demo .sim { padding: var(--s4); }
.hero-art { padding: 0; border: 0; background: transparent; }
.campus-visual { border-radius: var(--r) !important; }
.float { padding: var(--s2) var(--s3); background: var(--surface); }
.float strong { font-weight: 600; }

/* nested surfaces become plain sections: no card inside a card */
.panel .panel, .panel .metric, .twin-quick .twin-quick-profile, .twin-coverage, .twin-saved-comparison,
.company-leadership-card .company-portrait figcaption, .rec {
  background: transparent; border: 0; border-radius: 0; padding-left: 0; padding-right: 0;
}
.twin-quick .twin-quick-profile, .twin-coverage { border-top: 1px solid var(--border); padding-top: var(--s3); margin-top: var(--s3); }
.rec { border-left: 2px solid var(--border); padding: var(--s2) 0 var(--s2) var(--s3); margin: var(--s2) 0; }

/* ---------- navigation ---------- */
.nav {
  background: var(--bg); border: 0; border-bottom: 1px solid var(--border); border-radius: 0;
  margin: 0; top: 0; padding: var(--s3) var(--s5); height: auto; max-width: none;
}
.switch { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 2px; gap: 2px; }
.switch a, .switch button { border-radius: var(--r-sm); padding: var(--s1) var(--s3); color: var(--text-2); border: 0; background: transparent; }
.switch .active { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.sidebar { background: var(--bg); border-right: 1px solid var(--border); gap: 2px; padding: var(--s4) var(--s3); }
.sidebar button {
  display: flex; align-items: center; gap: var(--s2); width: 100%; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); font-weight: 500; padding: var(--s2) var(--s3);
}
.sidebar button:hover { background: var(--surface-2); color: var(--text); }
.sidebar button.active { background: var(--accent-weak); color: var(--accent); border-color: transparent; font-weight: 600; }
.dark .sidebar button.active { color: var(--accent); }
.sidebar .side-label { margin: var(--s3) var(--s3) var(--s1); }
@media (max-width: 600px) {
  .sidebar { background: var(--surface); border-top: 1px solid var(--border); }
}

.topbar { border-bottom: 1px solid var(--border); padding-bottom: var(--s3); margin-bottom: var(--s4); }
.tag { border: 1px solid var(--border); background: transparent; color: var(--text-2); border-radius: var(--r-sm); padding: 2px var(--s2); font-size: 12px; font-weight: 500; }
.tag::before { display: none; }

/* ---------- forms ---------- */
.field { color: var(--text-2); font-weight: 550; gap: var(--s1); }
.field input, .field select, .field textarea, input[type="text"], input[type="number"], input[type="search"], input[type="email"], select, textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s2) 12px;
  transition: border-color var(--t);
}
.field input:focus, .field select:focus, .field textarea:focus, input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; }
input[type="range"] { accent-color: var(--accent); background: none !important; }

/* ---------- data ---------- */
table { font-size: 13px; }
th { background: var(--surface-2); border-bottom: 1px solid var(--border); }
th, td { border-bottom: 1px solid var(--border); padding: var(--s2) 12px; }
.timeline span { background: var(--surface-2); border-radius: 2px; }
.timeline .on { background: var(--accent); color: var(--accent-text); }
.energybar { border-radius: var(--r-sm); background: var(--surface-2); }
.chart line { stroke: var(--border); }
.chart text { fill: var(--text-3); }

/* map: neutral land, accent only for selection */
.mapviewport { background: var(--surface-2); }
.country { fill: #d9dcd7; stroke: var(--surface); }
.country:hover { fill: #c2c7c0; stroke: var(--text-3); }
.dark .country { fill: #2a2a2e; stroke: var(--bg); }
.dark .country:hover { fill: #3a3a3f; }
.mapbuttons button { background: var(--surface); padding: var(--s1) var(--s2); }
.mapcard.expanded { box-shadow: none; outline: 9999px solid rgba(9, 9, 11, 0.55); }
.campus-label, .twin-map-allocation, .twin-place-hint {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.twin-place-hint { background: var(--text); color: var(--bg); }
.flowline, .twin-active-flow { animation: none !important; }

/* ---------- overlays ---------- */
dialog { padding: var(--s4); }
dialog::backdrop { background: rgba(9, 9, 11, 0.45); }
#toast { background: var(--text); color: var(--bg); border-radius: var(--r); padding: 12px var(--s3); }
.footer { background: var(--bg); border-top: 1px solid var(--border); color: var(--text-2); }

/* ---------- company & leadership ---------- */
.company-role { background: transparent; border: 1px solid var(--border); color: var(--text-2); border-radius: var(--r-sm); padding: 2px var(--s2); font-size: 13px; }
.company-portrait { border-radius: var(--r); }
.company-portrait figcaption { position: static; color: var(--text-2); padding: var(--s2) 0 0; }

/* ---------- states: empty, loading, error ---------- */
.state { padding: var(--s5) var(--s4); text-align: center; color: var(--text-2); }
.state .icon { width: 20px; height: 20px; color: var(--text-3); margin-bottom: var(--s2); }
.state h3 { font-size: 15px; font-weight: 600; margin: 0 0 var(--s1); color: var(--text); }
.state p { margin: 0 auto var(--s3); max-width: 420px; font-size: 14px; }
.state.error h3, .state.error .icon { color: var(--danger); }
.empty { padding: var(--s5) var(--s4); color: var(--text-2); }

.skeleton { display: grid; gap: var(--s3); }
.skeleton-line, .skeleton-block { background: var(--surface-2); border-radius: var(--r-sm); }
.skeleton-line { height: 12px; }
.skeleton-line.w-40 { width: 40%; } .skeleton-line.w-60 { width: 60%; } .skeleton-line.w-80 { width: 80%; }
.skeleton-block { height: 160px; }
.skeleton-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); }
.skeleton-row .skeleton-block { height: 88px; }
[aria-busy="true"] { cursor: progress; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print { .nav, .sidebar, .mapbuttons { display: none; } .panel, .metric { border-color: #d1d5db; } }

/* sidebar labels stay on one line */
.sidebar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1050px) { .sidebar button { font-size: 13px; padding: var(--s2); } }

/* segmented controls inside the twin (legacy hard-coded white) */
.twin-setup-switch, .twin-stage-header { gap: 2px; }
.twin-setup-switch button, .twin-stage-header button { background: transparent; border-color: transparent; color: var(--text-2); }
.twin-setup-switch button.active, .twin-stage-header button.active {
  background: var(--surface); color: var(--text); border-color: var(--border);
}

/* ---------- Live Control ---------- */
.live-section { border-top: 1px solid var(--border); padding: var(--s4) 0; }
.live-section h2 { font-size: 18px; margin: 0; }
.live-section h3 { font-size: 14px; margin: var(--s4) 0 var(--s2); }
.live-section-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s3); }
.live-section-head .quiet { padding: var(--s1); vertical-align: middle; }
.live-steps { list-style: none; counter-reset: step; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.live-steps > li { counter-increment: step; display: grid; grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s3); align-items: start; }
.live-steps > li::before { content: counter(step); font-weight: 600; color: var(--text-3); font-variant-numeric: tabular-nums; }
.live-steps p { margin: 0; font-size: 14px; }
.live-steps .btn, .live-steps .row { justify-self: start; }
.live-steps select { max-width: 280px; }
.live-pairing p { margin: 0 0 var(--s2); }
.live-pairing .switch { display: inline-flex; flex-wrap: wrap; margin-bottom: var(--s2); }
.live-cmd { display: flex; align-items: center; gap: var(--s2); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: var(--s2) var(--s3); }
.live-cmd code { flex: 1; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: nowrap; }
.live-table td, .live-table th { vertical-align: top; white-space: nowrap; }
.live-table .num-col { text-align: right; font-variant-numeric: tabular-nums; }
.live-table select { padding: var(--s1) var(--s2); }
.live-table .quiet { padding: var(--s1); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); margin-right: var(--s2); }
.live-dot.on { background: var(--accent); }
.live-now { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--s4); }
.live-hour { margin: 0 0 var(--s2); color: var(--text); }
.live-bar { display: flex; height: 16px; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); margin-bottom: var(--s3); }
.live-bar i { display: block; height: 100%; }
.live-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: var(--s2); vertical-align: -1px; }
.live-sources tr.muted td { color: var(--text-3); }
.live-now-side { display: grid; gap: var(--s3); align-content: start; }
.live-kv span { display: block; font-size: 12px; color: var(--text-3); }
.live-kv b { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.live-kv small { color: var(--text-3); font-size: 12px; }
.live-reasons { margin: 0; padding-left: 18px; color: var(--text-2); }
.live-reasons li { margin: var(--s1) 0; }
.live-outlook { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; height: 120px; align-items: end; border-bottom: 1px solid var(--border); }
.live-col { position: relative; height: 100%; display: flex; flex-direction: column-reverse; }
.live-col i { display: block; width: 100%; }
.live-col-total { display: none; }
.live-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); margin-top: var(--s1); font-variant-numeric: tabular-nums; }
.live-legend { display: flex; flex-wrap: wrap; gap: var(--s3); font-size: 12px; color: var(--text-2); margin-top: var(--s2); }
.live-note { font-size: 12px; margin-top: var(--s3); }
.live-paywall { border-top: 1px solid var(--border); padding-top: var(--s4); }
.live-paywall > p { max-width: 640px; }
.live-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s3); margin: var(--s4) 0; }
.live-plan { border: 1px solid var(--border); border-radius: var(--r); padding: var(--s4); background: var(--surface); }
.live-plan h3 { margin: 0 0 var(--s1); font-size: 16px; }
.live-plan .live-price { color: var(--text); font-weight: 600; margin: 0 0 var(--s2); }
.live-plan p { font-size: 14px; }
.live-plan ul { padding-left: 18px; margin: 0 0 var(--s3); color: var(--text-2); font-size: 14px; }
.live-free { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
@media (max-width: 800px) {
  .live-steps > li { grid-template-columns: 24px minmax(0, 1fr); }
  .live-steps > li > :last-child { grid-column: 2; }
  .live-now { grid-template-columns: 1fr; }
}

/* Brand wordmark (logo v8): "ai" in dark green, "ellogic" in ink */
.brand .brand-word{font-weight:700;letter-spacing:-0.02em;color:#1c1f1d}
.brand .brand-ai{color:#1f5f43}
:root[data-theme="dark"] .brand .brand-word,.dark .brand .brand-word{color:#efece6}
:root[data-theme="dark"] .brand .brand-ai,.dark .brand .brand-ai{color:#7cc7a0}
