/* Phone first; wider layouts are added at 768px. Flat style: borders, not shadows (only floating things get one). */
:root {
  --bg: #f4f2ee; --surface: #ffffff; --ink: #1c2422; --muted: #5a6562; --line: #dedad1; --line-strong: #b9b4a8; --field-line: #857f71;
  --accent: #0f6b5f; --accent-hover: #0c594f; --accent-ink: #ffffff; --accent-soft: #e2f1ee;
  --danger: #b3261e; --danger-soft: #fbe9e7;
  --new: #1d5fa8; --new-bg: #e4eefa; --prog: #7a4f00; --prog-bg: #fbefd3; --done: #1c6b3a; --done-bg: #dff3e6;
  --arch: #555c5a; --arch-bg: #e9e9e6;
  --radius: 12px; --tabbar: 60px; --ease: 160ms ease;
  --float: 0 6px 20px rgb(20 30 28 / 22%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --surface: #1b2120; --ink: #e9eeec; --muted: #a3aeaa; --line: #2c3533; --line-strong: #4a5552; --field-line: #717d79;
    --accent: #3fb8a5; --accent-hover: #58c9b7; --accent-ink: #06211d; --accent-soft: #17332f;
    --danger: #ff8a80; --danger-soft: #3b1512;
    --new: #8fc0f5; --new-bg: #15293f; --prog: #f0c56a; --prog-bg: #3a2c0c; --done: #7fd59c; --done-bg: #143021;
    --arch: #a9b1ae; --arch-bg: #2a302f;
    --float: 0 6px 20px rgb(0 0 0 / 55%);
  }
}

* { box-sizing: border-box; }
/* scroll-padding keeps a focused control clear of the fixed tab bar (phones) and the sticky header (wide screens) */
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 1rem); }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 1rem; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; text-wrap: balance; overflow-wrap: anywhere; }
h1:focus { outline: none; }
h2 { font-size: 1.125rem; line-height: 1.3; margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
.icon { flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; display: block; }
.pad { padding: 3rem 1rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.link { color: var(--accent); font-weight: 600; background: none; border: 0; padding: .8rem 0; /* 44px tap height, also when inline */ font: inherit; font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }
.lead { margin-bottom: 1rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }

/* ---------------------------------------------------------------- controls */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-height: 48px; padding: .65rem .75rem; background: var(--surface); border: 1px solid var(--field-line); border-radius: 8px; /* 3:1 against the page: the border is what shows where to type */
  font-size: 1rem; /* 16px keeps iOS from zooming the page on focus */
  transition: border-color var(--ease);
}
textarea { resize: vertical; min-height: 5.5rem; }
::placeholder { color: var(--muted); opacity: 1; }
select { cursor: pointer; }
input:disabled, select:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
[aria-invalid="true"] { border-color: var(--danger) !important; border-width: 2px; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field > label, .label { font-size: .875rem; font-weight: 600; color: var(--muted); }
.req { color: var(--danger); }
.hint { font-size: .875rem; color: var(--muted); }
.error { font-size: .875rem; font-weight: 600; color: var(--danger); }
.draft-note { display: flex; align-items: center; justify-content: space-between; gap: .25rem 1rem; flex-wrap: wrap; padding: 0 1rem; border-radius: 8px; background: var(--accent-soft); font-size: .9375rem; }
.form-alert { padding: .75rem 1rem; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-weight: 600; border: 1px solid currentColor; }
.check { display: flex; gap: .65rem; align-items: center; min-height: 44px; cursor: pointer; }
.check input { width: 1.25rem; height: 1.25rem; flex-shrink: 0; accent-color: var(--accent); }
.check.inline { font-size: .875rem; color: var(--muted); }
.with-peek { position: relative; }
.with-peek input { padding-right: 3rem; }
.peek { position: absolute; right: 2px; top: 2px; bottom: 2px; width: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 6px; cursor: pointer; }
.peek[aria-pressed="true"] { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 48px; padding: .5rem 1.1rem;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); font-weight: 600; cursor: pointer; max-width: 100%; text-align: center; /* may wrap at very large text sizes rather than push the page sideways */
  transition: background-color var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
}
@media (hover: hover) { .btn:hover { border-color: var(--accent); } }
.btn:active { background: var(--accent-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover, .btn.primary:active { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.ghost { background: transparent; border-color: transparent; }
@media (hover: hover) { .btn.ghost:hover { background: var(--accent-soft); border-color: transparent; } }
.btn.danger-text { color: var(--danger); }
.btn.small { min-height: 44px; padding: .3rem .8rem; font-size: .875rem; }
.btn.wide { width: 100%; }
.btn.icon-btn { width: 48px; padding: 0; flex-shrink: 0; }
.btn:disabled, .btn.loading { opacity: .6; cursor: progress; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }
.form-actions { flex-direction: column; align-items: stretch; margin-top: .25rem; }
.card-actions { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.card-actions .btn, .quick .btn { flex: 1; }

.badge { display: inline-block; padding: .1rem .6rem; border-radius: 999px; font-size: .8125rem; font-weight: 700; white-space: nowrap; }
.st-new { color: var(--new); background: var(--new-bg); }
.st-in_progress { color: var(--prog); background: var(--prog-bg); }
.st-done { color: var(--done); background: var(--done-bg); }
.st-arch, .st-plain { color: var(--arch); background: var(--arch-bg); }
.count { font-size: .8125rem; font-weight: 700; color: var(--muted); margin-left: .4rem; }

.avatar { width: 2.25rem; height: 2.25rem; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: .95rem; }

.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.1rem; letter-spacing: -.01em; min-height: 44px; }
.mark { width: 26px; height: 26px; border-radius: 7px; background:
  linear-gradient(#fff, #fff) 7px 8px / 12px 2px no-repeat, linear-gradient(#fff, #fff) 7px 12px / 12px 2px no-repeat,
  linear-gradient(#fff, #fff) 7px 16px / 7px 2px no-repeat, #0f6b5f; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.segmented button { border: 0; background: var(--surface); padding: .4rem .9rem; font-size: .875rem; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 44px; transition: background-color var(--ease), color var(--ease); }
.segmented button.on { background: var(--accent-soft); color: var(--accent); }
.segmented button:focus-visible, .tabbar a:focus-visible, a.row:focus-visible, .more:focus-visible { outline-offset: -3px; } /* their containers clip an outer ring */

/* ------------------------------------------------------------ sign-in pages */
.auth { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }
.auth-top { width: 100%; max-width: 26rem; display: flex; justify-content: space-between; align-items: center; }
.auth-card { width: 100%; max-width: 26rem; margin: auto 0; display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; }
.code { font-size: 1.5rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------- shell */
.top { display: flex; align-items: center; padding: .5rem max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left)); padding-top: max(.5rem, env(safe-area-inset-top)); }
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); padding-inline: env(safe-area-inset-left) env(safe-area-inset-right);
}
.tabbar a { flex: 1; min-width: 0; height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem;
  font-size: .75rem; font-weight: 600; color: var(--muted); transition: color var(--ease); }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-inline: .25rem; }
.tabbar a.on { color: var(--accent); }
.tabbar a:active { background: var(--accent-soft); }
.page { max-width: 46rem; margin: 0 auto; padding: .75rem max(1rem, env(safe-area-inset-right)) calc(var(--tabbar) + env(safe-area-inset-bottom) + 6rem) max(1rem, env(safe-area-inset-left)); }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack .page-head { margin-bottom: 0; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; min-height: 44px; }
.fab { position: fixed; z-index: 9; right: max(1rem, env(safe-area-inset-right)); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 1rem);
  min-height: 52px; border-radius: 999px; padding-inline: 1.25rem; box-shadow: var(--float); }
.back { display: inline-flex; align-items: center; gap: .15rem; min-height: 44px; margin-left: -.25rem; color: var(--accent); font-weight: 600; }

.filters { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.search { position: relative; }
.search .icon { position: absolute; left: .8rem; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.search input { padding-left: 2.5rem; }
/* one swipeable line on phones instead of wrapping into three */
.chips { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; margin: -4px -1rem; padding: 4px 1rem; } /* the 4px leaves room for the focus ring */
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: .3rem; flex-shrink: 0; min-height: 44px; padding: .35rem .9rem; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); font-weight: 600; font-size: .875rem; color: var(--muted); cursor: pointer; transition: background-color var(--ease), color var(--ease), border-color var(--ease); }
.chip .count { margin-left: .1rem; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip.on .count { color: inherit; }
.chip.quiet { border-style: dashed; }

.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list:has(> .empty) { background: none; border: 0; }
.row { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; min-height: 64px; transition: background-color var(--ease); }
.row + .row { border-top: 1px solid var(--line); }
a.row:active { background: var(--accent-soft); }
@media (hover: hover) { a.row:hover { background: var(--accent-soft); } }
.row > .icon { color: var(--muted); }
.row.static { align-items: flex-start; }
.row.off .row-title { color: var(--muted); } /* dimmed by colour, not opacity, so the small text stays readable */
.row-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: .1rem; }
.row-title { display: flex; align-items: center; gap: .4rem .5rem; flex-wrap: wrap; }
.row-title strong { overflow-wrap: anywhere; }
.row-sub { color: var(--ink); font-size: .9375rem; overflow-wrap: anywhere; }
.row-meta { color: var(--muted); font-size: .8125rem; display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; margin-top: .25rem; }
.row-meta:not(:has(.badge)) { margin-top: 0; }
.more { border-top: 1px solid var(--line); border-radius: 0; color: var(--accent); }
.list + .form { margin-top: 1.5rem; }
.row-actions { margin-top: .5rem; }
.empty { text-align: center; padding: 3rem 1rem; border: 1px dashed var(--line-strong); border-radius: var(--radius); display: flex; flex-direction: column; align-items: center; gap: .75rem; }
.empty-title { font-weight: 700; font-size: 1.1rem; }

.form { display: flex; flex-direction: column; gap: 1rem; }
.grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.subform { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: .75rem 1rem 1rem; margin: 0; min-width: 0; }
.subform legend { font-weight: 700; font-size: .9375rem; padding: 0 .4rem; }

/* ------------------------------------------------------------------ records */
.detail-head { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.client-strip { display: flex; flex-wrap: wrap; gap: .5rem; align-items: stretch; margin-top: 1rem; }
.client-link { flex: 1 1 11rem; min-width: 0; display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; transition: background-color var(--ease), border-color var(--ease); }
.client-link:active { background: var(--accent-soft); border-color: var(--accent); }
@media (hover: hover) { .client-link:hover { background: var(--accent-soft); border-color: var(--accent); } }
.client-link > .icon { color: var(--muted); margin-left: auto; }
.client-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; overflow-wrap: anywhere; }
.client-strip .icon-btn { height: auto; color: var(--accent); flex-grow: 1; max-width: 100%; }
@media (min-width: 22rem) { .client-strip .icon-btn { flex-grow: 0; } }
.quick { margin-top: 1rem; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 1rem 0; padding: 1rem 0; border-block: 1px solid var(--line); }
.fact.wide { grid-column: 1 / -1; }
.fact dt { font-size: .875rem; font-weight: 600; color: var(--muted); margin-bottom: .2rem; }
.fact dd { margin: 0; overflow-wrap: anywhere; }
.status-select { width: auto; max-width: 100%; min-height: 44px; padding: .3rem 2rem .3rem .8rem; border-radius: 999px; font-weight: 700; border-color: currentColor; }
.request { margin-bottom: 1rem; }
.request p { margin-top: .25rem; }

.section { margin-top: 1.75rem; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: .75rem; min-height: 44px; }
.composer { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.25rem; }
.history summary { display: flex; align-items: center; min-height: 44px; font-weight: 700; font-size: 1.125rem; cursor: pointer; }
.history[open] summary { margin-bottom: .75rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.ev { position: relative; padding: 0 0 1.25rem 3rem; }
.ev::before { content: ""; position: absolute; left: 1.1rem; top: 2.4rem; bottom: .1rem; width: 2px; background: var(--line); }
.ev:last-child::before { display: none; }
.ev > .avatar { position: absolute; left: 0; top: 0; }
.ev-head { display: flex; flex-direction: column; min-height: 2.25rem; justify-content: center; line-height: 1.35; }
.ev-head time { font-size: .8125rem; }
.ev-body, .changes { margin: .5rem 0 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; }
.changes { list-style: none; font-size: .9375rem; }
.changes li { display: flex; flex-direction: column; overflow-wrap: anywhere; }
.changes li + li { margin-top: .5rem; }
.change-field { font-size: .8125rem; font-weight: 600; color: var(--muted); }
.from { color: var(--muted); text-decoration: line-through; }
/* record changes (registered, edited, archived) read as a quiet log line between the notes */
.ev-sys { padding-bottom: 1rem; }
.ev-sys > .avatar { left: .75rem; top: .4rem; width: .75rem; height: .75rem; font-size: 0; background: var(--line-strong); }
.ev-sys::before { top: 1.5rem; }
.ev-sys .ev-head { min-height: 0; font-size: .875rem; color: var(--muted); }
.ev-sys .ev-head strong { font-weight: 600; }
.ev-sys .changes { margin-top: .25rem; padding: 0; border: 0; background: none; font-size: .875rem; }
.ev-sys .changes li { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 .4rem; }
.ev-sys .changes li + li { margin-top: .15rem; }
.to { font-weight: 600; }

.notice { margin-bottom: 1rem; border-color: var(--accent); background: var(--accent-soft); display: flex; flex-direction: column; gap: .75rem; }
.copy { display: flex; gap: .5rem; }
.signout { color: var(--danger); }

/* ------------------------------------------------------------------ overlays */
dialog.sheet { border: 0; padding: 1.25rem; padding-bottom: max(1.25rem, env(safe-area-inset-bottom)); background: var(--surface); color: var(--ink);
  width: 100%; max-width: 100%; max-height: calc(100dvh - 1rem); overflow: auto; margin: auto 0 0; border-radius: 16px 16px 0 0; box-shadow: var(--float); }
dialog.sheet[open] { display: flex; flex-direction: column; gap: .75rem; }
dialog.sheet::backdrop { background: rgb(10 15 14 / 55%); }
dialog.sheet .actions { margin-top: .5rem; }
dialog.sheet .btn { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 5.25rem); translate: -50% .5rem; width: max-content; max-width: calc(100vw - 2rem);
  padding: .75rem 1.1rem; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity 200ms ease-out, translate 200ms ease-out; z-index: 30; box-shadow: var(--float); }
#toast.show { opacity: 1; translate: -50% 0; }
#toast.error { background: var(--danger); color: var(--surface); }

/* slow-network indicator; app.js only adds .busy after 150ms so fast loads never flash it */
body.busy::before { content: ""; position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 40; background: var(--accent); transform-origin: left; animation: load 1.2s ease-in-out infinite; }
@keyframes load { 0% { transform: scaleX(.05); } 50% { transform: scaleX(.7); } 100% { transform: scaleX(.05); translate: 100% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; }
  body.busy::before { animation: none; }
}

/* phones held sideways: little height, so the fixed bar gets slimmer and its labels sit beside the icons */
@media (max-width: 767px) and (max-height: 480px) {
  :root { --tabbar: 46px; }
  .tabbar a { flex-direction: row; gap: .4rem; }
  .fab { min-height: 44px; }
  .page { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 4.5rem); }
}

/* ------------------------------------------------------------- wider screens */
@media (min-width: 768px) {
  html { scroll-padding: 5rem 0 1rem; }
  h1 { font-size: 1.75rem; }
  .card { padding: 1.5rem; }
  .top { position: sticky; top: 0; z-index: 10; gap: 1.5rem; padding: .6rem max(1.5rem, env(safe-area-inset-right), calc((100vw - 60rem) / 2)) .6rem max(1.5rem, env(safe-area-inset-left), calc((100vw - 60rem) / 2)); background: var(--bg); border-bottom: 1px solid var(--line); }
  .tabbar { position: static; flex: 1; gap: .25rem; background: none; border: 0; padding: 0; }
  .tabbar a { flex: none; flex-direction: row; gap: .45rem; height: 44px; padding: 0 .85rem; border-radius: 8px; font-size: .9375rem; }
  .tabbar a:last-child { margin-left: auto; }
  .tabbar a.on { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
  .tabbar a:hover { color: var(--ink); }
  .page { max-width: 60rem; padding: 1.75rem max(1.5rem, env(safe-area-inset-right)) 4rem max(1.5rem, env(safe-area-inset-left)); }
  .fab { position: static; min-height: 48px; border-radius: 8px; box-shadow: none; }
  .filters { flex-direction: row; align-items: center; }
  .search { flex: 1; }
  .chips { margin: 0; padding: 0; overflow: visible; flex-wrap: wrap; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form { max-width: 44rem; }
  .form-actions { flex-direction: row; }
  .card-actions .btn, .quick .btn { flex: none; }
  .facts { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); }
  .fact.wide { grid-column: auto; }
  .ev-head { flex-direction: row; align-items: baseline; justify-content: flex-start; gap: .6rem; padding-top: .35rem; }
  .changes li { flex-direction: row; gap: .6rem; align-items: baseline; }
  .change-field { min-width: 9rem; }
  dialog.sheet { width: 26rem; margin: auto; border-radius: 16px; padding: 1.5rem; }
  dialog.sheet .btn { flex: none; }
  #toast { bottom: 1.5rem; }
}

/* demo build only */
.demo-bar { display: flex; align-items: center; justify-content: center; gap: .75rem; flex-wrap: wrap; padding: .4rem 1rem; padding-top: max(.4rem, env(safe-area-inset-top));
  background: var(--prog-bg); color: var(--prog); font-size: .875rem; font-weight: 600; text-align: center; }
.demo-bar button { min-height: 32px; padding: .15rem .7rem; border: 1px solid currentColor; border-radius: 999px; background: none; color: inherit; font: inherit; cursor: pointer; }
