/* ============================================================
   The Sovereign Quant — dashboard theme
   Refreshed UI. All class hooks and CSS custom-property names are
   preserved (app.js injects var(--green/red/accent/warm/muted) and the
   canvas hardcodes --line/green/red/accent values).
   ============================================================ */
:root {
  /* Core palette — names kept stable for app.js + canvas. */
  --bg: #090d15;
  --panel: #121925;
  --line: #243043;
  --text: #e8eef6;
  --muted: #8492a6;
  --green: #2ec27e;
  --red: #f25f5c;
  --accent: #4c8dff;
  --warm: #f5a623;

  /* Extended tokens. */
  --bg-2: #0d121c;
  --panel-2: #18212f;
  --panel-hi: #1d2738;
  --line-soft: #1c2535;
  --text-dim: #b8c2d4;
  --accent-2: #7aa8ff;
  --accent-soft: rgba(76, 141, 255, .14);
  --green-soft: rgba(46, 194, 126, .15);
  --red-soft: rgba(242, 95, 92, .15);
  --warm-soft: rgba(245, 166, 35, .15);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 8px 24px -8px rgba(0, 0, 0, .55);
  --shadow-pop: 0 12px 32px -6px rgba(0, 0, 0, .6);
  --ring: 0 0 0 1px rgba(76, 141, 255, .35);
  --gut: 28px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 88% -8%, rgba(76, 141, 255, .10), transparent 60%),
    radial-gradient(900px 500px at -5% 0%, rgba(46, 194, 126, .06), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: .01em;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { height: 10px; width: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #2f3e56; background-clip: content-box; }

/* ---------------- Header ---------------- */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px var(--gut);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 20;
  background: rgba(9, 13, 21, .72);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
}
h1 {
  font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -.01em;
  background: linear-gradient(90deg, var(--text), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
h2 {
  font-size: 14px; margin: 0 0 14px; color: var(--text-dim); font-weight: 600;
  letter-spacing: -.005em; display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px;
}

/* ---------------- Badge / status ---------------- */
.badge {
  font-size: 11px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
  background: var(--line-soft); color: var(--muted);
  border: 1px solid var(--line); letter-spacing: .02em;
  display: inline-flex; align-items: center; gap: 7px;
}
.badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 0 0 currentColor;
}
.badge.ok { background: var(--green-soft); color: var(--green); border-color: rgba(46, 194, 126, .3); }
.badge.ok::before { animation: pulse 2s infinite; }
.badge.err { background: var(--red-soft); color: var(--red); border-color: rgba(242, 95, 92, .3); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 194, 126, .5); }
  70% { box-shadow: 0 0 0 6px rgba(46, 194, 126, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 194, 126, 0); }
}

/* ---------------- Cards (book summaries) ---------------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px; padding: 24px var(--gut) 8px;
}
.card {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-1);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .08), transparent);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-2); border-color: #2c3a52; }
.card .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.card .value { font-size: 27px; font-weight: 750; margin-top: 7px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 10px; line-height: 1.7; }
.card.book-real { border-left: 3px solid var(--green); }
.card.book-warm { border-left: 3px solid var(--warm); }
.card.book-cold { border-left: 3px solid var(--accent); }
.card.book-real::before,
.card.book-warm::before,
.card.book-cold::before {
  content: ""; position: absolute; top: -40%; right: -30%;
  width: 160px; height: 160px; border-radius: 50%; opacity: .12; pointer-events: none;
  filter: blur(8px);
}
.card.book-real::before { background: radial-gradient(var(--green), transparent 70%); }
.card.book-warm::before { background: radial-gradient(var(--warm), transparent 70%); }
.card.book-cold::before { background: radial-gradient(var(--accent), transparent 70%); }

/* ---------------- Legend ---------------- */
.legend { margin-left: auto; font-size: 11px; font-weight: 500; display: inline-flex; gap: 14px; }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .real { color: var(--green); }
.legend .warm { color: var(--warm); }
.legend .cold { color: var(--accent); }

/* ---------------- Panels ---------------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  margin: 0 var(--gut) 20px; padding: 20px 22px; box-shadow: var(--shadow-1);
}
canvas { width: 100%; height: auto; }

/* ---------------- Tables ---------------- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  background: var(--bg-2);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th {
  position: sticky; top: 0; z-index: 1;
  color: var(--muted); font-weight: 600; font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
}
tbody tr { transition: background .12s ease; }
tbody tr:nth-child(even):not(.detail-row) { background: rgba(255, 255, 255, .015); }
tbody tr:has(td):hover:not(.detail-row) { background: var(--accent-soft); }
td { font-variant-numeric: tabular-nums; color: var(--text-dim); }
tr:last-child td { border-bottom: none; }

.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; letter-spacing: 0; }

/* ---------------- Pills ---------------- */
.pill {
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600;
  letter-spacing: .02em; border: 1px solid transparent; display: inline-block;
}
.pill.OPEN { background: var(--accent-soft); color: var(--accent); border-color: rgba(76, 141, 255, .28); }
.pill.TP { background: var(--green-soft); color: var(--green); border-color: rgba(46, 194, 126, .28); }
.pill.SL { background: var(--red-soft); color: var(--red); border-color: rgba(242, 95, 92, .28); }
.pill.yes { background: var(--green-soft); color: var(--green); border-color: rgba(46, 194, 126, .28); }
.pill.no { background: var(--line-soft); color: var(--muted); border-color: var(--line); }
.pill.sig-BUY { background: var(--green-soft); color: var(--green); border-color: rgba(46, 194, 126, .28); }
.pill.sig-SELL { background: var(--red-soft); color: var(--red); border-color: rgba(242, 95, 92, .28); }
.pill.sig-NEUTRAL { background: var(--line-soft); color: var(--muted); border-color: var(--line); }

/* ---------------- Confidence bar ---------------- */
.conf {
  position: relative; min-width: 96px; height: 18px; background: var(--bg-2);
  border: 1px solid var(--line-soft); border-radius: 999px; overflow: hidden;
}
.conf-bar {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px;
  transition: width .4s cubic-bezier(.4, 0, .2, 1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
  filter: saturate(115%);
}
.conf-num {
  position: relative; z-index: 1; font-size: 11px; font-weight: 700;
  line-height: 18px; padding-left: 8px; color: var(--text);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5); font-variant-numeric: tabular-nums;
}

/* ---------------- Links ---------------- */
a.sym { color: var(--accent); cursor: pointer; text-decoration: none; font-weight: 600; }
a.sym:hover { color: var(--accent-2); text-decoration: underline; text-underline-offset: 2px; }

a.reason-toggle {
  color: var(--accent); cursor: pointer; font-weight: 600; white-space: nowrap;
  padding: 3px 8px; border-radius: var(--radius-xs); transition: background .12s ease;
}
a.reason-toggle:hover { background: var(--accent-soft); text-decoration: none; }

/* ---------------- Detail / tiles ---------------- */
.detail-row td { background: var(--bg-2); padding: 14px 14px 18px; }
.detail-wrap { display: flex; flex-direction: column; gap: 16px; }
.tile-group {
  background: rgba(255, 255, 255, .015); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.tile-head { font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 10px; letter-spacing: -.005em; }
.tile-head .muted { font-weight: 400; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 9px; }
.tile {
  position: relative; background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: var(--radius-xs); padding: 9px 11px; cursor: help;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: #2c3a52; z-index: 2; }
.tile.ok { border-left-color: var(--green); }
.tile.ok:hover { box-shadow: 0 8px 22px -10px var(--green); }
.tile.bad { border-left-color: var(--red); }
.tile.bad:hover { box-shadow: 0 8px 22px -10px var(--red); }
.tile-name { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile-val { font-size: 16px; font-weight: 700; margin-top: 3px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.tile-rule { font-size: 10px; color: var(--muted); margin-top: 3px; }
.tile[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 0;
  width: 240px; background: var(--panel-hi); color: var(--text-dim);
  border: 1px solid var(--line); border-radius: var(--radius-xs);
  padding: 9px 11px; font-size: 11px; font-weight: 400; line-height: 1.5;
  white-space: normal; z-index: 50; box-shadow: var(--shadow-pop);
}
.tile[data-tip]:hover::before {
  content: ""; position: absolute; bottom: calc(100% + 2px); left: 14px;
  border: 6px solid transparent; border-top-color: var(--line); z-index: 51;
}
.detail-reasons { font-size: 12px; padding-top: 4px; line-height: 1.6; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(4, 7, 12, .68);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal.hidden { display: none; }
.modal-box {
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; width: min(940px, 94vw); box-shadow: var(--shadow-pop);
  animation: pop .18s cubic-bezier(.2, .8, .2, 1);
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.modal-title { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.intervals { display: flex; gap: 6px; }
.iv {
  background: var(--line-soft); color: var(--muted); border: 1px solid var(--line);
  cursor: pointer; padding: 5px 11px; border-radius: var(--radius-xs);
  font-size: 12px; font-weight: 600; transition: all .12s ease;
}
.iv:hover { color: var(--text); border-color: #34465f; }
.iv.active { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 4px 12px -4px var(--accent); }
.modal-close {
  margin-left: auto; background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; line-height: 1; padding: 4px 8px;
  border-radius: var(--radius-xs); transition: all .12s ease;
}
.modal-close:hover { color: var(--text); background: var(--line-soft); }
#chartCanvas { width: 100%; height: auto; background: var(--bg); border-radius: var(--radius-sm); }
#chartMeta { margin-top: 10px; }

/* ---------------- Misc ---------------- */
footer { padding: 14px var(--gut) 36px; }
code { background: var(--line-soft); border: 1px solid var(--line); padding: 1px 6px; border-radius: var(--radius-xs); font-size: 12px; }
.empty { color: var(--muted); padding: 18px 6px; text-align: center; }

/* ---------------- Responsive ---------------- */
@media (max-width: 640px) {
  :root { --gut: 16px; }
  header { padding: 14px var(--gut); }
  h1 { font-size: 17px; }
  .card .value { font-size: 23px; }
  .legend { width: 100%; margin: 4px 0 0; }
}
