:root {
  --canvas: #f2f4f7;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --surface-raised: #ffffff;
  --ink: #171b22;
  --muted: #68717d;
  --line: #e2e6eb;
  --line-strong: #d2d8df;
  --red: #d1433c;
  --green: #128064;
  --amber: #b47617;
  --magenta: #a84473;
  --blue: #246e9b;
  --accent: #bf3832;
  --accent-soft: #fff0ee;
  --header-bg: rgba(255, 255, 255, 0.94);
  --hover: #f7f9fb;
  --shadow: 0 16px 40px rgba(26, 34, 44, 0.07);
  --shadow-small: 0 4px 14px rgba(26, 34, 44, 0.06);
  --focus-ring: rgba(191, 56, 50, 0.2);
}

:root[data-theme="dark"] {
  --canvas: #101317;
  --surface: #171b20;
  --surface-soft: #1c2127;
  --surface-raised: #20262d;
  --ink: #edf1f5;
  --muted: #9aa4af;
  --line: #2a3139;
  --line-strong: #3a444e;
  --red: #ff7169;
  --green: #43cba3;
  --amber: #f0b84e;
  --magenta: #df76a5;
  --blue: #61b8e6;
  --accent: #ef625a;
  --accent-soft: #382322;
  --header-bg: rgba(23, 27, 32, 0.94);
  --hover: #20262d;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.25);
  --shadow-small: 0 5px 16px rgba(0, 0, 0, 0.18);
  --focus-ring: rgba(239, 98, 90, 0.24);
}


html { background: var(--canvas); }
body {
  color: var(--ink);
  background: var(--canvas);
  transition: color 180ms ease, background-color 180ms ease;
}

button { color: inherit; }
button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.app-header {
  border-color: var(--line);
  background: var(--header-bg);
  box-shadow: 0 1px 0 rgba(25, 32, 39, 0.02);
}

.header-inner { min-height: 74px; }
.brand-mark {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  background: #22272e;
  box-shadow: var(--shadow-small);
}
:root[data-theme="dark"] .brand-mark { color: #171b20; background: var(--amber); }

.brand-name { font-size: 18px; font-weight: 800; }
.brand-subtitle { margin-top: 1px; font-size: 11px; }

.tabs {
  height: 42px;
  align-self: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}
.tab {
  min-width: 98px;
  padding: 0 16px;
  border: 0;
  border-radius: 4px;
  transition: color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}
.tab:hover { color: var(--ink); background: var(--hover); }
.tab.is-active {
  border-bottom: 0;
  color: var(--ink);
  background: var(--surface-raised);
  box-shadow: var(--shadow-small);
}
.tab.is-active::before {
  content: "";
  width: 5px;
  height: 5px;
  display: inline-block;
  margin: 0 7px 1px 0;
  border-radius: 50%;
  background: var(--accent);
}

.header-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.icon-button,
.refresh-button,
.retry-button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface-raised);
  box-shadow: 0 1px 2px rgba(25, 32, 39, 0.03);
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}
.icon-button {
  width: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}
.refresh-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.button-icon { font-size: 17px; line-height: 1; }
.icon-button:hover,
.refresh-button:hover,
.retry-button:hover { border-color: var(--muted); background: var(--hover); transform: translateY(-1px); }

.content-shell { margin-top: 22px; }
.source-banner {
  min-height: 34px;
  padding: 5px 0;
  border: 0;
  background: transparent;
}
.source-label {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  font-size: 11px;
}
.source-banner.is-demo .source-label { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, var(--line)); }
.source-banner.is-live .source-label { color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); }

.summary-strip {
  min-height: 154px;
  margin: 10px 0 20px;
  padding: 26px 30px;
  border-color: var(--line);
  border-top: 0;
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.summary-strip::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
}
.summary-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  border-radius: 4px;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}
.leader-name { margin-top: 9px; font-size: 30px; }
.leader-note { margin-top: 5px; }
.signal-clock { padding: 0 24px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.clock-value { margin-top: 4px; font-size: 32px; }
.summary-metrics { gap: 8px; }
.summary-metric {
  min-height: 72px;
  padding: 10px 14px;
  border: 0;
  border-radius: 5px;
  background: var(--surface-soft);
}
.metric-value { font-size: 24px; }

.view-stack { gap: 16px; }
.candidate-section,
.technical-view,
.review-view {
  border-color: var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow-small);
  overflow: hidden;
}
.candidate-section { border-top: 0; }
.candidate-section.tone-amber,
.candidate-section.tone-magenta { border-top: 0; }
.section-heading,
.view-heading {
  min-height: 66px;
  padding: 12px 18px;
  border-color: var(--line);
  background: var(--surface-soft);
  position: relative;
}
.section-heading::before {
  content: "";
  position: absolute;
  left: 0;
  top: 17px;
  bottom: 17px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--green);
}
.tone-amber .section-heading::before { background: var(--amber); }
.tone-magenta .section-heading::before { background: var(--magenta); }
.section-title,
.view-title { font-size: 16px; font-weight: 750; }
.badge { color: var(--muted); background: var(--surface-soft); }
.badge-primary { color: var(--red); background: color-mix(in srgb, var(--red) 12%, var(--surface)); }
.badge-muted { border: 1px solid var(--line); }
.badge-board { color: #ffffff; background: var(--red); }
.badge-concept { color: var(--blue); background: color-mix(in srgb, var(--blue) 12%, var(--surface)); }
.count-badge { color: var(--ink); border-color: var(--line-strong); background: var(--surface-raised); }

.data-table th {
  height: 42px;
  color: var(--muted);
  background: var(--surface);
  border-color: var(--line);
  text-transform: none;
}
.data-table td { height: 70px; border-color: var(--line); }
.data-table tbody tr { transition: background-color 120ms ease; }
.data-table tbody tr:hover { background: var(--hover); }
.stock-name { color: var(--ink); }
.stock-code { color: var(--muted); }
.role-cell,
.reason-cell,
.signal-reason { color: color-mix(in srgb, var(--ink) 76%, var(--muted)); }

.signal-grid { gap: 12px; padding: 14px; background: var(--surface-soft); }
.signal-card,
.signal-card:nth-child(3n) {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-raised);
  box-shadow: 0 2px 8px rgba(25, 32, 39, 0.03);
}
.signal-card:nth-child(2n) { border-right: 1px solid var(--line); }
.signal-score { color: var(--amber); }
.loading-state,
.error-state { color: var(--muted); }

@media (max-width: 980px) {
  .header-inner { padding: 12px 0 0; }
  .tabs { align-self: end; border-bottom: 0; border-radius: 6px 6px 0 0; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .signal-clock { border-right: 0; }
}

@media (max-width: 640px) {
  .header-inner { padding-top: 10px; }
  .header-actions { gap: 6px; }
  .button-label { display: none; }
  .refresh-button { width: 38px; padding: 0; }
  .tabs { width: 100%; height: 44px; padding: 3px; }
  .tab { min-width: 116px; }
  .source-banner { align-items: center; }
  .summary-strip { padding: 22px 20px; }
  .signal-clock { padding: 0; border: 0; }
  .summary-metrics { gap: 6px; }
  .summary-metric { min-height: 66px; padding: 8px; }
  .candidate-section,
  .technical-view,
  .review-view { border-radius: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .tab,
  .icon-button,
  .refresh-button,
  .retry-button,
  .data-table tbody tr { transition: none; }
}
