/* The portal. One stylesheet, no build. Colors are tokens on :root; dark mode follows the device. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --ink: #1c2330; --muted: #5d6778; --line: #d9dde5; --brand: #1f4e8c; --brand-ink: #ffffff; --brand-soft: #e6eef9;
  --ok: #1d7a46; --ok-soft: #e4f4ea; --warn: #8a5a00; --warn-soft: #fff3d6; --bad: #b3261e; --bad-soft: #fdeceb; --focus: #1f6fe0; --radius: 10px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.06);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151c; --surface: #1a212c; --ink: #e8ecf3; --muted: #9aa5b8; --line: #2d3748; --brand: #6aa3ee; --brand-ink: #0e1a2c; --brand-soft: #1e2d45;
    --ok: #5ac488; --ok-soft: #14301f; --warn: #e8b64c; --warn-soft: #342a0e; --bad: #f08a83; --bad-soft: #3a1917; --focus: #7db4ff; --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .2px; }
#nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#nav a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
#nav a:hover { background: var(--brand-soft); color: var(--ink); }
#nav a.on { background: var(--brand-soft); color: var(--brand); }
.who { color: var(--muted); font-size: 14px; }
.linkish { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

main { max-width: 860px; margin: 0 auto; padding: 24px 16px 120px; }
.page-head h1, main h1 { font-size: 26px; margin: 8px 0 12px; }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 15px; margin: 14px 0 4px; }
.lead { color: var(--muted); margin: 4px 0 16px; }
.loading { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 18px; box-shadow: var(--shadow); }
.narrow-card { max-width: 480px; margin: 40px auto; }
.fields { display: grid; gap: 20px; margin-top: 14px; }
.field label:not(.switch):not(.check) { display: block; font-weight: 600; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: 14px; margin-top: 4px; }
.hint.muted { font-style: italic; }
.hint.code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.live { color: var(--brand); font-size: 14px; margin-top: 4px; min-height: 1px; }
.warn { color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 0; font-size: 14px; margin-top: 6px; }
.warn:not(:empty) { padding: 6px 10px; }
.error { color: var(--bad); font-size: 14px; margin-top: 4px; font-weight: 500; }

input[type=text], input[type=email], input[type=number], input[type=password], select, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input[aria-invalid=true], textarea[aria-invalid=true] { border-color: var(--bad); background: var(--bad-soft); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
.money, .with-unit { display: flex; align-items: center; gap: 8px; max-width: 260px; }
.money .prefix, .with-unit .unit { color: var(--muted); }
.with-unit input, .money input { flex: 1; }

.switch-field .switch { display: flex; align-items: center; gap: 12px; font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 44px; height: 24px; border-radius: 12px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }
.switch-state { color: var(--muted); font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.check input { width: auto; }
.radios { border: 0; padding: 0; margin: 12px 0; }
.radios legend { font-weight: 600; padding: 0; }
.radios label { display: block; margin: 4px 0; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 500; }
.btn:hover:not(:disabled) { background: var(--brand-soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--brand); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-text { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 24px; display: flex; gap: 10px; align-items: center; z-index: 4; box-shadow: 0 -4px 14px rgba(20,30,50,.08); }
.savebar .bar-text { color: var(--muted); }

.notice { background: var(--brand-soft); border-radius: 8px; padding: 10px 14px; margin: 0 0 14px; }
.notice.error { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.whose { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.whose label { font-weight: 600; white-space: nowrap; }
.whose select { max-width: 320px; }

.grid { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
.grid th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.grid td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid .narrow { width: 90px; } .grid .center { text-align: center; }
.grid .hidden-row input[type=text] { opacity: .55; }
.grid input[type=checkbox] { width: 20px; height: 20px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.two-col { display: grid; grid-template-columns: 230px 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } .savebar { padding: 10px 14px; } .top { padding: 10px 14px; gap: 8px; } }
.picker { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.pick { width: 100%; text-align: left; font: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--ink); }
.pick.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.tag { margin-left: 8px; font-size: 12px; background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 1px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font: 12px ui-monospace, Consolas, monospace; background: var(--brand-soft); color: var(--brand); border: 0; border-radius: 6px; padding: 4px 8px; cursor: pointer; }
.chip:hover { filter: brightness(.95); }
.preview { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.result ul { margin: 4px 0 0 18px; padding: 0; }

#toasts { position: fixed; right: 16px; bottom: 76px; display: grid; gap: 8px; z-index: 30; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; }
.toast.error { background: var(--bad); color: #fff; }

.backdrop { position: fixed; inset: 0; background: rgba(10,15,25,.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dialog { background: var(--surface); border-radius: var(--radius); padding: 22px; max-width: 520px; width: 100%; box-shadow: var(--shadow); }
.dialog ul { padding-left: 20px; }
.dialog .actions { justify-content: flex-end; }

/* People, History, Outbox */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row input[type=search] { flex: 1; min-width: 220px; width: auto; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--surface); color: inherit; }
.strong { font-weight: 600; }
.results { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.badge { display: inline-block; font-size: 13px; font-weight: 600; border-radius: 12px; padding: 2px 10px; background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.plain { background: var(--line); color: var(--muted); }
.idbox { margin: 6px 0; min-height: 28px; } .idbox code { font-size: 18px; letter-spacing: 1px; background: var(--brand-soft); padding: 4px 10px; border-radius: 6px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.grid.history td, .grid.history th { font-size: 14px; }
.detail { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow: auto; font: 12.5px/1.4 ui-monospace, Consolas, monospace; white-space: pre-wrap; margin: 6px 0; }
.messages { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.messages li { border: 1px solid var(--line); border-radius: 8px; }
.msg-head { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; text-align: left; font: inherit; background: none; border: 0; padding: 10px 12px; cursor: pointer; color: inherit; }
.msg-body { padding: 0 12px 12px; }
main { max-width: 960px; }

/* Documents and Orders */
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.actions-cell .btn.small { white-space: nowrap; }
input.short { width: 110px; flex: none; }
.dialog .field { margin: 12px 0; }
.dialog textarea, .dialog input[type=text], .dialog input[type=number] { width: 100%; }

/* billing and operator screens */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.terms { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px 12px; margin: 8px 0; background: var(--bg); }

/* tags (People tab) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); border-radius: 12px; padding: 2px 4px 2px 10px; background: var(--surface); color: var(--ink, inherit); }
.chip.flag { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.chip-x { border: 0; background: transparent; font: inherit; font-size: 16px; line-height: 1; cursor: pointer; color: inherit; padding: 0 6px; border-radius: 8px; }
.chip-x:hover, .chip-x:focus-visible { background: rgba(0, 0, 0, .12); }
.tags-block .row input[type=text] { flex: 1; min-width: 200px; font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--surface); }
.subtabs { display: flex; gap: 6px; margin: 0 0 14px; flex-wrap: wrap; }
.subtabs .btn[aria-pressed="true"] { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
