/* Horizon-style admin UI: soft blue-grey canvas, white 20px-radius cards with
   diffuse shadows, indigo brand (#4318FF), navy text, DM Sans, and a matching
   graphite dark mode. Semantic status colours (green / amber / red) stay
   distinct from the brand for readability.
   Feature-specific styles go in the "Feature styles" section at the bottom. */
:root {
  --bg: #f4f7fe;
  --surface: #ffffff;
  --surface-2: #f4f7fe;
  --ink: #2b3674;             /* navy headings & body */
  --ink-soft: #707eae;        /* secondary text (readable on white) */
  --faint: #a3aed0;           /* labels, table headers, placeholders */
  --line: #e9edf7;
  --line-strong: #d9e0f0;
  --accent: #4318ff;          /* brand indigo */
  --accent2: #868cff;         /* brand gradient start */
  --accent-solid: #4318ff;    /* fill behind white text (buttons, active page) */
  --danger-solid: #c8372a;    /* red fill behind white text */
  --accent-ink: #ffffff;
  --purple: #7551ff;
  --ok: #05a57c;
  --warn: #e08600;
  --danger: #c8372a;          /* text-safe red (≥4.5:1 on white and on --danger-bg) */
  --danger-soft: #ee5d50;
  --ok-bg: #e6faf5;
  --warn-bg: #fff6e5;
  --danger-bg: #fdeeec;
  --accent-bg: #efebff;
  --grey-bg: #f4f7fe;
  --shadow: 0 18px 40px rgba(112,144,176,.12);
  --shadow-s: 0 6px 18px rgba(112,144,176,.10);
  --radius: 14px;
  --radius-card: 20px;
  --h: 44px;
  --sbw: 264px;               /* sidebar width */
  --sbw-collapsed: 80px;      /* icon-only rail width (desktop collapse) */
  --maxw: 1320px;             /* content + topbar max width (kept in sync) */
  --font: 'DM Sans', 'Noto Sans Khmer', Arial, Helvetica, sans-serif;
}
/* Dark mode: neutral graphite (not tinted navy) so text stays crisp; indigo is
   used only as the accent. --accent is the lighter shade for text/links on
   dark panels; --accent-solid is the deeper shade behind white button text. */
[data-theme=dark] {
  --bg: #0f1013;
  --surface: #18191d;
  --surface-2: #1f2125;
  --ink: #ececf0;
  --ink-soft: #a6a9b3;
  --faint: #868a95;
  --line: #2b2d33;
  --line-strong: #3b3e46;
  --accent: #a497ff;
  --accent2: #c0b7ff;
  --accent-solid: #5b47f5;
  --danger-solid: #c2382c;
  --purple: #b9adff;
  --ok: #4cd497;
  --warn: #f2b84b;
  --danger: #ff7a6e;
  --danger-soft: #ff7a6e;
  --ok-bg: #15291f;
  --warn-bg: #2c2414;
  --danger-bg: #331c1b;
  --accent-bg: #26233d;
  --grey-bg: #24262b;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 0 0 1px var(--line);
  --shadow-s: 0 1px 2px rgba(0,0,0,.45), 0 0 0 1px var(--line);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 3px solid var(--bg); }

/* ---- Admin layout: sidebar + main ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sbw); z-index: 60;
  display: flex; flex-direction: column; gap: 6px; padding: 26px 0 20px 18px;
  background: var(--surface); box-shadow: 14px 17px 40px 4px rgba(112,144,176,.08);
  overflow-y: auto; overflow-x: hidden; transition: transform .22s ease, width .2s ease;
}
/* Brand block with a hairline separator under it (Horizon sidebar header). */
.sb-brand { display: flex; align-items: center; justify-content: left; gap: 10px; padding: 4px 18px 22px 0; margin-bottom: 14px;
  color: var(--ink); border-bottom: 1px solid var(--line); }
.sb-brand:hover { text-decoration: none; }
.logo-mark { display: inline-flex; flex: none; }
.logo-mark svg { display: block; border-radius: 9px; box-shadow: 0 1px 5px rgba(18,58,107,.22); }
.brand-word { display: flex; flex-direction: column; line-height: 1.05; }
.brand-word b { font-weight: 800; font-size: 15px; letter-spacing: -.02em; color: var(--ink); }
.brand-word .bw-sub { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }

.sb-nav { display: flex; flex-direction: column; gap: 2px; }
/* Nav items: muted until active; active = navy bold text, indigo icon and an
   indigo bar on the sidebar's right edge. */
.sb-nav a {
  position: relative; display: flex; align-items: center; gap: 14px; height: 44px; padding: 0 14px;
  border-radius: 12px 0 0 12px; color: var(--faint); font-weight: 500; font-size: 15px;
}
.sb-nav a:hover { color: var(--ink); text-decoration: none; background: var(--grey-bg); }
.sb-nav a.active { color: var(--ink); font-weight: 700; background: var(--accent-bg);}
.sb-nav a.active .sb-ic { color: var(--accent); }
.sb-nav a.active::after { content: ''; position: absolute; right: 0; top: 6px; bottom: 6px; width: 4px; border-radius: 5px; background: var(--accent); }
.sb-nav .sb-ic { flex: none; }

.sb-backdrop { display: none; }

/* Main column (offset by the always-visible sidebar on desktop) */
.main { flex: 1; min-width: 0; margin-left: var(--sbw); display: flex; flex-direction: column; transition: margin-left .2s ease; }

/* Desktop collapse: shrink the sidebar to an icon-only rail. */
@media (min-width: 901px) {
  html.sb-collapsed .sidebar { width: var(--sbw-collapsed); }
  html.sb-collapsed .main { margin-left: var(--sbw-collapsed); }
  html.sb-collapsed .sidebar { padding-left: 0; }
  html.sb-collapsed .sb-brand { justify-content: center; padding-left: 0; padding-right: 0; }
  html.sb-collapsed .sb-brand .brand-word { display: none; }
  html.sb-collapsed .sb-nav a { justify-content: center; gap: 0; padding: 0; border-radius: 0; }
  html.sb-collapsed .sb-nav a span { display: none; }
}

/* Circular collapse handle, centred on the sidebar/content divider (desktop). */
.sb-collapse { display: none; }
@media (min-width: 901px) {
  .sb-collapse {
    position: fixed; bottom: 24px; left: var(--sbw); transform: translateX(-50%);
    width: 26px; height: 26px; padding: 0; border-radius: 50%; z-index: 61; cursor: pointer;
    display: grid; place-items: center;
    background: var(--surface); color: var(--ink-soft);
    border: 1px solid var(--line-strong); box-shadow: var(--shadow-s);
    transition: left .2s ease, background .15s, color .15s, border-color .15s;
  }
  .sb-collapse:hover { color: var(--accent); border-color: var(--accent); }
  .sb-collapse svg { transition: transform .2s ease; }
  html.sb-collapsed .sb-collapse { left: var(--sbw-collapsed); }
  html.sb-collapsed .sb-collapse svg { transform: rotate(180deg); }
}

/* Floating, frosted topbar — constrained to the same width as the content container. */
.topbar { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  transition: box-shadow .18s, background-color .18s; }
/* Once the page is scrolled (app.js), a soft shadow + hairline shows where the bar ends. */
.topbar.is-scrolled { background: color-mix(in srgb, var(--bg) 88%, transparent);
  box-shadow: 0 1px 0 var(--line), 0 6px 16px -8px color-mix(in srgb, var(--ink) 22%, transparent); }
@media (prefers-reduced-motion: reduce) { .topbar { transition: none; } }
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0 28px;
  height: 76px; display: flex; align-items: center; gap: 12px;
}
/* Hamburger opens the drawer on mobile only (desktop uses the divider handle). */
.sb-toggle { width: 38px; height: 38px; flex: none; padding: 0; border: 0; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--ink); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.sb-toggle:hover { background: var(--grey-bg); }
.sb-toggle span { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 2px; }
.spacer { flex: 1; }

/* Topbar brand lockup — desktop hides it (the sidebar carries the brand); on
   mobile it replaces the breadcrumb. */
.tb-brand { display: none; align-items: center; gap: 9px; min-width: 0; color: var(--ink); }
.tb-brand:hover { text-decoration: none; }
.tb-brand .logo-mark svg { width: 30px; height: 30px; }

/* Breadcrumb */
.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 14px; }
.crumbs a { color: var(--ink-soft); text-decoration: none; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.crumbs a:hover { color: var(--ink); }
.crumbs .crumb-sep { color: var(--ink-soft); opacity: .5; flex: none; }
.crumbs .crumb-cur { color: var(--ink); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Topbar action cluster (notifications, user) — a white pill. */
.topbar-actions { display: flex; align-items: center; gap: 4px; flex: none; background: var(--surface);
  border-radius: 30px; padding: 6px 8px; box-shadow: 14px 17px 40px 4px rgba(112,144,176,.08); }
.tb-icon { width: 38px; height: 38px; flex: none; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: var(--faint); display: grid; place-items: center; }
.tb-icon:hover { background: var(--grey-bg); color: var(--ink); }

/* Notifications dropdown */
.notifmenu { position: relative; }
.notif-dd { position: absolute; right: 0; top: calc(100% + 8px); width: 340px; max-width: calc(100vw - 16px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.12); padding: 6px; z-index: 60;
  opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top right; pointer-events: none; transition: opacity .14s, transform .14s; }
.notifmenu.open .notif-dd { opacity: 1; transform: none; pointer-events: auto; }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 700; font-size: 14px; padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.notif-readall { border: 0; background: none; padding: 4px 6px; border-radius: 6px; color: var(--accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.notif-readall:hover { background: var(--accent-bg); }
.notif-readall[hidden], .notif-empty[hidden], .notif-badge[hidden] { display: none; }
.tb-icon { position: relative; }
.notif-badge { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface); font-variant-numeric: tabular-nums; pointer-events: none; }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: min(420px, 70vh); overflow-y: auto; }
.notif-item a { display: flex; gap: 10px; padding: 10px; border-radius: 8px; color: var(--ink); text-decoration: none; min-width: 0; }
.notif-item a:hover, .notif-item a:focus-visible { background: var(--grey-bg); }
.notif-dot { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: transparent; }
.notif-item.is-unread .notif-dot { background: var(--accent); }
.notif-item.is-unread .notif-text { font-weight: 700; }
.notif-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.notif-text { font-size: 13.5px; line-height: 1.4; overflow-wrap: anywhere; }
.notif-reason { font-size: 12.5px; padding: 4px 8px; border-radius: 6px; background: var(--danger-bg); color: var(--danger); overflow-wrap: anywhere; white-space: pre-line; }
.notif-when { font-size: 12px; color: var(--ink-soft); }
.notif-overdue .notif-text::before { content: '! '; color: var(--warn); font-weight: 800; }
.notif-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  color: var(--ink-soft); font-size: 13.5px; padding: 24px 14px 20px; }
.notif-empty svg { color: var(--ink-soft); opacity: .6; }

/* User menu (topbar avatar + dropdown) */
.usermenu { position: relative; }
.avatar { font-weight: 800; font-size: 14px; }
.avatar.lg { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-solid); color: #fff; display: grid; place-items: center; flex: none; font-size: 16px; }
.user-dd { position: absolute; right: 0; top: calc(100% + 8px); min-width: 224px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.12); padding: 6px; z-index: 60;
  opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top right; pointer-events: none; transition: opacity .14s, transform .14s; }
.usermenu.open .user-dd { opacity: 1; transform: none; pointer-events: auto; }
.user-dd-head { display: flex; gap: 10px; align-items: center; padding: 8px 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.udd-name { font-weight: 700; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; }
.udd-sub { color: var(--ink-soft); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.udd-item { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 10px 11px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); font: inherit; font-weight: 600; font-size: 14.5px; cursor: pointer; }
.udd-item:hover { background: var(--grey-bg); }
a.udd-item, a.udd-item:hover { text-decoration: none; }
.udd-item.danger { color: var(--danger); }
.udd-item.danger:hover { background: var(--danger-bg); }

/* Segmented control — Settings > Preferences and any scope/filter tabs */
.seg, .scope-tabs { display: inline-flex; flex-wrap: wrap; max-width: 100%; background: var(--grey-bg); border-radius: 14px; padding: 4px; gap: 2px; }
.seg-btn, .scope-tab { border: 0; background: transparent; cursor: pointer; font: inherit; font-weight: 700; font-size: 14.5px; color: var(--ink-soft);
  padding: 9px 16px; border-radius: 11px; text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap; }
.seg-btn:hover, .scope-tab:hover { color: var(--ink); text-decoration: none; }
.seg-btn.active, .scope-tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-s); }

/* Underline tab bar (Settings). Panels stack for no-JS; JS activates tab mode. */
.tabs { display: none; }
.js-tabs .tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.settings-tab { border: 0; background: transparent; cursor: pointer; font: inherit; font-weight: 700; font-size: 14.5px;
  color: var(--ink-soft); padding: 10px 14px 11px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.settings-tab:hover { color: var(--ink); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.js-tabs .tab-panel { display: none; }
.js-tabs .tab-panel.active { display: block; }
.settings-save { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }


/* ---- Layout ---- */
.container { width: 100%; max-width: var(--maxw); margin: 8px auto 32px; padding: 0 28px; flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 32px; line-height: 1.15; margin: 0; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.page-head .sub { color: var(--ink-soft); font-size: 14.5px; margin-top: 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 0; border-radius: var(--radius-card); box-shadow: var(--shadow); }
.card-pad { padding: 22px 24px; margin: 18px 0;}
/* Vertical rhythm between stacked blocks (cards, table cards, and form wrappers). */
.card + .card, .card + .table-wrap, .table-wrap + .card, .table-wrap + .table-wrap,
form + .card, .card + form, form + .table-wrap, .table-wrap + form { margin: 18px 0; }
.card h2, .card h3 { margin: 0 0 14px; font-size: 18px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }

/* ---- KPI tiles ---- */
/* "Mini statistics" cards: round icon chip on the left, label above a bold
   value. The chip (and value) take the tile's status colour. */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 20px; }
.kpi { --chip: var(--accent); --chip-bg: var(--grey-bg);
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "ic l" "ic n" "ic s"; column-gap: 16px; align-content: center;
  background: var(--surface); border: 0; border-radius: var(--radius-card); padding: 18px 20px; box-shadow: var(--shadow); min-height: 96px;
  min-width: 0; }   /* let grid columns shrink below the label's width on phones */
.kpi-l, .kpi-n, .kpi-sub { min-width: 0; overflow-wrap: anywhere; }
.kpi::before { content: ''; grid-area: ic; align-self: center; width: 56px; height: 56px; border-radius: 50%;
  background: var(--chip-bg); }
.kpi::after { content: ''; grid-area: ic; align-self: center; justify-self: center; width: 26px; height: 26px; background: var(--chip);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20V10M10 20V4M16 20v-7M22 20H2'/%3E%3C/svg%3E") center / contain no-repeat; }
.kpi-l { grid-area: l; color: var(--faint); font-size: 14px; font-weight: 500; line-height: 1.35; margin: 0; }
.kpi-n { grid-area: n; font-size: 24px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.3; }
.kpi-sub { grid-area: s; font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.kpi-n.txt { font-size: 18px; line-height: 1.3; overflow-wrap: break-word; }   /* text values (names), not numbers */
.kpi.ok { --chip: var(--ok); --chip-bg: var(--ok-bg); } .kpi.ok .kpi-n { color: var(--ok); }
.kpi.warn { --chip: var(--warn); --chip-bg: var(--warn-bg); } .kpi.warn .kpi-n { color: var(--warn); }
.kpi.accent { --chip: var(--accent); --chip-bg: var(--accent-bg); } .kpi.accent .kpi-n { color: var(--accent); }
.kpi.danger { --chip: var(--danger-soft); --chip-bg: var(--danger-bg); } .kpi.danger .kpi-n { color: var(--danger-soft); }
.kpi.muted-tile .kpi-n { color: var(--ink-soft); }
/* Tiles nested inside a card are flat tinted panels (no shadow-on-shadow). */
.card .kpi { box-shadow: none; background: var(--surface-2); }
.card .kpi::before { background: var(--surface); }

/* ---- Dashboard viz (pure CSS charts) ---- */
.dash-row { display: grid; gap: 16px; margin: 16px 0px; align-items: stretch; }
.dash-row.cols-2 { grid-template-columns: 1fr 1fr; }
.dash-row > .card { height: 100%; margin-top: 0; }
.dash-card { display: flex; flex-direction: column; }
.dash-card > h2 { flex: none; }
.dash-card-body { flex: 1; display: flex; flex-direction: column; justify-content: flex-start; }

.donuts { display: flex; gap: 28px; flex-wrap: wrap; }
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.donut { --pct: 0; --col: var(--accent); width: 132px; height: 132px; border-radius: 50%;
  background: conic-gradient(var(--col) calc(var(--pct) * 1%), color-mix(in srgb, var(--ink) 8%, transparent) 0);
  display: grid; place-items: center; }
.donut-hole { width: 96px; height: 96px; border-radius: 50%; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-pct { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.donut-cap { font-size: 12px; color: var(--ink-soft); }
.donut-legend { font-size: 13px; color: var(--ink-soft); }
.donut-legend b { color: var(--ink); }

.stackbar { display: flex; height: 18px; border-radius: 99px; overflow: hidden; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.stackbar.sm { height: 10px; }
.stackbar span { display: block; height: 100%; }
.distrib-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin-top: 14px; }
.distrib-legend.inline { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; }
.dl-item { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.dl-item .dl-lab { color: var(--ink-soft); }
.dl-item .dl-n { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.barchart { display: flex; align-items: flex-end; gap: 6px; height: 170px; }
.bc-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bc-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bc-stack { width: 60%; max-width: 30px; display: flex; flex-direction: column-reverse; border-radius: 10px 10px 4px 4px; overflow: hidden; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.bc-stack span { display: block; width: 100%; }
.bc-col.is-current .bc-stack { outline: 2px solid var(--accent); outline-offset: 1px; }
.bc-total { font-size: 12px; color: var(--ink-soft); margin-top: 6px; height: 14px; font-variant-numeric: tabular-nums; }
.bc-label { font-size: 12px; color: var(--ink-soft); }
.bc-col.is-current .bc-label { color: var(--accent); font-weight: 800; }

.progressbar { height: 8px; background: color-mix(in srgb, var(--ink) 9%, transparent); border-radius: 99px; overflow: hidden; margin: 9px 0 11px; }
.progressbar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent2), var(--purple)); transition: width .4s; }
.progressbar span.warn { background: var(--warn); }
.progressbar span.ok { background: var(--ok); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 0; border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow); }
/* Long lists scroll inside the table box (only when they're taller than it) so the
   column headers stay pinned at the top while the rows move. */
.table-wrap { max-height: calc(100vh - 300px); overflow-y: auto; }
.table-wrap thead { position: sticky; top: 0; z-index: 3; }
.table-wrap thead th { background: var(--surface); }
.table-wrap.flush { border: none; box-shadow: none; border-radius: 0; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14.5px; }
th, td { text-align: left; padding: 14px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 22px; }
th:last-child, td:last-child { padding-right: 22px; }
th { color: var(--faint); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td { color: var(--ink); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.wrap, th.wrap { white-space: normal; overflow-wrap: anywhere; }
td.nowrap, th.nowrap { white-space: nowrap; }
.muted { color: var(--ink-soft); }
.small { font-size: 14.5px; }

/* ---- Badges (pills) ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 980px; font-size: 13px; font-weight: 700; line-height: 1.4; }
/* In a table a badge never breaks inside itself ("Conditio / n"); a very long one is cut with … rather than leaving its cell. */
.table-wrap td .badge { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.badge.freq, .badge.pending, .badge.grey { background: var(--grey-bg); color: var(--ink-soft); }
.badge.accent { background: var(--accent-bg); color: var(--accent); }
.badge.done, .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.partial, .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.overdue, .badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.skipped, .badge.purple { background: color-mix(in srgb, var(--purple) 16%, transparent); color: var(--purple); }

/* ---- Buttons ---- */
/* One class selector (not `button.btn`, which out-ranked .btn-primary etc. and
   left every <button> variant grey). */
.btn { font-family: var(--font); font-weight: 700; font-size: 14.5px; height: var(--h); box-shadow: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; border-radius: var(--radius); padding: 0 16px; cursor: pointer; transition: .15s;
  white-space: nowrap; letter-spacing: -.01em; text-decoration: none;
  background: var(--grey-bg); color: var(--ink); }
/* Hover tints toward the brand (never toward the text colour, which flips to
   white in dark mode and would wash the button out). */
.btn:hover { background: color-mix(in srgb, var(--grey-bg) 86%, var(--accent)); color: var(--ink); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent-solid); color: #fff; box-shadow: 0 8px 18px color-mix(in srgb, var(--accent-solid) 28%, transparent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-solid) 86%, #000); color: #fff; }
.btn-dark { background: var(--ink); color: var(--surface); }
.btn-dark:hover { background: color-mix(in srgb, var(--ink) 85%, var(--accent)); color: var(--surface); }
/* Dark mode: an inverted (white) button would glare — use the brand instead. */
[data-theme=dark] .btn-dark { background: var(--accent-solid); color: #fff; }
[data-theme=dark] .btn-dark:hover { background: color-mix(in srgb, var(--accent-solid) 86%, #000); color: #fff; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger-solid); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--grey-bg); color: var(--ink); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15.5px; }

/* ---- Forms ---- */
label { display: block; font-size: 14px; color: var(--ink); font-weight: 600; margin-bottom: 8px; }
input[type=text], input[type=tel], input[type=search], input[type=password], input[type=number], input[type=date], input[type=time], input[type=email], input[type=file], select, textarea {
  font-family: var(--font); font-size: 16px; width: 100%; height: var(--h);
  padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 16px;
  background: var(--surface); color: var(--ink);
}
textarea { height: auto; padding: 12px 16px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
input::placeholder, textarea::placeholder { color: var(--faint); }
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none; cursor: pointer; padding-right: 32px; font-weight: 600;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239a9aa0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.field { margin-bottom: 16px; }
/* Plain fieldset used to make a whole form read-only for non-editors. */
.fs-plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px 16px; }
/* Inside grids the gap handles spacing — drop the per-field bottom margin so
   card padding stays symmetric… */
.grid2 .field, .grid3 .field { margin-bottom: 0; }
/* …but keep vertical rhythm between a grid row and whatever follows it. */
.grid2 + *, .grid3 + * { margin-top: 16px; }
.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input { width: auto; height: auto; }
.checkline label { margin: 0; text-transform: none; font-size: 15px; letter-spacing: 0; color: var(--ink); }

/* iOS-style switch */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--line-strong); border-radius: 26px; transition: .18s; cursor: pointer; }
.switch .track::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- Custom select (app.js enhances every <select>) ---- */
.cselect { position: relative; display: inline-flex; vertical-align: middle; }
.cselect.cselect-block { display: flex; width: 100%; }
.cselect select.cselect-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.cselect-trigger { display: inline-flex; align-items: center; gap: 10px; justify-content: space-between;
  min-width: 120px; width: 100%; height: var(--h); padding: 0 13px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; transition: .12s; white-space: nowrap; }
.cselect-trigger:hover { border-color: var(--line-strong); }
.cselect.open .cselect-trigger { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.cselect-trigger .chev { flex: none; transition: transform .18s; color: var(--faint); }
.cselect.open .cselect-trigger .chev { transform: rotate(180deg); }
.cselect-value { overflow: hidden; text-overflow: ellipsis; }
.cselect-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; min-width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.12);
  padding: 5px; max-height: 280px; overflow-y: auto;
  opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top; pointer-events: none; transition: opacity .14s, transform .14s; }
.cselect.open .cselect-menu { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
/* Floated menu (positioned by app.js): above every card / table wrapper, never wider than the screen. */
.cselect.open .cselect-menu { z-index: 200; }
.cselect-menu { max-width: calc(100vw - 16px); }
/* Even before its first open, a menu must not take up room inside a scrolling
   table box. Fixed boxes don't count toward a container's scroll area; app.js places it on open. */
.cselect-menu { position: fixed; visibility: hidden; transition: opacity .14s, transform .14s, visibility 0s .14s; }
.cselect.open .cselect-menu { visibility: visible; transition: opacity .14s, transform .14s; }
.cselect-opt > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cselect.cselect-up .cselect-menu { transform-origin: bottom; }
/* Searchable variant: the filter box stays put, only the option list scrolls. */
.cselect-searchable .cselect-menu { display: flex; flex-direction: column; overflow: hidden; padding: 6px; }
.cselect-search { flex: none; width: 100%; height: 40px; margin-bottom: 6px; padding: 0 12px; font: 500 15px var(--font);
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); -webkit-appearance: none; appearance: none; }
.cselect-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
/* Filtered-out rows: their display:flex would otherwise beat the [hidden] attribute. */
.cselect-opt[hidden], .cselect-group[hidden] { display: none; }
.cselect-list { overflow-y: auto; min-height: 0; flex: 1; overscroll-behavior: contain; }
.cselect-group { padding: 8px 11px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.cselect-searchable .cselect-opt { font-size: 14.5px; padding: 8px 11px; }
.cselect-opt { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 11px; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.cselect-opt:hover, .cselect-opt.active { background: var(--accent-bg); }
.cselect-opt.selected { color: var(--accent); }
.cselect-opt .tick { opacity: 0; flex: none; }
.cselect-opt.selected .tick { opacity: 1; }

/* ---- Flash / results ---- */
.result { padding: 12px 15px; border-radius: var(--radius); font-size: 14.5px; margin-bottom: 14px; font-weight: 600; }
.result.ok { background: var(--ok-bg); color: var(--ok); }
.result.err { background: var(--danger-bg); color: var(--danger); }
.result.warn { background: var(--warn-bg); color: var(--ink); border-left: 4px solid var(--warn); font-weight: 500; }
.preview-box { background: #0b0d12; color: #c9d1d9; padding: 14px; border-radius: 8px; font-size: 13px; white-space: pre-wrap; margin-top: 10px; line-height: 1.55; }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.4); padding: 20px; animation: modalFade .15s ease; }
.modal { background: var(--surface); border-radius: var(--radius-card); width: 100%; max-width: 520px; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 14px 36px rgba(0,0,0,.22); animation: modalPop .16s ease; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.modal-close { background: none; border: none; font-size: 17px; cursor: pointer; color: var(--ink-soft); padding: 4px 8px; border-radius: 8px; line-height: 1; }
.modal-close:hover { background: var(--grey-bg); color: var(--ink); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalPop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 390px; padding: 28px; }
.auth-card h1 { font-size: 26px; margin: 0 0 4px; font-weight: 800; letter-spacing: -.03em; text-align: center; }
.auth-card .sub { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 22px; text-align: center; }
.auth-brand { display: flex; justify-content: center; align-items: center; gap: 13px; margin-bottom: 22px; }
.auth-brand .logo-mark svg { width: 48px; height: 48px; border-radius: 10px; box-shadow: 0 3px 10px rgba(18,58,107,.24); }
.auth-brand .brand-word { justify-content: center; line-height: 1.15; }
.auth-brand .brand-word b { font-size: 21px; letter-spacing: -.02em; }
.auth-brand .brand-word .bw-sub { font-size: 12px; letter-spacing: .08em; }
.auth-lang { display: flex; justify-content: center; gap: 14px; margin-top: 18px; font-size: 13.5px; }
.auth-lang a { color: var(--ink-soft); font-weight: 600; }
.auth-lang a.active { color: var(--accent); }

/* ---- Footer ---- */
.footer { text-align: center; color: var(--faint); font-size: 13px; padding: 24px; display: flex; gap: 8px; justify-content: center; }

/* ---- Utilities ---- */
.row-flex { display: flex; gap: 8px; align-items: center; }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
.empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }
.chip-code { background: var(--grey-bg); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.danger-text { color: var(--danger); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 10px; }
.kv dt { color: var(--ink-soft); font-size: 14px; } .kv dd { margin: 0; }

/* ---- File picker (drop zone) ---- */
.filepick { display: block; min-width: 0; max-width: 100%; }
.filepick input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.filepick-box { display: flex; align-items: center; gap: 14px; border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 18px; background: var(--surface-2); cursor: pointer; transition: .15s; }
.filepick-box:hover { border-color: var(--accent); background: var(--accent-bg); }
.filepick.dragover .filepick-box { border-color: var(--accent); background: var(--accent-bg); }
.filepick.has-file .filepick-box { border-style: solid; border-color: var(--accent); background: var(--accent-bg); }
.filepick-ico { width: 42px; height: 42px; flex: none; border-radius: 11px; display: grid; place-items: center; background: var(--accent-bg); color: var(--accent); }
.filepick-body { min-width: 0; flex: 1; }
.filepick-title, .filepick-sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filepick-title { font-weight: 700; font-size: 14px; color: var(--ink); }
.filepick-sub { color: var(--ink-soft); font-size: 13px; margin-top: 2px; font-weight: 400; }
.filepick-cta { font-size: 13px; font-weight: 700; color: var(--accent); flex: none; }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 22px; justify-content: center; }
.pagination .pg { min-width: 38px; height: 38px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.pagination a.pg:hover { border-color: var(--line-strong); text-decoration: none; }
.pagination .pg.active { background: var(--accent-solid); color: #fff; border-color: var(--accent-solid); }
.pagination .pg.disabled { opacity: .4; pointer-events: none; }
.pagination .pg.gap { border: none; background: none; pointer-events: none; min-width: 18px; }
.pagination .pg-info { margin-left: auto; color: var(--ink-soft); font-size: 14px; }

/* ---- Settings ---- */
.sec-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.sec-head h2 { margin: 0; font-size: 17.5px; }
.sec-desc { color: var(--ink-soft); font-size: 14px; margin: 0 0 16px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.toggle-row:first-of-type { border-top: none; }
.toggle-row .tr-label { font-weight: 700; font-size: 15px; }
.toggle-row .tr-desc { color: var(--ink-soft); font-size: 14.5px; margin-top: 2px; }

/* ===================== Responsive ===================== */
.hide-sm { display: table-cell; }

/* Sidebar becomes an off-canvas drawer on small screens. */
@media (max-width: 900px) {
  .dash-row.cols-2 { grid-template-columns: 1fr; }
  .sidebar { width: var(--sbw); transform: translateX(-100%); box-shadow: 0 12px 40px rgba(0,0,0,.3); padding-top: 14px; }
  .main { margin-left: 0; }
  .sb-open .sidebar { transform: none; }
  .sb-open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 55; }
  /* On mobile the brand lockup replaces the breadcrumb. */
  .crumbs { display: none; }
  .tb-brand { display: flex; }
  .topbar-inner { height: 62px; }
  .topbar-actions { padding: 4px 6px; }
  .notif-dd { position: fixed; top: 64px; left: 8px; right: 8px; width: auto; max-width: 380px; margin-left: auto; }   /* small screens: pinned to the right edge, never off the screen */
}
@media (max-width: 768px) {
  .container { margin: 16px auto; padding: 0 14px; }
  .topbar-inner { padding: 0 14px; }
  .topbar-inner { gap: 8px; }
  .page-head h1 { font-size: 22px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-n { font-size: 21px; }
  .kpi { padding: 14px; column-gap: 10px; }
  .kpi::before { width: 40px; height: 40px; }
  .kpi::after { width: 20px; height: 20px; }
  .toolbar { width: 100%; }
  .toolbar .cselect, .toolbar select, .toolbar input[type=text] { flex: 1; min-width: 0; }
  .hide-sm { display: none; }
  .filepick-cta { display: none; }          /* the whole box is the tap target */
  .filepick-box { padding: 14px; gap: 12px; }
  .distrib-legend { grid-template-columns: 1fr; }
  .barchart { height: 150px; gap: 3px; }
  .bc-label { font-size: 11px; }
  .modal-overlay { padding: 12px; }

  /* Stop iOS Safari from zooming the viewport when a control is focused: any
     control under 16px triggers auto-zoom. */
  input[type=text], input[type=tel], input[type=search], input[type=password], input[type=number], input[type=date],
  input[type=time], input[type=email], input[type=file], select, textarea,
  .cselect-trigger, .cselect-opt { font-size: 16px; }

  /* Filter / inline forms: let fields fill the width and stack instead of
     overflowing. !important overrides the per-input inline pixel widths. */
  .toolbar .field, .row-flex .field { width: 100%; margin: 0; }
  .toolbar .field input, .toolbar .field select, .toolbar .field .cselect,
  .row-flex .field input, .row-flex .field select { width: 100% !important; }
  .toolbar > .btn, form.toolbar > .btn { width: 100%; }
  .page-head > .toolbar { width: 100%; }
  .page-head > .toolbar > form, .page-head > .toolbar > .btn { width: 100%; }

  /* Thumb-friendly controls — 44px min per iOS / Android guidance. */
  .btn { height: 44px; padding: 0 8px; }
  .btn-sm { height: 38px; padding: 0 12px; }
  .btn-lg { min-height: 52px; }
  .tb-icon { width: 42px; height: 42px; }
  .sb-nav a { height: 48px; font-size: 15px; gap: 13px; }
  .sb-nav .sb-ic { width: 20px; height: 20px; }
  .pagination .pg { min-width: 40px; height: 40px; }
}

/* Wide data tables become stacked cards on phones. Opt in per table with
   class="table-wrap cards"; each <td> shows its header via data-label.
   Action/button cells use an empty data-label. */
@media (max-width: 640px) {
  .table-wrap.cards { border: 0; box-shadow: none; background: transparent; overflow: visible; max-height: none; }
  .table-wrap.cards thead { display: none; }
  .table-wrap.cards tbody, .table-wrap.cards tr, .table-wrap.cards td { display: block; width: 100%; }
  .table-wrap.cards tr {
    background: var(--surface); border: 0; border-radius: var(--radius-card);
    box-shadow: var(--shadow); padding: 4px 18px; margin-bottom: 14px; }
  .table-wrap.cards tbody tr:hover { background: var(--surface); }
  .card .table-wrap.cards tr, .card .table-wrap.cards tbody tr:hover { box-shadow: none; background: var(--surface-2); }
  .table-wrap.cards td {
    padding: 11px 0; border-bottom: 1px solid var(--line); white-space: normal; text-align: left; }
  .table-wrap.cards tr td:last-child { border-bottom: 0; }
  .table-wrap.cards td.hide-sm { display: none; }
  .table-wrap.cards td.empty { text-align: center; }
  .table-wrap.cards td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 6px;
    font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
  .table-wrap.cards td[data-label=""]::before { display: none; }
  /* Controls inside a card cell fill the row and stack. */
  .table-wrap.cards td .btn { width: 100%; }
  .table-wrap.cards td form, .table-wrap.cards td .row-flex { width: 100%; }
  .table-wrap.cards td .row-flex { flex-wrap: wrap; }
  .table-wrap.cards td .cselect, .table-wrap.cards td select,
  .table-wrap.cards td input[type=text], .table-wrap.cards td input[type=password] { width: 100% !important; }
}
@media (max-width: 480px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .toolbar { justify-content: stretch; }
  .scope-tabs { width: 100%; }
  .scope-tabs .scope-tab { flex: 1; justify-content: center; padding: 9px 8px; }
  .crumbs .crumb-cur { max-width: 44vw; }
}

/* ===================== Mobile bottom tab bar =====================
   On phones/tablets the role-based nav lives in a fixed bottom tab bar (thumb
   reach) instead of a hamburger. Overflow (>5 items) goes to a "More" tab that
   opens the off-canvas drawer. Desktop keeps the sidebar; this is hidden there. */
.tabbar { display: none; }
.sb-close { display: none; }
@media (max-width: 900px) {
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 12px rgba(18,40,74,.07);
  }
  .tabbar .tab {
    flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 2px 7px; min-height: 56px; border: 0; background: transparent; cursor: pointer;
    color: var(--ink-soft); font: inherit; font-size: 11px; font-weight: 700; text-decoration: none; -webkit-tap-highlight-color: transparent;
  }
  .tabbar .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar .tab svg { flex: none; }
  .tabbar .tab.active { color: var(--accent); }
  .tabbar .tab.active svg { stroke-width: 2.4; }
  .tabbar .tab:active { background: var(--grey-bg); }
  /* The tab bar is the primary nav on mobile — retire the hamburger. */
  .sb-toggle { display: none !important; }
  /* Keep content + footer clear of the fixed bar. */
  .main { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }
  .footer { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  /* Off-canvas drawer close (×). */
  .sb-close { display: grid; place-items: center; position: absolute; top: 12px; right: 12px;
    width: 38px; height: 38px; border: 0; border-radius: 9px; background: var(--grey-bg);
    color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; z-index: 2; }
  .sb-close:hover { background: var(--line-strong); }
}

/* Print / Save as PDF: just the page content. */
@media print {
  .sidebar, .topbar, .tabbar, .sb-collapse, .sb-backdrop, .footer, .no-print, .toasts { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc; break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* ===================== Feature styles =====================
   Add per-feature styles below, one commented section per feature. */

/* ---- Accounts & memberships (org switcher, picker, account) ---- */
.udd-label { padding: 6px 11px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); }
.udd-sep { height: 1px; background: var(--line); margin: 6px 0; }
.udd-org { justify-content: space-between; }
.udd-org .udd-org-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.udd-org .udd-org-role { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.udd-org.current { color: var(--accent); cursor: default; }
.udd-org.current:hover { background: transparent; }
.udd-org svg { flex: none; }
.org-list { display: flex; flex-direction: column; gap: 10px; margin: 0 0 6px; }
.org-list form { margin: 0; }
.org-pick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; transition: .12s; }
.org-pick:hover { border-color: var(--accent); background: var(--accent-bg); }
.org-pick .op-ic { width: 38px; height: 38px; flex: none; border-radius: 11px; display: grid; place-items: center; background: var(--accent-bg); color: var(--accent); font-weight: 800; }
.org-pick .op-body { flex: 1; min-width: 0; }
.org-pick .op-name { display: block; font-weight: 700; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-pick .op-role { display: block; font-size: 13px; color: var(--ink-soft); }
.org-pick.current { border-color: var(--accent); }
.auth-card.wide { max-width: 440px; }
.auth-foot { display: flex; justify-content: center; margin-top: 16px; }
.auth-foot form { margin: 0; }
.memb-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.field-hint { margin: 6px 0 0; font-size: 13px; color: var(--ink-soft); }
.grid2 > form .field, .grid3 > form .field { margin-bottom: 14px; }

/* Existing-account suggestions (admin console forms: input[data-user-suggest]) */
.suggest { position: relative; }
.suggest-menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 80; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow); }
.suggest-menu[hidden], [data-new-only][hidden], .suggest-note[hidden] { display: none !important; }
.suggest-opt { padding: 8px 11px; border-radius: 8px; cursor: pointer; }
.suggest-opt:hover, .suggest-opt.active { background: var(--accent-bg); }
.suggest-opt b { color: var(--ink); }
.suggest-opt .muted { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-note { margin: 8px 0 0; padding: 8px 11px; border-radius: 10px; font-size: 13px;
  background: var(--ok-bg); color: var(--ok); font-weight: 600; }
[data-console-only][hidden] { display: none !important; }

/* Toasts (views/partials/toasts.ejs + app.js): floating messages, top-right on
   desktop, top and full-width on phones. Above modals and menus. */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 400; display: flex; flex-direction: column; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 13px 12px 13px 16px;
  border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  border: 1px solid var(--line-strong); border-left: 4px solid var(--ok); font-size: 14.5px; font-weight: 600;
  animation: toastIn .22s ease; transition: opacity .25s, transform .25s; }
.toast-ok { border-left-color: var(--ok); }
.toast-err { border-left-color: var(--danger); }
.toast-warn { border-left-color: var(--warn); }
.toast-msg { flex: 1; min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }
.toast-link { color: var(--accent); text-decoration: underline; white-space: nowrap; }
.toast-x { flex: none; width: 28px; height: 28px; margin: -4px -2px -4px 0; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink-soft); font-size: 20px; line-height: 1; cursor: pointer; }
.toast-x:hover { background: var(--surface-2); color: var(--ink); }
.toast-out { opacity: 0; transform: translateY(-6px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
/* In the app shell, sit just below the top bar so its buttons stay clickable. */
.layout ~ .toasts { top: 86px; }
@media (max-width: 640px) { .toasts { left: 16px; right: 16px; top: 12px; width: auto; } .layout ~ .toasts { top: 70px; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; transition: none; } }

/* ---- Telegram (Settings → Telegram) ---- */
.tg-status { margin: 0 0 12px; }
.tg-failed { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; min-width: 0; }
.tg-chats { margin: 4px 0 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.tg-chats .sec-desc { margin-bottom: 4px; }
.tg-chats .toggle-row > div { min-width: 0; }
.card h3.tg-sub { margin: 22px 0 2px; font-size: 16px; }
/* Settings for one switch, shown under its row (Telegram → Work reminders). */
.tg-remind { padding: 0 0 14px; min-width: 0; }
.tg-remind .field-hint { margin-top: 0; }
.tg-actions { margin-top: 12px; }
/* The settings form's default button (Enter in a text box = Save, not a Telegram action). */
.default-submit { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

/* ---- Assets ---- */
.asset-filters { margin: 0 0 16px; }
.asset-filters input[type=search] { flex: 1 1 200px; min-width: 0; max-width: 320px; }
.asset-critical { margin: 4px 0 16px; align-items: flex-start; }
.asset-critical input { margin-top: 3px; flex: none; }
.asset-notes { white-space: pre-line; }
td.asset-code { white-space: normal; overflow-wrap: anywhere; min-width: 5.5rem; max-width: 9rem; }
td.asset-badges { white-space: normal; min-width: 7rem; }
td.asset-badges .badge { margin: 2px 4px 2px 0; }
/* Four columns (the location is a line under the name) so the list fits beside the sidebar
   (~630px at 1024) and at 641px; headers may wrap. */
.asset-table th { white-space: normal; }
/* Phones: the two filters side by side, the search on its own row; very narrow: one per row. */
@media (max-width: 768px) {
  .asset-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .asset-filters input[type=search], .asset-filters > .btn { grid-column: 1 / -1; max-width: none; width: 100%; }
  .asset-filters .cselect { width: 100%; }
}
@media (max-width: 420px) { .asset-filters { grid-template-columns: minmax(0, 1fr); } }

/* Pick-or-type field (input[data-combo] in app.js): a text box + ▾ list of the values already used. */
.combo { position: relative; }
.combo > input { width: 100%; padding-right: 46px; }
.combo-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center; border: 0; border-radius: 10px;
  background: transparent; color: var(--faint); cursor: pointer; }
.combo-toggle:hover { background: var(--grey-bg); color: var(--ink); }
.combo-toggle .chev { display: block; transform-origin: 50% 50%; transform-box: fill-box; transition: transform .18s; }
.combo.open .combo-toggle .chev { transform: rotate(180deg); }
.combo-menu { max-height: 260px; overflow-y: auto; overscroll-behavior: contain; }
.combo-menu .suggest-opt { font-weight: 600; overflow-wrap: anywhere; }
.combo-menu .suggest-opt.selected { color: var(--accent); }
.combo-note { padding: 8px 11px; font-size: 13.5px; color: var(--ink-soft); overflow-wrap: anywhere; }
.combo-menu .suggest-opt + .combo-note { border-top: 1px solid var(--line); margin-top: 4px; }
.combo-note.combo-new { color: var(--accent); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .combo-toggle .chev { transition: none; } }

/* ---- Schedule (views/schedule.ejs + app.js "Schedule") ----
   Month / week calendar. Day cells are drop targets for dragged task chips. */
.cal { padding: 18px 20px 16px; }
.cal-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 10px; }
.cal-nav, .cal-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-width: 0; }
.cal-nav > *, .cal-tools > * { min-width: 0; }
.cal-arrow { width: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.cal-title { margin: 0px !important; font-size: 20px; font-weight: 800; letter-spacing: -.02em; overflow-wrap: anywhere; }
.cal-who { margin: 0; }
.cal-who .cselect { width: 220px; max-width: 100%; }
.cal-hint { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-soft); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface-2); padding: 8px 4px; text-align: center; font-size: 12.5px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.cal-dow .dow-short { display: none; }
.cal-day { background: var(--surface); min-width: 0; min-height: 124px; padding: 6px; display: flex; flex-direction: column; gap: 4px; transition: background .12s; }
.cal-month .cal-day.is-out { background: var(--surface-2); }
.cal[data-can-move="1"] .cal-day { cursor: pointer; }
.cal[data-can-move="1"] .cal-day:hover { background: color-mix(in srgb, var(--accent-bg) 45%, var(--surface)); }
.cal-dhead { display: flex; align-items: center; justify-content: space-between; gap: 4px; min-width: 0; }
.cal-dname { overflow-wrap: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); min-width: 0; }
.cal-dnum { flex: none; width: 30px; height: 30px; padding: 0; white-space: nowrap; overflow-wrap: normal; border: 0; border-radius: 50%; background: transparent; color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.cal-month .cal-dnum { margin-left: auto; }
.cal-dnum:hover { background: var(--grey-bg); }
.is-out .cal-dnum { color: var(--faint); }
.cal-day.is-today .cal-dnum { background: var(--accent-solid); color: var(--accent-ink); }
.cal-tasks { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-chip { display: flex; align-items: baseline; gap: 5px; width: 100%; min-width: 0; margin: 0; padding: 3px 7px; text-align: left;
  border: 0; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--accent-bg); color: var(--ink);
  font: inherit; font-size: 13px; line-height: 1.35; cursor: pointer;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.cal-chip[data-drag] { cursor: grab; }
.cal-chip:hover { filter: brightness(.97); }
.cal-chip:focus-visible, .cal-dnum:focus-visible, .cal-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-chip-time { flex: 0 1 auto; min-width: 0; max-width: 100%; font-size: 12px; font-weight: 700; color: var(--accent); overflow-wrap: anywhere; }   /* "6:30 AM – 6:45 PM" may wrap in a narrow day */
.cal-chip-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip-meta { display: none; }
.cal-chip-mark { flex: none; font-size: 12px; font-weight: 800; }
.cal-chip.is-done { background: var(--ok-bg); border-left-color: var(--ok); }
.cal-chip.is-done .cal-chip-title { text-decoration: line-through; color: var(--ink-soft); }
.cal-chip.is-done .cal-chip-time, .cal-chip.is-done .cal-chip-mark { color: var(--ok); }
.cal-chip.is-overdue { background: var(--warn-bg); border-left-color: var(--warn); }
.cal-chip.is-overdue .cal-chip-time, .cal-chip.is-overdue .cal-chip-mark { color: var(--warn); }
.cal-chip.is-saving { opacity: .6; }
/* Multi-day: one piece per day, joined into a bar (square inner ends). */
.cal-chip.is-span { border-radius: 0; }
.cal-chip.span-first { border-radius: 6px 0 0 6px; }
.cal-chip.span-last { border-radius: 0 6px 6px 0; }
.cal-chip.span-first.span-last { border-radius: 6px; }
.cal-chip.span-cont { border-left-color: transparent; }
.cal-month .cal-chip.is-span:not(.span-last) { margin-right: -7px; width: calc(100% + 7px); }
.cal-month .cal-chip.span-cont { margin-left: -7px; width: calc(100% + 7px); }
.cal-month .cal-chip.span-cont:not(.span-last) { width: calc(100% + 14px); }
.cal-chip.span-cont .cal-chip-title { opacity: .75; }
/* Deleted: kept on its day, greyed out and read-only (opens with its history). */
.cal-chip.is-deleted { background: var(--grey-bg); border-left-color: var(--faint); color: var(--ink-soft); }
.cal-chip.is-deleted .cal-chip-title { text-decoration: line-through; color: var(--ink-soft); font-weight: 500; }
.cal-chip.is-deleted .cal-chip-time { color: var(--faint); }
.cal-chip-tag { flex: none; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--faint); }
/* Skipped: an overdue task was moved on from this day — red, with the reason. */
.cal-skips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-skips:empty { display: none; }
.cal-skip { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 5px; width: 100%; min-width: 0; margin: 0; padding: 3px 7px; text-align: left;
  border: 1px dashed color-mix(in srgb, var(--danger) 55%, transparent); border-left: 3px solid var(--danger); border-radius: 6px;
  background: var(--danger-bg); color: var(--danger); font: inherit; font-size: 13px; line-height: 1.35; cursor: pointer; }
.cal-skip:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }
.cal-skip .cal-chip-title { text-decoration: line-through; color: var(--danger); }
.cal-skip .cal-chip-mark { color: var(--danger); }
.cal-skip .cal-chip-meta { display: block; width: 100%; font-size: 12px; color: var(--danger); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-week .cal-skip .cal-chip-meta, .cal-agenda .cal-skip .cal-chip-meta { white-space: normal; overflow-wrap: break-word; }
.cal-week .cal-skip { padding: 6px 8px; }
.cal-chip.is-dragging-src { opacity: .3; }
.cal-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cal-extra { display: none; }
.cal-day.show-all .cal-extra { display: flex; }
.cal-more { align-self: flex-start; max-width: 100%; border: 0; border-radius: 6px; background: none; padding: 2px 6px; color: var(--accent);
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.cal-more:hover { background: var(--accent-bg); }
.cal-more[hidden] { display: none; }
.cal-more .more-short { display: none; }
/* Week: one column per day, every task shown with who / which asset. */
.cal-week .cal-day { min-height: 300px; padding: 8px; }
.cal-week .cal-chip { flex-wrap: wrap; padding: 6px 8px; }
.cal-week .cal-chip-title { white-space: normal; overflow-wrap: break-word; word-break: normal; }
.cal-week .cal-chip-title, .cal-agenda .cal-chip-title { flex-basis: 100%; }   /* time (and ✓ / !) above, title on its own line */
.cal-week .cal-chip-meta, .cal-agenda .cal-chip-meta { display: block; width: 100%; font-size: 12px; color: var(--ink-soft); overflow-wrap: anywhere; }
.cal-week .cal-chip-meta:empty, .cal-agenda .cal-chip-meta:empty { display: none; }
.cal-week .is-today .cal-dname { color: var(--accent); }
/* Dragging */
.cal-ghost { position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; margin: 0;
  box-shadow: var(--shadow); opacity: .95; rotate: 2deg; }
html.cal-dragging, html.cal-dragging * { cursor: grabbing !important; }
.cal-day.is-drop { background: var(--accent-bg); box-shadow: inset 0 0 0 2px var(--accent); }
/* Phone agenda (month view) — hidden on wider screens, where the grid shows everything. */
.cal-agenda { display: none; }
.cal-agenda-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 16px 0 8px; }
.cal-agenda-head h3 { margin: 0; font-size: 16px; min-width: 0; }
.cal-agenda-list { display: flex; flex-direction: column; gap: 6px; }
.cal-agenda .cal-chip { flex-wrap: wrap; min-height: var(--h); padding: 9px 12px; font-size: 15px; align-items: center; }
.cal-agenda .cal-chip-title { white-space: normal; overflow-wrap: break-word; }
.cal-agenda-empty { margin: 4px 0 0; font-size: 14px; }
.cal-agenda-empty[hidden] { display: none; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-key { width: 14px; height: 10px; border-radius: 3px; background: var(--accent-bg); border-left: 3px solid var(--accent); }
.cal-key.is-overdue { background: var(--warn-bg); border-left-color: var(--warn); }
.cal-key.is-done { background: var(--ok-bg); border-left-color: var(--ok); }
.cal-key.is-deleted { background: var(--grey-bg); border-left-color: var(--faint); }
.cal-key.is-skipped { background: var(--danger-bg); border-left-color: var(--danger); }
/* Task dialog */
.modal-form { display: flex; flex-direction: column; min-height: 0; flex: 1; margin: 0; }
.task-modal { padding: 16px; }
.task-modal .modal { max-width: 600px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
.task-modal .modal-head { padding: 20px 26px; }
.task-modal .modal-body { padding: 24px 26px 26px; }
.task-modal .modal-foot { flex-wrap: wrap; gap: 10px; padding: 18px 26px; }
/* One even rhythm between the dialog's rows; each hint stays with its own row. */
.task-modal .modal-body > .field, .task-modal .modal-body > .grid2, .task-modal .modal-body > .task-when { margin: 0; }
.task-modal .modal-body > :not([type=hidden]) + :not([type=hidden]) { margin-top: 20px; }
.task-modal .grid2, .task-modal .grid3 { gap: 16px 18px; }
.task-modal .task-time-hint { margin: 8px 0 0; }
.task-modal .task-done { padding-top: 18px; border-top: 1px solid var(--line); }
.task-modal .task-del { margin-right: auto; }
.task-modal .task-del[hidden], .task-done[hidden], .task-status-form[hidden] { display: none; }
.task-status-form { margin: 0; }
.task-modal .task-times { margin-top: 16px; }
/* Red-mark dialog */
.mark-reason { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); min-width: 0; }
.mark-reason-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.mark-reason-text { font-size: 15px; font-weight: 600; white-space: pre-line; overflow-wrap: break-word; }
.mark-reason-by { font-size: 12.5px; color: var(--ink-soft); }
.mark-reason-by:empty { display: none; }
#markModal .task-open-btn { margin-right: auto; }
.task-deleted-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 20px !important; color: var(--ink-soft); font-size: 14px; }
.task-deleted-note[hidden] { display: none; }
.task-modal.is-locked input:disabled, .task-modal.is-locked textarea:disabled, .task-modal.is-locked .cselect-trigger:disabled { background: var(--surface-2); color: var(--ink-soft); cursor: not-allowed; opacity: 1; }
#taskSubmit[hidden] { display: none; }
.task-modal .task-skip textarea { border-color: color-mix(in srgb, var(--danger) 45%, var(--line-strong)); }
.task-modal .task-skip label { color: var(--danger); }
.task-skip[hidden], .task-history[hidden] { display: none; }
/* History (newest first) */
.task-history { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.task-history h4 { margin: 0 0 10px; font-size: 14.5px; font-weight: 700; }
.task-hist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task-ev { position: relative; padding-left: 16px; min-width: 0; }
.task-ev::before { content: ''; position: absolute; left: 2px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--line-strong); }
.task-ev-done::before { background: var(--ok); }
.task-ev-skipped::before { background: var(--danger); }
.task-ev-moved::before { background: var(--accent); }
.task-ev > span { display: block; overflow-wrap: break-word; }
.task-ev-text { font-size: 14px; font-weight: 600; }
.task-ev-by { font-size: 12.5px; color: var(--ink-soft); }
.task-ev-reason { margin-top: 3px; padding: 6px 10px; border-radius: 8px; background: var(--danger-bg); color: var(--danger); font-size: 13.5px; white-space: pre-line; }
.task-modal .skip-modal { max-width: 480px; }
.skip-desc { margin: 0 0 16px; color: var(--ink-soft); }
#skipModal .modal-body > .field { margin: 0; }
.task-kv { row-gap: 12px; column-gap: 20px; margin: 0; }
.task-kv dt { padding-top: 1px; }
.task-kv dd { min-width: 0; }
@media (max-width: 900px) {
  .cal-week .cal-day { padding: 6px 4px; }
  .cal-week .cal-dname { font-size: 11px; letter-spacing: 0; }
}
@media (max-width: 640px) {
  .cal { padding: 14px 12px; }
  .cal-title { font-size: 17px; margin-left: 2px; flex-basis: 100%; }
  .cal-tools { width: 100%; }
  .cal-who { flex: 1 1 140px; }
  .cal-who .cselect { width: 100%; }
  /* Month: small cells with a coloured bar per task; the day's tasks are listed below. */
  .cal-dow { padding: 6px 0; font-size: 11.5px; letter-spacing: 0; }
  .cal-dow .dow-long { display: none; }
  .cal-dow .dow-short { display: inline; }
  .cal-month .cal-day { min-height: 58px; padding: 3px 2px 4px; gap: 2px; align-items: center; cursor: pointer; }
  .cal-month .cal-dnum { margin: 0; width: 28px; height: 28px; font-size: 13.5px; }
  .cal-month .cal-day.is-selected { box-shadow: inset 0 0 0 2px var(--accent); }
  .cal-month .cal-tasks { width: 100%; padding: 0 3px; gap: 2px; }
  .cal-month .cal-chip { height: 5px; padding: 0; border: 0; border-radius: 3px; background: var(--accent); pointer-events: none; }
  .cal-month .cal-chip > * { display: none; }
  .cal-month .cal-chip.is-done { background: var(--ok); }
  .cal-month .cal-chip.is-overdue { background: var(--warn); }
  .cal-month .cal-chip.is-deleted { background: var(--line-strong); }
  .cal-month .cal-skips { width: 100%; padding: 0 3px; gap: 2px; }
  .cal-month .cal-skip { height: 5px; padding: 0; border: 0; border-radius: 3px; background: var(--danger); pointer-events: none; }
  .cal-month .cal-skip > * { display: none; }
  .cal-agenda .cal-skip { min-height: var(--h); padding: 9px 12px; font-size: 15px; align-items: center; }
  .cal-month .cal-day.show-all .cal-extra { display: none; }
  .cal-month .cal-more { align-self: center; padding: 0; font-size: 11px; line-height: 1.2; pointer-events: none; }
  .cal-month .cal-more .more-long { display: none; }
  .cal-month .cal-more .more-short { display: inline; }
  .cal-month ~ .cal-agenda { display: block; }
  /* Week: days stacked, each a drop target. */
  .cal-week { grid-template-columns: minmax(0, 1fr); }
  .cal-week .cal-day { min-height: 0; padding: 8px 10px 10px; }
  .cal-week .cal-dhead { justify-content: flex-start; gap: 8px; }
  .cal-week .cal-dname { font-size: 12.5px; }
  .cal-week .cal-dnum { order: -1; }
  .cal-week .cal-tasks:empty::after { content: attr(data-empty); font-size: 13.5px; color: var(--faint); padding: 2px 2px 0; }
  .cal-week .cal-chip { min-height: var(--h); padding: 8px 10px; font-size: 14.5px; align-items: center; }
  .task-modal .task-del { margin-right: 0; order: 3; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .cal-day { transition: none; } .cal-ghost { rotate: none; } }

/* ===================== Responsive guards =====================
   Nothing may push past its container or the screen (see docs/design-system.md
   "Responsive"). Grid/flex children are allowed to shrink below their content's
   natural width; long unbroken text wraps; media scales down; select labels clip
   with "…" instead of widening the form. Check pages with checkOverflow() in dev. */
.grid2 > *, .grid3 > *, .kpis > *, .dash-row > *, .row-flex > *, .toolbar > *, .page-head > *, .field { min-width: 0; }
.cselect, .cselect-trigger { max-width: 100%; }
.toolbar .cselect-trigger, .grid2 .cselect-trigger, .grid3 .cselect-trigger { min-width: 0; }   /* shrinks with its slot instead of spilling over its neighbour */
.cselect-value { min-width: 0; white-space: nowrap; }
.card, .modal-body, .toast-msg, .page-head h1, .page-head .sub, .sec-desc, .kv dd, td { overflow-wrap: anywhere; }
/* Table cells hold one line by default; a cell with user text (a person's or an
   organization's name) gets .cell-text so a long name wraps instead of widening the table. */
td.cell-text { white-space: normal; min-width: 9rem; }
img, video, canvas, iframe { max-width: 100%; height: auto; }
input, select, textarea { max-width: 100%; }
/* Tab bars never hide tabs off to the side on phones: tabs share the width and
   long labels (Khmer) wrap onto two lines. */
@media (max-width: 640px) {
  .js-tabs .tabs { overflow-x: visible; }
  .settings-tab { flex: 1 1 0; min-width: 0; white-space: normal; text-align: center; padding: 10px 6px 11px; line-height: 1.3; }
}
/* Days of a multi-day task, ticked off one by one (task dialogs) */
.task-days { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); min-width: 0; }
.task-days[hidden] { display: none; }
.task-days h4 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 0 4px; font-size: 14.5px; font-weight: 700; }
.task-days-count { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.task-days-count.is-complete { color: var(--ok); }
.task-days .task-days-hint { margin: 0 0 10px; }
.task-days-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.task-day { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 12px; min-width: 0;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.task-day.is-done { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); }
.task-day.is-late { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.task-day.is-today { box-shadow: inset 3px 0 0 var(--accent); }
.task-day .checkline { min-width: 0; min-height: 28px; }
.task-day .checkline input { width: 20px; height: 20px; flex: none; accent-color: var(--ok); }
.task-day .checkline label { display: flex; flex-wrap: wrap; gap: 0 8px; min-width: 0; cursor: pointer; }
.task-day input:disabled + label { cursor: default; }
.task-day-n { font-weight: 700; }
.task-day-date { color: var(--ink-soft); }
.task-day-by { font-size: 12.5px; color: var(--ink-soft); overflow-wrap: anywhere; min-width: 0; }
.task-ev-day_done::before { background: var(--ok); }

/* ---- Dashboard (views/dashboard.ejs) ---- */
a.kpi { color: inherit; text-decoration: none; transition: transform .12s, box-shadow .12s; }
a.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
a.kpi:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { a.kpi, a.kpi:hover { transition: none; transform: none; } }
.dash-act { text-align: right; }
.dash-act form { margin: 0; display: inline; }
/* Table view (wider than a phone): the time and the action button may wrap so the table fits. */
@media (min-width: 641px) {
  td.dash-time { white-space: normal; min-width: 5.5rem; max-width: 7.5rem; }
  td.dash-tick { min-width: 9rem; }
  .dash-act .btn { white-space: normal; max-width: 10rem; height: auto; min-height: 36px; padding-top: 6px; padding-bottom: 6px; line-height: 1.25; }
}
tr.dash-mine td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.dash-more { margin: 12px 0 0; }
#today, #attention { scroll-margin-top: 80px; }
.dash-status { margin-top: 6px; }
/* Work progress card: big %, a done / overdue / to-come bar, and a chart (the .barchart styles). */
.prog-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.prog-head h2 { margin: 0; min-width: 0; overflow-wrap: break-word; }
.prog-top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 24px; margin: 4px 0 14px; }
.prog-big { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-width: 0; }
.prog-pct { font-size: 52px; font-weight: 800; line-height: 1; letter-spacing: -.03em; color: var(--ok); font-variant-numeric: tabular-nums; }
.prog-of { font-size: 16px; font-weight: 600; color: var(--ink-soft); }
.prog-ontrack { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; color: var(--ink-soft); min-width: 0; }
.prog-bar { display: flex; height: 18px; border-radius: 999px; overflow: hidden; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
.prog-bar span { display: block; height: 100%; }
.pb-done { background: var(--ok); }
.pb-overdue { background: var(--warn); }
.pb-upcoming { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.prog-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 14px; color: var(--ink-soft); }
.prog-legend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.pk { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }
.pk-done { background: var(--ok); } .pk-overdue { background: var(--warn); } .pk-upcoming { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.prog-sub { margin: 22px 0 10px !important; font-size: 14.5px !important; color: var(--ink-soft) !important; }
.prog-chart .bc-stack { max-width: 34px; width: 70%; background: transparent; }
.prog-chart .bc-stack span { flex: none; }
.prog-chart .bc-col { min-width: 0; }
.prog-chart .bc-label, .prog-chart .bc-total { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.bc-l-short { display: none; }
@media (max-width: 640px) {
  .prog-pct { font-size: 44px; }
  .prog-year .bc-l-long, .prog-month .bc-l-long { display: none; }
  .prog-year .bc-l-short, .prog-month .bc-l-short { display: inline; }
  .prog-month .bc-l-short { font-size: 10.5px; }
  .prog-year .bc-total.is-partial { visibility: hidden; }   /* "5/10" doesn't fit 12 columns; the bar above has the numbers */
}

/* ---- Account tab (views/partials/account.ejs): name · phone number · password, one block each ---- */
.acct-block { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.acct-block h3 { margin: 0 0 12px !important; font-size: 16px !important; }
.acct-form { max-width: 460px; }
.acct-form .field { margin-bottom: 14px; }
.acct-form [hidden] { display: none !important; }
/* The password manager's "which account" hint: present for the browser, invisible to people. */
.acct-form { position: relative; }
.acct-form input.acct-username { position: absolute; left: 0; top: 0; width: 1px !important; min-width: 0; height: 1px; padding: 0; margin: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; opacity: 0; pointer-events: none; }

/* 12-hour time (views/partials/time12.ejs): hour · minutes · AM / PM side by side. */
.time12-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.time12-row .cselect, .time12-row select { width: 100%; min-width: 0; }
.time12-row .cselect-trigger { min-width: 0; padding: 0 10px; gap: 4px; }

/* ---- Profile (views/profile.ejs) ---- */
.avatar { overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.xl { width: 88px; height: 88px; border-radius: 50%; background: var(--accent-solid); color: #fff; display: grid; place-items: center; flex: none; font-size: 34px; font-weight: 800; }
.tb-icon.has-photo { padding: 0; overflow: hidden; }
.tb-photo { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.profile-card[data-mode="view"] .profile-edit, .profile-card[data-mode="edit"] .profile-view { display: none; }
.profile-hero { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; margin-bottom: 18px; }
.profile-id { flex: 1 1 200px; min-width: 0; }
.profile-id h2 { margin: 0 0 2px !important; font-size: 22px !important; overflow-wrap: anywhere; }
.profile-role { margin-top: 4px; font-size: 14px; color: var(--ink-soft); overflow-wrap: anywhere; }
.profile-edit-btn { gap: 8px; }
.profile-kv { margin: 0; padding-top: 16px; border-top: 1px solid var(--line); }
.profile-orgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.profile-orgs li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.profile-edit { max-width: 520px; }
.profile-edit .field { margin-bottom: 16px; }
.profile-edit [hidden], .profile-photo [hidden] { display: none !important; }
.profile-photo { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin: 4px 0 20px; }
.profile-photo-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1 1 220px; min-width: 0; }
.profile-photo-actions .field-hint { flex-basis: 100%; margin: 2px 0 0; }
.profile-photo-actions { position: relative; }
.profile-photo-actions input.profile-file { position: absolute; left: 0; top: 0; width: 1px !important; min-width: 0; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.profile-photo-actions label.btn { cursor: pointer; margin: 0; text-transform: none; letter-spacing: 0; }
.profile-photo-actions label.btn:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
.profile-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.profile-nochange { margin: 0 auto 0 0; }
.profile-nochange[hidden] { display: none; }
.profile-pw-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.profile-pw-head h2 { margin: 0 !important; }
.profile-pw-head [hidden], #pwForm[hidden] { display: none !important; }
#pwForm { max-width: 520px; }
.prefs-profile { margin-top: 18px; }
#profileSave:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
@media (max-width: 480px) {   /* narrow: the three values must stay readable (":00", "AM"), so no ▾ */
  .time12-row .cselect-trigger { padding: 0 6px; justify-content: center; }
  .time12-row .cselect-trigger .chev { display: none; }
}

/* ---- Requests (views/requests.ejs, request.ejs, request-form.ejs) and places ---- */
.req-filter { margin-bottom: 14px; flex-wrap: wrap; }
.req-count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; }
.req-head-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.req-decide { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px 24px; }
.req-decide > .btn { flex: none; }
.req-decline { flex: 1 1 280px; min-width: 0; max-width: 520px; }
.req-decline .field { margin-bottom: 10px; }
.req-cols { margin-top: 0; }
.req-photo { display: block; margin-top: 16px; max-width: 420px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.req-photo img { display: block; width: 100%; height: auto; }
.req-own { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.req-own form { margin: 0; }
.req-timeline { margin-bottom: 14px; }
.req-waiting .task-ev-text { color: var(--ink-soft); font-weight: 600; }
.req-waiting::before { background: var(--accent) !important; }
.req-form { max-width: 720px; }
.req-form > .field, .req-form > .grid2 { margin-bottom: 16px; }
.label-like { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.req-urgent { margin: 0; }
.req-photo-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.req-photo-preview { width: 120px; height: 90px; flex: none; border-radius: 12px; border: 1px dashed var(--line-strong); background: var(--surface-2); overflow: hidden; display: grid; place-items: center; }
.req-photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.req-photo-pick [hidden] { display: none !important; }
.place-hint { margin: -6px 0 16px; }
.task-modal .place-hint { margin: 8px 0 0; }
.task-request-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 18px !important; padding: 8px 12px; border-radius: 10px; background: var(--accent-bg); color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.task-request-note[hidden], [data-tv-request][hidden] { display: none; }
.dash-reqs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.dash-reqs li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; padding: 12px 0; border-top: 1px solid var(--line); min-width: 0; }
.dash-reqs li:first-child { border-top: 0; padding-top: 4px; }
.dash-req-main { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.notif-req_new .notif-text::before, .notif-req_remind .notif-text::before { content: '✉ '; color: var(--accent); }
