/* Office UI. Light, quiet surfaces; one teal-blue accent for actions and
   "you are here"; status is carried by soft tinted labels. */

:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #F9FAFB;
  --line: #E3E7EC;
  --line-strong: #CDD4DC;
  --text: #16202B;
  --muted: #5F6B7A;
  --faint: #8A95A3;
  --accent: #15607E;
  --accent-hover: #0F4F69;
  --accent-soft: #E7F1F5;
  --accent-text: #FFFFFF;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --ok: #157347;
  --focus: rgba(21, 96, 126, .28);
  --row-hover: #F6F9FB;
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 6px rgba(16, 24, 40, .06);

  /* status tints: background / text */
  --st-open-bg: #EEF1F4;       --st-open: #46505C;
  --st-assigned-bg: #E6F0FB;   --st-assigned: #1D5FA8;
  --st-progress-bg: #FFF4E0;   --st-progress: #93570B;
  --st-suspended-bg: #F3ECFB;  --st-suspended: #6B3FA0;
  --st-finished-bg: #E5F5EC;   --st-finished: #16703F;
  --st-completed-bg: #DDF0F3;  --st-completed: #0D5C66;
  --st-cancelled-bg: #FBEAEA;  --st-cancelled: #A1302A;

  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 14px; --fs-md: 16px; --fs-lg: 20px; --fs-xl: 26px;
  --r-sm: 6px; --r: 8px; --r-lg: 12px;
  --side-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1419; --surface: #161C23; --surface-2: #1B222A; --line: #26303A; --line-strong: #34404C;
    --text: #E6EBF0; --muted: #9AA6B2; --faint: #6F7B88; --accent: #4FA6C8; --accent-hover: #6BB8D6;
    --accent-soft: #15303C; --accent-text: #0B1419; --danger: #F0796F; --danger-soft: #3A1D1B; --ok: #5CC58C;
    --row-hover: #1B232B; --focus: rgba(79, 166, 200, .35);
    --st-open-bg: #232B33; --st-open: #B5C0CB; --st-assigned-bg: #16304A; --st-assigned: #8CC0F2;
    --st-progress-bg: #3A2A10; --st-progress: #F2C277; --st-suspended-bg: #2E2240; --st-suspended: #C8A6F0;
    --st-finished-bg: #14352A; --st-finished: #7FD6A5; --st-completed-bg: #123339; --st-completed: #7CCFD8;
    --st-cancelled-bg: #3A1D1B; --st-cancelled: #F09A93;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 50; background: var(--surface); padding: 8px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px 20px; font-weight: 700; font-size: var(--fs-md); letter-spacing: -0.015em; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-text); right: 5px; top: 5px; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; overflow-y: auto; }
.nav-group { margin: 16px 0 6px 10px; font-size: var(--fs-xs); color: var(--faint); font-weight: 600; }
.nav a, .nav .nav-soon { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r); color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .nav-soon { color: var(--faint); cursor: default; }
.nav .nav-soon small { margin-left: auto; font-size: 11px; }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); flex: none; }
.whoami { min-width: 0; flex: 1; font-size: var(--fs-sm); line-height: 1.3; }
.whoami div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: var(--r-sm); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 32px; background: var(--bg); position: sticky; top: 0; z-index: 10; }
.search { flex: 1; max-width: 520px; position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { width: 100%; height: 38px; padding: 0 12px 0 38px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; position: relative; }
.menu-btn { display: none; }
.main { padding: 8px 32px 64px; outline: none; max-width: 1400px; width: 100%; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 20px; }
.page-head h1 { font-size: var(--fs-xl); font-weight: 700; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .sub { margin: 4px 0 0; color: var(--muted); }
.crumb { font-size: var(--fs-sm); margin-bottom: 6px; color: var(--muted); }
.crumb a { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-block { width: 100%; height: 40px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 600; font-size: inherit; }

/* dropdown menu */
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); padding: 6px; min-width: 200px; z-index: 30; }
.menu a, .menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm); border: 0; background: none;
  color: var(--text); cursor: pointer; text-align: left; font-weight: 500; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }

/* ---------- cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: var(--fs-md); font-weight: 650; }
.card-body { padding: 16px 18px; }
.card + .card, .stack > .card + .card { margin-top: 16px; }
.split { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
.split > div > .card + .card { margin-top: 16px; }
.split > *, .cols-2 > * { min-width: 0; }
.split.side-right { grid-template-columns: 1fr minmax(280px, 360px); }
.split.form-split { grid-template-columns: minmax(320px, 420px) 1fr; }
.scroll-x { overflow-x: auto; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

dl.facts { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; margin: 0; }
dl.facts dt { color: var(--muted); font-size: var(--fs-sm); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; }

/* ---------- toolbar / table ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: var(--fs-sm); }
.input, .toolbar input, .toolbar select { height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); }
.toolbar input[type=search] { min-width: 260px; }
.input:focus, .toolbar input:focus, .toolbar select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 2px; }
.segmented button { border: 0; background: none; padding: 0 12px; height: 30px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: var(--fs-sm); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.grid th { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); background: var(--surface-2); }
.grid th button { all: unset; cursor: pointer; }
.grid th button:focus-visible { outline: 2px solid var(--accent); }
.grid th[aria-sort="ascending"] button::after { content: " ↑"; }
.grid th[aria-sort="descending"] button::after { content: " ↓"; }
.grid tbody tr.clickable { cursor: pointer; }
.grid tbody tr.clickable:hover { background: var(--row-hover); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid td.wrap { white-space: normal; min-width: 220px; }
.grid .right, .grid th.right { text-align: right; }
.cell-main { font-weight: 600; color: var(--text); }
.cell-sub { font-size: var(--fs-xs); color: var(--muted); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty h2 { font-size: var(--fs-md); color: var(--text); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.pager { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; align-items: center; font-size: var(--fs-sm); color: var(--muted); }

/* ---------- tags ---------- */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600;
  background: var(--st-open-bg); color: var(--st-open); white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.plain::before { display: none; }
.tag-Open { background: var(--st-open-bg); color: var(--st-open); }
.tag-Assigned { background: var(--st-assigned-bg); color: var(--st-assigned); }
.tag-InProgress { background: var(--st-progress-bg); color: var(--st-progress); }
.tag-Suspended { background: var(--st-suspended-bg); color: var(--st-suspended); }
.tag-Finished { background: var(--st-finished-bg); color: var(--st-finished); }
.tag-Completed { background: var(--st-completed-bg); color: var(--st-completed); }
.tag-Cancelled { background: var(--st-cancelled-bg); color: var(--st-cancelled); }
.tag-Todo { background: var(--st-open-bg); color: var(--st-open); }
.tag-Done { background: var(--st-finished-bg); color: var(--st-finished); }
.tag-active { background: var(--st-finished-bg); color: var(--st-finished); }
.tag-inactive { background: var(--st-open-bg); color: var(--st-open); }
.tag-accent { background: var(--accent-soft); color: var(--accent); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; color: var(--text); }
a.stat:hover { border-color: var(--line-strong); text-decoration: none; }
.stat strong { display: block; font-size: var(--fs-xl); font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: var(--fs-sm); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 84px 1fr auto; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--line); align-items: center; }
.timeline li:last-child { border-bottom: 0; }
.timeline .time { font-weight: 600; font-size: var(--fs-sm); }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li > :first-child { min-width: 0; }
.list > li > .actions { flex-wrap: nowrap; flex: none; }

/* ---------- forms ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: var(--fs-sm); font-weight: 600; }
.field input, .field select, .field textarea {
  height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); width: 100%; }
.field textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.field select[multiple] { height: auto; min-height: 110px; padding: 6px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); }
.field .error { font-size: var(--fs-xs); color: var(--danger); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
fieldset.group { border: 0; padding: 0; margin: 8px 0 0; grid-column: 1 / -1; }
fieldset.group legend { font-weight: 700; padding: 0; font-size: var(--fs-md); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; border-top: 1px solid var(--line); margin-top: 16px; z-index: 5; }
.alert { padding: 10px 14px; border-radius: var(--r); margin: 0 0 14px; font-size: var(--fs-sm); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 12px; border-radius: var(--r); overflow-wrap: anywhere; user-select: all; }

/* autocomplete */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-pop); max-height: 280px; overflow-y: auto; z-index: 40; padding: 4px; }
.picker-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.picker-list button:hover, .picker-list button.hi { background: var(--accent-soft); }
.picker-list .cell-sub { display: block; }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; height: 38px; padding: 0 6px 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface-2); font-weight: 600; }

/* line items editor */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.lines td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines input[type=text], .lines input[type=number] { width: 100%; height: 34px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); }
.lines input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.lines .qty { width: 84px; } .lines .price { width: 110px; } .lines .tot { width: 110px; text-align: right; padding-top: 14px; font-weight: 600; }
.lines .tx { width: 64px; text-align: center; padding-top: 14px; }
.lines .rm { width: 36px; }
.totals { margin-left: auto; width: 280px; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: var(--fs-md); }

/* visits */
.visit { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; background: var(--surface-2); }
.visit + .visit { margin-top: 10px; }
.visit-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }
.visit-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.visit-row:last-child { border-bottom: 0; }
.people { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: var(--fs-xs); font-weight: 600; }
.chip .avatar { width: 20px; height: 20px; font-size: 10px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* history */
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: var(--fs-sm); }
.history li:last-child { border-bottom: 0; }

/* ---------- modal + toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 60; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px; padding: 22px 24px; box-shadow: var(--shadow-pop); }
.modal.wide { max-width: 820px; }
.modal h2 { margin: 0 0 16px; font-size: var(--fs-lg); font-weight: 700; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 16px); opacity: 0; background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; transition: opacity .16s, transform .16s; pointer-events: none; z-index: 80; font-weight: 500; box-shadow: var(--shadow-pop); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- login / error pages ---------- */
.login-page, .plain-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--bg); }
.login, .plain-card { background: var(--surface); width: 100%; max-width: 400px; padding: 32px; border-radius: 16px; border: 1px solid var(--line); }
.login .brand { padding: 0 0 24px; }
.login h1 { font-size: var(--fs-lg); font-weight: 700; margin-bottom: 4px; }
.login p.sub { color: var(--muted); margin: 0 0 22px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) { .split, .split.side-right, .split.form-split, .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-pop); }
  .sidebar.open { transform: none; }
  .menu-btn { display: grid; }
  .topbar, .main { padding-left: 16px; padding-right: 16px; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .toolbar input[type=search] { min-width: 0; flex: 1; }
  .page-head h1 { font-size: var(--fs-lg); }
  .stats { grid-template-columns: 1fr 1fr; }
  .timeline li { grid-template-columns: 64px 1fr; }
  .timeline li > :last-child { grid-column: 2; }
  .totals { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- work order record (long, sectioned page) ---------- */
.record-head { position: sticky; top: 62px; z-index: 8; background: var(--bg); padding: 4px 0 10px; margin-bottom: 6px; }
.section-nav { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.section-nav::-webkit-scrollbar { display: none; }
.section-nav a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.section-nav a:hover { color: var(--text); border-color: var(--line-strong); text-decoration: none; }
.section-nav a .count { color: var(--faint); font-weight: 500; margin-left: 4px; }

.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); margin-bottom: 16px; scroll-margin-top: 130px; }
.section-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.section.collapsed .section-head { border-bottom: 0; }
.section-toggle { all: unset; display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; min-width: 0; }
.section-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.section-toggle h2 { font-size: var(--fs-md); font-weight: 650; }
.section-toggle .chev { width: 16px; height: 16px; color: var(--faint); transition: transform .15s; flex: none; }
.section.collapsed .section-toggle .chev { transform: rotate(-90deg); }
.section-toggle .meta { color: var(--muted); font-size: var(--fs-sm); font-weight: 500; }
.section-body { padding: 18px; }
.section.collapsed .section-body { display: none; }
.section-body.flush { padding: 0; }

.info-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.info-cols h3 { font-size: var(--fs-sm); font-weight: 650; color: var(--muted); margin: 0 0 10px; }
.info-cols dl.facts { grid-template-columns: 110px 1fr; }

/* notes: the reading surface of the page */
.notes-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.notes-grid .stack-col { display: flex; flex-direction: column; gap: 16px; }
.note-box { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); display: flex; flex-direction: column; min-width: 0; }
.note-box > header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.note-box > header h3 { font-size: var(--fs-sm); font-weight: 650; margin: 0; }
.note-box > header span { font-size: var(--fs-xs); color: var(--faint); }
.note-text { padding: 14px 16px; font-size: 15px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 120px; }
.note-box.main .note-text { min-height: 260px; }
.note-text.empty-note { color: var(--faint); font-style: italic; }
.note-box textarea { border: 0; border-radius: 0 0 var(--r) var(--r); background: var(--surface); padding: 14px 16px; font-size: 15px; line-height: 1.65;
  min-height: 160px; resize: vertical; width: 100%; font-family: inherit; color: var(--text); }
.note-box.main textarea { min-height: 300px; }
.note-box textarea:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.field textarea.big { min-height: 220px; font-size: 15px; line-height: 1.6; }
.field textarea.medium { min-height: 130px; font-size: 15px; line-height: 1.6; }

/* activity notes */
.composer { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.composer textarea { width: 100%; min-height: 96px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r); font-size: 15px;
  line-height: 1.6; resize: vertical; background: var(--surface); }
.composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 16px 0; border-top: 1px solid var(--line); }
.activity .who { font-size: var(--fs-sm); color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.activity .who strong { color: var(--text); font-weight: 600; }
.activity .body { font-size: 15px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.activity li.flagged .body { border-left: 3px solid var(--st-progress); padding-left: 10px; }
.activity .row-actions { margin-left: auto; display: flex; gap: 4px; }

/* custom fields */
.cf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 24px; }
.cf-grid .cf label, .cf-grid .cf .label { display: block; font-size: var(--fs-xs); color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.cf-grid .cf .val { font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.cf-grid .cf .val.none { color: var(--faint); }
.cf-grid .cf.wide { grid-column: 1 / -1; }
.cf-group + .cf-group { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.cf-group h3 { font-size: var(--fs-sm); font-weight: 650; margin: 0 0 12px; }

/* photos */
.photo-group + .photo-group { margin-top: 22px; }
.photo-group h3 { font-size: var(--fs-sm); font-weight: 650; margin: 0 0 10px; display: flex; gap: 8px; align-items: center; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.photo { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface-2); display: flex; flex-direction: column; }
.photo a.img { display: block; aspect-ratio: 4 / 3; background: var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .cap { padding: 8px 10px; font-size: var(--fs-xs); color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 6px; min-height: 40px; }
.photo .cap span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropzone { border: 1.5px dashed var(--line-strong); border-radius: var(--r); padding: 18px; text-align: center; color: var(--muted); background: var(--surface-2); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

@media (max-width: 1100px) { .info-cols { grid-template-columns: 1fr 1fr; } }
@media (max-width: 960px) { .notes-grid { grid-template-columns: 1fr; } }
@media (max-width: 780px) {
  .info-cols { grid-template-columns: 1fr; }
  .record-head { top: 56px; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
