/* ============================================================
   Reading Chest — additions on top of the shared design system.
   style.css owns the palette, type and base components; this file
   only adds what this app needs (controls, charts, ledger, dialog).
   ============================================================ */

/* The shared stylesheet gives #login `display: flex`, which outranks the UA rule
   behind the `hidden` attribute — so without this the sign-in screen never goes
   away once it has been shown. */
[hidden] { display: none !important; }

/* ---- STICKY BAR ---- */
/* The shared stylesheet makes `nav` sticky at top:0. The controls bar was too,
   also at top:0 — so they overlapped rather than stacked, and a 1px sliver of the
   controls' lighter --surface showed beneath the nav's border as a white hairline.
   Stick ONE wrapper instead, and let the two sit statically inside it. */
.stickybar { position: sticky; top: 0; z-index: 50; background: var(--panel); }
.stickybar #nav { position: static; z-index: auto; }
.stickybar .controls { position: static; z-index: auto; }

/* Anchor targets must clear the whole bar, not just the old nav. */
main section { scroll-margin-top: 112px; }

/* ---- CONTROL BAR ---- */
.controls {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border2);
  /* Left padding lines "VIEW" up with the "O" of "OVERVIEW" in the nav above:
     the nav's own 28px padding plus each link's 14px. */
  padding: 12px 28px 12px 42px;
}
.ctl-group { display: flex; align-items: center; gap: 8px; }
.ctl-group .label { margin-right: 2px; }
.ctl-spacer { flex: 1; }

.seg {
  padding: 6px 14px; font-size: 0.78rem; font-weight: 600; font-family: inherit;
  color: var(--ink3); background: var(--panel); border: 1px solid var(--border2);
  border-radius: var(--r-pill); cursor: pointer;
}
.seg.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.ctl-check { display: flex; align-items: center; gap: 7px; font-size: 0.8rem; color: var(--ink2); cursor: pointer; }
.ctl-check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.btn {
  padding: 7px 15px; font-size: 0.78rem; font-weight: 600; font-family: inherit;
  background: var(--ink); color: #fff; border: 1px solid var(--ink);
  border-radius: var(--r-btn); cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--accent2); border-color: var(--accent2); }
.btn.ghost { background: transparent; color: var(--ink3); border-color: var(--border2); }
.btn.ghost:hover { color: var(--accent2); border-color: var(--accent); background: var(--inset); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---- CHART CARDS ---- */
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 16px 18px 10px;
  box-shadow: var(--shadow); margin-top: 16px;
}
.chart-card .label { margin-bottom: 12px; display: block; }
.chart-card svg { width: 100%; height: auto; display: block; overflow: visible; }

.ax { stroke: var(--border2); stroke-width: 1; }
.gridline { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.axlabel { font-size: 9px; fill: var(--ink4); font-family: 'Hanken Grotesk', sans-serif; }
.serieslab { font-size: 10px; fill: var(--ink3); font-family: 'Hanken Grotesk', sans-serif; }
.bar-pos { fill: var(--accent); }
.bar-neg { fill: var(--red); }
.bar-mut { fill: var(--ink4); opacity: 0.45; }
.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.line.alt { stroke: var(--blue); stroke-dasharray: 4 3; }
.line.gold { stroke: var(--gold); }
.zeroline { stroke: var(--ink4); stroke-width: 1; }
.threshold { stroke: var(--gold); stroke-width: 1; stroke-dasharray: 5 4; }
.area { fill: var(--accent); opacity: 0.10; }
.dot { fill: var(--accent); }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin: 4px 0 8px; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--ink3); }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---- FILTERS ---- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select {
  padding: 7px 10px; font-size: 0.8rem; font-family: inherit; color: var(--ink2);
  background: var(--inset); border: 1px solid var(--border2); border-radius: var(--r-in);
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95,117,96,0.16);
}
#f-q { min-width: 260px; flex: 1; }

.pager { display: flex; align-items: center; gap: 14px; margin-top: 14px; }

/* ---- LEDGER ---- */
#tbl-ledger tbody tr { cursor: pointer; }
#tbl-ledger td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: var(--r-pill);
  font-size: 0.66rem; font-weight: 700; background: var(--panel); color: var(--ink3);
}
.tag.disc  { background: var(--amber-bg); color: var(--amber); }
.tag.unmap { background: var(--red-bg);   color: var(--red); }
.tag.manual{ background: var(--blue-bg);  color: var(--blue); }
.tag.mkt   { background: var(--green-bg); color: var(--green); }

/* ---- TRACKER TABLE ---- */
/* Numbers must never wrap — a narrow column was breaking "−£3,460.45" after the
   minus sign and putting the amount on a second line. */
td.mono, th.right, .right.mono { white-space: nowrap; }
#tbl-tracker th, #tbl-tracker td { white-space: nowrap; }

#tbl-tracker tfoot td {
  background: var(--panel);
  border-top: 2px solid var(--border2);
  border-bottom: none;
  padding-top: 12px;
  padding-bottom: 12px;
  color: var(--ink);
  font-weight: 700;
}
#tbl-tracker tfoot td:first-child {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink3);
}
#tbl-tracker tfoot td.spacer { background: var(--panel); }

/* ---- COHORT GRID ---- */
.cohort { border-collapse: separate; border-spacing: 2px; font-size: 0.72rem; }
.cohort th { padding: 4px 6px; font-size: 0.62rem; }
.cohort td { padding: 5px 7px; text-align: center; border-radius: 4px; border: none; color: var(--ink2); }
.cohort td.c0 { background: transparent; color: var(--ink4); }

/* ---- SYNC ---- */
.synclog {
  margin-top: 14px; padding: 14px 16px; background: var(--inset);
  border: 1px solid var(--border); border-radius: var(--r-card);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem; color: var(--ink3); white-space: pre-wrap; max-height: 320px; overflow: auto;
}
.freshness {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 0.75rem; color: var(--ink4); white-space: nowrap;
}
.stale-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.stale-dot.ok { background: #8fbf94; }
.stale-dot.bad { background: #d98a6a; }

/* ---- DIALOG ---- */
dialog {
  border: 1px solid var(--border2); border-radius: var(--r); padding: 0;
  background: var(--surface); color: var(--ink2); max-width: 460px; width: 92vw;
  box-shadow: var(--shadow-lg);
  /* A modal dialog is `position: fixed; inset: 0` and relies on `margin: auto`
     to centre. The shared stylesheet's `* { margin: 0 }` reset wipes that out,
     which pinned it to the top-left — so put it back explicitly. */
  margin: auto;
}
dialog::backdrop { background: rgba(47,58,49,0.35); }
#dlg-form { padding: 24px 26px; }
#dlg h3 { font-size: 1.2rem; font-weight: 500; color: var(--ink); margin-bottom: 16px; }
.fld { margin-bottom: 13px; }
.fld label { display: block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
             color: var(--ink4); font-weight: 600; margin-bottom: 5px; }
.fld input, .fld select, .fld textarea {
  width: 100%; padding: 8px 10px; font-size: 0.88rem; font-family: inherit; color: var(--ink2);
  background: var(--inset); border: 1px solid var(--border2); border-radius: var(--r-in);
}
.fld input:focus, .fld select:focus, .fld textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95,117,96,0.16);
}
.fld.row { display: flex; gap: 10px; }
.fld.row > div { flex: 1; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.dlg-actions .btn.danger { margin-right: auto; }
.dlg-meta { font-size: 0.74rem; color: var(--ink4); line-height: 1.6; margin-bottom: 14px; }

/* ---- BANNERS ---- */
#banner:not(:empty) { margin-bottom: 24px; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: var(--r-card); font-size: 0.84rem; margin-bottom: 10px;
}
.banner.amber { background: var(--amber-bg); color: var(--amber); }
.banner.red   { background: var(--red-bg);   color: var(--red); }
.banner a { color: inherit; font-weight: 700; }

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
  .two { grid-template-columns: 1fr; }
  .grid.g4 { grid-template-columns: repeat(2, 1fr); }
  .grid.g3 { grid-template-columns: repeat(2, 1fr); }
  .controls { padding: 10px 16px 10px 42px; gap: 12px; }
  main { padding: 24px 16px 20px; }
}
@media (max-width: 560px) {
  .grid.g4, .grid.g3, .grid.g2 { grid-template-columns: 1fr; }
  #f-q { min-width: 100%; }
}
