/* Orotron Status — orotron.com brand: Work Sans, red #FF0000 + blue #0674B7 on clean white.
   Light is the default; dark is optional (toggle). Mobile-first: bottom tabs + quick-add FAB on phones. */
:root,
:root[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f3f6f9;
  --hover: #f7f9fc;
  --border: #e2e7ee;
  --border-strong: #cfd7e2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px -12px rgba(16, 24, 40, .25);
  --topbar: rgba(255, 255, 255, .92);
  --field: #ffffff;
  --line: #edf0f4;
  --text: #1c2433;
  --muted: #5f6c80;
  --primary: #0674b7;
  --primary-hover: #055f96;
  --primary-text: #ffffff;
  --primary-soft: #e6f2fa;
  --brand-red: #ff0000;
  --accent: #0674b7;
  --meter: linear-gradient(90deg, #0674b7, #2b9be0);
  --focus: rgba(6, 116, 183, .35);
  --gray-bg: #eef1f5;   --gray-fg: #4a5568;
  --blue-bg: #e6f2fa;   --blue-fg: #0561a0;
  --amber-bg: #fff3dc;  --amber-fg: #955800;
  --red-bg: #ffe8e6;    --red-fg: #c81e1e;
  --green-bg: #e1f5ea;  --green-fg: #0d7a45;
  --purple-bg: #efe9ff; --purple-fg: #6a3fc4;
  --backdrop: rgba(15, 23, 42, .4);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a1120;
  --surface: #111a2c;
  --surface-2: #17223a;
  --hover: #162137;
  --border: #223049;
  --border-strong: #2e3f5e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7);
  --topbar: rgba(10, 17, 32, .92);
  --field: #0e1627;
  --line: #1c2840;
  --text: #e7ecf4;
  --muted: #95a3ba;
  --primary: #3aa3e8;
  --primary-hover: #5bb4ee;
  --primary-text: #041320;
  --primary-soft: rgba(58, 163, 232, .15);
  --brand-red: #ff4d4d;
  --accent: #3aa3e8;
  --meter: linear-gradient(90deg, #1f8fd6, #5bc0ff);
  --focus: rgba(58, 163, 232, .45);
  --gray-bg: rgba(255, 255, 255, .08); --gray-fg: #c3ccda;
  --blue-bg: rgba(58, 163, 232, .16);  --blue-fg: #8ccaf5;
  --amber-bg: rgba(245, 180, 60, .16); --amber-fg: #f5c877;
  --red-bg: rgba(255, 90, 80, .16);    --red-fg: #ff9a92;
  --green-bg: rgba(52, 211, 153, .15); --green-fg: #74e0b2;
  --purple-bg: rgba(167, 139, 250, .16); --purple-fg: #c7b3ff;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
:root { --radius: 14px; --radius-sm: 10px; --tabbar-h: 0px; --safe-b: env(safe-area-inset-bottom, 0px); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 14.5px/1.55 "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  #view > * { animation: rise .3s ease both; }
}
@keyframes rise { from { opacity: 0; transform: translateY(5px); } }

[hidden] { display: none !important; }
a { color: var(--primary); text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--red-fg); margin: 0; font-size: 13px; }
.plain { text-decoration: none; color: inherit; }
::selection { background: var(--focus); }

/* ---------- Surfaces ---------- */
.glass, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Buttons / inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; min-height: 36px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--red-fg); }
.btn-success { background: var(--green-bg); border-color: transparent; color: var(--green-fg); font-weight: 600; }
.btn-success:hover { background: var(--green-bg); filter: brightness(.97); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn-block { width: 100%; padding: 11px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; padding: 8px; border-radius: 9px; display: inline-grid; place-items: center; min-width: 36px; min-height: 36px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--field);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 11px; min-height: 40px;
}
select option { background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.btn:focus-visible, .chip:focus-visible, .pcard:focus-visible, .tcard:focus-visible, .tabs a:focus-visible, .fab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
textarea { resize: vertical; min-height: 84px; }
label { display: grid; gap: 6px; font-weight: 500; font-size: 13px; }
input[type="color"] { padding: 3px; height: 40px; }
input[type="range"] { padding: 0; min-height: 28px; border: 0; box-shadow: none; accent-color: var(--primary); background: transparent; }
.inline-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; cursor: pointer; min-height: 36px; }
.inline-check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 15% 0%, rgba(255, 0, 0, .06), transparent 50%), radial-gradient(ellipse at 90% 100%, rgba(6, 116, 183, .1), transparent 55%); }
.login-card { width: 100%; max-width: 400px; padding: 34px 28px 28px; display: grid; gap: 20px; position: relative; text-align: center; }
.login-card label { text-align: left; }
.login-wordmark { height: 34px; justify-self: center; }
.login-title { font-size: 20px; }
.login-card p { margin: 4px 0 0; }
.login-theme { position: absolute; top: 8px; right: 8px; }
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 46px; }
.pw-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--topbar);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
/* Brand stripe: red → blue, like the logo. */
.topbar::before { content: ""; display: block; height: 3px; background: linear-gradient(90deg, #ff0000 0 45%, #0674b7 45% 100%); }
.topbar-inner, .toolbar-inner, .main, .footer { max-width: 1280px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.topbar-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex: none; }
.brand-wordmark { height: 22px; display: block; }
.brand-sub { font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding-left: 10px; border-left: 1px solid var(--border-strong); }
.tabs { display: flex; gap: 2px; flex: 1; padding: 4px; }
.tabs a { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; color: var(--muted); font-weight: 500; padding: 7px 13px; border-radius: 10px; white-space: nowrap; transition: color .15s, background .15s; }
.tabs a svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.role-badge { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 99px; padding: 3px 10px; background: var(--surface-2); white-space: nowrap; }
:root[data-theme="dark"] .brand-wordmark, :root[data-theme="dark"] .login-wordmark { filter: brightness(1.3) saturate(1.1); }

.toolbar-inner { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding-top: 14px; padding-bottom: 4px; flex-wrap: wrap; }
.toolbar-inner:has(> .chips:empty):has(> .toolbar-actions:empty) { display: none; }
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px;
  padding: 5px 13px; font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; transition: background .15s, border-color .15s; min-height: 32px;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; font: inherit; font-size: 13px; cursor: pointer; min-height: 32px; }
.seg button.active { background: var(--primary); color: var(--primary-text); font-weight: 600; }

.main { padding-top: 18px; padding-bottom: 40px; }
.footer { padding-bottom: 28px; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 980px) {
  .brand-sub, .role-badge { display: none; }
  .topbar-inner { gap: 12px; }
}

/* ---------- Layout ---------- */
.section { margin-bottom: 20px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.section-title h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-pad { padding: 16px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: minmax(0, 1fr); } }

/* KPI strip */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { padding: 14px 16px; display: grid; gap: 4px; text-decoration: none; color: var(--text); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); opacity: .6; }
.kpi.bad::before { background: var(--red-fg); opacity: 1; }
.kpi.good::before { background: var(--green-fg); opacity: 1; }
a.kpi:hover { border-color: var(--border-strong); background: var(--hover); }
.kpi .label { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.kpi .value { font-size: 26px; font-weight: 600; line-height: 1.1; }
.kpi.bad .value { color: var(--red-fg); }
.kpi.good .value { color: var(--green-fg); }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Pills / tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill-gray { background: var(--gray-bg); color: var(--gray-fg); }
.pill-blue { background: var(--blue-bg); color: var(--blue-fg); }
.pill-amber { background: var(--amber-bg); color: var(--amber-fg); }
.pill-red { background: var(--red-bg); color: var(--red-fg); }
.pill-green { background: var(--green-bg); color: var(--green-fg); }
.pill-purple { background: var(--purple-bg); color: var(--purple-fg); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.lock { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--amber-fg); background: var(--amber-bg); border-radius: 99px; padding: 1px 7px; white-space: nowrap; }
.lock svg { width: 11px; height: 11px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12px; color: var(--muted); }
.overdue { color: var(--red-fg); font-weight: 600; }
.soon { color: var(--amber-fg); font-weight: 500; }
.ic { display: inline-flex; align-items: center; gap: 4px; }
.ic svg { width: 13px; height: 13px; }

/* Meter */
.meter { height: 6px; border-radius: 99px; background: var(--gray-bg); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--meter); min-width: 2px; transition: width .4s; }
.meter.sm { height: 4px; }
.meter-row { display: flex; align-items: center; gap: 8px; }
.meter-row .meter { flex: 1; }
.pct { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

/* Avatar */
.avatar {
  --c: #64748b; flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 13px; line-height: 1; color: #fff; background: var(--c);
}
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.xs { width: 22px; height: 22px; font-size: 10px; }
.who { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }

/* ---------- Overview cards (person / project) ---------- */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.pcard { padding: 16px; display: grid; gap: 12px; align-content: start; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.pcard:hover { border-color: var(--border-strong); box-shadow: 0 6px 20px -8px rgba(16, 24, 40, .18); transform: translateY(-1px); }
.pcard.idle { opacity: .75; }
.pcard-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pcard-title { min-width: 0; flex: 1; }
.pcard-title h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.pcard-title .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mini-list li { display: grid; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.mini-list li:first-child { padding-top: 0; border-top: 0; }
.mini-title { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { font-size: 12px; color: var(--primary); font-weight: 500; }
.proj-mark { width: 12px; height: 12px; border-radius: 4px; flex: none; background: var(--c); }
.devsplit { display: flex; flex-wrap: wrap; gap: 6px; }
.devchip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px 2px 2px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); min-height: 28px; }
.devchip b { font-weight: 600; }
a.devchip { transition: border-color .15s; }
a.devchip:hover { border-color: var(--primary); }

/* ---------- Target rows ---------- */
.tlist { display: grid; overflow: hidden; }
.tcard { display: grid; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .15s; }
.tcard:last-child { border-bottom: 0; }
.tcard:hover { background: var(--hover); }
.tcard-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tcard-title { font-weight: 500; min-width: 0; }
.tcard.done .tcard-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border-strong); }
.tcard .meter-row { max-width: 320px; }
.group-head { padding: 8px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.group-head a { color: inherit; text-decoration: none; }
.group-head a:hover { color: var(--primary); }

/* Board (kanban) */
.board { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.column { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 140px; scroll-snap-align: start; }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px 10px; font-weight: 600; font-size: 13px; }
.column .tcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.column .tcard:hover { border-color: var(--primary); }

/* Filters bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-bar select { width: auto; max-width: 180px; padding: 6px 9px; font-size: 13px; min-height: 36px; }

/* ---------- Detail page header ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 10px; min-height: 32px; }
.back svg { width: 16px; height: 16px; }
.back:hover { color: var(--primary); }
.detail-head { padding: 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head .grow { flex: 1; min-width: 200px; display: grid; gap: 4px; }
.detail-head h1 { font-size: 24px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.contact { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.contact a { color: var(--primary); }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; text-decoration: none; color: var(--text);
  padding: 4px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.link-btn:hover { border-color: var(--primary); }
.link-btn svg { width: 13px; height: 13px; }

/* ---------- Notes ---------- */
.notes { display: grid; gap: 10px; }
.note { padding: 14px 16px; display: grid; gap: 6px; }
.note.pinned { border-left: 3px solid var(--brand-red); }
.note-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.note-head h3 { font-size: 14.5px; }
.note .md { font-size: 13.5px; }
.pin { color: var(--brand-red); font-size: 12px; font-weight: 600; }

/* ---------- Markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow: auto; }
.md pre code { background: none; padding: 0; }
.md a { color: var(--primary); }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }

/* ---------- Drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: var(--backdrop); }
.drawer-panel {
  position: absolute; top: 10px; right: 10px; bottom: 10px; width: min(560px, calc(100% - 20px)); overflow: auto; padding: 26px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
.drawer-close { position: absolute; top: 12px; right: 12px; }
.drawer h1 { font-size: 21px; padding-right: 34px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13px; margin: 0 0 16px; align-items: center; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.quick { display: grid; gap: 12px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 16px; }
.quick .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.quick select { width: auto; flex: 1; min-width: 140px; }
.quick .range { display: flex !important; align-items: center; gap: 10px; flex: 2; min-width: 200px; }
.quick .range input { flex: 1; }
.comments { display: grid; gap: 10px; margin-top: 8px; }
.comment { border: 1px solid var(--border); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.comment.system { border-style: dashed; background: transparent; font-size: 13px; color: var(--muted); padding: 6px 12px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.comment-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; align-items: center; }

/* ---------- Modal (form) ---------- */
.modal {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(660px, calc(100% - 32px)); color: var(--text);
  background: var(--surface); box-shadow: var(--shadow-lg); max-height: calc(100dvh - 48px); overflow: hidden;
}
.modal::backdrop { background: var(--backdrop); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100dvh - 48px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 18px 20px; overflow: auto; display: grid; gap: 14px; flex: 1; overscroll-behavior: contain; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.fields .full { grid-column: 1 / -1; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface); }

.toast {
  position: fixed; bottom: calc(20px + var(--tabbar-h) + var(--safe-b)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px);
}

/* ---------- Quick add (FAB + action sheet) — phones only ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(16px + var(--tabbar-h) + var(--safe-b)); z-index: 40;
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer; display: none; place-items: center;
  background: var(--primary); color: var(--primary-text); box-shadow: 0 10px 24px -6px rgba(6, 116, 183, .55);
  transition: transform .15s;
}
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; transition: transform .2s; }
.fab[aria-expanded="true"] svg { transform: rotate(45deg); }
.fab:active { transform: scale(.95); }
.sheet { position: fixed; inset: 0; z-index: 39; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--backdrop); }
.sheet-panel {
  position: absolute; left: 12px; right: 12px; bottom: calc(84px + var(--tabbar-h) + var(--safe-b));
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; display: grid;
}
.sheet-panel button {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 15px; font-weight: 500; padding: 10px 12px; border-radius: 10px; cursor: pointer; min-height: 54px;
}
.sheet-panel button:hover, .sheet-panel button:active { background: var(--surface-2); }
.sheet-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.sheet-ic svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sheet-panel small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  :root { --tabbar-h: 62px; }
  body { font-size: 15px; padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  /* 16px inputs stop iOS zooming in on focus. */
  input, select, textarea { font-size: 16px; min-height: 44px; }
  /* backdrop-filter would make .topbar the containing block of the fixed tab bar. */
  .topbar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--surface); }
  .topbar-inner { height: 54px; gap: 8px; padding-left: 14px; padding-right: 8px; }
  .brand-wordmark { height: 18px; }
  .topbar-right { margin-left: auto; gap: 0; }
  #logout { padding: 8px; min-height: 40px; }
  #logout span { display: none; }

  /* Tabs → fixed bottom tab bar */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; height: calc(var(--tabbar-h) + var(--safe-b));
    padding: 6px 6px var(--safe-b); gap: 0; display: grid; grid-template-columns: repeat(4, 1fr);
    background: var(--topbar); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
  }
  .tabs a { flex-direction: column; justify-content: center; gap: 3px; padding: 4px 2px; font-size: 11.5px; border-radius: 12px; }
  .tabs a svg { width: 22px; height: 22px; padding: 3px 16px; box-sizing: content-box; border-radius: 99px; transition: background .15s; }
  .tabs a:hover { background: transparent; }
  .tabs a.active { background: transparent; }
  .tabs a.active svg { background: var(--primary-soft); }

  .toolbar-inner, .main, .footer { padding-left: 14px; padding-right: 14px; }
  .toolbar-inner { padding-top: 12px; gap: 10px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -14px; padding-right: 14px; width: calc(100% + 14px); }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .toolbar-actions { width: 100%; }
  /* Admin add buttons move into the FAB on phones. */
  .toolbar-actions [data-act] { display: none; }
  .toolbar-actions:not(:has(> :not([data-act]))) { display: none; }
  .main { padding-top: 12px; }
  .footer { padding-bottom: 20px; }

  .kpis { grid-template-columns: repeat(5, minmax(100px, 1fr)); gap: 8px; margin: 0 -14px 16px; padding: 0 14px 2px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x mandatory; scroll-padding: 0 14px; }
  .kpis::-webkit-scrollbar { display: none; }
  .kpi { padding: 10px 12px; scroll-snap-align: start; }
  .kpi .value { font-size: 22px; }
  .kpi .label { font-size: 10px; letter-spacing: .05em; white-space: nowrap; }
  .pgrid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .pcard { padding: 14px; }
  .filter-bar { width: 100%; }
  .filter-bar select { max-width: none; flex: 1 1 calc(50% - 4px); font-size: 14px; min-height: 40px; }
  .tcard { padding: 12px 14px; }
  .tcard .meter-row { max-width: none; }
  .group-head { padding: 8px 14px; }
  .board { grid-template-columns: none !important; grid-auto-flow: column; grid-auto-columns: 84%; margin: 0 -14px; padding: 0 14px 8px; scroll-padding: 0 14px; }
  .detail-head { padding: 14px; gap: 12px; }
  .detail-head h1 { font-size: 20px; }
  .detail-head .inline-actions { width: 100%; }
  .detail-head .inline-actions .btn { flex: 1; }
  #app:not(.viewer) .fab { display: grid; }

  /* Drawer → full screen */
  .drawer-panel { inset: 0; width: 100%; border-radius: 0; border: 0; padding: 16px 16px calc(24px + var(--safe-b)); }
  .drawer-close { top: 8px; right: 8px; }
  .quick .row > * { flex: 1 1 100%; }
  .quick .inline-actions .btn { flex: 1; min-height: 42px; }

  /* Form → bottom sheet, Save always visible */
  .modal { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; max-height: 94dvh; }
  .modal-form { max-height: 94dvh; }
  .modal-head { padding: 12px 10px 10px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-actions { padding: 10px 16px calc(10px + var(--safe-b)); }
  .modal-actions .btn { flex: 1; min-height: 46px; font-size: 15px; }
  .fields { gap: 12px; }
  .fields label:not(.half) { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 640px) {
  .modal[open] { animation: sheet-up .22s ease-out; }
  .sheet:not([hidden]) .sheet-panel { animation: sheet-up .18s ease-out; }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } }
