/*
  Overhaul — shared page-level CSS for admin / auth / time / people / stock
  and the generic CRUD shells (_partials/*_shell.html).

  Contents:
    1. Extracted utilities (replacing inline style="…" in templates)
    2. Responsive table patterns (.table-sticky-col, .table-cards)
    3. Toolbar / filter bars (.toolbar-wrap + .list-toolbar modifiers)
    4. Polish: flashes, focus-visible, stat grid, touch targets

  Theme safety: no hardcoded colours — everything reads tokens.css vars.
  Breakpoints mirror components.css: 1100 / 760 / 640 / 560.
*/

/* ═══ 1. Extracted utilities ═══════════════════════════════════ */

/* Spacing (on the token scale) */
.mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); } .mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); } .mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-0 { margin-bottom: 0; }
.push-end { margin-left: auto; }
.pt-2 { padding-top: var(--sp-2); } .pt-3 { padding-top: var(--sp-3); }
.gap-3 { gap: var(--sp-3); }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.fw-400 { font-weight: 400; }

/* Row modifiers (base.css .row is flex with sp-4 gap, no wrap) */
.row.wrap  { flex-wrap: wrap; }
.row.gap-2 { gap: var(--sp-2); }
.row.end   { align-items: flex-end; }

/* Constrained cards (forms, settings panels) */
.card-narrow { max-width: 880px; }
.card-slim   { max-width: 560px; }

/* Card body hosting a flush table */
.card-body-flush { padding: 0; border-radius: 0 0 var(--card-radius) var(--card-radius); overflow: hidden; }
.card-body-flush > table.data { border-radius: 0; }

/* Tinted icon chips (tone variants of .card-header .icon-chip) */
.icon-chip.tint-amber   { background: var(--tint-amber) !important;   color: var(--accent-amber) !important; }
.icon-chip.tint-rose    { background: var(--tint-rose) !important;    color: var(--accent-rose) !important; }
.icon-chip.tint-emerald { background: var(--tint-emerald) !important; color: var(--accent-emerald) !important; }
.icon-chip.tint-violet  { background: var(--tint-violet) !important;  color: var(--accent-violet) !important; }
.icon-chip.tint-cyan    { background: var(--tint-cyan) !important;    color: var(--accent-cyan) !important; }

/* Entity header — big icon + title + meta + badge cluster
   (people/profile, stock/location, stock/check_detail) */
.entity-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.entity-head .icon-chip.lg { width: 44px; height: 44px; flex: 0 0 auto; }
.entity-head .icon-chip.lg svg { width: 20px; height: 20px; }
.entity-main { flex: 1; min-width: 220px; }
.entity-main h1 { margin: 0; }
.entity-sub { margin-top: 2px; }
.entity-badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 560px) {
  .entity-head { gap: 12px; }
  .entity-badges { width: 100%; }
}

/* Chart / card section titles (analytics) */
.chart-title { font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.chart-title svg { color: var(--fg-muted); flex: 0 0 auto; }

/* Table cell helpers */
.nowrap   { white-space: nowrap; }
.fs-12    { font-size: 12px; }
.fs-13    { font-size: 13px; }
.minw-220 { min-width: 220px; }
.minw-110 { min-width: 110px; }
.grow-clip { flex: 1; min-width: 0; }
.cell-sub   { font-size: 11px; margin-top: 2px; }
.td-actions { text-align: right; white-space: nowrap; }
.td-center  { text-align: center; }
.td-ellipsis { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-depleted { opacity: 0.55; }

/* Mono text (base.css has .mono at inherited size; these set explicit sizes) */
.mono-sm    { font-family: var(--f-mono); font-feature-settings: 'tnum','zero'; font-size: 12px; }
.mono-input { font-family: var(--f-mono); font-size: 12px; }

/* Small fixed-width inputs inside tables/forms (!important beats base input width:100%) */
.w-90   { width: 90px !important; }
.w-120  { width: 120px !important; }
.w-note { min-width: 180px; }

/* Required-field asterisk, hint line under an input */
.req        { color: var(--accent-rose); }
.field-hint { margin-top: 4px; font-size: 11px; }

/* Form submit row */
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; flex-wrap: wrap; }

/* Inline checkbox + label (settings forms) */
.field-check { display: flex; align-items: center; gap: 8px; }
.field-check input[type="checkbox"] { width: auto; margin: 0; flex: 0 0 auto; }
.field-check label {
  margin: 0; text-transform: none; letter-spacing: 0;
  font-size: 13px; color: var(--fg); font-weight: 500;
}

/* Inline POST forms sitting inside action cells */
.form-inline { display: inline; }

/* Ghost button in a destructive role */
.btn-ghost.danger { color: var(--accent-rose); }
.btn-ghost.danger:hover {
  background: var(--tint-rose);
  border-color: color-mix(in srgb, var(--accent-rose) 30%, transparent);
  color: var(--accent-rose);
}

/* Full-width button (auth pages) */
.btn-block { width: 100%; justify-content: center; }

/* "OR" divider between local and SSO sign-in */
.divider-or { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--fg-muted); font-size: 12px; }
.divider-or::before, .divider-or::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Disclosure widgets (verification history, inline "mark checked") */
.details-toggle { margin-top: 12px; }
.details-toggle > summary {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--fg-muted);
}
.details-toggle > summary::-webkit-details-marker { display: none; }
.details-toggle > summary::before {
  content: '›'; display: inline-block;
  transition: transform var(--t-fast) var(--ease);
}
.details-toggle[open] > summary::before { transform: rotate(90deg); }

/* Little popover form hanging off a summary button (reject-reason) */
.popover-wrap { display: inline-block; position: relative; }
.popover-wrap > summary { list-style: none; cursor: pointer; }
.popover-wrap > summary::-webkit-details-marker { display: none; }
.popover-form {
  position: absolute; right: 0; z-index: 30;
  padding: 12px; min-width: 240px;
  box-shadow: var(--shadow-lg);
}

/* Small brand-colour swatch (companies list) — background stays inline, it's data */
.swatch-sm {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 4px; vertical-align: middle; margin-right: 6px;
  border: 1px solid var(--border-strong);
}

/* Detail-shell header action cluster + field cards */
.detail-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.info-cell { padding: 14px 16px; }
.info-cell .ic-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.info-cell .ic-value { margin-top: 4px; font-size: 14px; font-weight: 500; }
.body-pre { white-space: pre-wrap; font-size: 14px; line-height: 1.6; }

/* Inline phone-number chips (emergency contacts) */
.contact-num { display: inline-flex; gap: 8px; align-items: center; margin-right: 18px; }

/* Toggle switch (GuardM8 access, settings) */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 38px; height: 22px; flex: 0 0 auto; margin: 0;
  border-radius: var(--r-pill);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  position: relative; cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.switch input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  transition: transform var(--t-fast) var(--ease);
}
.switch input[type="checkbox"]:checked {
  background: color-mix(in srgb, var(--brand-500) 75%, var(--bg-soft));
  border-color: var(--brand-500);
}
.switch input[type="checkbox"]:checked::after { transform: translateX(16px); }
.switch .switch-label { font-size: 12px; color: var(--fg-muted); }

/* ═══ 2. Responsive tables ═════════════════════════════════════ */

/* Sticky first column inside a scrollable .table-wrap */
.table-sticky-col th:first-child,
.table-sticky-col td:first-child {
  position: sticky; left: 0; z-index: 2;
  background: var(--bg-elevated);
  box-shadow: 1px 0 0 var(--border);
}
.table-sticky-col th:first-child { background: var(--bg-soft); z-index: 3; }

/* Cards reflow: rows of table.data become stacked cards on narrow screens.
   Requires data-label="…" on each td (rendered by list_shell + page tables).
   Apply .table-cards to the .table-wrap. */
@media (max-width: 760px) {
  .table-cards {
    border: 0; background: transparent; box-shadow: none; overflow: visible;
  }
  .table-cards table.data thead {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .table-cards table.data,
  .table-cards table.data tbody,
  .table-cards table.data tr,
  .table-cards table.data td { display: block; width: 100%; }
  .table-cards table.data tr {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    margin-bottom: var(--sp-3);
    padding: 4px 0;
  }
  .table-cards table.data tr:hover { background: var(--card-bg); }
  .table-cards table.data td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    white-space: normal; text-align: right; font-size: 13px;
  }
  .table-cards table.data td::before {
    content: attr(data-label);
    font-size: 10px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--fg-subtle); text-align: left;
  }
  .table-cards table.data td:last-child { border-bottom: 0; }
  .table-cards table.data td:not([data-label]) { justify-content: flex-end; }
  .table-cards table.data td:not([data-label])::before { display: none; }
  .table-cards table.data td.td-ellipsis { max-width: none; }
  .table-cards table.data td.td-actions { text-align: right; }
  .table-cards table.data .cell-sub { text-align: right; }
}

/* ═══ 3. Toolbars / filter bars ════════════════════════════════ */

/* Generic wrapping toolbar (filters, actions, date pickers) */
.toolbar-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar-wrap.end { align-items: flex-end; }

/* Modifiers — work on .toolbar-wrap and the existing .list-toolbar */
.toolbar-wrap .grow, .list-toolbar .grow { flex: 1; min-width: 200px; max-width: 360px; }
.toolbar-wrap .w-filter, .list-toolbar .w-filter { max-width: 220px; }
.toolbar-wrap .end, .list-toolbar .end { margin-left: auto; }

@media (max-width: 560px) {
  .toolbar-wrap > input, .toolbar-wrap > select,
  .toolbar-wrap .grow, .toolbar-wrap .w-filter { flex: 1 1 100%; max-width: none; }
  .toolbar-wrap .end { margin-left: 0; }
}

/* ═══ 4. Polish ════════════════════════════════════════════════ */

/* Generic responsive stat grid (kpi-grid is fixed 4-up; this auto-fits) */
.stat-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* Flash messages — tinted to category, keep existing shape/animation */
.flash { border-radius: var(--r-md); line-height: 1.45; }
.flash.success {
  background: linear-gradient(var(--tint-emerald), var(--tint-emerald)), var(--bg-elevated);
  border-color: color-mix(in srgb, var(--accent-emerald) 35%, transparent);
  border-left-color: var(--accent-emerald);
}
.flash.error {
  background: linear-gradient(var(--tint-rose), var(--tint-rose)), var(--bg-elevated);
  border-color: color-mix(in srgb, var(--accent-rose) 35%, transparent);
  border-left-color: var(--accent-rose);
}
.flash.warn {
  background: linear-gradient(var(--tint-amber), var(--tint-amber)), var(--bg-elevated);
  border-color: color-mix(in srgb, var(--accent-amber) 35%, transparent);
  border-left-color: var(--accent-amber);
}
/* Static variant for auth/login-shell pages (no fixed position, no auto-dismiss) */
.flash-inline { position: static; margin-bottom: 14px; min-width: 0; max-width: none; animation: none; }

/* Keyboard focus ring using the theme accent (form controls already ring on :focus) */
a:focus-visible,
button:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand-500) 75%, transparent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.switch input[type="checkbox"]:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--brand-500) 75%, transparent);
  outline-offset: 2px;
}

/* Touch targets ≥ 44px at phone width (components.css covers pointer:coarse;
   this guarantees the same on narrow windows regardless of pointer type) */
@media (max-width: 760px) {
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 38px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { min-height: 44px; }
  .switch input[type="checkbox"] { min-height: 0; }
  .seg-btn { padding: 10px 16px; }
  .table-cards .btn-sm { min-height: 44px; }
  .field-check { min-height: 44px; }
}
