/* Cedarwood components. Pixel reference: _design_guide/frontend/Cedarwood App.html.
   Fleshed out with the scanner UI in the frontend task. */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}
h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: -0.02em; }
.mono { font-family: var(--font-mono); }

/* ---------- shared bits ---------- */
.brand { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-logo { height: 80px; width: auto; display: block; }
.brand em { color: var(--ink-mute); font-style: normal; font-weight: 400; font-size: 13px; }

.btn {
  background: var(--card); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: var(--radius-control);
  font: inherit; font-size: 13px; cursor: pointer; color: var(--ink);
}
.btn:hover { background: var(--card-2); border-color: var(--ink-mute); }
.btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); box-shadow: var(--glow-accent); }
.btn.ghost { background: transparent; color: var(--ink-2); }
/* Estimated premium (fell back to last trade off-hours) — dotted underline + help cursor. */
.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.3); }
.btn.danger:hover { background: rgba(248, 113, 113, 0.12); border-color: var(--bad); color: var(--bad); }
.btn.primary.danger { background: var(--bad); color: var(--bg); border-color: var(--bad); }

.field label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-mute); display: block; margin-bottom: 6px;
}
.field input, .field select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius-control); padding: 8px 10px;
  font: inherit; font-family: var(--font-mono); font-size: 13px; color: var(--ink);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card {
  width: min(380px, 100%);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-modal);
  padding: 28px 32px 26px;
}
.auth-title { font-size: 22px; margin: 18px 0 6px; }
.auth-blurb { color: var(--ink-mute); font-size: 13px; margin: 0 0 6px; }
.auth-card .field { margin-top: 14px; }
.auth-error { color: var(--bad); font-size: 12px; margin-top: 8px; }
.auth-submit { width: 100%; margin-top: 20px; padding: 9px 14px; }
.auth-alt { margin-top: 16px; font-size: 12px; color: var(--ink-mute); }
.auth-alt a { color: var(--accent); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(10, 10, 12, 0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 32px;
}
.top-right { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--ink-mute); }
.top-right b { color: var(--ink); font-weight: 500; }
.top-right .logout { background: none; border: none; padding: 0; margin-left: 2px; color: var(--ink-mute); font: inherit; font-size: 12px; cursor: pointer; }
.top-right .logout:hover { color: var(--ink); }

/* strategy nav */
.nav { display: flex; gap: 2px; padding: 0 24px; }
.nav-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 11px 14px; margin-bottom: -1px;
  font: inherit; font-size: 13px; cursor: pointer; color: var(--ink-mute);
  display: flex; align-items: center; gap: 8px;
}
.nav-tab:hover { color: var(--ink); }
.nav-tab.on { color: var(--ink); border-bottom-color: var(--accent); }
.soon {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-mute); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 4px;
}

/* coming-soon strategy placeholder */
.coming-soon { border: 1px dashed var(--line); border-radius: 14px; padding: 72px 24px; text-align: center; color: var(--ink-mute); margin-top: 28px; }
.coming-soon .cs-icon { font-size: 30px; }
.coming-soon h2 { font-size: 22px; color: var(--ink); margin: 14px 0 6px; }
.coming-soon p { font-size: 13px; max-width: 440px; margin: 0 auto; line-height: 1.6; }

/* scan history */
.history-wrap { position: relative; }
#btn-history { white-space: nowrap; }
.hcount {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  background: var(--card-2); color: var(--ink-2);
  font-size: 10px; font-family: var(--font-mono); margin-left: 4px;
}
.history-panel {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  width: 348px; max-height: 64vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55); z-index: 60; padding: 6px;
}
.history-panel.open { display: block; }
.hp-head {
  padding: 10px 12px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-mute);
}
.hp-empty { padding: 10px 12px; color: var(--ink-mute); font-size: 13px; }
.hitem {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.hitem:hover { background: var(--card-2); }
.hitem.on { background: var(--accent-soft); }
.hitem .sdot { margin-top: 5px; }
.hbody { flex: 1; min-width: 0; }
.htop { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.hstrat { font-size: 13px; font-weight: 500; color: var(--ink); }
.hrel { font-size: 11px; color: var(--ink-mute); font-family: var(--font-mono); white-space: nowrap; }
.habs { font-size: 11px; color: var(--ink-2); font-family: var(--font-mono); margin-top: 3px; }
.hmeta { font-size: 11px; color: var(--ink-mute); font-family: var(--font-mono); margin-top: 2px; }

/* staleness dot + tag (shared by history items and the scan banner) */
.sdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sdot.fresh { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.sdot.aging { background: var(--amber); }
.sdot.stale { background: var(--bad); }

.scan-banner { display: flex; align-items: center; gap: 10px; margin: 18px 0 0; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.scan-banner:empty { display: none; }
.scan-banner b { color: var(--ink); font-weight: 500; }
.scan-banner .btn { margin-left: 2px; padding: 4px 10px; font-size: 12px; }
.stale-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 9px; border-radius: 999px; }
.stale-tag.fresh { color: var(--accent); background: var(--accent-soft); }
.stale-tag.aging { color: var(--amber); background: rgba(224,185,74,0.12); }
.stale-tag.stale { color: var(--bad); background: rgba(248,113,113,0.12); }

/* ---------- main ---------- */
.main { max-width: 1280px; margin: 0 auto; padding: 36px 32px 80px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 10px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; }
.page-head .blurb { color: var(--ink-mute); font-size: 13px; margin-top: 4px; }
.actions { display: flex; gap: 8px; }

/* scan error banner */
.scan-error {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: rgba(248, 113, 113, 0.08); border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-control);
  padding: 10px 16px; margin-bottom: 20px;
  color: var(--bad); font-size: 13px; font-family: var(--font-mono);
}
.scan-error[hidden] { display: none; }
.scan-error .btn { color: var(--bad); border-color: rgba(248,113,113,0.3); font-family: var(--font-ui); }
.scan-error .btn:hover { background: rgba(248,113,113,0.12); }

/* filter summary strip */
.filter-strip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 18px 0 26px;
}
.fchip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line);
  padding: 4px 12px; border-radius: var(--radius-pill);
  font-size: 12px; color: var(--ink-2);
}
.fchip b { color: var(--ink); font-weight: 500; font-family: var(--font-mono); font-size: 11.5px; }
.fchip.edit { cursor: pointer; color: var(--accent); border-color: var(--accent-line); }
.fchip.edit:hover { background: var(--accent-soft); }

/* ---------- loading ---------- */
.loading {
  display: none;
  align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--accent-line);
  border-radius: 10px; padding: 12px 16px; margin-bottom: 22px;
  font-size: 13px; color: var(--ink-2);
}
.loading.on { display: flex; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--accent); border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { flex: 1; height: 4px; background: var(--bg-2); border-radius: 2px; overflow: hidden; position: relative; }
/* Indeterminate sweep: the dummy scan returns in one shot, so no real fraction. */
.progress .fill {
  position: absolute; height: 100%; width: 35%; left: 0;
  background: var(--accent); border-radius: 2px;
  box-shadow: 0 0 8px rgba(132, 239, 100, 0.5);
  animation: sweep 1.1s ease-in-out infinite;
}
@keyframes sweep {
  0% { left: -35%; }
  100% { left: 100%; }
}

/* ---------- hero grid ---------- */
.hero-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; transition: opacity 0.15s; }
.hero {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 22px; cursor: pointer; position: relative;
  transition: border-color 0.15s, transform 0.15s; overflow: hidden;
  text-align: left; color: inherit; font: inherit; display: block; width: 100%;
}
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at top right, rgba(132, 239, 100, 0.07), transparent 60%);
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.hero:hover { border-color: var(--ink-mute); transform: translateY(-1px); }
.hero:hover::before { opacity: 1; }
.hero.best { border-color: var(--accent-line); background: linear-gradient(180deg, rgba(132, 239, 100, 0.05), transparent 55%), var(--card); }
.hero.best::before { opacity: 1; }
.hero-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); position: absolute; top: 20px; right: 22px; }
.hero.best .hero-tag { color: var(--accent); }
.hero-tick { font-size: 32px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.hero-spot { font-size: 12px; color: var(--ink-mute); margin-top: 4px; font-family: var(--font-mono); }
.hero-spot .up { color: var(--accent); }
.hero-spot .down { color: var(--bad); }
.hero-divider { border-top: 1px solid var(--line); margin: 16px 0 12px; }
.hero-strike { font-size: 13px; color: var(--ink-2); font-family: var(--font-mono); margin-bottom: 12px; }
.hero-big { font-size: 46px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; }
.hero.best .hero-big { color: var(--accent); }
.hero-big-l { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mute); margin-top: 6px; }
.hero-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.hero-meta .k { font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.06em; }
.hero-meta .v { font-family: var(--font-mono); font-size: 13px; }
.hero-foot { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; color: var(--accent); font-size: 13px; font-weight: 500; }
.hero-empty-body { padding: 20px 0; font-size: 13px; }
.hero-empty-body .t { font-weight: 500; color: var(--ink-2); }
.hero-empty-body .d { margin-top: 4px; color: var(--ink-mute); }
.hero.empty { background: repeating-linear-gradient(135deg, var(--card) 0 8px, var(--bg-2) 8px 16px); cursor: default; }
.hero.empty:hover { transform: none; border-color: var(--line); }
.hero.empty::before { display: none; }
.hero.empty .hero-tick { color: var(--ink-mute); }

/* ---------- modal scaffold ---------- */
.modal-bd {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(8px);
  display: none; align-items: flex-start; justify-content: center;
  padding: 48px 20px; overflow-y: auto;
}
.modal-bd.open { display: flex; }
.modal {
  width: min(760px, 100%);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-modal);
  padding: 28px 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
/* The drilldown is the only modal whose content is unbounded (app/11): a long
   trade list must not push it past the viewport, and a wide table must not
   compress its columns. So it becomes a flex column capped to the viewport —
   head, intro and footnote stay put while only .table-wrap scrolls, in both
   axes. calc() matches .modal-bd's 48px top and bottom padding, so the cap is
   whichever is smaller: 80vh, or the space actually available. */
.modal.wide {
  width: min(960px, 100%);
  display: flex; flex-direction: column;
  max-height: min(80vh, calc(100vh - 96px));
}
.modal.wide .modal-head, .modal.wide .drill-intro, .modal.wide .foot-note { flex: none; }
.modal.confirm { width: min(440px, 100%); }
.modal.confirm .confirm-body { color: var(--ink-2); font-size: 14px; line-height: 1.5; margin-bottom: 4px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.modal-head h2 { font-size: 22px; }
.modal-close {
  background: none; border: none; color: var(--ink-mute);
  font-size: 18px; cursor: pointer; line-height: 1; padding: 4px;
}
.modal-close:hover { color: var(--ink); }
.modal .sub { color: var(--ink-mute); font-size: 13px; margin-bottom: 20px; font-family: var(--font-mono); }

/* ---------- config form ---------- */
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
.form .full { grid-column: 1 / -1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 4px 11px; border-radius: var(--radius-control); font-size: 12px; margin: 2px 4px 2px 0;
  cursor: pointer; color: var(--ink-2); font-family: var(--font-mono);
}
.chip .x { color: var(--ink-mute); }
.chip .x:hover { color: var(--bad); }
.chip.on { background: var(--accent-soft); color: var(--ink); border-color: var(--accent-line); }
.chip.add { border-style: dashed; }
.chip.add:hover { border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-control); padding: 2px; }
.seg button { background: none; border: none; padding: 5px 14px; font: inherit; font-size: 12px; cursor: pointer; border-radius: 5px; color: var(--ink-mute); }
.seg button.on { background: var(--card-2); color: var(--ink); }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }
.sort-row { display: flex; gap: 8px; align-items: center; }
.sort-row select { flex: 1; }
.modal-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line);
  gap: 10px; flex-wrap: wrap;
}
.foot-actions { display: flex; gap: 8px; }

/* ---------- drilldown modal ---------- */
.drill-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.drill-tick { font-size: 42px; font-weight: 600; letter-spacing: -0.04em; line-height: 1; }
.drill-tick .spot { color: var(--accent); font-size: 18px; margin-left: 12px; font-weight: 500; letter-spacing: -0.01em; font-family: var(--font-mono); }
.drill-sub { color: var(--ink-mute); font-size: 13px; margin-top: 6px; }
.drill-stats { display: flex; gap: 28px; }
.drill-stat .l { font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.08em; }
.drill-stat .v { font-family: var(--font-mono); font-size: 20px; font-weight: 500; margin-top: 2px; }
.drill-intro { margin: 20px 0 12px; display: flex; justify-content: space-between; align-items: center; }
.drill-intro .label { font-size: 12px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.08em; }

.table-wrap {
  overflow: auto; border-radius: 10px; border: 1px solid var(--line); position: relative;
  flex: 1; min-height: 0; /* min-height:0 lets a flex child actually shrink and scroll */
}
/* min-width, not width: the table grows past the wrap when the columns need
   the room, and .table-wrap scrolls horizontally instead of squeezing them. */
table { min-width: 100%; border-collapse: collapse; background: var(--bg-2); }
th, td { padding: 10px 14px; text-align: right; font-size: 13px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-mute); font-weight: 500;
  background: var(--card-2);
  /* Sticky through vertical scroll so a long list never loses its column
     names. border-collapse drops a sticky cell's own border, so the rule under
     the header row is an inset shadow instead. */
  position: sticky; top: 0; z-index: 2;
  box-shadow: inset 0 -1px 0 var(--line);
}
td { font-family: var(--font-mono); }

/* sortable column headers (app/10) — a real button so keyboard users get it */
.th-sort {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; letter-spacing: inherit; text-transform: inherit;
  color: inherit; cursor: pointer;
}
.th-sort:hover { color: var(--ink); }
.th-sort:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
th.sorted .th-sort { color: var(--accent); }
.th-arrow { font-size: 9px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.top-row { background: var(--accent-soft); }
tbody tr.top-row td:first-child { color: var(--accent); font-weight: 600; }

/* ---------- column header tooltips ---------- */
.col-tip {
  display: inline-flex;
  align-items: center;
  cursor: default;
  color: var(--ink-mute);
  font-size: 10px;
  margin-left: 3px;
  vertical-align: middle;
}
.col-tip:hover { color: var(--accent); }
/* portal tooltip — appended to <body> by JS, escapes all overflow contexts */
.col-tooltip {
  position: fixed;
  z-index: 9999;
  display: none;
  max-width: 220px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--ink-2);
  line-height: 1.5;
  white-space: normal;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.foot-note { color: var(--ink-mute); font-size: 12px; margin-top: 12px; }

/* empty grid state */
.empty-state {
  border: 1px dashed var(--line); border-radius: var(--radius-card);
  padding: 60px 20px; text-align: center; color: var(--ink-mute);
}
.empty-state b { color: var(--ink-2); display: block; font-size: 15px; margin-bottom: 6px; }

@media (max-width: 720px) {
  .main { padding: 24px 16px 60px; }
  .form { grid-template-columns: 1fr; }
  /* Narrow viewports give the modal back the space the backdrop padding took,
     so the capped drilldown still has room for a useful number of rows. */
  .modal-bd { padding: 16px 10px; }
  .modal { padding: 20px 18px; }
  .modal.wide { max-height: calc(100vh - 32px); }
  .drill-tick { font-size: 30px; }
  .drill-stats { gap: 18px; }
}
