@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;600&display=swap');

/* =========================================================
   ASTRON ALGO — Redesigned UI (2026-04-18 v2)
   Clean, calm, data-first. Light + dark theme.
   Focused on information hierarchy and user flow.
   ========================================================= */

:root {
  color-scheme: light;

  --bg-app: #f4f7fc;
  --bg-app-2: #eef2f8;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --surface-3: #f3f5f9;
  --surface-inset: #f7f9fc;
  --border-1: #e6eaf0;
  --border-2: #d6dce6;
  --border-strong: #c3cbd8;

  --text-1: #0d1424;
  --text-2: #424a5c;
  --text-3: #697085;
  --text-muted: #8a92a5;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e0ecff;
  --accent-ring: rgba(37, 99, 235, 0.18);

  --positive: #0f9d58;
  --positive-soft: #e6f6ee;
  --positive-border: #b9e3cd;
  --negative: #d0394a;
  --negative-soft: #fdeaec;
  --negative-border: #f1c1c7;
  --warning: #b9761a;
  --warning-soft: #fdf3df;
  --warning-border: #eadab1;
  --info: #2563eb;
  --info-soft: #e5efff;

  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;

  --shadow-xs: 0 1px 2px rgba(13, 20, 36, 0.04);
  --shadow-sm: 0 2px 6px rgba(13, 20, 36, 0.05), 0 1px 2px rgba(13, 20, 36, 0.04);
  --shadow-md: 0 6px 20px rgba(13, 20, 36, 0.06), 0 2px 6px rgba(13, 20, 36, 0.04);
  --shadow-lg: 0 18px 40px rgba(13, 20, 36, 0.08);
  --ring: 0 0 0 3px var(--accent-ring);

  --content-gap: 16px;

  --ff-sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --ff-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-app: #0b0f1a;
  --bg-app-2: #0e1320;
  --surface: #141a28;
  --surface-2: #181f30;
  --surface-3: #1e2638;
  --surface-inset: #0f1422;
  --border-1: #23293a;
  --border-2: #2c3448;
  --border-strong: #3a455e;

  --text-1: #eef1f7;
  --text-2: #c2c8d6;
  --text-3: #8b93a7;
  --text-muted: #6a7289;

  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-soft: rgba(96, 165, 250, 0.14);
  --accent-ring: rgba(96, 165, 250, 0.28);

  --positive: #34d399;
  --positive-soft: rgba(52, 211, 153, 0.12);
  --positive-border: rgba(52, 211, 153, 0.3);
  --negative: #f87171;
  --negative-soft: rgba(248, 113, 113, 0.12);
  --negative-border: rgba(248, 113, 113, 0.3);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --warning-border: rgba(251, 191, 36, 0.3);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.12);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 22px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 22px 48px rgba(0, 0, 0, 0.45);
}

/* =========================================================
   Base
   ========================================================= */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--ff-sans);
  color: var(--text-1);
  background: var(--bg-app);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4, h5 {
  font-family: var(--ff-sans);
  color: var(--text-1);
  letter-spacing: -0.015em;
  margin: 0;
}
h1 { font-size: clamp(22px, 2.2vw, 32px); font-weight: 800; letter-spacing: -0.028em; line-height: 1.12; }
h2 { font-size: clamp(17px, 1.5vw, 20px); font-weight: 700; }
h3 { font-size: 14.5px; font-weight: 700; }
h4 { font-size: 13px; font-weight: 700; }
p { margin: 0; }

.eyebrow {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0 0 5px;
}

.muted { color: var(--text-3); font-size: 13.5px; line-height: 1.55; }
.strong { font-weight: 700; color: var(--text-1); }
.hidden { display: none !important; }

/* =========================================================
   App shell & header
   ========================================================= */
.app-shell {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px 22px 28px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 8px;
  z-index: 40;
  backdrop-filter: saturate(1.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}
.brand-text { min-width: 0; }
.brand-text h1 { margin-top: 2px; }
.brand-text .subhead {
  margin-top: 4px;
  color: var(--text-3);
  max-width: 70ch;
  font-size: 13.5px;
  line-height: 1.45;
}

.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  object-fit: cover;
  border: 1px solid var(--border-1);
  background: var(--surface-2);
  flex-shrink: 0;
}

.header-actions {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

/* =========================================================
   Account dropdown (top-right)
   ========================================================= */
.account-menu {
  position: relative;
  display: inline-flex;
}

.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 8px;
  min-height: 42px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: 999px;
  color: var(--text-1);
  font-family: var(--ff-sans);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.08s;
}
.account-trigger:hover {
  background: var(--surface-3);
  border-color: var(--border-2);
  box-shadow: var(--shadow-xs);
}
.account-trigger:active { transform: translateY(1px); }
.account-menu[data-open="true"] .account-trigger {
  background: var(--surface-3);
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.account-trigger-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.account-trigger-avatar svg { width: 18px; height: 18px; }

.account-trigger-label {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
  min-width: 0;
}
.account-trigger-state {
  font-weight: 700;
  font-size: 13px;
  color: var(--text-1);
  letter-spacing: -0.005em;
}
.account-trigger-sub {
  font-size: 10.5px;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}

[data-auth="signed-out"] .account-state-signedin,
[data-auth="signed-in"]  .account-state-signedout { display: none; }
[data-auth="signed-in"] .account-trigger-avatar {
  background: var(--positive-soft);
  color: var(--positive);
}

.account-trigger-chevron {
  display: inline-flex;
  color: var(--text-3);
  transition: transform 0.22s ease, color 0.18s;
  margin-left: 2px;
}
.account-trigger-chevron svg { width: 16px; height: 16px; }
.account-menu[data-open="true"] .account-trigger-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

.account-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(420px, calc(100vw - 28px));
  max-height: min(78vh, 760px);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.2s ease, visibility 0s linear 0.2s;
  z-index: 1200;
  overflow: hidden;
}
.account-menu[data-open="true"] .account-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.18s ease, transform 0.2s ease, visibility 0s linear 0s;
}

.account-panel-inner {
  max-height: inherit;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.account-panel-inner::-webkit-scrollbar { width: 8px; }
.account-panel-inner::-webkit-scrollbar-track { background: transparent; }
.account-panel-inner::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }

.account-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.account-section-head { display: flex; flex-direction: column; gap: 2px; }
.account-section-head .eyebrow {
  margin: 0;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 700;
}
.account-section-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Profile view inside the panel */
.auth-profile {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  border: 1px solid var(--border-1);
}
.auth-profile-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--positive-soft);
  color: var(--positive);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.auth-profile-avatar svg { width: 22px; height: 22px; }
.auth-profile-info { min-width: 0; }
.auth-profile-info p { margin: 0; line-height: 1.25; }
.auth-profile-info p.muted {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--text-3);
}
.auth-profile-info p.strong {
  margin-top: 2px;
  font-weight: 700;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.auth-profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--positive-soft);
  color: var(--positive);
  border: 1px solid var(--positive-border);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
}
.auth-profile-badge svg { width: 12px; height: 12px; }

.auth-actions-stack { display: flex; flex-direction: column; gap: 8px; }
.auth-actions-stack .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.auth-actions-row {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}
.auth-actions-row .ghost { flex: 1; }

.auth-face-head { margin-bottom: 4px; }

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 11px;
  border: 1px solid var(--border-1);
  background: var(--surface-2);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.08s;
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text-1);
  border-color: var(--border-2);
}
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 18px; height: 18px; }

[data-theme="light"] .theme-icon-moon,
[data-theme="dark"]  .theme-icon-sun  { display: none; }
[data-theme="light"] .theme-icon-sun,
[data-theme="dark"]  .theme-icon-moon { display: block; }

/* =========================================================
   Banner
   ========================================================= */
.banner {
  margin: 12px 0 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--warning);
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-md);
}
.banner svg { width: 17px; height: 17px; flex-shrink: 0; }

/* =========================================================
   Layout
   ========================================================= */
.content {
  display: flex;
  flex-direction: column;
  gap: var(--content-gap);
  min-width: 0;
}

/* =========================================================
   Cards & Panels
   ========================================================= */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  min-width: 0;
}
.panel { padding: 16px; }

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-head > div { min-width: 0; }
.panel-head h2, .panel-head h3 { margin-bottom: 2px; }
.panel-head .muted { margin-top: 2px; }

/* =========================================================
   Compliance (auto-collapses when accepted)
   ========================================================= */
.compliance-card {
  border-color: var(--border-2);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  transition: padding 0.25s, border-color 0.2s, background 0.25s;
}
.compliance-card.needs-attention {
  border-color: var(--negative-border);
  box-shadow: 0 0 0 3px var(--negative-soft);
}
.compliance-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.compliance-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--accent-soft);
  transition: color 0.2s, background 0.2s;
}
.compliance-icon svg { width: 22px; height: 22px; }
.compliance-text h2 { margin-bottom: 4px; }
.compliance-title-compact { display: none; }
.compliance-short { display: none; }

.compliance-toggle {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  border: 1px solid var(--border-1);
}
.compliance-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border-1);
  font-size: 12.5px;
}
.compliance-links a { font-weight: 500; }

/* Collapsed state when accepted */
.compliance-card:has(#accept-terms:checked) {
  padding: 12px 16px;
  background: var(--positive-soft);
  border-color: var(--positive-border);
}
.compliance-card:has(#accept-terms:checked) .compliance-head { margin-bottom: 0; }
.compliance-card:has(#accept-terms:checked) .compliance-icon {
  background: transparent;
  color: var(--positive);
  width: 30px;
  height: 30px;
}
.compliance-card:has(#accept-terms:checked) .compliance-icon svg { width: 20px; height: 20px; }
.compliance-card:has(#accept-terms:checked) .eyebrow { display: none; }
.compliance-card:has(#accept-terms:checked) .compliance-title-full { display: none; }
.compliance-card:has(#accept-terms:checked) .compliance-title-compact {
  display: block;
  font-size: 14px;
  color: var(--positive);
  margin: 0;
}
.compliance-card:has(#accept-terms:checked) .compliance-long { display: none; }
.compliance-card:has(#accept-terms:checked) .compliance-short {
  display: block;
  font-size: 12px;
  margin-top: 2px;
}
.compliance-card:has(#accept-terms:checked) .compliance-toggle {
  padding: 6px 10px;
  margin-top: 10px;
  font-size: 12px;
  background: var(--surface);
}
.compliance-card:has(#accept-terms:checked) .compliance-toggle span { font-size: 12px; }
.compliance-card:has(#accept-terms:checked) .compliance-links {
  display: none;
}

/* =========================================================
   Workspace layout — left rail + right surface
   ========================================================= */
.workspace-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.workspace-rail {
  position: sticky;
  top: 82px;
  align-self: start;
  z-index: 25;
}

.workspace-surface {
  display: flex;
  flex-direction: column;
  gap: var(--content-gap);
  min-width: 0;
}

/* Vertical tabs inside the rail */
.workspace-tabs {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.08s, padding 0.18s;
}

/* Vertical (rail) tab layout */
.workspace-tabs .tab {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 6px;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}
.workspace-tabs .tab::after {
  content: "";
  width: 4px;
  height: 0;
  border-radius: 999px;
  background: var(--accent);
  justify-self: end;
  transition: height 0.22s ease;
}
.workspace-tabs .tab:hover {
  color: var(--text-1);
  background: var(--surface-3);
}
.workspace-tabs .tab:active { transform: translateY(1px); }
.workspace-tabs .tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-ring);
}
.workspace-tabs .tab.active::after { height: 18px; }

.tab-icon {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-3);
  background: var(--surface-inset);
  border: 1px solid transparent;
  transition: color 0.18s, background 0.18s, border-color 0.18s;
}
.tab-icon svg { width: 15px; height: 15px; }
.workspace-tabs .tab:hover .tab-icon { color: var(--text-1); }
.workspace-tabs .tab.active .tab-icon {
  color: var(--accent);
  background: var(--surface);
  border-color: var(--accent-ring);
}

.tab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-panel { display: none; flex-direction: column; gap: var(--content-gap); }
.tab-panel.active { display: flex; }

/* Each tab's input/header card sticks just below the app header */
.tab-header-card {
  position: sticky;
  top: 82px;
  z-index: 20;
  padding: 16px 20px;
}
.tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.tab-header-text { min-width: 0; flex: 1; }
.tab-header-text h2 { margin-bottom: 2px; }
.tab-header-text .muted { font-size: 13px; margin-top: 2px; }

/* =========================================================
   Pulse section (collapsible)
   ========================================================= */
.pulse-section {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  padding: 0;
  overflow: hidden;
}
.pulse-summary {
  list-style: none;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.pulse-summary::-webkit-details-marker { display: none; }
.pulse-summary:hover { background: var(--surface-3); }
.pulse-summary-text { min-width: 0; flex: 1; }
.pulse-summary-text h2 { font-size: 15px; margin-bottom: 2px; }
.pulse-summary-text .muted { font-size: 12.5px; margin-top: 2px; }

.chevron {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-inset);
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.chevron svg { width: 16px; height: 16px; }
details[open] > summary .chevron { transform: rotate(180deg); }
details:not([open]) > summary:hover .chevron {
  background: var(--accent-soft);
  color: var(--accent);
}

.pulse-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px;
  padding: 0 14px 14px;
}
.pulse-card {
  padding: 16px;
  box-shadow: none;
  background: var(--surface-inset);
  border-color: var(--border-1);
}
.pulse-card .panel-head { margin-bottom: 10px; }
.pulse-card .panel-head button { align-self: flex-start; }
.pulse-card h3 { font-size: 15px; }

/* =========================================================
   Rail pulse (compact in sidebar)
   ========================================================= */
.rail-pulse {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.rail-section-label {
  margin: 4px 4px 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}
.rail-pulse-card {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.rail-pulse-card > .pulse-summary {
  padding: 10px 12px;
  gap: 8px;
}
.rail-pulse-card .pulse-summary-text .eyebrow {
  margin: 0;
  font-size: 9.5px;
  letter-spacing: 0.12em;
}
.rail-pulse-card .pulse-summary-text h3 {
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 700;
}
.rail-pulse-card .chevron {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}
.rail-pulse-card .chevron svg { width: 14px; height: 14px; }

.rail-pulse-body {
  padding: 8px 12px 0;
  font-size: 12px;
  max-height: 260px;
  overflow-y: auto;
}
.rail-pulse-body::-webkit-scrollbar { width: 6px; }
.rail-pulse-body::-webkit-scrollbar-track { background: transparent; }
.rail-pulse-body::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }
.rail-pulse-body > * + * { margin-top: 6px; }
.rail-pulse-body h4 { font-size: 12px; margin: 0 0 4px; }
.rail-pulse-body h5 { font-size: 11.5px; margin: 0; }
.rail-pulse-body p, .rail-pulse-body li { font-size: 11.5px; line-height: 1.4; margin: 0; }
.rail-pulse-body .card { padding: 8px; border-radius: var(--radius-sm); box-shadow: none; }
.rail-pulse-body table { font-size: 11px; }
.rail-pulse-body .table-wrap { max-height: 180px; }

.rail-pulse-open {
  display: block;
  width: calc(100% - 24px);
  margin: 10px 12px;
  padding: 7px 10px;
  font-size: 12px;
}

/* =========================================================
   Forms
   ========================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
  flex: 1;
}
.field label,
.watch-control label {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}
.field label small { font-weight: 500; color: var(--text-3); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-1);
  font-family: var(--ff-sans);
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23697085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* Toggle / checkbox */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.toggle small { color: var(--text-3); }

/* Input row with trailing button */
.input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 12px;
}
.input-row > .field { min-width: 220px; }
.input-row > button { align-self: stretch; min-height: 42px; padding: 10px 20px; }

.single-symbol-wrap,
.watch-symbol-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
  z-index: 10;
}
.single-symbol-wrap:focus-within,
.watch-symbol-wrap:focus-within { z-index: 1200; }
.single-symbol-wrap input,
.watch-symbol-wrap input {
  padding-left: 38px;
  height: 42px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  display: inline-flex;
  pointer-events: none;
  z-index: 2;
}
.input-icon svg { width: 16px; height: 16px; }

/* =========================================================
   Buttons
   ========================================================= */
button {
  font-family: var(--ff-sans);
  font-weight: 600;
  font-size: 13.5px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.08s;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: var(--shadow-xs);
}
button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}
button.primary.is-cancelable {
  background: var(--negative);
  border-color: var(--negative);
  color: #fff;
}
button.primary.is-cancelable:hover:not(:disabled) {
  background: #b52e3f;
  border-color: #b52e3f;
}

button.ghost {
  color: var(--text-2);
  background: var(--surface);
  border-color: var(--border-2);
}
button.ghost:hover:not(:disabled) {
  color: var(--text-1);
  background: var(--surface-3);
  border-color: var(--border-strong);
}

button.full { width: 100%; }
button.is-loading { pointer-events: none; }

.btn-spinner {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
button.ghost .btn-spinner {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--accent);
}

.btn-watch {
  border-color: var(--positive-border) !important;
  color: var(--positive) !important;
  background: var(--positive-soft) !important;
}
.btn-watch:hover:not(:disabled) {
  background: var(--positive-soft) !important;
  filter: brightness(0.98);
}
.btn-watch.added { cursor: default; opacity: 0.9; }

/* =========================================================
   Auth
   ========================================================= */
.auth-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  align-self: center;
  border: 1px solid var(--border-1);
  background: var(--surface-2);
  padding: 4px;
}
.auth-card {
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--surface-inset);
  border: 1px solid var(--border-1);
}
.auth-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-1);
}
.auth-sub, .auth-foot {
  margin: 0;
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.5;
}
.auth-foot { margin-top: 4px; text-align: center; }
.auth-pass-toggle { margin-top: 2px; font-size: 12.5px; }

.auth-message {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  padding: 9px 11px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-1);
  background: var(--surface);
}
.auth-message.info    { border-color: var(--accent-ring); background: var(--info-soft); color: var(--info); }
.auth-message.success { border-color: var(--positive-border); background: var(--positive-soft); color: var(--positive); }
.auth-message.error   { border-color: var(--negative-border); background: var(--negative-soft); color: var(--negative); }

.auth-flip {
  position: relative;
  min-height: 560px;
  perspective: 1200px;
}
.account-panel .auth-flip { min-height: 520px; }
.auth-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backface-visibility: hidden;
  transition: transform 0.5s ease;
  overflow-y: auto;
  padding-right: 2px;
}
.auth-front { transform: rotateY(0deg); }
.auth-back  { transform: rotateY(180deg); }
.auth-flip.is-signup .auth-front { transform: rotateY(-180deg); }
.auth-flip.is-signup .auth-back  { transform: rotateY(0deg); }

.auth-divider {
  position: relative;
  text-align: center;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 4px 0;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border-1);
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }
.auth-divider span { padding: 0 10px; background: var(--surface-inset); position: relative; }

.auth-disclosure {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--surface);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
}
.auth-links a { font-weight: 500; }

.auth-identity {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  border: 1px solid var(--border-1);
}
.auth-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.auth-avatar svg { width: 22px; height: 22px; }
.auth-identity-text { min-width: 0; }
.auth-identity p { margin: 0; font-size: 13px; line-height: 1.3; }
.auth-identity p.muted {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
}
.auth-identity p.strong {
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* =========================================================
   Symbol suggestions
   ========================================================= */
.symbol-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1300;
  max-height: min(340px, 46vh);
  overflow-y: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-2);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.symbol-suggest-item {
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 9px 12px;
  background: transparent;
  color: var(--text-1);
  text-align: left;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  box-shadow: none;
  cursor: pointer;
}
.symbol-suggest-item + .symbol-suggest-item { border-top: 1px solid var(--border-1); }
.symbol-suggest-item:hover,
.symbol-suggest-item.active { background: var(--surface-3); }
.symbol-suggest-symbol {
  font-family: var(--ff-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  padding-top: 2px;
}
.symbol-suggest-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.symbol-suggest-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.symbol-suggest-meta {
  font-size: 11.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.symbol-suggest mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 2px;
}

/* =========================================================
   Layout helpers
   ========================================================= */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.small { gap: 6px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0 10px; }
#single-output > .card:first-child { padding: 16px 18px; }
#single-output > .card:first-child > h3 { margin: 0; font-size: 18px; }
#single-output > .card:first-child > .muted { margin: 2px 0; font-size: 12.5px; line-height: 1.35; }
.kv { display: flex; justify-content: space-between; gap: 10px; color: var(--text-3); font-size: 13px; }
.divider { height: 1px; background: var(--border-1); margin: 10px 0; }

/* =========================================================
   Watchlist
   ========================================================= */
.watchlist-control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 6px;
}
.watch-control {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface-inset);
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
}
.watch-control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.watch-control-row-add { grid-template-columns: minmax(0, 1fr) auto; }
.watch-control-row-group { grid-template-columns: minmax(0, 1fr); }
.watch-symbol-wrap { min-width: 0; }

.watch-groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.watch-group-card {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 12px;
  background: var(--surface);
}
.watch-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.watch-group-head h4 { font-size: 13px; letter-spacing: 0; }
.watch-group-actions { display: flex; gap: 6px; }
.watch-group-actions .ghost { padding: 5px 8px; font-size: 11px; }
.watch-dropzone {
  min-height: 72px;
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-inset);
}
.watch-dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.watch-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--surface);
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.watch-item:hover { border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.watch-item.dragging { opacity: 0.55; cursor: grabbing; }
.watch-item-handle { color: var(--text-muted); font-weight: 700; line-height: 1; }
.watch-item-main { display: flex; flex-direction: column; min-width: 0; }
.watch-item-main strong {
  font-family: var(--ff-mono);
  font-size: 13px;
  color: var(--text-1);
}
.watch-item-main .muted {
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.watch-item-remove { padding: 5px 8px; font-size: 11px; }

/* =========================================================
   Admin
   ========================================================= */
.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
  margin-top: 14px;
}
.admin-block {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--surface-inset);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-block h3 { font-size: 13px; margin-bottom: 2px; }

.admin-job-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.admin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.admin-kpi {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface);
}
.admin-kpi-label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.admin-kpi-value {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-1);
}
.admin-kpi-note {
  margin-top: 4px;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.4;
}
.admin-status { min-height: 18px; font-size: 12.5px; }
.admin-status.is-ok { color: var(--positive); }
.admin-status.is-error { color: var(--negative); }

.admin-console {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--surface-inset);
  color: var(--text-2);
  font-family: var(--ff-mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 420px;
  overflow-y: auto;
}
.admin-console strong { color: var(--text-1); font-family: var(--ff-sans); }
.admin-debug-shell { display: grid; gap: 12px; }
.admin-debug-section { display: grid; gap: 8px; }
.admin-debug-section h4 {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.admin-debug-list { display: grid; gap: 8px; }
.admin-debug-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--surface);
}
.admin-debug-label {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.admin-debug-value {
  color: var(--text-1);
  font-family: var(--ff-mono);
  font-size: 12px;
  line-height: 1.55;
  word-break: break-word;
}

.workspace-page { display: grid; gap: 14px; }
.workspace-page.hidden { display: none !important; }
.workspace-page-hero {
  position: sticky;
  top: 82px;
  z-index: 10;
}
.workspace-page-back { min-width: 96px; }

/* =========================================================
   Metrics (compact grid — more cards per row, scannable)
   ========================================================= */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 8px;
}
.metric {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--surface);
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border-1);
  transition: background 0.18s;
}
.metric.tone-positive::before { background: var(--positive); }
.metric.tone-negative::before { background: var(--negative); }
.metric.tone-neutral::before  { background: var(--accent); }

.metric-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.metric-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.metric-icon svg { width: 12px; height: 12px; }
.metric h4 {
  margin: 0;
  color: var(--text-3);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}
.metric p {
  margin: 2px 0 0;
  font-size: clamp(17px, 1.35vw, 21px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--text-1);
}
.metric small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-3);
}
/* Hide the trailing "Updated:" line by default — shown on hover */
.metric small:last-child {
  display: none;
}
.metric:hover small:last-child {
  display: block;
  opacity: 0.75;
}
.metric .metric-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  margin-top: 3px;
  font-size: 11.5px;
}
.metric .metric-delta.positive { color: var(--positive); }
.metric .metric-delta.negative { color: var(--negative); }
.metric .metric-delta.neutral  { color: var(--text-3); }

.metric-click { cursor: pointer; }
.metric-click:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.metric-click.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* =========================================================
   Single-output split layout: scores left, explanation right (sticky)
   ========================================================= */
@media (min-width: 1180px) {
  #single-output.stack {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 1fr);
    gap: 14px;
    align-items: start;
  }
  #single-output.stack > .card:first-child {
    grid-column: 1;
    grid-row: 1;
  }
  #single-output.stack > #score-explain-panel {
    grid-column: 2;
    grid-row: 1 / span 3;
    position: sticky;
    top: 162px;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
  }
  #single-output.stack > #score-explain-panel::-webkit-scrollbar { width: 6px; }
  #single-output.stack > #score-explain-panel::-webkit-scrollbar-track { background: transparent; }
  #single-output.stack > #score-explain-panel::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }
  #single-output.stack > *:not(.card:first-child):not(#score-explain-panel) {
    grid-column: 1;
  }
}

.news-drilldown {
  margin-top: 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--surface-inset);
}
.news-drilldown h4 { margin: 0 0 10px; }

/* =========================================================
   Chips, pills, badges
   ========================================================= */
.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 600;
  margin-right: 6px;
  margin-top: 6px;
  border: 1px solid var(--border-1);
  background: var(--surface-inset);
  color: var(--text-2);
}
.stat-chip.positive { color: var(--positive); border-color: var(--positive-border); background: var(--positive-soft); }
.stat-chip.negative { color: var(--negative); border-color: var(--negative-border); background: var(--negative-soft); }
.stat-chip.neutral  { color: var(--accent);   border-color: var(--accent-ring);    background: var(--accent-soft); }
.stat-chip svg { width: 11px; height: 11px; }

.scan-distribution {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.scan-distribution .stat-chip { margin: 0; padding: 4px 8px; font-size: 12px; }

.header-pill,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}

.mode-badge { margin-right: 6px; margin-top: 4px; }
.mode-badge-precomputed { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-ring); }
.mode-badge-live { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-border); }

.return-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
}
.return-pill.up   { color: var(--positive); border: 1px solid var(--positive-border); background: var(--positive-soft); }
.return-pill.down { color: var(--negative); border: 1px solid var(--negative-border); background: var(--negative-soft); }
.return-pill.flat { color: var(--text-3);   border: 1px solid var(--border-1); background: var(--surface-inset); }

.trend-glyph { width: 11px; height: 11px; display: inline-flex; }
.trend-glyph svg { width: 11px; height: 11px; }

.table-direction {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border-1);
  color: var(--text-2);
  background: var(--surface-inset);
}
.table-direction.positive { color: var(--positive); border-color: var(--positive-border); background: var(--positive-soft); }
.table-direction.negative { color: var(--negative); border-color: var(--negative-border); background: var(--negative-soft); }

/* =========================================================
   Score display
   ========================================================= */
.score-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  line-height: 1.15;
}
.score-stack .score-main { font-weight: 700; }
.score-stack .score-sub {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
}
.score-stack .score-sub.positive { color: var(--positive); }
.score-stack .score-sub.negative { color: var(--negative); }
.score-stack .score-sub.neutral  { color: var(--text-3); }

.score-reasons { margin: 8px 0 0; padding-left: 18px; }

.score-explain-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.score-explain-header h3 {
  font-size: 22px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.score-lead {
  margin: 0 0 10px;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.6;
  max-width: 78ch;
}
.score-lead-meta {
  margin: 4px 0 0;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
}

.score-note {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--surface-inset);
  color: var(--text-2);
  font-size: 13px;
}

.explain-list { display: grid; gap: 10px; }
.explain-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--surface);
}
.explain-item h4 {
  margin: 0 0 3px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.explain-item p {
  margin: 0;
  color: var(--text-2);
  line-height: 1.5;
  font-size: 13px;
}

/* =========================================================
   Tables
   ========================================================= */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-1);
  background: var(--surface);
  color: var(--text-1);
  font-size: 13.5px;
}
.table-shell { display: flex; flex-direction: column; gap: 8px; }
.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-3);
  font-size: 12px;
}
.table-meta-count { font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.table-meta-hint { color: var(--text-3); }
.table-empty { margin: 0; }
.table-wrap { width: 100%; overflow-x: auto; border-radius: var(--radius-md); }
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 999px; }

.table th, .table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-1);
  text-align: left;
  vertical-align: top;
}
.table th {
  position: sticky;
  top: 0;
  background: var(--surface-inset);
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  z-index: 1;
}
.table th.sortable-col { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable-col:hover { color: var(--text-1); }
.table th.sortable-col .sort-indicator {
  display: inline-block;
  margin-left: 4px;
  color: var(--text-muted);
  font-weight: 700;
}
.table th.sortable-col[aria-sort="ascending"] .sort-indicator,
.table th.sortable-col[aria-sort="descending"] .sort-indicator { color: var(--accent); }

.table td { color: var(--text-1); font-weight: 500; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-3); }

.thematic-sector-row { cursor: pointer; }
.thematic-sector-row td { transition: background 0.15s; }
.thematic-sector-row.active td { background: var(--accent-soft) !important; }
.thematic-sector-cell { display: flex; flex-direction: column; gap: 2px; }
.thematic-sector-cell small { font-size: 11px; letter-spacing: 0.04em; }

.thematic-sub-row td {
  background: var(--surface-inset) !important;
  padding: 10px 14px 14px;
}
.thematic-sub-list-wrap {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.thematic-sub-list-head {
  padding: 9px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border-1);
  font-weight: 700;
}
.thematic-sub-list { list-style: none; margin: 0; padding: 0; }
.thematic-sub-item {
  display: grid;
  grid-template-columns: 40px 1fr 92px;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-1);
}
.thematic-sub-item:last-child { border-bottom: 0; }
.thematic-sub-rank { color: var(--text-muted); font-weight: 700; font-family: var(--ff-mono); }
.thematic-sub-name { color: var(--text-1); font-weight: 600; }
.thematic-sub-momentum { color: var(--accent); font-weight: 700; text-align: right; font-family: var(--ff-mono); }

.watchlist-table td:first-child {
  font-family: var(--ff-mono);
  letter-spacing: 0.02em;
  font-weight: 600;
}

/* =========================================================
   Loading states
   ========================================================= */
.loading-card {
  border-color: var(--border-2);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}
.loading-header {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}
.loading-indicator {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  position: relative;
  overflow: hidden;
}
.loading-indicator::after {
  content: "";
  position: absolute;
  inset: -70% 0 0 0;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: scan 1.6s linear infinite;
}
[data-theme="dark"] .loading-indicator::after {
  background: linear-gradient(180deg, transparent, rgba(96, 165, 250, 0.3), transparent);
}
.loading-text h3 { margin: 0 0 3px; }
.countdown {
  border-radius: var(--radius-md);
  padding: 6px 10px;
  min-width: 72px;
  text-align: center;
  font-family: var(--ff-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}
.loading-bar {
  margin-top: 12px;
  height: 5px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-inset);
}
.loading-bar span {
  display: block;
  height: 100%;
  width: 44%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 1.4s ease-in-out infinite;
}
.loading-dots { display: flex; gap: 6px; margin-top: 10px; }
.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

/* =========================================================
   Toast
   ========================================================= */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-1);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.25s ease;
}
.toast-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  color: var(--text-1);
}
.toast-close {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border-1);
  background: var(--surface-inset);
  color: var(--text-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.toast-close:hover { background: var(--surface-3); color: var(--text-1); }

/* =========================================================
   Footer
   ========================================================= */
.app-footer {
  margin-top: 20px;
  border-top: 1px solid var(--border-1);
  padding: 14px 4px 4px;
  color: var(--text-3);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.app-footer-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--ff-mono);
  color: var(--text-3);
}

/* =========================================================
   Keyframes
   ========================================================= */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scan {
  0% { transform: translateY(-40%); }
  100% { transform: translateY(95%); }
}
@keyframes sweep {
  0% { transform: translateX(-62%); }
  100% { transform: translateX(170%); }
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1200px) {
  .app-shell { max-width: 100%; }
}

@media (max-width: 1200px) and (min-width: 1001px) {
  .workspace-layout { grid-template-columns: 200px minmax(0, 1fr); gap: 14px; }
  .workspace-tabs .tab { padding: 9px 10px; font-size: 13px; }
}

@media (max-width: 1000px) {
  .watchlist-control-grid { grid-template-columns: 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
  .pulse-grid { grid-template-columns: 1fr; }
  .app-header { top: 0; border-radius: var(--radius-lg); }
  .workspace-page-hero { top: 74px; }

  /* Rail collapses to a horizontal scroll strip above content */
  .workspace-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .workspace-rail {
    position: sticky;
    top: 74px;
    z-index: 30;
    background: linear-gradient(180deg, var(--bg-app) 0%, var(--bg-app) 70%, transparent 100%);
    margin: 0 -2px;
    padding: 4px 2px;
  }
  .workspace-tabs {
    flex-direction: row;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 6px;
    gap: 4px;
  }
  .workspace-tabs .tab {
    flex: 0 0 auto;
    grid-template-columns: 22px auto;
    padding: 8px 12px;
  }
  .workspace-tabs .tab::after { display: none; }
  .tab-header-card { top: 130px; }
}

@media (max-width: 720px) {
  .app-shell { padding: 12px; }
  .app-header {
    padding: 12px 14px;
    gap: 10px;
  }
  .brand { gap: 10px; }
  .brand-logo { width: 40px; height: 40px; }
  .brand-text .subhead { display: none; }
  .brand-text h1 { font-size: 17px; }
  .header-actions .icon-btn { width: 36px; height: 36px; }
  .header-actions .icon-btn svg { width: 16px; height: 16px; }
  .account-trigger { padding: 4px 10px 4px 6px; min-height: 38px; gap: 8px; }
  .account-trigger-avatar { width: 26px; height: 26px; }
  .account-trigger-avatar svg { width: 16px; height: 16px; }
  .account-trigger-label { display: none; }
  .account-panel {
    position: fixed;
    top: 70px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: calc(100vh - 90px);
  }
  .workspace-tabs .tab { padding: 7px 10px; font-size: 12.5px; gap: 8px; }
  .workspace-rail { top: 62px; }
  .tab-header { flex-direction: column; align-items: stretch; }
  .tab-header button { width: 100%; }
  .row { flex-direction: column; align-items: stretch; }
  .watch-control-row { grid-template-columns: 1fr; }
  .field { min-width: 0; }
  .single-symbol-wrap, .watch-symbol-wrap { min-width: 0; }
  .symbol-suggest { max-height: min(300px, 44vh); }
  .auth-flip { min-height: 600px; }
  .countdown { min-width: 64px; font-size: 16px; }
  .metrics { grid-template-columns: 1fr; }
  .table-wrap { white-space: nowrap; }
  .toast { top: 12px; right: 12px; left: 12px; width: auto; }
  .compliance-head { flex-direction: column; gap: 10px; }
  .input-row { flex-direction: column; }
  .input-row > button { width: 100%; }
  h1 { font-size: 20px; }
  .workspace-rail { top: 62px; }
  .tab-header-card { top: 120px; position: relative; }
  .pulse-summary { padding: 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
