/* ==========================================================================
   Reusable components: shell, buttons, cards, forms, tables, badges,
   modals, toasts, empty/loading states.
   ========================================================================== */

/* ── App shell ─────────────────────────────────────────────────────────── */

.shell { display: flex; min-height: 100dvh; }

.sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  /* RTL: the sidebar is on the right, so the rule facing the content is its
     inline-end edge. */
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5);
  border-bottom: 1px solid var(--divider);
  min-height: var(--topbar-h);
}
.brand-mark {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--accent-solid);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text { min-width: 0; }
.brand-name { font-weight: 700; font-size: var(--fs-md); letter-spacing: -0.02em; }
.brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.side-nav { padding: var(--sp-4) var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-1); }
.side-group-label {
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0;
  color: var(--text-subtle);
  text-transform: none;
}
.side-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  min-height: 46px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-weight: 550;
  font-size: var(--fs-base);
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.side-link:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.side-link svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: 0.85; }
.side-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 650;
  box-shadow: inset 0 0 0 1px var(--accent-border);
}
.side-link.is-active svg { opacity: 1; }
.side-link.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 28%; bottom: 28%;
  width: 3px;
  border-radius: var(--r-full);
  background: var(--accent);
}

.side-foot {
  margin-top: auto;
  padding: var(--sp-4);
  border-top: 1px solid var(--divider);
  display: flex; flex-direction: column; gap: var(--sp-3);
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 25;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) clamp(1rem, 2.8vw, 2.75rem);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 650; font-size: var(--fs-md); }
.topbar-meta { font-size: var(--fs-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }

.content {
  flex: 1 1 auto;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--sp-8) clamp(1rem, 2.8vw, 2.75rem) var(--sp-12);
}
.content-narrow { max-width: 900px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-6);
}
.page-title { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.page-sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-2); max-width: 75ch; line-height: 1.7; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Centered layout for login / identity screens. */
.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-5);
  background: var(--bg);
  background: radial-gradient(ellipse at top, var(--accent-soft), transparent 65%), var(--bg);
}
.auth-card { width: 100%; max-width: 460px; min-width: 0; }
.auth-card > .card { box-shadow: var(--shadow-md); }
.auth-card .card-body { padding: clamp(1.25rem, 5vw, 2rem); }
.auth-head { text-align: center; margin-bottom: var(--sp-6); }
.auth-logo {
  width: 52px; height: 52px;
  margin: 0 auto var(--sp-4);
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--accent-solid);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.auth-logo svg { width: 26px; height: 26px; }

/* ── Mobile shell ──────────────────────────────────────────────────────── */

.topbar .nav-toggle { display: none; }
.scrim { display: none; }

@media (max-width: 1023px) {
  /* Off-canvas drawer, anchored to the reading start (the right in RTL) and
     pushed off that same edge when closed. translateX is not direction-aware,
     so +100% always means "off to the right". */
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    transform: translateX(100%);
    transition: transform var(--t-base);
    box-shadow: var(--shadow-lg);
    border-inline-end: none;
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell:not(.nav-open) .sidebar { display: none; }
  .topbar .nav-toggle { display: inline-flex; }
  .shell.nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 28;
  }
  .content { padding: var(--sp-4) var(--sp-4) var(--sp-12); }
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  --btn-bg: var(--surface);
  --btn-ink: var(--text);
  --btn-border: var(--field-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.5rem 0.9rem;
  min-height: 44px;
  border: 1px solid var(--btn-border);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-ink);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              box-shadow var(--t-fast), transform var(--t-fast);
  box-shadow: var(--shadow-xs);
}
.btn:hover { text-decoration: none; background: var(--surface-hover); border-color: var(--text-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

.btn-primary {
  --btn-bg: var(--accent-solid);
  --btn-ink: #fff;
  --btn-border: transparent;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--accent-solid) 35%, transparent);
}
.btn-primary:hover { background: var(--accent-solid-hover); }

.btn-ok {
  --btn-bg: var(--ok-solid);
  --btn-ink: var(--ok-solid-ink);
  --btn-border: transparent;
}
.btn-ok:hover { background: color-mix(in srgb, var(--ok-solid) 88%, #000); }

.btn-danger { --btn-bg: var(--danger-soft); --btn-ink: var(--danger-ink); --btn-border: var(--danger-border); }
.btn-danger:hover { background: var(--danger-solid); color: #fff; border-color: transparent; }

.btn-ghost { --btn-bg: transparent; --btn-border: transparent; box-shadow: none; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn-soft { --btn-bg: var(--accent-soft); --btn-ink: var(--accent-ink); --btn-border: var(--accent-border); }

.btn-sm { min-height: 36px; padding: 0.3rem 0.7rem; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { min-height: 46px; padding: 0.65rem 1.3rem; font-size: var(--fs-md); border-radius: var(--r-lg); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: 44px; min-height: 44px; }
.btn-icon.btn-sm { width: 36px; min-height: 36px; }

/* Segmented control for view switching. */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  max-width: 100%;
  flex-wrap: wrap;
}
.segmented a, .segmented button {
  min-height: 36px;
  padding: 0.32rem 0.8rem;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  transition: background var(--t-fast), color var(--t-fast);
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented .is-active {
  background: var(--surface);
  color: var(--accent-ink);
  box-shadow: var(--shadow-xs);
}
.segmented svg { width: 15px; height: 15px; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-6); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--divider);
  flex-wrap: wrap;
}
.card-title { font-size: var(--fs-md); font-weight: 650; display: flex; align-items: center; gap: var(--sp-2); }
.card-title svg { width: 18px; height: 18px; color: var(--accent); flex-shrink: 0; }
.card-desc { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--sp-1); }
.card-body { padding: var(--sp-6); }
.card-body-flush { padding: 0; }
.card-foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
  border-end-start-radius: var(--r-lg);
  border-end-end-radius: var(--r-lg);
  display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap;
}

.grid { display: grid; gap: var(--sp-5); }
/* min(Npx, 100%) keeps the track floor from exceeding the container on a narrow
   phone — a bare minmax(300px, 1fr) overflows a 288px content box. */
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(min(280px, 100%), 1fr); }
@media (max-width: 1100px) { .grid-main { grid-template-columns: 1fr; } }

/* ── Stat tiles ────────────────────────────────────────────────────────── */

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: var(--sp-5);
  height: 2px;
  background: var(--border-strong);
}
.stat-ok::before { background: var(--ok); }
.stat-danger::before { background: var(--danger); }
.stat-accent::before { background: var(--accent); }
.stat-warn::before { background: var(--warn); }

.stat-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  display: flex; align-items: center; gap: var(--sp-2);
}
.stat-label svg { width: 14px; height: 14px; }
.stat-value {
  font-size: var(--fs-3xl);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-top: var(--sp-3);
  font-variant-numeric: tabular-nums;
}
.stat-ok .stat-value { color: var(--ok-ink); }
.stat-danger .stat-value { color: var(--danger-ink); }
.stat-accent .stat-value { color: var(--accent); }
.stat-warn .stat-value { color: var(--warn-ink); }
.stat-hint { font-size: var(--fs-xs); color: var(--text-subtle); margin-top: var(--sp-2); line-height: 1.65; }
.row-wrap > .stat { align-self: stretch; display: flex; flex-direction: column; }
.row-wrap > .stat .stat-value { margin-top: auto; padding-block-start: var(--sp-3); }
.stat-value:has(.stat-of) { direction: ltr; unicode-bidi: isolate; text-align: end; }
.stat-of { font-size: var(--fs-md); font-weight: 600; color: var(--text-subtle); }

/* Thin progress meter used inside tiles and team rows. */
.meter {
  height: 6px;
  border-radius: var(--r-full);
  background: var(--bg-subtle);
  overflow: hidden;
  margin-top: var(--sp-2);
}
.meter-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width var(--t-base);
}
.meter-ok .meter-fill { background: var(--ok); }
.meter-warn .meter-fill { background: var(--warn); }
.meter-danger .meter-fill { background: var(--danger); }

/* ── Badges & status ───────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1.6;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; }
.badge-ok { background: var(--ok-soft); color: var(--ok-ink); border-color: var(--ok-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger-ink); border-color: var(--danger-border); }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); border-color: var(--warn-border); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent-border); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--fs-sm);
  font-weight: 550;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: var(--fs-xs);
  font-weight: 700;
  flex: 0 0 auto;
  border: 1px solid var(--accent-border);
}
.avatar-lg { width: 46px; height: 46px; font-size: var(--fs-base); }

/* ── Forms ─────────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.field-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  display: flex; align-items: center; gap: var(--sp-2);
}
.field-label .req { color: var(--danger); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; }

.input, .select, .textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  border: 1px solid var(--field-border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-subtle); cursor: not-allowed; }
.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }

.select {
  appearance: none;
  padding-inline-end: 2rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: left 0.6rem center;
  background-size: 15px;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2398a7bd' stroke-width='2.2' stroke-linecap='round'><path d='M6 9l6 6 6-6'/></svg>");
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-inline-start: 2.25rem; }
.input-group-icon {
  position: absolute;
  inset-inline-start: 0.7rem;
  color: var(--text-subtle);
  pointer-events: none;
  display: grid; place-items: center;
}
.input-group-icon svg { width: 16px; height: 16px; }

.pin-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: var(--fs-xl);
  font-family: var(--font-num);
  min-height: 52px;
  padding-inline: 0.5rem;
}

.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.field-span-2 { grid-column: span 2; }
@media (max-width: 640px) { .field-span-2 { grid-column: span 1; } }

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.check:hover { border-color: var(--accent-border); }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: 0 0 auto; }
.check:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }
.check-text { font-size: var(--fs-sm); }
.check-title { font-weight: 600; }

.toolbar {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-end;
  flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--divider);
}
.toolbar .field { flex: 1 1 140px; }
.toolbar .field-search { flex: 1 1 220px; min-width: 180px; }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap {
  position: relative;
  max-width: 100%;
  contain: inline-size;
  scrollbar-color: var(--border-strong) var(--surface-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  /* Inside a flex/grid layout, an item's default min-width is "auto" (at
     least as wide as its content) — for a wrapper around a wide table, that
     defeats overflow-x:auto entirely and pushes the real page width past
     the viewport instead of scrolling internally. min-width:0 lets it
     actually shrink to the available column width. */
  min-width: 0;
}
.table { width: 100%; font-size: var(--fs-base); }
.table th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: start;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--divider);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover td { background: var(--surface-hover); }
.table tbody tr:focus-within td { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: none; }
.table .col-actions { text-align: end; white-space: nowrap; width: 1%; }
.table .cell-num { font-variant-numeric: tabular-nums; text-align: center; }
.table-band td {
  background: var(--accent-soft) !important;
  color: var(--accent-ink);
  font-weight: 700;
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--accent-border);
}
.row-inactive td { color: var(--text-muted); background: var(--surface-2); }
.person { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.person-name { display: block; font-weight: 650; }
.person-meta { display: block; font-size: var(--fs-xs); color: var(--text-muted); }
#roster-table .person, #drivers-table .person { min-width: 180px; }

.table-sort {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: none; padding: var(--sp-1) 0; min-height: 32px;
  font: inherit; font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.02em;
  color: inherit;
}
.table-sort:hover { color: var(--text); }
.table-sort svg { width: 12px; height: 12px; opacity: 0.4; }
.table-sort[aria-sort="ascending"] svg,
.table-sort[aria-sort="descending"] svg { opacity: 1; color: var(--accent); }
.table-sort[aria-sort="descending"] svg { transform: rotate(180deg); }

/* ── Alerts, toasts, states ────────────────────────────────────────────── */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: var(--fs-sm);
}
.alert svg { width: 17px; height: 17px; flex: 0 0 auto; margin-top: 1px; }
.alert-title { font-weight: 650; }
.alert-ok { background: var(--ok-soft); border-color: var(--ok-border); color: var(--ok-ink); }
.alert-danger { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-ink); }
.alert-warn { background: var(--warn-soft); border-color: var(--warn-border); color: var(--warn-ink); }
.alert-info { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent-ink); }

.toast-region {
  position: fixed;
  inset-block-start: var(--sp-4);
  inset-inline: var(--sp-4);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 460px;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  font-weight: 550;
  animation: toast-in var(--t-base);
}
.toast svg { width: 18px; height: 18px; flex: 0 0 auto; }
.toast-ok { border-inline-start: 3px solid var(--ok); }
.toast-ok svg { color: var(--ok); }
.toast-error { border-inline-start: 3px solid var(--danger); }
.toast-error svg { color: var(--danger); }
.toast-warning { border-inline-start: 3px solid var(--warn); }
.toast-warning svg { color: var(--warn); }
.toast-info { border-inline-start: 3px solid var(--accent); }
.toast-info svg { color: var(--accent); }
.toast-close { border: none; background: none; color: var(--text-subtle); padding: 0; display: grid; place-items: center; }
.toast-close { min-width: 36px; min-height: 36px; }
.toast-text { overflow-wrap: anywhere; }
.toast-close:hover { color: var(--text); }
.toast.is-leaving { animation: toast-out var(--t-base) forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-5);
  color: var(--text-muted);
}
.empty-icon {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-subtle);
}
.empty-icon svg { width: 24px; height: 24px; }
.empty-title { font-weight: 650; color: var(--text); font-size: var(--fs-md); }
.empty-text { font-size: var(--fs-sm); max-width: 40ch; }

/* ── Loading states ────────────────────────────────────────────────────── */

/* Navigation progress. Every page here is server-rendered, so a click on
   "Excel" or a 61-day matrix costs a real round trip with nothing to show for
   it until the new document paints. */
.progress {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: 2px;
  z-index: 2000;
  pointer-events: none;
  background: transparent;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: width 320ms ease-out, opacity 200ms linear 120ms;
}
.progress[hidden] { display: none; }

.spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* A busy control keeps its label — only the icon is swapped for a spinner, so
   the button neither resizes nor loses its meaning mid-action. */
.btn.is-busy {
  pointer-events: none;
  opacity: 0.8;
}
.btn.is-busy > svg { display: none; }
.btn.is-busy::before {
  content: "";
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  /* Keep the affordance, drop the motion: a static bar and a dimmed control. */
  .progress-bar { transition: none; }
  .spinner, .btn.is-busy::before { animation: none; opacity: 0.6; }
}

/* ── Modal ─────────────────────────────────────────────────────────────── */

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  /* On a narrow phone, this page (like most with an off-canvas RTL nav
     drawer) has a small amount of horizontal overflow that mobile browsers
     use to size their "layout viewport" — which `inset:0`/width:100% then
     inherit, well past the real screen. That silently blows out this fixed
     overlay and pushes its content, including the Save button, off-screen.
     100vw is defined against the true visual viewport regardless, so it
     stays correct even while the underlying overflow exists. The same
     inflation happens on the vertical axis too (100dvh-based centering
     drifted downward on a short phone), so both axes get the same fix. */
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  z-index: 1000;
  display: grid;
  /* Without an explicit column, the implicit "auto" column sizes to the
     max-content width of whatever's inside .modal-box (e.g. a date input's
     native intrinsic width) — on very narrow phones (320px) that can exceed
     the viewport and push the box, including its Save button, off-screen.
     minmax(0, 1fr) caps the column at the available width regardless. */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: var(--sp-4);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  animation: fade-in var(--t-fast);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  width: 100%;
  min-width: 0;
  max-width: 560px;
  max-height: calc(100dvh - 2 * var(--sp-6));
  /* Clip to the rounded corners; .modal-body is the one scrolling region. */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--t-base);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
/* Every modal wraps its head/body/foot in a <form> — the actual flex child
   of .modal-box is that <form>, not .modal-body. Without this rule the form
   is a plain block box that refuses to shrink below its content's natural
   height (min-height:auto is the flex default), so .modal-box's max-height
   just clips it with nothing scrollable underneath: exactly the bug where a
   tall form's bottom half — including the submit button — becomes
   permanently unreachable on a short viewport. Making the form itself a
   flex column (and letting it shrink) is what lets that constraint reach
   .modal-body below. */
.modal-box > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--divider);
  flex: 0 0 auto;
}
.modal-title { font-size: var(--fs-md); font-weight: 650; }
.modal-title svg { flex-shrink: 0; }
.modal-body {
  padding: var(--sp-5);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* The two lines below are the actual fix: a flex item's default min-height
     is `auto`, which means "at least as tall as my content" — so it never
     shrinks to the space left by max-height on .modal-box, and overflow-y:auto
     never has anything to do. flex:1 + min-height:0 let it actually take only
     the remaining space and scroll within it, on any screen height. */
  flex: 1 1 auto;
  min-height: 0;
}
.modal-foot {
  display: flex; gap: var(--sp-2); justify-content: flex-end; flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
  border-end-start-radius: var(--r-xl);
  border-end-end-radius: var(--r-xl);
  flex: 0 0 auto;
}

/* ── Combobox (searchable person picker) ───────────────────────────────── */

.combo { position: relative; }
.combo-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 4px);
  z-index: 60;
  max-height: 300px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--field-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-1);
}
.combo-list[hidden] { display: none; }
.combo-option {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.combo-option:hover, .combo-option.is-active { background: var(--accent-soft); }
.combo-option[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.combo-option-name { font-weight: 600; }
.combo-option-meta { margin-inline-start: auto; font-size: var(--fs-xs); color: var(--text-muted); }
.combo-empty { padding: var(--sp-4); text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }

/* ── Misc ──────────────────────────────────────────────────────────────── */

.divider { height: 1px; background: var(--divider); border: none; margin: var(--sp-4) 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { font-weight: 600; margin: 0; }
.kv dd, .field-hint, .feed-detail { overflow-wrap: anywhere; }

/* Preserve document flow while giving long data regions a clear boundary. */
.card > .table-wrap:last-child { border-end-start-radius: var(--r-lg); border-end-end-radius: var(--r-lg); }
summary.card-head { list-style-position: inside; }
summary.card-head::after { content: "⌄"; font-size: var(--fs-lg); color: var(--text-muted); }
details[open] > summary.card-head::after { transform: rotate(180deg); }

@media (max-width: 720px) {
  .topbar { gap: var(--sp-2); padding-inline: var(--sp-4); }
  .page-head { align-items: flex-start; }
  .page-title { font-size: var(--fs-xl); }
  .page-actions { width: 100%; }
  .card-head, .card-body, .toolbar { padding: var(--sp-4); }
  .toolbar .field { flex: 1 1 100%; }
  .toolbar .field-search { min-width: 0; }
  .btn-sm, .btn-icon.btn-sm { min-height: 44px; }
  .btn-icon.btn-sm { width: 44px; }
  .segmented a, .segmented button, .table-sort { min-height: 44px; }
  .modal { padding: var(--sp-2); }
  .modal-box { max-height: calc(100dvh - 2 * var(--sp-2)); }
  .modal-head, .modal-body, .modal-foot { padding: var(--sp-4); }
  .toast-region { inset-inline: var(--sp-3); }
}

@media (forced-colors: active) {
  .badge, .cal-day.is-selected, .side-link.is-active { border: 2px solid CanvasText; }
  .btn:focus-visible, a:focus-visible { outline: 3px solid Highlight; }
}

.copy-source { position: absolute; inset-inline-start: -9999px; opacity: 0; }
