/* FundWatch — hand-written CSS, no framework. Light and dark (html[data-theme]), print-friendly.
   Sibling to ExactSum's main.css in spirit: CSS custom properties, restrained
   palette, dense tables because this is a working screen, not a marketing page. */

:root {
  /* Palette and type from the exactcov.com design system (website/website/css/v3.css),
     mapped onto the app's variable names. Keep both files in step. */
  color-scheme: light;
  --ink:            #16222F;   /* v3 --ink */
  --ink-soft:       #4A5A6B;   /* v3 --ink-2 */
  --ink-faint:      #7A8797;   /* v3 --ink-3 */
  --bg:             #FAF8F4;   /* v3 --paper */
  --surface:        #FFFFFF;   /* v3 --surface */
  --surface-alt:    #FDFCFA;   /* v3 --surface-2 */
  --line:           #E7E1D5;   /* v3 --line */
  --line-strong:    #CFC6B5;
  --accent:         #0E5E52;   /* v3 --accent */
  --accent-soft:    #EAF1EC;   /* v3 --accent-soft */
  --accent-ink:     #0A453C;   /* v3 --accent-deep */
  --mint:           #7BE0C3;
  --good:           #067647;   /* v3 --green-ok */
  --good-soft:      #E7F4EC;
  --warn:           #B45309;   /* v3 --amber */
  --warn-soft:      #FDF3E7;
  --bad:            #B42318;   /* v3 --red */
  --bad-soft:       #FDECEA;
  --font:           "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;   /* v3 --font-ui */
  --font-display:   "Fraunces", Georgia, "Times New Roman", serif;                        /* v3 --font-display */
  --mono:           ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  --radius:         8px;
  --shadow:         0 1px 2px rgba(22, 34, 47, .04), 0 8px 24px -12px rgba(22, 34, 47, .10);  /* v3 --shadow-card */
  --tip-bg:         #16222F;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --ink:            #E7ECF1;
  --ink-soft:       #A7B3BF;
  --ink-faint:      #74818E;
  --bg:             #10171E;
  --surface:        #151E27;
  --surface-alt:    #1A2430;
  --line:           #273340;
  --line-strong:    #3A4A5A;
  --accent:         #3BA48C;
  --accent-soft:    rgba(66, 179, 152, .13);
  --accent-ink:     #7BE0C3;
  --good:           #5BC98F;
  --good-soft:      rgba(91, 201, 143, .14);
  --warn:           #E0A05C;
  --warn-soft:      rgba(224, 160, 92, .14);
  --bad:            #F2867B;
  --bad-soft:       rgba(242, 134, 123, .13);
  --shadow:         0 1px 2px rgba(0, 0, 0, .35), 0 8px 24px -12px rgba(0, 0, 0, .5);
  --tip-bg:         #1A2430;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-family: var(--font-display); font-size: 22px; margin: 0 0 2px; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 620; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 620; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
p { margin: 0 0 10px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; border-radius: var(--radius); }

/* ── Chrome ───────────────────────────────────────────────────────────── */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar { max-width: 1440px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; height: 52px; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand .mark { width: 30px; height: 30px; display: block; flex: none; }
.brand-stack { display: flex; flex-direction: column; line-height: 1; }
.brand-word { font-family: var(--font-display); font-weight: 600; font-size: 19px; letter-spacing: -.01em; color: var(--ink); }
.brand-word em { font-style: normal; color: var(--accent); }
.brand-sub { margin-top: 3px; font-size: 8.5px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--ink-faint); align-self: flex-end; }

.nav { display: flex; gap: 2px; margin-right: auto; }
.nav a { padding: 6px 10px; border-radius: var(--radius); color: var(--ink-soft); font-weight: 520; }
.nav a:hover { background: var(--surface-alt); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }

.who { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--ink-faint); }
.who .actor { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-quiet { color: var(--ink-faint); }

.wrap { max-width: 1440px; margin: 0 auto; padding: 20px; }
.wrap.wide { max-width: 1760px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head .sub { color: var(--ink-faint); font-size: 13px; margin: 0; }
.page-actions { display: flex; gap: 8px; align-items: center; }

.foot { max-width: 1440px; margin: 8px auto 32px; padding: 0 20px; color: var(--ink-faint); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.foot .dot { opacity: .5; }
.foot .foot-right { margin-left: auto; }
.v3-theme-toggle { display: inline-flex; align-items: center; font: inherit; font-size: 12px; font-weight: 600; color: var(--ink-soft);
  background: transparent; border: 1px solid var(--line); border-radius: 99px; padding: 5px 12px; cursor: pointer; transition: color .15s ease, border-color .15s ease; }
.v3-theme-toggle:hover { color: var(--ink); border-color: var(--ink-faint); }
.v3-theme-toggle span { display: none; align-items: center; gap: 7px; }
.v3-theme-toggle[data-mode="auto"] .tt-auto { display: inline-flex; }
.v3-theme-toggle[data-mode="light"] .tt-light { display: inline-flex; }
.v3-theme-toggle[data-mode="dark"] .tt-dark { display: inline-flex; }

/* ── Blocks ───────────────────────────────────────────────────────────── */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card > .card-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card > .card-head h2 { margin: 0; }
.card > .card-body { padding: 14px; }
.card > .card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); color: inherit; }
a.tile:hover { text-decoration: none; border-color: var(--line-strong); box-shadow: 0 2px 10px rgba(22,32,46,.10); }
.tile-value { font-size: 24px; font-weight: 640; letter-spacing: -.02em; line-height: 1.15; }
.tile-label { font-size: 12px; color: var(--ink-soft); font-weight: 520; }
.tile-detail { font-size: 11px; color: var(--ink-faint); }
.tile.tone-good { border-left-color: var(--good); }
.tile.tone-warn { border-left-color: var(--warn); }
.tile.tone-bad  { border-left-color: var(--bad); }
.tile.tone-accent { border-left-color: var(--accent); }

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-scroll { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl thead th { background: var(--surface-alt); color: var(--ink-soft); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--surface-alt); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.nowrap, table.tbl th.nowrap { white-space: nowrap; }
table.tbl tbody tr.row-bad { background: var(--bad-soft); box-shadow: inset 3px 0 0 var(--bad); }
table.tbl tbody tr.row-warn { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
table.tbl tbody tr.row-bad td:first-child, table.tbl tbody tr.row-warn td:first-child { font-weight: 600; }
/* Dark theme: the soft tints are near-invisible on a dark surface, so use stronger fills */
html[data-theme="dark"] table.tbl tbody tr.row-bad { background: rgba(242, 134, 123, .26); }
html[data-theme="dark"] table.tbl tbody tr.row-warn { background: rgba(224, 160, 92, .24); }
html[data-theme="dark"] table.tbl tbody tr.row-bad:hover { background: rgba(242, 134, 123, .34); }
html[data-theme="dark"] table.tbl tbody tr.row-warn:hover { background: rgba(224, 160, 92, .32); }
html[data-theme="dark"] .tile.tone-bad { background: rgba(242, 134, 123, .10); }
html[data-theme="dark"] .tile.tone-warn { background: rgba(224, 160, 92, .10); }
html[data-theme="dark"] .chip-bad { background: rgba(242, 134, 123, .28); }
html[data-theme="dark"] .chip-warn { background: rgba(224, 160, 92, .26); }
table.tbl th[data-sort] { cursor: pointer; user-select: none; }
table.tbl th[data-sort]::after { content: ' ↕'; opacity: .3; }
table.tbl th[data-sort].asc::after { content: ' ↑'; opacity: .8; }
table.tbl th[data-sort].desc::after { content: ' ↓'; opacity: .8; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; }

/* ── Controls ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit;
  font-size: 13px; font-weight: 520; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }

input[type=text], input[type=search], input[type=number], input[type=email], input[type=password], input[type=date], select, textarea {
  font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--ink); max-width: 100%;
}
textarea { width: 100%; font-family: var(--mono); font-size: 12px; line-height: 1.45; }
input:focus, select:focus, textarea:focus, .btn:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: 12px; color: var(--ink-soft); display: inline-flex; flex-direction: column; gap: 3px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.filters .spacer { margin-left: auto; }

.inline-form { display: inline-flex; gap: 4px; align-items: center; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Chips, notes ─────────────────────────────────────────────────────── */

.chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; text-transform: capitalize; }
.chip.tone-good { background: var(--good-soft); color: var(--good); }
.chip.tone-warn { background: var(--warn-soft); color: var(--warn); }
.chip.tone-bad  { background: var(--bad-soft); color: var(--bad); }
.chip.tone-muted{ background: var(--surface-alt); color: var(--ink-soft); border: 1px solid var(--line); }

.note { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-alt); font-size: 13px; margin-bottom: 14px; }
.note-good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); color: var(--good); }
.note-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.note-bad  { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad); }
.note code { font-family: var(--mono); font-size: 12px; }

.muted { color: var(--ink-faint); }
.empty { color: var(--ink-faint); padding: 18px; text-align: center; font-style: italic; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

.cite { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px dashed var(--line-strong); border-radius: 3px; color: var(--accent); }
.cite:hover { background: var(--accent-soft); text-decoration: none; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.pager-nav { display: flex; align-items: center; gap: 10px; }

/* ── Timeline / audit ─────────────────────────────────────────────────── */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 12px 18px; border-left: 2px solid var(--line); }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.timeline li.tone-bad::before { background: var(--bad); }
.timeline li.tone-warn::before { background: var(--warn); }
.timeline li:last-child { border-left-color: transparent; }
.timeline .when { font-size: 11px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ── Chart ────────────────────────────────────────────────────────────── */

.chart-box { position: relative; height: 340px; }
.chart-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

/* ── Passage viewer (api/passage.php) ─────────────────────────────────── */

.passage-doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; white-space: pre-wrap; font-family: var(--mono); font-size: 12px; line-height: 1.6; }
.passage-doc mark { background: var(--warn-soft); color: var(--ink); outline: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); padding: 1px 0; }
.passage-head { display: flex; gap: 12px; flex-wrap: wrap; align-items: baseline; margin-bottom: 12px; }

/* ── Login ────────────────────────────────────────────────────────────── */

.login-wrap { max-width: 380px; margin: 12vh auto; }
.login-wrap .card-body { padding: 22px; }
.login-wrap label { display: block; margin-bottom: 12px; font-size: 12px; }
.login-wrap input { width: 100%; margin-top: 3px; padding: 8px 10px; font-size: 14px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 18px; text-align: center; }
.login-brand .mark { width: 44px; height: 44px; }
.login-brand .brand-word { font-size: 26px; }
.login-brand small { display: block; color: var(--ink-faint); font-size: 12px; font-weight: 500; }

/* ── Print ────────────────────────────────────────────────────────────── */

@media print {
  .topbar, .filters, .page-actions, .pager, .btn, .actions-cell, .chart-toolbar, .foot .dot { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .card { break-inside: avoid; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
  .wrap { max-width: none; padding: 0; }
}

@media (max-width: 900px) {
  .bar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
}

/* ── Glossary tooltips (assets/app.js fwGlossary; includes/lib/glossary.php) ── */
.term { position: relative; cursor: help; border-bottom: 1px dotted var(--ink-soft); }
.term-mark { font-size: 9px; margin-left: 2px; opacity: .55; font-weight: 600; }
.term::after {
  content: attr(data-tip);
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 220px; max-width: 340px; padding: 8px 10px;
  background: var(--tip-bg); color: #E7ECF1; border: 1px solid var(--line); font-size: 12px; font-weight: 400; line-height: 1.4;
  text-transform: none; letter-spacing: 0; white-space: normal; text-align: left;
  border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  opacity: 0; visibility: hidden; transition: opacity .12s ease; pointer-events: none;
}
.term:hover::after, .term:focus::after, .term:focus-within::after { opacity: 1; visibility: visible; }
.term.tip-right::after { left: auto; right: 0; }
th .term, .tile-label .term { border-bottom-color: transparent; }
th .term:hover, .tile-label .term:hover { border-bottom-color: var(--ink-soft); }
@media print { .term::after, .term-mark { display: none; } .term { border-bottom: none; } }
