/* Landplan -- dark by design, light as an escape hatch, print as a lender pack.
 *
 * Hand-written tokens rather than a framework, per decision 8.5: the dark theme
 * becomes a block of variable overrides instead of a retrofit, and there is no
 * toolchain between editing this file and seeing the change.
 *
 * Series colours come from a pre-validated categorical palette (fixed order,
 * never cycled) and are kept separate from the UI accent and from the semantic
 * status colours -- a chart series must never be mistaken for a warning.
 */

:root {
  /* --- dark, the default ------------------------------------------------ */
  --ground:       #0E1211;
  --surface:      #151A18;
  --surface-2:    #1D2321;
  --surface-3:    #262E2B;
  --rule:         #29312E;
  --rule-strong:  #3A443F;

  --ink:          #E4E8E3;
  --ink-2:        #98A29B;
  --ink-3:        #6B756F;

  --accent:       #4FBFA8;
  --accent-ink:   #8FD9C9;
  --accent-soft:  #12302B;

  /* Semantic state. Reserved -- never used as a chart series. */
  --good:         #6FBF73;
  --good-soft:    #14261A;
  --warn:         #E0A054;
  --warn-soft:    #2C2214;
  --danger:       #E07A62;
  --danger-soft:  #2E1B17;
  --info:         #7FA8D8;
  --info-soft:    #16202C;

  /* Categorical series, dark steps. Fixed order, never cycled. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "DejaVu Sans Mono", Menlo, monospace;

  --radius: 3px;
  --gap: 1rem;
  --shell: 1400px;
}

:root[data-theme="light"] {
  --ground:       #F1F2EE;
  --surface:      #FAFAF8;
  --surface-2:    #E9EBE5;
  --surface-3:    #DEE1DA;
  --rule:         #D3D7CE;
  --rule-strong:  #A9AFA5;

  --ink:          #161A18;
  --ink-2:        #4E564F;
  --ink-3:        #79817A;

  --accent:       #0B5D52;
  --accent-ink:   #073F38;
  --accent-soft:  #D8E9E4;

  --good:         #2F7A3D;
  --good-soft:    #DCEBDD;
  --warn:         #97590F;
  --warn-soft:    #F3E6D2;
  --danger:       #A43D28;
  --danger-soft:  #F2DED8;
  --info:         #2C5C93;
  --info-soft:    #DCE6F2;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.5rem; letter-spacing: -0.015em; }
h2 { font-size: 1.15rem; letter-spacing: -0.01em; }
h3 { font-size: 0.98rem; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-ink); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- layout */

.shell { max-width: var(--shell); margin: 0 auto; padding: 0 1.25rem 4rem; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-tight { display: flex; gap: .35rem; align-items: center; }
.spread { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.small { font-size: .84rem; }
.tiny { font-size: .72rem; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

.grid { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ------------------------------------------------------------- topbar */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 40;
}
.topbar-inner {
  max-width: var(--shell); margin: 0 auto; padding: 0 1.25rem;
  display: flex; align-items: center; gap: 1.25rem; min-height: 52px; flex-wrap: wrap;
}
.brand {
  font-weight: 650; letter-spacing: -0.02em; font-size: 1.02rem;
  color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: .5rem;
}
.brand-mark {
  width: 9px; height: 9px; background: var(--accent);
  transform: rotate(45deg); flex: none;
}
.nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.nav a {
  padding: .38rem .68rem; border-radius: var(--radius);
  color: var(--ink-2); text-decoration: none; font-size: .89rem; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }

.identity { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: .68rem; font-weight: 700; color: var(--ground);
  background: var(--accent); flex: none;
}

/* --------------------------------------------------------------- page */

.page-head {
  padding: 1.5rem 0 1.1rem; margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--rule);
  display: flex; gap: 1rem; align-items: flex-end; justify-content: space-between; flex-wrap: wrap;
}
.eyebrow {
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .14em;
  text-transform: uppercase; color: var(--accent); font-weight: 600;
  display: block; margin-bottom: .3rem;
}

/* --------------------------------------------------------------- card */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.card-tight { padding: .8rem; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .75rem; margin-bottom: .85rem; flex-wrap: wrap;
}
.card-title { font-size: .92rem; font-weight: 620; }

/* ---------------------------------------------------------- stat tiles */

.stat {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: .85rem .95rem;
  display: flex; flex-direction: column; gap: .18rem; min-width: 0;
}
.stat-label {
  font-size: .7rem; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600;
}
.stat-value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em;
  line-height: 1.15; color: var(--ink);
}
.stat-value.lg { font-size: 1.85rem; }
.stat-sub { font-size: .78rem; color: var(--ink-2); }
.stat-accent { border-left: 2px solid var(--accent); }

/* ------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th {
  font-size: .66rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
tr.group-head td {
  background: var(--surface-2); font-weight: 620; font-size: .78rem;
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink-2);
}
tr.total-row td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--rule-strong); }

/* -------------------------------------------------------------- forms */

label { font-size: .78rem; color: var(--ink-2); font-weight: 500; display: block; margin-bottom: .25rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="email"], input[type="file"], select, textarea {
  width: 100%; padding: .42rem .55rem;
  background: var(--ground); color: var(--ink);
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  font-family: inherit; font-size: .88rem; line-height: 1.4;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input.num, td input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
textarea { resize: vertical; min-height: 4.5rem; line-height: 1.5; }
.field { margin-bottom: .7rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: var(--ink); }
.check input { width: auto; }
.hint { font-size: .74rem; color: var(--ink-3); margin-top: .25rem; }

/* Inline table editing: an input that reads as text until touched.
   Used only on the dense cost sheet, where visible borders on 46 rows would
   be unreadable. Forms elsewhere use ordinary bordered inputs. */
.cell-input {
  background: transparent; border: 1px solid transparent;
  padding: .2rem .35rem; width: 100%;
}
.cell-input:hover { border-color: var(--rule); background: var(--ground); }
.cell-input:focus { border-color: var(--accent); background: var(--ground); }

/* An input carrying its unit, so a bare number is never ambiguous about
   whether it means percent, dollars, or years. The affix is part of the
   control's frame rather than floating text beside it. */
.affix {
  display: flex; align-items: stretch;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--ground); overflow: hidden;
}
.affix:focus-within { border-color: var(--accent); }
.affix input {
  border: 0; border-radius: 0; background: transparent;
  flex: 1 1 auto; min-width: 0;
}
.affix input:focus { border: 0; outline: none; }
.affix > .affix-unit {
  display: flex; align-items: center; padding: 0 .55rem;
  background: var(--surface-2); color: var(--ink-3);
  font-size: .78rem; font-weight: 600; white-space: nowrap;
  border-left: 1px solid var(--rule);
}
.affix > .affix-unit:first-child {
  border-left: 0; border-right: 1px solid var(--rule);
}

/* Form sections inside a settings card. */
.form-section + .form-section {
  margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--rule);
}
.form-section-title {
  font-size: .72rem; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 650; margin-bottom: .2rem;
}
.form-section-note {
  font-size: .8rem; color: var(--ink-2); margin-bottom: .8rem; max-width: 62ch;
}
.form-actions {
  display: flex; gap: .5rem; align-items: center;
  margin-top: 1.1rem; padding-top: .9rem; border-top: 1px solid var(--rule);
}

/* A settings grid whose columns do not reflow into ragged widths the way
   auto-fit does when the last row is short. */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .75rem 1rem;
}
.settings-grid .field { margin-bottom: 0; }

/* Label sitting on the same line as its control, for compact rate rows. */
.rate-row {
  display: grid; grid-template-columns: 1fr 132px;
  gap: .6rem; align-items: center;
  padding: .35rem 0;
}
.rate-row + .rate-row { border-top: 1px solid var(--rule); }
.rate-row label { margin: 0; font-size: .85rem; color: var(--ink); }
.rate-row .rate-hint { display: block; font-size: .72rem; color: var(--ink-3); font-weight: 400; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .42rem .8rem; border-radius: var(--radius);
  border: 1px solid var(--rule-strong); background: var(--surface-2); color: var(--ink);
  font-family: inherit; font-size: .85rem; font-weight: 550; line-height: 1.3;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #06201C; }
.btn-primary:hover { background: var(--accent-ink); color: #06201C; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--danger); border-color: var(--rule-strong); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .25rem .5rem; font-size: .76rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* --------------------------------------------------------------- chips */

.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .12rem .42rem; border-radius: 2px;
  font-size: .68rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; border: 1px solid currentColor; white-space: nowrap;
}
.chip-financed { color: var(--info); background: var(--info-soft); }
.chip-cash { color: var(--warn); background: var(--warn-soft); }
.chip-recurring { color: var(--accent); background: var(--accent-soft); }
.chip-guess { color: var(--ink-3); background: var(--surface-2); }
.chip-quoted { color: var(--info); background: var(--info-soft); }
.chip-contracted { color: var(--good); background: var(--good-soft); }
.chip-open { color: var(--good); background: var(--good-soft); }
.chip-closed { color: var(--ink-3); background: var(--surface-2); }
.chip-plain { color: var(--ink-2); background: var(--surface-2); }

/* ------------------------------------------------------------- notices */

.notice {
  border-left: 2px solid var(--rule-strong); background: var(--surface);
  padding: .6rem .8rem; border-radius: var(--radius); font-size: .86rem;
  display: flex; gap: .6rem; align-items: flex-start;
}
.notice-success { border-color: var(--good); background: var(--good-soft); }
.notice-error { border-color: var(--danger); background: var(--danger-soft); }
.notice-warning { border-color: var(--warn); background: var(--warn-soft); }
.notice-info { border-color: var(--info); background: var(--info-soft); }

.flashes { position: fixed; top: 62px; right: 1.25rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; max-width: 380px; }
.flashes .notice { box-shadow: 0 6px 22px rgba(0,0,0,.35); }

/* -------------------------------------------------------------- charts */

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 330px; }
.chart-box.short { height: 190px; }

.legend { display: flex; flex-wrap: wrap; gap: .35rem .9rem; margin-top: .7rem; }
.legend-item { display: flex; align-items: center; gap: .35rem; font-size: .76rem; color: var(--ink-2); }
.swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

/* A horizontal magnitude bar for tables -- cheaper than a chart, and reads
   at a glance next to the number it encodes. */
.meter { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; min-width: 40px; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* -------------------------------------------------------- attachments */

/* A thumbnail grid, because a list of filenames tells you nothing about a
   photograph. Tiles size themselves; the image is cropped to a consistent
   aspect so a row of mixed portrait and landscape scans still reads as a grid. */
.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: .6rem;
}
.thumb {
  margin: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.thumb-open {
  display: block; width: 100%; padding: 0; border: 0; cursor: zoom-in;
  /* A chequerboard, so a transparent PNG reads as transparent rather than as
     whatever the surface happens to be in this theme. */
  background-color: var(--surface-3);
  background-image:
    linear-gradient(45deg, var(--surface) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface) 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
}
.thumb-open img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  transition: transform .18s ease;
}
.thumb-open:hover img { transform: scale(1.03); }
.thumb figcaption {
  padding: .45rem .5rem .5rem;
  display: flex; flex-direction: column; gap: .15rem; min-width: 0;
}
.thumb-name {
  font-size: .78rem; font-weight: 550; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thumb-meta { font-size: .68rem; color: var(--ink-3); }
.thumb-actions { display: flex; gap: .1rem; margin-top: .2rem; }
.thumb-actions form { display: inline; }

.filerow {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: .5rem .6rem;
}
.file-icon { color: var(--ink-3); font-size: 1rem; flex: none; }
.file-name {
  font-size: .85rem; font-weight: 550;
  overflow-wrap: anywhere;
}

/* Inline PDF. A fixed height with its own scroll, so a 40-page quote does not
   push the rest of the page off screen. */
.pdf-frame { margin-top: .6rem; }
.pdf-frame iframe {
  width: 100%; height: 60vh; min-height: 320px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: #fff;  /* PDFs are white documents in either theme */
}

/* Lightbox. Plain dialog element -- no library, closes on Escape natively. */
dialog.lightbox {
  border: 0; padding: 0; max-width: 94vw; max-height: 94vh;
  background: transparent; color: var(--ink); overflow: visible;
}
dialog.lightbox::backdrop { background: rgba(0, 0, 0, .82); }
dialog.lightbox img {
  display: block; max-width: 94vw; max-height: 82vh;
  width: auto; height: auto;
  border-radius: var(--radius);
  background: var(--surface);
}
.lightbox-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .5rem .2rem 0; color: #E4E8E3;
}
.lightbox-bar .btn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.lightbox-bar .btn:hover { background: rgba(255,255,255,.22); color: #fff; }

.site-plan {
  width: 100%; height: auto; display: block;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface-2);
  cursor: zoom-in;
}

@media print {
  .thumbs { grid-template-columns: repeat(3, 1fr); }
  .thumb-actions, .pdf-frame { display: none !important; }
  .thumb-open img { aspect-ratio: auto; object-fit: contain; }
}

/* --------------------------------------------------------------- misc */

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-2); }
.divider { height: 1px; background: var(--rule); margin: 1rem 0; }
.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: .3rem .8rem; font-size: .85rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); }

.warn-list { display: flex; flex-direction: column; gap: .45rem; }
.warn-list li { list-style: none; font-size: .84rem; color: var(--ink-2); display: flex; gap: .5rem; }
.warn-list li::before { content: "!"; color: var(--warn); font-weight: 700; flex: none; }

.comment { border-left: 2px solid var(--rule); padding: .1rem 0 .1rem .75rem; }
.comment + .comment { margin-top: .8rem; }
.comment-meta { font-size: .74rem; color: var(--ink-3); margin-bottom: .15rem; }
.comment-body { font-size: .88rem; white-space: pre-wrap; }

.tabs { display: flex; gap: .15rem; border-bottom: 1px solid var(--rule); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a {
  padding: .45rem .8rem; font-size: .86rem; color: var(--ink-2);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.slider-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: center; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.ballot-option {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--ground);
  cursor: grab;
}
.ballot-option + .ballot-option { margin-top: .4rem; }
.ballot-option.dragging { opacity: .4; }

/* --------------------------------------------------------------- print */

@media print {
  :root {
    --ground: #fff; --surface: #fff; --surface-2: #f4f4f2; --surface-3: #e9e9e6;
    --rule: #ccc; --rule-strong: #999;
    --ink: #111; --ink-2: #444; --ink-3: #666;
    --accent: #0B5D52; --accent-ink: #073F38; --accent-soft: #eaf2f0;
  }
  body { background: #fff; color: #111; font-size: 10.5pt; }
  .topbar, .flashes, .no-print, .tabs, form.no-print { display: none !important; }
  .shell { max-width: none; padding: 0; }
  .card { border: 1px solid #ccc; break-inside: avoid; }
  .stat { break-inside: avoid; }
  table { font-size: 9pt; }
  th { background: #f4f4f2 !important; position: static; }
  .page-break { break-before: page; }
  a { color: #111; text-decoration: none; }
}

@media (max-width: 720px) {
  .topbar-inner { min-height: auto; padding: .5rem 1rem; }
  .nav { order: 3; width: 100%; }
  .shell { padding: 0 1rem 3rem; }
  .stat-value { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
