/* StockSys public read-only view — light theme.
 * Ported from the Google Stitch "financial research dashboard" design into
 * plain, self-contained CSS (no Tailwind, no external fonts/CDNs — the public
 * fork must render offline behind CloudFront). The dark panels (.g3d, .spc) are
 * kept for the shared graph3d.js / pricechart.js viewers.
 */
:root {
  --bg: #f8fafc;          /* page background (cool slate) */
  --panel: #ffffff;       /* cards, tables, surfaces */
  --panel-alt: #eff4ff;   /* subtle raised fill (tabs track, detail rows) */
  --ink: #0f172a;         /* primary text */
  --muted: #64748b;       /* secondary text */
  --line: #e2e8f0;        /* borders / dividers */
  --th: #f1f5f9;          /* table header fill */
  --input-line: #cbd5e1;  /* input borders */
  --accent: #2563eb;      /* primary action / links / focus */
  --accent-dark: #1d4ed8;
  --up: #16a34a;          /* positive */
  --down: #dc2626;        /* negative */
  --amber: #b45309;       /* caution banner + volatility */
  --err-bg: #fef2f2;
  --err-ink: #b91c1c;
  --graph-navy: #0b1c30;  /* dark chart/graph panel */
  --sans: "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* --- caution banner (top, amber) + disclaimer ------------------------------ */
.disclaimer {
  position: sticky; top: 0; z-index: 50;
  background: var(--amber); color: #fff; padding: 6px 24px; font-size: 12px;
  font-weight: 600; letter-spacing: .06em; text-transform: uppercase; text-align: center;
}

/* Auth gate: while body.checking, hide the app and show a placeholder. The gate
   clears once a session-gated request succeeds; a 401 redirects to /login.html
   instead, so the app shell never flashes for a signed-out visitor. */
.auth-checking { display: none; }
body.checking .site-head,
body.checking main,
body.checking .site-foot { display: none; }
body.checking .auth-checking {
  display: flex; align-items: center; justify-content: center; min-height: 62vh;
}
.auth-checking .ac-box { color: var(--muted); font-size: 14px; letter-spacing: .01em; }

/* --- header --------------------------------------------------------------- */
.site-head {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px; height: 64px;
  padding: 0 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.site-head .brand { font-weight: 900; font-size: 22px; letter-spacing: -.02em; }
.paper-pill {
  background: var(--amber); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; letter-spacing: .05em;
}
.site-head .generated { margin-left: auto; color: var(--muted); font-size: 13px; font-family: var(--mono); }

main { max-width: 1100px; margin: 0 auto; padding: 40px 24px; }
section + section { margin-top: 48px; }
h1 { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 16px; }
.sec-head { display: flex; align-items: center; gap: 12px; margin: 0 0 20px; }
.sec-head h1 { margin: 0; }

/* --- 3D knowledge-graph viewer (dark panel; shared graph3d.js) ------------- */
.g3d {
  position: relative; width: 100%; height: 560px;
  background: radial-gradient(circle at 50% 40%, #0f1b30 0%, #070b14 100%);
  border: 1px solid #1e293b; border-radius: 12px; overflow: hidden;
  box-shadow: inset 0 0 60px rgba(37, 99, 235, .10);
}
.g3d.g3d-mini { height: 220px; box-shadow: none; }
/* company neighbourhood: small, square, light, centred (see graph3d focus mode) */
.g3d.g3d-neighbourhood {
  width: 360px; max-width: 100%; height: 360px; margin: 0 auto;
  background: var(--panel); border-color: var(--line); box-shadow: none;
}
.g3d.g3d-loading::after {
  content: "loading graph…"; position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; color: #93a4c3; font-size: 14px;
}
.g3d-error { color: #fca5a5; padding: 16px; }
.g3d-tip {
  background: #0f172a; color: #e2e8f0; padding: 6px 9px; border-radius: 8px;
  font-size: 12px; border: 1px solid #334155;
}
.g3d-tip span { color: #94a3b8; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-left: auto; font-size: 14px; color: var(--muted); }
.legend .k { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.meta { font-size: 13px; color: var(--muted); margin: 8px 0 0; font-family: var(--mono); }

.refresh {
  display: inline-flex; align-items: center; padding: 5px 9px; font-size: 13px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; line-height: 1;
}
.refresh:hover { background: var(--panel-alt); border-color: var(--accent); }
.refresh:disabled { opacity: .8; cursor: default; }
.refresh .spinner {
  display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* graph panel busy overlay while a rebuild runs */
.g3d-busy::before {
  content: ""; position: absolute; inset: 0; z-index: 5; background: rgba(7, 11, 20, .55);
}
.g3d-busy::after {
  content: ""; position: absolute; top: 50%; left: 50%; z-index: 6;
  width: 38px; height: 38px; margin: -19px 0 0 -19px;
  border: 3px solid rgba(147, 164, 195, .35); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}

/* --- signals: tabs + table ------------------------------------------------ */
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--panel-alt); padding: 4px; border-radius: 8px; }
.tabs button {
  background: transparent; color: var(--muted); border: 0;
  padding: 6px 16px; border-radius: 6px; font-size: 14px; cursor: pointer; font-family: var(--sans);
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(15, 23, 42, .08); font-weight: 600; }

.table-wrap { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
table.signals { border-collapse: collapse; width: 100%; }
table.signals th {
  background: var(--th); text-align: left; padding: 12px 24px; font-size: 13px;
  font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
table.signals th.num, table.signals td.num { text-align: right; }
table.signals td { padding: 16px 24px; border-bottom: 1px solid var(--line); }
table.signals tbody tr:last-child td { border-bottom: 0; }
table.signals tr.sig-row { cursor: pointer; }
table.signals tr.sig-row:hover { background: var(--panel-alt); }
table.signals tr.sig-row.open { background: var(--panel-alt); }
td.ticker { font-weight: 700; }
td.mono, .mono { font-family: var(--mono); font-size: 14px; }
.v.up { color: var(--up); } .v.down { color: var(--down); }
.dir {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px;
  border-radius: 5px; text-transform: uppercase; letter-spacing: -.01em;
}
.dir-UP { background: #dbe9ff; color: #1e40af; }
.dir-DOWN { background: #ffe0d6; color: #9a3412; }
.dir-ELEVATED_VOLATILITY { background: #fef3c7; color: #92400e; }
.hit { color: var(--up); } .miss { color: var(--down); }

/* expanded detail row */
tr.detail-row > td { padding: 0 24px 24px; background: var(--panel-alt); }
.detail {
  display: grid; grid-template-columns: 7fr 5fr; gap: 32px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px;
}
.detail h4 { margin: 0 0 8px; font-size: 15px; font-weight: 700; }
.detail .thesis { color: var(--muted); line-height: 1.6; margin: 0 0 16px; }
.detail .stat { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.detail .outcome-row { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.detail ol { margin: 8px 0 0; padding-left: 0; list-style: none; }
.detail ol li { display: flex; gap: 12px; align-items: flex-start; margin: 8px 0; font-size: 14px; color: var(--muted); }
.detail ol li .n {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 999px; margin-top: 1px;
  background: #dae2fd; color: #3f465c; font-size: 10px; display: flex;
  align-items: center; justify-content: center; font-family: var(--mono);
}
.detail a { color: var(--accent); }
.detail .broken { background: var(--err-bg); color: var(--err-ink); padding: 2px 6px; border-radius: 6px; font-size: 12px; }
.detail-side { display: flex; flex-direction: column; }
.detail-side .cap { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.empty { color: var(--muted); padding: 24px; }
.table-foot { padding: 14px 24px; text-align: center; background: var(--th); border-top: 1px solid var(--line); }

.site-foot {
  max-width: 1100px; margin: 80px auto 0; padding: 32px 24px;
  color: var(--muted); font-size: 14px; text-align: center; border-top: 1px solid var(--line);
}
.site-foot .brand { color: var(--accent); font-weight: 700; font-size: 18px; margin-bottom: 8px; }

/* --- login page ----------------------------------------------------------- */
.login-wrap { display: flex; min-height: 78vh; align-items: center; justify-content: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 360px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.login-box .pad { padding: 32px 32px 40px; }
.login-box .brand { font-size: 24px; font-weight: 900; letter-spacing: -.02em; }
.login-box .sub { color: var(--muted); font-size: 14px; margin: 4px 0 20px; line-height: 1.4; }
.login-box label { display: block; margin: 16px 0 6px; font-weight: 600; font-size: 13px;
  text-transform: uppercase; letter-spacing: .05em; color: #434655; }
.login-box input {
  width: 100%; padding: 10px 12px; font-size: 15px; font-family: var(--sans);
  background: var(--panel); color: var(--ink); border: 1px solid var(--input-line); border-radius: 8px;
}
.login-box input#code { font-family: var(--mono); letter-spacing: .5em; text-align: center; }
.login-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--bg), 0 0 0 6px var(--accent); }
.login-box .hint { font-size: 12px; color: var(--muted); font-style: italic; margin: 6px 0 0; }
.login-box button {
  width: 100%; margin-top: 20px; background: var(--accent); color: #fff;
  border: 0; padding: 12px; border-radius: 8px; font-size: 18px; font-weight: 600; cursor: pointer;
}
.login-box button:hover { background: var(--accent-dark); }
.login-box .code-block { padding-top: 16px; border-top: 1px solid var(--th); }
.login-box .foot { background: var(--panel-alt); padding: 16px; text-align: center; border-top: 1px solid var(--line);
  font-size: 11px; text-transform: uppercase; letter-spacing: .15em; color: var(--muted); }
.login-error {
  background: var(--err-bg); color: var(--err-ink); border-left: 4px solid var(--down);
  padding: 12px; font-size: 14px; font-weight: 500; margin: 0 0 4px; border-radius: 4px;
}

/* --- interactive price chart (white panel; shared pricechart.js) ---------- */
.spc { margin: 4px 0 8px; }
.spc-toolbar { display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
.spc-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.spc-presets button, .spc-reset { background: var(--panel); color: var(--ink);
  border: 1px solid var(--input-line); padding: 5px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: var(--sans); }
.spc-presets button:hover, .spc-reset:hover { background: var(--panel-alt); }
.spc-presets button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.spc-canvas-wrap { position: relative; width: 100%; height: 320px; user-select: none;
  background: #fff;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.spc-canvas-wrap canvas { position: absolute; inset: 0; }
.spc-readout { position: absolute; top: 8px; left: 8px; pointer-events: none;
  display: flex; flex-direction: column; gap: 1px; background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 8px; padding: 6px 9px; font-size: 12px;
  line-height: 1.4; white-space: nowrap; }
.spc-readout .d { font-weight: 700; }
.spc-readout .ohlc { font-family: var(--mono); }
.spc-readout .muted { color: #93a4c3; }
.spc-readout[hidden] { display: none; }
.spc-error { color: var(--err-ink); padding: 12px; }

/* --- connected information nodes (report "Information sources" list) ------- */
.info-nodes { list-style: none; margin: 4px 0 8px; padding: 0;
  display: flex; flex-direction: column; gap: 4px; }
.info-nodes li { display: flex; align-items: baseline; gap: 10px;
  padding: 7px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; }
.info-nodes .in-type { flex: 0 0 auto; min-width: 84px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.info-nodes .in-name { color: var(--ink); font-weight: 500; }

/* --- global stock search --------------------------------------------------- */
.site-search { position: relative; flex: 1 1 300px; max-width: 400px; }
.site-search input[type="search"] {
  width: 100%; padding: 9px 12px; font-size: 14px; font-family: var(--sans);
  background: var(--panel-alt); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.site-search input[type="search"]:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .2); }
.search-results { position: absolute; z-index: 60; width: 100%; margin-top: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .12); padding: 8px; }
.search-results:empty { display: none; }
.search-hits { list-style: none; margin: 0; padding: 0; }
.search-hits li a { display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 8px; color: var(--ink); text-decoration: none; }
.search-hits li a:hover { background: var(--panel-alt); }
.search-hits .tk { font-family: var(--mono); font-size: 13px; background: #dae2fd;
  color: #3f465c; padding: 2px 8px; border-radius: 5px; }
.search-empty { padding: 10px 12px; margin: 0; color: var(--muted); }

/* --- per-ticker report ---------------------------------------------------- */
.back-link { color: var(--accent); text-decoration: none; font-size: 14px; display: inline-block; margin: 0 0 12px; }
.tv-title { display: flex; align-items: baseline; gap: 12px; }
.tv-title .tk { font-family: var(--mono); font-weight: 700; font-size: 24px; }
.tv-title .name { color: var(--muted); font-weight: 400; font-size: 20px; }
.tv-meta { color: var(--muted); font-size: 14px; margin: 4px 0 20px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 24px; }
.stat-row .stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; min-width: 100px; flex: 1 1 0; }
.stat-row .stat .k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 4px; }
.stat-row .stat .v { font-size: 20px; font-weight: 600; font-family: var(--mono); }
.analyze-box { display: flex; gap: 12px; align-items: center; margin: 24px 0; flex-wrap: wrap;
  background: var(--panel-alt); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; }
.analyze-box .lead { margin-right: auto; }
.analyze-box .lead strong { display: block; font-size: 16px; }
.analyze-box .lead span { color: var(--muted); font-size: 14px; }
.analyze-box button { background: var(--accent); color: #fff; border: 0; padding: 10px 18px;
  border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; font-family: var(--sans); }
.analyze-box button:hover { background: var(--accent-dark); }
.analyze-box button:disabled { opacity: .6; cursor: default; }
.analyze-status { color: var(--muted); font-size: 13px; }
.trigger-list { margin: 0; padding: 0; list-style: none; }
.trigger-list li { display: flex; gap: 10px; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line); }
.trigger-list li:last-child { border-bottom: 0; }
.trigger-list .type { font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--th); padding: 2px 8px; border-radius: 5px; }
.tv-disclaimer { color: var(--muted); font-size: 12px; margin: 24px 0 0; }

@media (max-width: 720px) {
  .detail { grid-template-columns: 1fr; }
  .site-head { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  main { padding: 24px 16px; }
  table.signals th, table.signals td { padding: 10px 12px; }
}
