:root {
  --bg: #EEF1EF; --surface: #FFFFFF; --ink: #1F2A2E; --muted: #5E6B6A; --line: #CBD3D0;
  --pine: #2F5D57; --pine-ink: #FFFFFF; --pine-soft: #DCE8E4;
  --needle: #B83A4B; --needle-soft: #F6E1E4; --amber: #9A6414; --amber-soft: #F6EAD3;
  --grey-soft: #E6E8E7; --code-bg: #F4F6F5;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141A1B; --surface: #1C2426; --ink: #E6ECEA; --muted: #9AA7A5; --line: #2E393B;
    --pine: #7FB5AA; --pine-ink: #0F1A18; --pine-soft: #22332F; --needle: #E07586; --needle-soft: #3A2127;
    --amber: #E0A94F; --amber-soft: #3A2F1B; --grey-soft: #262E30; --code-bg: #182022;
  }
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15.5px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--pine); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--pine); outline-offset: 2px; }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 28px; line-height: 1.15; margin: 0 0 4px; }
h2 { font-size: 20px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 22px 0 8px; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.mark { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.mark img { width: 28px; height: 28px; }
.wordmark { font: 600 20px/1 var(--serif); }
.agency { color: var(--pine); font: 700 17px/1.2 var(--sans); letter-spacing: -0.01em; }
.nav { margin-left: auto; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a, .nav button { text-decoration: none; color: var(--muted); font-weight: 600; font-size: 13.5px; padding: 7px 9px; border-radius: 8px; background: none; border: 0; cursor: pointer; white-space: nowrap; }
.nav a:hover, .nav button:hover, .nav a[aria-current="page"] { color: var(--ink); background: var(--grey-soft); }
@media (max-width: 720px) {
  .agency { font-size: 15.5px; }
  /* One scrollable row on phones, instead of three stacked rows of links. */
  .nav { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
}

.page { max-width: 1080px; margin: 0 auto; padding: 22px 20px 60px; }
.narrow { max-width: 640px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- flash ---------- */
.flash { border-radius: 10px; padding: 11px 14px; margin: 0 0 16px; font-size: 14.5px; }
.flash.ok { background: var(--pine-soft); color: var(--pine); }
.flash.error { background: var(--needle-soft); color: var(--needle); }

/* ---------- cards and lists ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.head-row { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: inline-grid; grid-auto-flow: column; gap: 4px; background: var(--grey-soft); border-radius: 10px; padding: 4px; }
.tabs a { text-decoration: none; padding: 7px 14px; border-radius: 7px; font-weight: 600; font-size: 14px; color: var(--muted); }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); }
.case-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.case-list li + li { border-top: 1px solid var(--line); }
.case-list a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 14px 18px; text-decoration: none; color: var(--ink); }
.case-list a:hover { background: var(--bg); }
.case-name { font-weight: 600; }
.case-meta { color: var(--muted); font-size: 13.5px; grid-column: 1 / -1; }
.empty { padding: 28px 18px; color: var(--muted); text-align: center; }
.chip { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--grey-soft); color: var(--muted); white-space: nowrap; align-self: start; }
.chip.active { background: var(--pine-soft); color: var(--pine); }
.chip.delayed { background: var(--amber-soft); color: var(--amber); }
.chip.done { background: var(--pine); color: var(--pine-ink); }
.chip.demo { background: var(--needle-soft); color: var(--needle); }

/* ---------- buttons and forms ---------- */
.btn { display: inline-block; border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; background: var(--pine); color: var(--pine-ink); cursor: pointer; text-decoration: none; font-size: 15px; }
.btn.plain { background: var(--grey-soft); color: var(--ink); }
.btn.warn { background: var(--needle); color: #fff; }
.primary { width: 100%; border: 0; border-radius: 12px; background: var(--pine); color: var(--pine-ink); padding: 16px 18px; text-align: left; min-height: 68px; cursor: pointer; }
.primary small { display: block; font-size: 12.5px; opacity: .85; margin-bottom: 2px; }
.primary strong { font-size: 18px; font-weight: 600; }
.primary:disabled { background: var(--grey-soft); color: var(--muted); cursor: default; }
.field { display: grid; gap: 5px; margin-bottom: 14px; align-content: start; }
.field label, .label { font-size: 13.5px; font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; background: var(--surface);
  width: 100%; align-self: start; font-size: 15.5px; line-height: 1.4;
}
.field input, .field select { height: 44px; }
.field textarea { min-height: 84px; resize: vertical; }
.field label, .field .label, .field label.small { line-height: 1.3; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 1px; }
.field > label + .hint, .field > .label + .hint { margin-top: -2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; align-items: start; }
.checks { display: flex; gap: 8px 20px; flex-wrap: wrap; align-items: center; }
.checks label { font-weight: 500; font-size: 15px; display: flex; gap: 8px; align-items: center; line-height: 1.2; }
input[type="checkbox"] { width: 17px; height: 17px; margin: 0; flex: none; accent-color: var(--pine); }
label.small { display: inline-flex; gap: 8px; align-items: center; line-height: 1.3; }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------- case page ---------- */
.case-grid { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .case-grid { grid-template-columns: 1fr; } }
.ids { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.actions { display: grid; gap: 8px; margin-top: 12px; }
details.act { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
details.act > summary { list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 600; font-size: 14.5px; }
details.act > summary::-webkit-details-marker { display: none; }
details.act[open] > summary { border-bottom: 1px solid var(--line); }
details.act.warn > summary { color: var(--needle); }
details.act .body { padding: 14px; }
.linkbox { margin-top: 16px; padding: 14px; border-radius: 10px; background: var(--code-bg); font-size: 13.5px; }
.linkbox input[readonly] { width: 100%; font: 12.5px var(--mono); padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin: 6px 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.fact { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.fact .l { color: var(--muted); font-size: 12.5px; }
.fact .v { font-weight: 600; margin-top: 2px; }
.log { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.log li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log .who { color: var(--muted); font-size: 12.5px; }

/* ---------- timeline ---------- */
.bearing { list-style: none; margin: 0; padding: 0; position: relative; }
.bearing::before { content: ""; position: absolute; left: 11px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.bearing li { position: relative; padding: 0 0 16px 38px; }
.bearing li:last-child { padding-bottom: 0; }
.bearing .dot { position: absolute; left: 4px; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line); }
.bearing li.done .dot { background: var(--pine); border-color: var(--pine); }
.bearing li.done::after { content: ""; position: absolute; left: 11px; top: 20px; bottom: 0; width: 2px; background: var(--pine); }
.bearing li.now .dot { border: 0; left: 0; top: 0; width: 24px; height: 24px; }
.bearing li.now .dot svg { width: 24px; height: 24px; display: block; }
.bearing li.held .ring { stroke: var(--amber); }
.bearing .t-name { font-weight: 600; }
.bearing li.todo .t-name { color: var(--muted); font-weight: 500; }
.bearing .t-time { color: var(--muted); font-size: 13px; }

/* ---------- partner view ---------- */
.from { color: var(--muted); font-size: 13.5px; }
.who-name { font: 600 30px/1.15 var(--serif); margin: 6px 0 4px; }
.status-line { font-size: 17px; max-width: 60ch; margin: 10px 0 0; }
.banner { margin-top: 16px; border-radius: 12px; padding: 13px 16px; font-size: 14.5px; }
.banner b { display: block; font-size: 15.5px; margin-bottom: 2px; }
.banner.delayed { background: var(--amber-soft); color: var(--amber); }
.banner.ruled { background: var(--grey-soft); color: var(--ink); }
.banner.done { background: var(--pine-soft); color: var(--pine); }
.banner.hold { background: var(--needle-soft); color: var(--needle); }
.window { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; align-items: center; }
.window svg { grid-row: 1 / span 2; width: 34px; height: 34px; }
.window .l { color: var(--muted); font-size: 13px; }
.window .v { font-size: 19px; font-weight: 600; }
.summary { border: 1px solid var(--pine); border-radius: 12px; padding: 14px 16px; background: var(--pine-soft); }
.summary p { margin: 4px 0 0; }
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { padding: 10px 0; border-top: 1px solid var(--line); }
.notes li:first-child { border-top: 0; padding-top: 0; }
.notes .t { color: var(--muted); font-size: 13px; }
.expiry { margin-top: 24px; color: var(--muted); font-size: 13px; }

/* ---------- small screens ---------- */
.min-wrap { min-height: 100%; display: grid; place-items: center; padding: 40px 16px; }
.min-card { width: 100%; max-width: 440px; }
.min-card .mark { margin-bottom: 18px; }

table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th { text-align: left; color: var(--muted); font-size: 12.5px; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); }
table.users td { padding: 10px 10px 10px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.scroll { overflow-x: auto; }

/* ---------- people ---------- */
.people { list-style: none; margin: 0; padding: 0; }
.people > li { border-top: 1px solid var(--line); padding: 12px 0; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.people > li:first-child { border-top: 0; padding-top: 0; }
.people .pn { font-weight: 600; }
.people .pa { color: var(--muted); font-size: 13px; }
.people .pr { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.people .pr span { font-size: 11.5px; font-weight: 600; background: var(--pine-soft); color: var(--pine); border-radius: 999px; padding: 1px 8px; }
.people .pr span.off { background: var(--grey-soft); color: var(--muted); }
.people .pb { display: flex; gap: 6px; align-items: start; }
.mini { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.mini:hover { border-color: var(--muted); }
details.inline { margin-top: 6px; }
details.inline > summary { cursor: pointer; color: var(--pine); font-size: 13px; }
details.inline form { margin-top: 8px; }
pre.mail-text { white-space: pre-wrap; word-break: break-word; background: var(--code-bg); border-radius: 10px; padding: 14px; font: 13.5px/1.55 var(--sans); }

/* ---------- tags ---------- */
.tagrow { display: grid; grid-template-columns: 112px 1fr; gap: 14px; align-items: start; margin-top: 8px; }
.tagrow .qr { width: 112px; height: 112px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #fff; }
.tagrow .qr svg { width: 100%; height: 100%; display: block; }
.code { font: 600 17px/1.2 var(--mono); letter-spacing: .04em; }
.fms-card { margin-top: 16px; border-radius: 12px; padding: 13px 16px; background: var(--code-bg); font-size: 14px; }
.fms-card .muted { font-size: 13px; }

/* ---------- dashboard and metrics ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .n { font: 600 26px/1.1 var(--serif); }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.stat.warn .n { color: var(--amber); }
.stat.crit .n { color: var(--needle); }
.dash-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.dash-row { display: grid; gap: 7px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; text-decoration: none; color: var(--ink); }
.dash-row:hover { border-color: var(--muted); }
.dash-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.clockbar { height: 6px; border-radius: 3px; background: var(--grey-soft); overflow: hidden; }
.clockbar i { display: block; height: 100%; background: var(--pine); }
.clockbar.warn i { background: var(--amber); }
.clockbar.crit i { background: var(--needle); }
.dash-line { font-size: 13px; color: var(--muted); }
.dash-line.wait { color: var(--amber); font-weight: 600; }
.dash-line.crit { color: var(--needle); font-weight: 600; }
.stages { display: grid; gap: 10px; margin-top: 20px; }
.stage-row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); }
.stage-row.here { border-color: var(--pine); background: var(--pine-soft); }
.stage-row.past { color: var(--muted); }
.stage-row .mk { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.stage-row.here .mk { background: var(--pine); }
.stage-row.past .mk { background: var(--pine); opacity: .5; }
