/* Kinetic Utility, phone first (docs/DESIGN.md): pale ground, white cards,
   4px corners, 1px outlines, one blue for things you can press. Written for
   390px first; grows at 768px and 1000px. Fonts are local-only (no network). */
:root {
  color-scheme: light;
  --surface: #f8f9ff;
  --card: #ffffff;
  --ink: #0b1c30;
  --ink-soft: #45464d;
  --outline: #e2e8f0;
  --field: #6b7686;
  --press: #1d4ed8;
  --on-press: #ffffff;
  --error: #ba1a1a;
  --error-bg: #ffdad6;
  --ok: #15803d;
  --row-hover: #eff4ff;
  --waiting: #fcdeb5;
  --note: #e8edf7;
  --shade: rgba(11, 18, 32, 0.45);
  --font: Geist, Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --t-h1: 22px; --t-h2: 18px; --t-body: 16px; --t-small: 14px; --t-label: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --tap: 44px;
  --bar: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface: #0b1220; --card: #131b2e; --ink: #eaf1ff; --ink-soft: #9aa6bd;
    --outline: #26334d; --field: #6f7f9c; --press: #7aa5f5; --on-press: #0b1220;
    --error: #ffb4ab; --error-bg: #3b1a1a; --ok: #4ade80;
    --row-hover: #18223a; --waiting: #574425; --note: #1b2740;
    --shade: rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #0b1220; --card: #131b2e; --ink: #eaf1ff; --ink-soft: #9aa6bd;
  --outline: #26334d; --field: #6f7f9c; --press: #7aa5f5; --on-press: #0b1220;
  --error: #ffb4ab; --error-bg: #3b1a1a; --ok: #4ade80;
  --row-hover: #18223a; --waiting: #574425; --note: #1b2740;
  --shade: rgba(0, 0, 0, 0.6);
}

/* ---- base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: calc(var(--bar) + var(--s4)); }
body { margin: 0; background: var(--surface); color: var(--ink); font: var(--t-body)/1.5 var(--font); overflow-wrap: anywhere; }
a { color: var(--press); }
h1 { font-size: var(--t-h1); font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; margin: 0 0 var(--s3); }
h2 { font-size: var(--t-h2); font-weight: 600; line-height: 1.3; margin: var(--s5) 0 var(--s2); }
p { margin: 0 0 var(--s3); }
ul, ol { margin: 0 0 var(--s3); padding-left: var(--s5); }
li { margin-bottom: var(--s1); }
.label, .count { font: 500 var(--t-label)/1.4 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); }
.grow { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; top: var(--s2); z-index: 50; background: var(--card); padding: var(--s3) var(--s4); border: 1px solid var(--field); border-radius: 4px; }
.skip:focus { left: var(--s2); }
:focus-visible { outline: 3px solid var(--press); outline-offset: 2px; }
main:focus { outline: 0; }

/* ---- top bar and navigation ---- */
.top { display: flex; align-items: center; gap: var(--s2); min-height: 48px; padding: 0 var(--s4); background: var(--card); border-bottom: 1px solid var(--outline); }
.brand { font-weight: 600; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; display: inline-flex; align-items: center; min-height: var(--tap); padding-right: var(--s2); }
.tab { display: flex; align-items: center; justify-content: center; min-height: var(--bar); padding: 0 var(--s2); color: var(--press); text-decoration: none; font-size: var(--t-small); font-weight: 500; text-align: center; }
.tab[aria-current="page"] { color: var(--ink); font-weight: 700; box-shadow: inset 0 3px 0 var(--press); }
/* Phone: the main places are a bar along the bottom edge, under the thumb. */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--card); border-top: 1px solid var(--outline); padding-bottom: env(safe-area-inset-bottom, 0px); }
.wide-only { display: none; }
.has-bar .foot { padding-bottom: calc(var(--bar) + var(--s5) + env(safe-area-inset-bottom, 0px)); }
main { max-width: 1040px; margin: 0 auto; padding: var(--s4) var(--s4) var(--s6); }
.foot { max-width: 1040px; margin: 0 auto; padding: 0 var(--s2) var(--s5); color: var(--ink-soft); font-size: var(--t-small); display: flex; flex-wrap: wrap; gap: 0 var(--s1); }
.foot a { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); min-width: var(--tap); padding: 0 var(--s2); }

/* ---- sheets: Later, More, Wrong pile, the bar's More ---- */
details.sheet { position: relative; }
details.sheet > summary { list-style: none; cursor: pointer; }
details.sheet > summary::-webkit-details-marker { display: none; }
details.sheet[open] > summary::before { content: ""; position: fixed; inset: 0; z-index: 30; background: var(--shade); cursor: default; }
details.sheet > .panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; display: grid; gap: var(--s2); max-height: 80vh; overflow-y: auto;
  padding: var(--s4) var(--s4) calc(var(--s4) + env(safe-area-inset-bottom, 0px)); background: var(--card); color: var(--ink);
  border-top: 1px solid var(--field); border-radius: 12px 12px 0 0; text-align: left; font-size: var(--t-body); font-weight: 400; }
details.sheet > .panel form { display: grid; gap: var(--s2); margin: 0; }
details.sheet > .panel a, details.sheet > .panel button { width: 100%; justify-content: flex-start; }
details.sheet > .panel a { display: flex; align-items: center; min-height: var(--tap); padding: 0 var(--s4); text-decoration: none; font-weight: 500; }
details.sheet > .panel a[aria-current="page"] { color: var(--ink); font-weight: 700; }
details.sheet > .panel p { margin: 0; }
details.sheet > .panel label { margin-top: var(--s2); }
/* The bar's own sheet sits above the bar, so a second press on More never lands on Log out. */
details.tab-more > .panel { bottom: calc(var(--bar) + 1px + env(safe-area-inset-bottom, 0px)); border-radius: 12px 12px 0 0; border-bottom: 1px solid var(--outline); }
.panel .account { padding: var(--s2) var(--s4); text-transform: none; letter-spacing: 0; }
@media (prefers-reduced-motion: no-preference) {
  details.sheet[open] > .panel { animation: rise 160ms ease-out; }
  @keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* ---- cards and text blocks ---- */
.card { background: var(--card); border: 1px solid var(--outline); border-radius: 4px; padding: var(--s4); margin-bottom: var(--s4); }
.card > :last-child, .card form > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.card.narrow.wide { max-width: 720px; }
.card.alert { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.card.alert a { color: inherit; font-weight: 600; }
.card.note { background: var(--note); border-color: transparent; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); }
.card.note > span { flex: 1 1 200px; }
.card.draft { background: var(--waiting); border-color: transparent; }
.head { display: flex; align-items: center; gap: var(--s2) var(--s3); margin-bottom: var(--s2); flex-wrap: wrap; }
.head h1, .head h2 { margin: 0; }
.inline { display: inline; margin: 0; }
.hint { color: var(--ink-soft); font-size: var(--t-small); }
input + .hint, select + .hint, textarea + .hint, .two + .hint { margin-top: 6px; }
form + .hint { margin-top: var(--s3); }
.hint.ok { color: var(--ok); }
.error, .hint.error { color: var(--error); }
.empty, .quiet { color: var(--ink-soft); }
hr { border: 0; border-top: 1px solid var(--outline); margin: var(--s5) 0; }
section { margin-bottom: var(--s5); }
section > h2 { display: flex; gap: var(--s2); align-items: baseline; margin: 0 0 var(--s2); }
.legal { max-width: 720px; }
kbd { font: 500 var(--t-label) var(--mono); border: 1px solid var(--field); border-radius: 4px; padding: 1px 5px; }
code { font-family: var(--mono); }

/* ---- forms ---- */
label { display: block; margin: var(--s4) 0 6px; font-size: var(--t-small); font-weight: 600; color: var(--ink); }
input, select, textarea { width: 100%; min-height: var(--tap); padding: var(--s2) var(--s3); border: 1px solid var(--field); border-radius: 4px; background: var(--card); color: var(--ink); font: var(--t-body)/1.5 var(--font); }
textarea { display: block; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0; flex: none; accent-color: var(--press); }
input[type="file"] { padding: var(--s2); }
label.check { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); margin: var(--s1) 0; font-size: var(--t-body); font-weight: 400; }
fieldset { border: 1px solid var(--outline); border-radius: 4px; margin: var(--s3) 0; padding: var(--s2) var(--s3); min-width: 0; }
legend { font-size: var(--t-small); font-weight: 600; padding: 0 var(--s1); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) 88px; gap: var(--s3); align-items: end; }
.short { max-width: 120px; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 var(--s4); border: 1px solid var(--field); border-radius: 4px; background: var(--card); color: var(--ink); font: 500 var(--t-body)/1.2 var(--font); cursor: pointer; text-decoration: none; text-align: center; }
button.primary, .button.primary { background: var(--press); border-color: var(--press); color: var(--on-press); }
button.danger { color: var(--error); border-color: var(--error); }
button.ghost, .button.ghost { border-color: transparent; background: transparent; color: var(--press); }
button:disabled { opacity: 1; background: var(--outline); border-color: var(--outline); color: var(--ink-soft); cursor: not-allowed; }
.actions { display: flex; gap: var(--s3); align-items: center; margin-top: var(--s4); flex-wrap: wrap; }
.actions > * { flex: 1 1 100%; }
.actions > a:not(.button) { display: flex; align-items: center; justify-content: center; min-height: var(--tap); }
.actions > label { margin: 0; }
.card form > button, .card > p > .button { width: 100%; margin-top: var(--s3); }
.card > p > .button + .button { margin-top: var(--s2); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-top: var(--s3); }
.pair > *, .pair button { width: 100%; }
.pair form { margin: 0; }
.card .pair form > button { margin-top: 0; }
/* The buttons of a long page stay above the bottom bar, under the thumb. */
.actions.stick { position: sticky; bottom: calc(var(--bar) + 1px + env(safe-area-inset-bottom, 0px)); z-index: 10; background: var(--card); margin: var(--s4) calc(-1 * var(--s4)) calc(-1 * var(--s4)); padding: var(--s3) var(--s4); border-top: 1px solid var(--outline); flex-wrap: nowrap; }
.actions.stick > * { flex: 1 1 0; }
body:not(.has-bar) .actions.stick { bottom: 0; }
.big { min-height: 56px; font-size: 18px; }

/* ---- rows: a person, a pile item ---- */
.rows { list-style: none; margin: 0 0 var(--s3); padding: 0; background: var(--card); border: 1px solid var(--outline); border-radius: 4px; }
.row { display: grid; gap: var(--s1) var(--s3); align-items: center; margin: 0; padding: var(--s3); border-bottom: 1px solid var(--outline);
  grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "who age" "subj subj" "box box" "acts acts"; }
.row:last-child { border-bottom: 0; }
.row .who { grid-area: who; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who .addr { font-size: var(--t-small); color: var(--ink-soft); margin-left: var(--s1); }
.row .age { grid-area: age; white-space: nowrap; }
.row .subj { grid-area: subj; display: flex; align-items: center; min-height: var(--tap); }
.row .subj > span { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.row .box { grid-area: box; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .acts { grid-area: acts; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: var(--s2); margin-top: var(--s2); }
.row .acts.one { grid-template-columns: minmax(0, 1fr); }
.row .acts form { display: block; margin: 0; }
.row .acts > *, .row .acts > form > button, .row .acts summary { width: 100%; }
.row .acts button, .row .acts .button { padding: 0 var(--s2); }
.row:focus { outline: 0; }
.row.current { outline: 3px solid var(--press); outline-offset: -3px; }
.dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: transparent; vertical-align: middle; }
.unread .dot { background: var(--press); }
.unread .subj { font-weight: 600; }
.row.kv { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: none; }
.row.plain { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
.pill { display: inline-flex; align-items: center; font: 500 var(--t-label)/1 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; padding: var(--s1) 6px; border: 1px solid var(--outline); border-radius: 4px; color: var(--ink-soft); white-space: nowrap; }
.piles { display: flex; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s4); }
.piles .pill { min-height: var(--tap); padding: 0 var(--s3); text-decoration: none; color: var(--press); border-color: var(--field); background: var(--card); }
.keys-hint, .help { display: none; }
pre.quote, p.quote { white-space: pre-wrap; overflow-wrap: anywhere; font: var(--t-body)/1.5 var(--font); border-left: 3px solid var(--outline); padding: var(--s1) var(--s3); margin: var(--s3) 0; }
details.fold > summary { cursor: pointer; color: var(--press); min-height: var(--tap); display: flex; align-items: center; font-weight: 500; }
details.fold > summary::before { content: "+"; display: inline-block; width: 1.2em; font-family: var(--mono); }
details.fold[open] > summary::before { content: "-"; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary { list-style: none; }
.to-line { margin-bottom: var(--s1); }

/* ---- connect, help ---- */
.steps { padding-left: var(--s5); }
.steps li { margin-bottom: var(--s2); }
.providers { list-style: none; padding: 0; display: grid; gap: var(--s2); }
.providers li { margin: 0; }
.providers .button { display: flex; justify-content: flex-start; }
.links { list-style: none; padding: 0; }
.links a { display: flex; align-items: center; min-height: var(--tap); }

/* ---- tables (admin): one small card per line on a phone ---- */
table.plain { width: 100%; border-collapse: collapse; }
table.plain thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
table.plain tr { display: block; background: var(--card); border: 1px solid var(--outline); border-radius: 4px; padding: var(--s2) var(--s3); margin-bottom: var(--s2); }
table.plain td { display: flex; justify-content: space-between; gap: var(--s3); padding: 2px 0; text-align: right; }
table.plain td::before { content: attr(data-th); color: var(--ink-soft); font-size: var(--t-small); text-align: left; }

/* ---- demo banner, feedback ---- */
.demo-banner { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); align-items: center; justify-content: center; padding: var(--s2) var(--s4); background: var(--note); color: var(--ink); border-bottom: 1px solid var(--outline); font-size: var(--t-small); }
.feedback-fab { display: none; }

/* ================= 768px and up: tablet ================= */
@media (min-width: 768px) {
  :root { --t-h1: 26px; }
  .top { padding: 0 var(--s5); gap: var(--s4); }
  .tabs { position: static; flex: 1; display: flex; align-items: center; gap: var(--s1); background: none; border: 0; padding: 0; z-index: auto; }
  .tab { min-height: var(--tap); padding: 0 var(--s3); font-size: var(--t-body); }
  .tab[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--press); }
  .wide-only { display: flex; }
  .narrow-only { display: none !important; }
  .tab-more { margin-left: auto; }
  html { scroll-padding-bottom: 0; }
  .has-bar .foot { padding-bottom: var(--s6); }
  main { padding: var(--s5) var(--s5) var(--s7); }
  .foot { padding: 0 var(--s4) var(--s6); }
  .card { padding: var(--s5); }
  .card.narrow { margin-top: var(--s6); }
  details.sheet[open] > summary::before { background: transparent; }
  details.sheet > .panel { position: absolute; left: auto; right: 0; top: calc(100% + var(--s1)); bottom: auto; width: max-content; min-width: 240px; max-width: 320px; max-height: none;
    padding: var(--s3); border: 1px solid var(--field); border-radius: 4px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); animation: none; }
  details.tab-more > .panel { bottom: auto; border-radius: 4px; border-bottom: 1px solid var(--field); }
  .actions > * { flex: 0 0 auto; }
  .actions > input { flex: 0 1 240px; }
  .card form > button, .card > p > .button { width: auto; }
  .pair { display: flex; margin-top: 0; }
  .pair > *, .pair button { width: auto; }
  .actions.stick { position: static; margin: var(--s4) 0 0; padding: 0; border: 0; flex-wrap: wrap; }
  .actions.stick > * { flex: 0 0 auto; }
  .row .acts { display: flex; justify-content: flex-end; }
  .row .acts > *, .row .acts > form > button, .row .acts summary { width: auto; }
  .row .acts button, .row .acts .button { padding: 0 var(--s4); }
  .row.four { grid-template-columns: 1fr 1fr 1fr 2fr; grid-template-areas: none; }
  .feedback-fab { position: fixed; right: var(--s4); bottom: var(--s4); z-index: 5; display: inline-flex; align-items: center; min-height: var(--tap); padding: 0 var(--s4);
    border-radius: 999px; background: var(--card); border: 1px solid var(--field); color: var(--press); font-weight: 500; text-decoration: none; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15); }
  table.plain { background: var(--card); border: 1px solid var(--outline); }
  table.plain thead { position: static; width: auto; height: auto; clip: auto; }
  table.plain tr { display: table-row; border: 0; padding: 0; margin: 0; }
  table.plain th, table.plain td { display: table-cell; text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--outline); }
  table.plain td::before { content: none; }
  table.plain th { font: 500 var(--t-label)/1.4 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); }
}

/* ================= 1000px and up: desktop ================= */
@media (min-width: 1000px) {
  .row { grid-template-columns: minmax(0, 1.6fr) minmax(0, 2fr) minmax(0, auto) auto auto; grid-template-areas: "who subj box age acts"; gap: var(--s3); padding: var(--s2) var(--s3); }
  .row:hover { background: var(--row-hover); }
  .row .subj > span { display: block; white-space: nowrap; text-overflow: ellipsis; }
  .row .subj { min-width: 0; }
  .row .box { max-width: 140px; }
  .row .acts { margin-top: 0; }
}
/* Keys are for a real keyboard: shown where there is a fine pointer and room. */
@media (min-width: 1000px) and (hover: hover) {
  .keys-hint { display: block; }
  .help { display: block; position: fixed; left: var(--s4); bottom: var(--s4); max-width: 260px; z-index: 6; }
  .help[hidden] { display: none; }
}
