:root {
  --bg: #f6f5f2; --card: #fff; --text: #1f2328; --muted: #646a73; --line: #e3e1dc;
  --accent: #6b3fa0; --accent-ink: #fff;
  --red: #b42318; --red-bg: #fdecea; --amber: #9a5b00; --amber-bg: #fff4dc;
  --green: #1a7f37; --green-bg: #e6f4ea; --blue: #1f5fbf; --blue-bg: #e7efff;
  --purple: #6b3fa0; --purple-bg: #f1eafb; --grey-bg: #eeedea; --teal: #0f6e6e; --teal-bg: #e0f3f2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b; --card: #212226; --text: #e8e6e3; --muted: #a0a4ab; --line: #34363b;
    --accent: #a77de0; --accent-ink: #17181b;
    --red: #ff8a80; --red-bg: #3b1d1b; --amber: #f4c06a; --amber-bg: #3a2c10; --green: #7ee2a0; --green-bg: #173322;
    --blue: #8fb6ff; --blue-bg: #1b2840; --purple: #c9a8f2; --purple-bg: #2c2140; --grey-bg: #2c2d31; --teal: #7fd6d2; --teal-bg: #133331;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
header.top { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
header.top .bar, header.top .tabs { max-width: 980px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
header.top .bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; text-decoration: none; color: var(--text); }
.brand img { border-radius: 7px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs.more-right { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; white-space: nowrap; padding: 6px 12px; border-radius: 999px; text-decoration: none; font-weight: 500; }
.tabs a:hover { background: var(--grey-bg); }
.tabs a[aria-current] { background: var(--accent); color: var(--accent-ink); }
.tabs a[aria-current] .badge { background: var(--accent-ink); color: var(--accent); }
.logout { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); min-width: 0; }
.logout .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-only { display: none; }
.appicon { display: block; border-radius: 16px; margin-bottom: 8px; }
main { max-width: 980px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
h1 { font-size: 1.6rem; margin: 0.5rem 0; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.5rem; }
.muted { color: var(--muted); } .small { font-size: 0.875rem; } .big { font-size: 1.15rem; } .red { color: var(--red); }
.warn { color: var(--amber); font-weight: 600; }
.testbanner { background: var(--amber-bg); color: var(--amber); text-align: center; padding: 6px 16px; font-weight: 600; font-size: 14px; }
.badge { display: inline-block; min-width: 1.5em; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 12px; text-align: center; font-weight: 700; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.card.narrow { max-width: 420px; margin: 10vh auto; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--green-bg); color: var(--green); } .flash.error { background: var(--red-bg); color: var(--red); }
.alerts { display: grid; gap: 8px; margin-bottom: 16px; }
.alert { display: flex; justify-content: space-between; gap: 16px; padding: 12px 14px; border-radius: 10px; border-left: 4px solid; background: var(--card); }
.alert.urgent { border-color: var(--red); background: var(--red-bg); } .alert.warning { border-color: var(--amber); background: var(--amber-bg); } .alert.info { border-color: var(--blue); background: var(--blue-bg); }
.alert .actions { display: flex; gap: 12px; align-items: baseline; white-space: nowrap; }
.alert .actions form { margin: 0; }
.alert .actions button.link { padding: 0; min-height: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; color: var(--text); text-decoration: none; }
.tile .num { font-size: 2rem; font-weight: 700; } .tile .num.small { font-size: 1.1rem; padding: 0.6rem 0; }
.tile.warn { border-color: var(--amber); background: var(--amber-bg); }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list thead th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--grey-bg); white-space: nowrap; }
.tag.red { background: var(--red-bg); color: var(--red); } .tag.amber { background: var(--amber-bg); color: var(--amber); }
.tag.green { background: var(--green-bg); color: var(--green); } .tag.blue { background: var(--blue-bg); color: var(--blue); }
.tag.purple { background: var(--purple-bg); color: var(--purple); } .tag.teal { background: var(--teal-bg); color: var(--teal); }
.callout { padding: 12px 14px; border-radius: 10px; margin: 12px 0; }
.callout.purple { background: var(--purple-bg); } .callout.red { background: var(--red-bg); } .callout.grey { background: var(--grey-bg); }
.stack { display: grid; gap: 10px; } .row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 8px 0; }
.row.secondary { justify-content: space-between; margin-top: 16px; }
form.inline { display: inline-block; margin: 8px 8px 0 0; }
label { font-weight: 600; } label.check { display: flex; gap: 8px; font-weight: 400; margin-top: 8px; }
textarea, input, select { width: 100%; font: inherit; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
label.check input { width: auto; }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.big { width: 100%; padding: 12px; }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; }
button.link.danger { color: var(--red); }
blockquote { margin: 8px 0; padding: 12px; background: var(--bg); border-radius: 8px; white-space: pre-wrap; }
pre { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; font-size: 13px; }
details.email { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }
.pager { display: flex; justify-content: space-between; }
body.login main { padding: 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters a { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); text-decoration: none; background: var(--card); }
.filters a.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.filters a.on .muted { color: inherit; }
table.messages td.msg { white-space: pre-wrap; max-width: 420px; }

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 1.4rem; }
  .testbanner { font-size: 13px; padding: 4px 12px; }
  .logout .who { display: none; }
  .m-only { display: inline; }
  .d-only { display: none; }
  .card { padding: 16px; border-radius: 14px; }
  .card.narrow { margin: 8vh auto; }

  /* Dashboard tiles: two per row, the "to write" tile full width */
  .tiles { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tiles .tile:first-child { grid-column: 1 / -1; }
  .tile { padding: 12px 14px; }
  .tile .num { font-size: 1.6rem; line-height: 1.2; }
  .tile .num.small { font-size: 1rem; padding: 0.3rem 0; }

  .alert { flex-direction: column; gap: 6px; }
  .alert .actions { gap: 16px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
  .filters::-webkit-scrollbar { display: none; }
  .filters a { flex: none; white-space: nowrap; }

  /* Big, easy-to-tap buttons */
  button { min-height: 44px; }
  button.link { min-height: 0; padding: 8px 0; }
  .actions-row { flex-direction: column; align-items: stretch; }
  .actions-row form, .actions-row button { width: 100%; }
  form.stack .row button.primary { width: 100%; }
  .row.secondary { flex-direction: column; align-items: flex-start; gap: 4px; }
  .callout form.inline { display: block; margin: 8px 0 0; }
  .callout form.inline button { width: 100%; }

  /* Tables become cards; tapping a card opens it */
  table.list, table.list tbody { display: block; border: none; background: none; border-radius: 0; }
  table.list thead { display: none; }
  table.list tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; position: relative;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
  table.list td, table.list th { display: block; border: none; padding: 0; }
  table.list .c-name { order: 1; flex: 1 1 calc(100% - 70px); font-weight: 600; }
  table.list .c-act { order: 2; margin-left: auto; font-weight: 600; }
  table.list .c-act a { text-decoration: none; }
  table.list .c-act a::after { content: ""; position: absolute; inset: 0; border-radius: 12px; }
  table.list .c-date { order: 3; color: var(--muted); font-size: 0.9rem; }
  table.list .c-age { order: 4; color: var(--muted); font-size: 0.9rem; }
  table.list .c-age::before { content: "· "; }
  table.list .c-age:empty { display: none; }
  table.list .c-status { order: 5; margin-left: auto; }
  table.list tr:active { background: var(--grey-bg); }
  table.messages .c-status { flex-basis: 100%; margin-left: 0; }
  table.messages .c-msg { order: 6; flex-basis: 100%; max-width: none; background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 4px; }

  /* Admin: settings as label/value, activity log as compact cards */
  /* Settings and activity log: one card with dividers rather than a card per row */
  table.kv tbody, table.log tbody { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  table.kv tr, table.log tr { display: block; margin: 0; border: none; border-radius: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; }
  table.kv tr:last-child, table.log tr:last-child { border-bottom: none; }
  table.log tr { display: flex; }
  table.kv th { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
  table.log tr { gap: 2px 8px; }
  table.log td { font-size: 0.85rem; }
  table.log .c-when, table.log .c-who { color: var(--muted); }
  table.log .c-what { flex-basis: 100%; font-weight: 600; }
  table.log .c-details { flex-basis: 100%; overflow-wrap: anywhere; }
  pre, .flash, details.email { overflow-wrap: anywhere; }
}
