/* Optional: drop DejaVuSans.ttf / DejaVuSans-Bold.ttf into wwwroot/fonts for a preview that matches the Pi exactly. */
@font-face { font-family: "FTR Preview Sans"; src: local("DejaVu Sans"), url("../fonts/DejaVuSans.ttf") format("truetype"); font-weight: normal; }
@font-face { font-family: "FTR Preview Sans"; src: local("DejaVu Sans Bold"), local("DejaVuSans-Bold"), url("../fonts/DejaVuSans-Bold.ttf") format("truetype"); font-weight: bold; }

/* Dark interface for everyone (black background). Printed reports switch back to white; see @media print. */
:root {
  --bg: #050506;               /* page background: near black */
  --surface: #121418;          /* cards, top bar, inputs */
  --surface-2: #1b1e24;        /* table headings, hover */
  --text: #e9ebf0;
  --muted: #9aa1ad;
  --line: #2a2e36;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --accent-soft: #3a1820;
  --focus: #5b9cff;
  --ok: #5fd39a; --ok-bg: #12301f;
  --warn: #f2c14e; --warn-bg: #33290f;
  --info: #8ab8ff; --info-bg: #142540;
  --bad: #ff8a80; --bad-bg: #3a1714;
  --changed: #47357a;          /* purple: changed but not published yet */
  --changed-edge: #a98ae6;
  --radius: 8px;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--info); }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 1rem; margin: 0 0 .75rem; }
h4 { font-size: .9rem; margin: 1rem 0 .5rem; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--text); text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-logo.lg { height: 44px; }
.brand-mark { background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .75rem; letter-spacing: .06em; padding: .2rem .4rem; border-radius: 4px; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { color: var(--muted); text-decoration: none; padding: .35rem .65rem; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.who { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.who .role { margin-left: .4rem; font-size: .75rem; padding: .1rem .4rem; border: 1px solid var(--line); border-radius: 999px; }

/* ---------- layout */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; display: grid; gap: 1rem; }
.page.narrow { max-width: 560px; }
.page-head { display: flex; align-items: baseline; gap: .75rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.stack { display: grid; gap: .75rem; }
.loading { color: var(--muted); padding: 2rem; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.strong { font-weight: 600; }
.hint { color: var(--muted); margin: 0 0 .75rem; font-size: .88rem; }
.notice { background: var(--info-bg); color: var(--info); padding: .6rem .8rem; border-radius: 6px; font-size: .88rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.link-list { margin: 0; padding-left: 1.2rem; line-height: 2; }

/* ---------- forms */
.field { display: grid; gap: .3rem; min-width: 0; }
.field-label { font-weight: 550; font-size: .85rem; }
.field small { color: var(--muted); font-size: .78rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .45rem .55rem; width: 100%; min-width: 0; }
textarea { resize: vertical; line-height: 1.4; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="color"] { width: 2.3rem; height: 2.1rem; padding: .15rem; flex: none; cursor: pointer; }
input[type="file"] { display: none; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; user-select: none; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .9rem 1rem; align-items: start; }
.form-actions { grid-column: 1 / -1; }
.auth-wrap { min-height: 80vh; display: grid; place-items: center; padding: 1rem; }
.auth-card { width: min(380px, 100%); display: grid; gap: .9rem; padding: 1.5rem; }
.auth-brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; font-size: 1.1rem; margin-bottom: .25rem; }
.color-control { display: flex; gap: .35rem; align-items: center; }
.color-text { min-width: 5.5rem; }
.color-control { flex-wrap: wrap; }
.color-control .color-text { width: 7.5rem; flex: none; }
.swatches { display: inline-flex; gap: .3rem; }
.swatch { width: 1.6rem; height: 1.6rem; border-radius: 5px; border: 1px solid var(--line); cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.swatch:hover { transform: scale(1.12); }
.swatch:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.copy-row { display: flex; gap: .4rem; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 550; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; }
/* Publish button: red = changes not on the display yet, green = everything published. */
.btn.publish-btn { color: #fff; transition: background-color .2s, border-color .2s; }
.btn.publish-btn.publish-pending { background: #d92d20; border-color: #d92d20; }
.btn.publish-btn.publish-pending:hover { background: #b42318; }
.btn.publish-btn.publish-done { background: #15803d; border-color: #15803d; }
.btn.publish-btn.publish-done:hover { background: #116932; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { color: var(--bad); background: transparent; }
.btn.danger-ghost:hover { background: var(--bad-bg); }
.file-btn { position: relative; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; width: 1.7rem; height: 1.7rem; border-radius: 5px; font-size: .9rem; }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.add-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }

/* ---------- chips */
.chip { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 550; background: var(--surface-2); color: var(--muted); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.info { background: var(--info-bg); color: var(--info); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.sm { margin-left: .4rem; font-size: .7rem; }

/* ---------- list tables */
.table-scroll { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
table.list td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .actions { text-align: right; white-space: nowrap; }
table.list .actions > * + * { margin-left: .35rem; }
table.list select, table.list input { min-width: 8rem; }

/* ---------- editor */
.editor { padding: 1rem 1.25rem 4rem; max-width: 1500px; margin: 0 auto; }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.editor-head .muted { margin-top: .35rem; }
.head-actions { display: flex; gap: .5rem; }
.editor-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 1.25rem; align-items: start; }
.editor-main { min-width: 0; }
.panel { display: grid; gap: 1rem; }
.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tab { font: inherit; font-weight: 550; padding: .55rem .9rem; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.preview { position: sticky; top: 4.2rem; }
.preview-frame { background: #000; border-radius: 10px; padding: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); }
.preview-canvas { display: block; width: 100%; height: auto; aspect-ratio: 9 / 16; cursor: crosshair; touch-action: none; }
.preview-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: .78rem; margin-top: .4rem; }

.content-card { transition: border-color .2s, box-shadow .2s; }
.content-card.selected { border-color: color-mix(in srgb, var(--focus) 55%, var(--line)); }
.content-card.flash { box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 35%, transparent); }

/* spreadsheet grid */
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 0; }
table.grid thead th { background: var(--surface-2); }
table.grid tfoot td { background: var(--surface-2); font-weight: 650; }
table.grid .rownum { width: 2.2rem; text-align: center; color: var(--muted); font-size: .75rem; padding: 0 .25rem; }
table.grid .row-tools { width: 5.4rem; white-space: nowrap; text-align: center; border-left: 1px solid var(--line); }
table.grid .cell { border: 0; border-radius: 0; padding: .4rem .5rem; background: transparent; min-width: 4.5rem; }
table.grid .cell:focus { box-shadow: inset 0 0 0 2px var(--focus); }
table.grid .cell.num { text-align: center; }
table.grid .cell.head { font-weight: 650; text-align: center; }
table.grid .cell.total { display: block; text-align: center; color: var(--ok); }
table.grid .cell.foot { font-weight: 650; }
table.grid.compact .cell, table.grid.compact input, table.grid.compact select { border: 0; border-radius: 0; background: transparent; }
table.grid.compact th { font-size: .75rem; padding: .3rem .4rem; text-align: left; color: var(--muted); }
table.grid.compact td { padding: .1rem; }
table.grid.compact .w-num { width: 5rem; }
table.grid .center { text-align: center; }
table.grid .cell.head-ro { font-weight: 650; color: var(--text); }
fieldset.perms { border: 1px solid var(--line); border-radius: 6px; padding: .5rem .8rem .7rem; margin: .9rem 0 0; display: grid; gap: .35rem; }
fieldset.perms legend { font-weight: 600; font-size: .85rem; padding: 0 .3rem; }
fieldset.perms .hint { margin: .2rem 0 0; }
.ro-text { white-space: pre-wrap; color: var(--muted); padding: .45rem .55rem; border: 1px dashed var(--line); border-radius: 6px; margin-bottom: .6rem; }
table.readonly-grid td { padding: 0; }
table.readonly-grid th { padding: .4rem .5rem; font-weight: 650; text-align: center; }
table.readonly-grid th.editable-head { background: var(--info-bg); color: var(--info); }
table.grid .cell.ro { display: block; padding: .4rem .5rem; color: var(--muted); text-align: center; }
table.grid td:first-child .cell.ro { text-align: left; color: var(--text); }
table.grid .cell.editable { background: var(--info-bg); font-weight: 650; }
table.grid .cell.invalid { box-shadow: inset 0 0 0 2px var(--bad); background: var(--bad-bg); }
.table-tools { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: .6rem; }

/* layout widgets */
.wlist { display: grid; border: 1px solid var(--line); border-radius: 6px; max-height: 360px; overflow-y: auto; }
.witem { display: flex; align-items: center; gap: .6rem; padding: .35rem .5rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.witem:last-child { border-bottom: 0; }
.witem:hover { background: var(--surface-2); }
.witem.sel { background: var(--info-bg); }
.wtype { flex: none; width: 3.6rem; text-align: center; font-size: .7rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: .1rem 0; border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.wtype.t-text { background: #142540; color: #8ab8ff; }
.wtype.t-table { background: #12301f; color: #5fd39a; }
.wtype.t-image { background: #2c1840; color: #c9a2f2; }
.wtype.t-rect, .wtype.t-line { background: #33290f; color: #f2c14e; }
.wlabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wtools { flex: none; display: flex; }
.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; margin-top: .75rem; }
.prop-check { align-self: end; padding-bottom: .5rem; }
.advanced { margin-top: 1rem; }
.advanced summary { cursor: pointer; color: var(--muted); font-weight: 550; margin-bottom: .5rem; }
.advanced textarea.json { font-size: .8rem; margin-bottom: .5rem; }
.columns-editor .color-control input[type="color"] { width: 1.9rem; height: 1.8rem; }
.columns-editor .color-text { min-width: 5rem; width: 5.5rem; }

/* images */
.image-row { display: flex; gap: 1rem; align-items: center; }
.thumb { width: 84px; height: 84px; flex: none; border-radius: 6px; background: #000 repeating-conic-gradient(#222 0 25%, #111 0 50%) 0 0 / 16px 16px; display: grid; place-items: center; overflow: hidden; }
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-list { display: grid; gap: .5rem; }
.asset { display: flex; gap: .9rem; align-items: center; padding: .5rem; border: 1px solid var(--line); border-radius: 6px; }
.asset .thumb { width: 64px; height: 64px; }
.asset-meta { flex: 1; min-width: 0; display: grid; gap: .2rem; }
.asset-tools { display: flex; gap: .35rem; }
.asset-missing { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .4rem .6rem; background: var(--warn-bg); border-radius: 6px; }

.branding-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .branding-grid { grid-template-columns: 1fr; } }

pre.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: .75rem; overflow-x: auto; font-size: .82rem; margin: 0 0 .75rem; }

/* changed-but-unsaved: light purple until Save draft / Publish */
textarea.changed, input.changed, table.grid .cell.changed, .color-control.changed .color-text,
.witem.changed, label.check.changed {
  background-color: var(--changed) !important;
}
textarea.changed, input.changed, .color-control.changed .color-text { border-color: var(--changed-edge); }
label.check.changed { border-radius: 5px; box-shadow: 0 0 0 3px var(--changed); }
.witem.changed .wlabel::after { content: " · unsaved"; color: var(--changed-edge); font-size: .8em; }

.anim-style { display: grid; gap: .75rem; margin-top: .75rem; }
.anim-row { display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 200px); gap: 1rem; align-items: start; }
@media (max-width: 600px) { .anim-row { grid-template-columns: 1fr; } }

/* year card */
.years-card .year-now { margin: 0 0 .25rem; font-size: 1rem; }
.years-card select { width: auto; }

/* modal popup */
dialog.modal { border: 1px solid var(--line); border-radius: 10px; padding: 1.25rem 1.4rem; max-width: min(540px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog.modal::backdrop { background: rgba(10, 12, 16, .55); }
dialog.modal h2 { margin: 0 0 .75rem; font-size: 1.25rem; }
dialog.modal .modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
ul.bullets { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; }
.btn.danger { background: #d92d20; border-color: #d92d20; color: #fff; }
.btn.danger:hover { background: #b42318; }

/* printable year report */
.print-page { max-width: 900px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.print-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.25rem; }
table.print-layout { width: 100%; border-collapse: collapse; }
table.print-layout > tbody > tr > td, table.print-layout > tfoot > tr > td { padding: 0; }
.print-footer-space { display: none; }
.print-head { display: flex; align-items: flex-start; gap: 1.25rem; }
.print-title { flex: 1; min-width: 0; }
.print-logo { width: 110px; height: auto; max-height: 120px; object-fit: contain; flex: none; }
.print-footer { margin-top: 2rem; padding-top: .5rem; border-top: 1px solid var(--line); text-align: center; font-size: .8rem; color: var(--muted); letter-spacing: .02em; }
.print-head h1 { font-size: 1.6rem; }
.print-head h2 { font-size: 1.2rem; margin: .25rem 0; font-weight: 600; }
.print-sections { display: grid; gap: 1.5rem; margin-top: 1rem; }
.print-section h3 { font-size: 1.05rem; border-bottom: 2px solid var(--text); padding-bottom: .25rem; margin-bottom: .4rem; }
table.print-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.print-table th, table.print-table td { padding: .28rem .5rem; border-bottom: 1px solid var(--line); text-align: left; }
table.print-table .num { text-align: right; width: 7rem; }
table.print-table tfoot td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: 0; }
/* one-page 3-year comparison: two columns, compact rows */
.print-sections.compare { grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
.print-col { display: grid; gap: 1rem; min-width: 0; }
.print-page.compact table.print-table { font-size: .82rem; }
.print-page.compact table.print-table th, .print-page.compact table.print-table td { padding: .14rem .35rem; }
.print-page.compact table.print-table .num { width: auto; white-space: nowrap; }
.print-page.compact .print-section h3 { font-size: .95rem; margin-bottom: .2rem; }
.print-page.compact .print-head .print-logo { width: 84px; }
@media (max-width: 700px) { .print-sections.compare { grid-template-columns: 1fr; } }

/* ¼-inch left/right page margins on prints */
@page { margin: 0.4in 0.25in; }
@media print {
  .topbar, .no-print, .toasts { display: none !important; }
  :root { --bg: #fff; --surface: #fff; --surface-2: #f3f4f6; --text: #000; --line: #bbb; --muted: #444; color-scheme: light; }
  body { background: #fff; color: #000; }
  .print-page { padding: 0; max-width: none; }
  table.print-layout > tfoot { display: table-footer-group; }
  .print-footer-space { display: block; height: 1.3cm; }
  .print-footer { position: fixed; bottom: 0; left: 0; right: 0; height: 1cm; margin: 0; padding: .25cm 0 0; background: #fff; }
  .print-logo { width: 1.1in; max-height: 1.2in; }
  .print-page.compact .print-head .print-logo { width: .8in; max-height: .85in; }
  .print-page.compact table.print-table { font-size: 8.5pt; }
  .print-page.compact table.print-table th, .print-page.compact table.print-table td { padding: 1.5pt 4pt; }
  .print-page.compact .print-sections { margin-top: .4rem; }
  .print-page.compact .print-head h1 { font-size: 15pt; }
  .print-page.compact .print-head h2 { font-size: 11pt; }
  .print-sections.compare { grid-template-columns: 1fr 1fr; }   /* keep two columns on paper */
  .print-section { break-inside: auto; }
  table.print-table tr { break-inside: avoid; }
  table.print-table thead { display: table-header-group; }   /* column headings repeat on each page */
  table.print-table tfoot { display: table-row-group; }      /* totals appear once, at the real end */
}

/* toasts */
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; max-width: min(420px, calc(100vw - 2rem)); }
.toast { padding: .65rem .9rem; border-radius: 8px; background: #1c1f24; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: .9rem; }
.toast.ok { background: #18794e; }
.toast.error { background: #b42318; }

@media (max-width: 900px) {
  .editor-body { grid-template-columns: 1fr; }
  .preview { position: static; max-width: 420px; margin: 0 auto; width: 100%; order: -1; }
  .topbar { gap: .75rem; }
  .who { width: 100%; justify-content: space-between; }
}
