/* ==========================================================================
   CHMIS design system
   Reproduces the D&A Hauliers operating-system interface: green gradient
   sidebar, white top bar, light-grey canvas, bordered white cards, uppercase
   bold headings in Plus Jakarta Sans. Colours sampled from the reference.
   ========================================================================== */

@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("../vendor/fonts/plus-jakarta-sans-latin-wght-normal.7660bd9909fb.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("../vendor/fonts/plus-jakarta-sans-latin-ext-wght-normal.341687eeeb6a.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens ------------------------------------------------------ */
:root {
  --font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;

  --fs-xs: 0.75rem;     /* 12 */
  --fs-sm: 0.8125rem;   /* 13 */
  --fs-base: 0.9375rem; /* 15 */
  --fs-md: 1rem;        /* 16 */
  --fs-lg: 1.0625rem;   /* 17 — nav, card rows */
  --fs-xl: 1.25rem;     /* 20 */
  --fs-title: 2rem;     /* 32 — page title */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --fw-heavy: 800;
  --tracking-tight: -0.01em;

  --green-500: #0aa34f;   /* sidebar top */
  --green-600: #098942;
  --green-700: #1e6b3c;   /* primary actions, badges, radios */
  --green-800: #05562a;   /* active nav item */
  --green-900: #043f21;
  --green-950: #000302;   /* sidebar bottom */
  --color-primary: var(--green-700);
  --color-primary-hover: #185a32;

  --color-bg: #f4f5f8;
  --color-surface: #ffffff;
  --color-surface-muted: #f2f4f7;  /* table header, section rows */
  --color-border: #dde1e6;
  --color-input-border: #c5cbd3;
  --color-text: #1b1f23;
  --color-text-muted: #5f6b76;
  --color-footer: #1b1f23;          /* dark form action bar */
  --color-accent-strip: #27403c;    /* thin strip at the very top */
  --color-avatar: #111111;
  --color-avatar-text: #ffffff;

  --color-danger: #b42318;
  --color-danger-soft: #fdecea;
  --color-warning: #b54708;
  --color-warning-soft: #fef4e6;
  --color-info: #175cd3;
  --color-info-soft: #eaf1fd;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;   /* logo container */

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 28px;
  --space-7: 40px;

  --sidebar-width: 300px;
  --topbar-height: 80px;
  --input-height: 48px;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-pop: 0 10px 30px rgba(16, 24, 40, 0.14);

  /* Chart palette — CHMIS theme only: greens, black, white (gaps between marks).
     Fixed order; adjacent slices alternate dark/light. Measured on #ffffff:
     worst adjacent colour-blind ΔE 24.0, normal-vision ΔE 25.6. Never reorder. */
  --series-1: #1e6b3c;  /* forest green  */
  --series-2: #1b1f23;  /* black         */
  --series-3: #0aa34f;  /* sidebar green */
  --series-4: #0b3d22;  /* deep green    */
  --series-5: #7fd3a1;  /* mint          */
  --series-6: #5f6b76;  /* slate (black, softened) */
  /* Document status in theme colours; the legend names each status. */
  --chart-status-good: #0aa34f; --chart-status-warning: #7fd3a1;
  --chart-status-serious: #5f6b76; --chart-status-critical: #1b1f23;
  --color-primary-chart: var(--series-1);
  --chart-grid: #e7e9ee;
  --chart-axis: #c2c7cf;

  --sidebar-gradient: linear-gradient(180deg, #0aa34f 0%, #098942 30%, #066834 50%, #043f21 70%, #021c0f 87%, #000302 100%);
}

[data-theme="dark"] {
  --color-bg: #0f1419;
  --color-surface: #1a2027;
  --color-surface-muted: #212830;
  --color-border: #2c343d;
  --color-input-border: #3a434d;
  --color-text: #e8ecef;
  --color-text-muted: #9aa5b1;
  --color-footer: #0b0f13;
  --color-avatar: #e8ecef;
  --color-avatar-text: #111111;
  --color-danger-soft: rgba(180, 35, 24, 0.18);
  --color-warning-soft: rgba(181, 71, 8, 0.18);
  --color-info-soft: rgba(23, 92, 211, 0.18);
  --shadow-pop: 0 10px 30px rgba(0, 0, 0, 0.5);
  /* Dark mode: same roles, black becomes white. Measured on #1a2027:
     worst adjacent colour-blind ΔE 23.5, normal-vision ΔE 26.8. */
  --series-1: #2e7d4f; --series-2: #e8ecef; --series-3: #1fb866;
  --series-4: #14532d; --series-5: #a6e6c0; --series-6: #7c8794;
  --chart-status-good: #1fb866; --chart-status-warning: #a6e6c0;
  --chart-status-serious: #7c8794; --chart-status-critical: #e8ecef;
  --color-primary-chart: #1fb866;
  --chart-grid: #29313a;
  --chart-axis: #46505b;
  color-scheme: dark;
}

/* ---------- Base -------------------------------------------------------- */
html, body { height: 100%; }
body {
  font-family: var(--font-family);
  font-size: var(--fs-base);
  color: var(--color-text);
  background: var(--color-bg);
  border-top: 6px solid var(--color-accent-strip);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); }
.text-muted, .muted { color: var(--color-text-muted) !important; }
.upper { text-transform: uppercase; letter-spacing: var(--tracking-tight); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.skip-link { position: absolute; left: -999px; top: 8px; z-index: 2000; background: #fff; padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { left: 12px; }

/* ---------- Shell ------------------------------------------------------- */
.app-shell { display: flex; min-height: calc(100vh - 6px); }

.sidebar {
  position: sticky; top: 0;
  width: var(--sidebar-width); flex: 0 0 var(--sidebar-width);
  height: calc(100vh - 6px);
  background: var(--sidebar-gradient);
  color: #fff;
  display: flex; flex-direction: column;
  padding: 20px 18px 0;
  z-index: 1040;
}
.sidebar-logo {
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-radius: var(--radius-xl);
  height: 176px; padding: 12px; margin-bottom: 26px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}
.sidebar-logo img { max-height: 100%; max-width: 100%; object-fit: contain; }

.sidebar-nav { flex: 1 1 auto; overflow-y: auto; margin: 0 -6px; padding: 0 6px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.nav-link-top, .nav-group-toggle {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 12px 14px; border: 0; background: none; border-radius: var(--radius);
  color: #fff; text-decoration: none; text-align: left;
  font-size: var(--fs-lg); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--tracking-tight);
}
.nav-link-top i, .nav-group-toggle > i:first-child { width: 22px; text-align: center; font-size: 1.05rem; }
.nav-link-top:hover, .nav-group-toggle:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-link-top.active { background: rgba(0, 0, 0, 0.32); }
.nav-group-toggle .chev { margin-left: auto; font-size: 0.8rem; transition: transform .2s ease; }
.nav-group-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.nav-sub { list-style: none; margin: 4px 0 8px 24px; padding: 0 0 0 14px; border-left: 1px solid rgba(255, 255, 255, 0.28); }
.nav-sub a, .nav-sub .nav-planned {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; margin: 2px 0; border-radius: var(--radius);
  color: #fff; text-decoration: none;
  font-size: var(--fs-base); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--tracking-tight);
}
.nav-sub a:hover { background: rgba(255, 255, 255, 0.08); }
.nav-sub a.active { background: rgba(0, 0, 0, 0.32); }
.nav-sub .nav-planned { color: rgba(255, 255, 255, 0.55); cursor: default; }
.phase-pill { font-size: 0.625rem; font-weight: var(--fw-bold); padding: 2px 7px; border-radius: 999px; background: rgba(255,255,255,.14); color: rgba(255,255,255,.8); white-space: nowrap; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, 0.15); padding: 14px 0 22px; flex-shrink: 0; }
.sidebar-footer button { cursor: pointer; }

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

/* ---------- Top bar ----------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 1030;
  height: var(--topbar-height);
  display: flex; align-items: center; gap: 18px;
  padding: 0 40px 0 36px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.topbar .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: var(--radius); border: 0; background: transparent;
  color: var(--color-text); font-size: 1.25rem;
}
.topbar .icon-btn:hover { background: var(--color-surface-muted); }
.system-name { font-weight: var(--fw-bold); font-size: var(--fs-lg); color: var(--color-text-muted); text-transform: uppercase; letter-spacing: var(--tracking-tight); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 24px; }
.user-menu-btn { display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 4px 6px; border-radius: var(--radius); color: var(--color-text); text-align: left; }
.user-menu-btn:hover { background: var(--color-surface-muted); }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--color-avatar); color: var(--color-avatar-text); display: inline-flex; align-items: center; justify-content: center; font-weight: var(--fw-bold); font-size: var(--fs-md); flex-shrink: 0; }
.user-name { display: block; font-weight: var(--fw-bold); font-size: var(--fs-lg); line-height: 1.15; text-transform: uppercase; letter-spacing: var(--tracking-tight); }
.user-role { display: block; font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--color-text-muted); text-transform: uppercase; }
.dropdown-menu { border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 6px; background: var(--color-surface); min-width: 240px; }
.dropdown-item { border-radius: var(--radius-sm); padding: 10px 12px; font-weight: var(--fw-semibold); color: var(--color-text); display: flex; align-items: center; gap: 10px; }
.dropdown-item i { width: 18px; text-align: center; color: var(--color-text-muted); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--color-surface-muted); color: var(--color-text); }
.dropdown-header { text-transform: uppercase; font-size: var(--fs-xs); font-weight: var(--fw-bold); }
.dropdown-divider { border-color: var(--color-border); }

/* ---------- Page -------------------------------------------------------- */
.content { padding: 34px 28px 48px; flex: 1 1 auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.eyebrow, .breadcrumbs { font-size: var(--fs-md); font-weight: var(--fw-medium); text-transform: uppercase; letter-spacing: var(--tracking-tight); color: var(--color-text); margin-bottom: 6px; }
.breadcrumbs a { color: var(--color-text); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .sep { margin: 0 4px; color: var(--color-text-muted); }
.breadcrumbs .current { color: var(--color-text-muted); }
.page-title { display: flex; align-items: center; gap: 14px; margin: 0; font-size: var(--fs-title); font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: var(--tracking-tight); line-height: 1.1; }
.page-title i { font-size: 1.75rem; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Cards ------------------------------------------------------- */
.ch-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.ch-card + .ch-card { margin-top: 20px; }
.ch-card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--color-border); }
.ch-card-title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: var(--tracking-tight); display: flex; align-items: center; gap: 10px; }
.ch-card-body { padding: 20px 24px; }

/* Navigation grid card — the "System Registers" pattern */
.nav-grid { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.nav-grid > .nav-grid-item { border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border); margin: 0 -1px -1px 0; }
.nav-grid-item { display: flex; align-items: center; gap: 18px; min-height: 63px; padding: 14px 26px; color: var(--color-text); text-decoration: none; font-size: var(--fs-lg); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-tight); transition: background .15s ease; }
.nav-grid-item i { width: 30px; text-align: center; font-size: 1.3rem; }
a.nav-grid-item:hover { background: var(--color-surface-muted); color: var(--color-text); }
a.nav-grid-item:hover i { color: var(--color-primary); }
.nav-grid-item.is-planned { color: var(--color-text-muted); }
.nav-grid-item .phase-tag { margin-left: auto; }

/* KPI tiles */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 20px 22px; display: flex; align-items: center; gap: 16px; }
.kpi-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--color-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.kpi-value { font-size: 1.75rem; font-weight: var(--fw-heavy); line-height: 1; letter-spacing: -0.02em; }
.kpi-label { font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--color-text-muted); text-transform: uppercase; margin-top: 6px; }

/* ---------- Tables (Currencies / Audit Trail pattern) ------------------- */
.ch-table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.ch-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--color-border); }
.ch-toolbar .record-count { margin-left: auto; font-weight: var(--fw-semibold); color: var(--color-text-muted); text-transform: uppercase; }
.ch-table { width: 100%; margin: 0; border-collapse: collapse; }
.ch-table th { background: var(--color-surface-muted); font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase; padding: 14px 12px; border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border); color: var(--color-text); text-align: left; white-space: nowrap; }
.ch-table td { padding: 14px 12px; border-bottom: 1px solid var(--color-border); border-right: 1px solid var(--color-border); text-transform: uppercase; font-weight: var(--fw-medium); vertical-align: middle; }
.ch-table th:last-child, .ch-table td:last-child { border-right: 0; }
.ch-table tbody tr:last-child td { border-bottom: 0; }
.ch-table tbody tr:hover td { background: var(--color-surface-muted); }
.ch-table .code-link { font-weight: var(--fw-bold); color: var(--color-text); text-decoration: underline; text-underline-offset: 3px; }
.empty-state { padding: 36px 20px; text-align: center; color: var(--color-text-muted); }
.empty-state i { font-size: 1.8rem; margin-bottom: 10px; display: block; }

/* Badges */
.ch-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: 0.01em; }
.ch-badge-success { background: var(--color-primary); color: #fff; }
.ch-badge-muted { background: var(--color-surface-muted); color: var(--color-text-muted); border: 1px solid var(--color-border); }
.ch-badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.ch-badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.ch-badge-info { background: var(--color-info-soft); color: var(--color-info); }
.phase-tag { font-size: 0.6875rem; font-weight: var(--fw-heavy); text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--color-surface-muted); border: 1px solid var(--color-border); color: var(--color-text-muted); white-space: nowrap; }

/* ---------- Buttons ----------------------------------------------------- */
.btn { font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--tracking-tight); border-radius: var(--radius); padding: 10px 20px; font-size: var(--fs-md); display: inline-flex; align-items: center; gap: 10px; justify-content: center; }
.btn-lg { padding: 12px 22px; font-size: var(--fs-lg); }
.btn-sm { padding: 6px 12px; font-size: var(--fs-sm); gap: 6px; }
.btn-primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active { background: var(--color-primary-hover) !important; border-color: var(--color-primary-hover) !important; color: #fff; }
.btn-outline { background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-surface-muted); border-color: var(--color-input-border); color: var(--color-text); }
.btn-ghost-light { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.55); }
.btn-ghost-light:hover { background: rgba(255,255,255,.08); color: #fff; border-color: #fff; }
.btn-split { display: inline-flex; }
.btn-split .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-split .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; padding-left: 12px; padding-right: 12px; }

/* ---------- Forms (Director / Reporting Line pattern) ------------------- */
.ch-form { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.ch-form-body { padding: 28px; }
.form-section { border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 20px 24px 24px; }
.form-section + .form-section { margin-top: 20px; }
.form-section-title { font-size: var(--fs-md); font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: var(--tracking-tight); padding-bottom: 14px; margin: 0 0 18px; border-bottom: 1px solid var(--color-border); }
.form-label { font-size: var(--fs-md); font-weight: var(--fw-bold); text-transform: uppercase; letter-spacing: var(--tracking-tight); color: var(--color-text); margin-bottom: 8px; }
.form-label .req { color: var(--color-danger); margin-left: 2px; }
.form-control, .form-select {
  min-height: var(--input-height); border: 1px solid var(--color-input-border); border-radius: var(--radius);
  font-size: var(--fs-md); color: var(--color-text); background-color: var(--color-surface); padding: 10px 14px;
}
textarea.form-control { min-height: 96px; }
.form-select { padding-right: 40px; background-position: right 14px center; }
.form-control:focus, .form-select:focus { border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary); background-color: var(--color-surface); color: var(--color-text); }
.form-control:disabled, .form-select:disabled { background-color: var(--color-surface-muted); color: var(--color-text); opacity: 1; }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--color-danger); }
.invalid-feedback { display: block; font-weight: var(--fw-semibold); color: var(--color-danger); }
.form-text { color: var(--color-text-muted); font-size: var(--fs-sm); }
.form-check-input { width: 1.35em; height: 1.35em; border: 2px solid var(--color-input-border); }
.form-check-input:checked { background-color: var(--color-primary); border-color: var(--color-primary); }
.form-check-label { font-weight: var(--fw-bold); text-transform: uppercase; }
.form-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 28px; background: var(--color-footer);
}
.form-actions .btn-primary { min-width: 180px; }
.logo-preview { width: 120px; height: 120px; border: 1px dashed var(--color-input-border); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; background: #fff; padding: 8px; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Alerts / messages ------------------------------------------ */
.ch-alert { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--color-border); background: var(--color-surface); font-weight: var(--fw-semibold); margin-bottom: 16px; }
.ch-alert-success { border-color: var(--color-border); border-left: 4px solid var(--color-primary); background: var(--color-surface); }
.ch-alert-success > i { color: var(--color-primary); }
.ch-alert-error { border-color: rgba(180,35,24,.35); background: var(--color-danger-soft); color: var(--color-danger); }
.ch-alert-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.ch-alert-info { background: var(--color-info-soft); }
.ch-alert .btn-close { margin-left: auto; }
[data-theme="dark"] .btn-close { filter: invert(1); }

/* ---------- AI entry card ---------------------------------------------- */
.ai-card { display: flex; align-items: center; gap: 18px; padding: 20px 24px; border-radius: var(--radius-lg); background: linear-gradient(120deg, #0a3d22 0%, #0f5a32 60%, #098942 100%); color: #fff; margin-bottom: 24px; }
.ai-card .ai-icon { width: 52px; height: 52px; border-radius: 14px; background: rgba(255,255,255,.14); display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.ai-card h2 { font-size: var(--fs-lg); font-weight: var(--fw-heavy); text-transform: uppercase; margin: 0 0 4px; }
.ai-card p { margin: 0; color: rgba(255,255,255,.82); }
.ai-card .ai-text { flex: 0 1 auto; min-width: 0; }
.ai-card input { flex: 1; min-height: 48px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; padding: 0 14px; }
.ai-card input::placeholder { color: rgba(255,255,255,.6); }

/* ---------- Activity list ---------------------------------------------- */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li { display: flex; align-items: center; gap: 14px; padding: 12px 24px; border-bottom: 1px solid var(--color-border); }
.activity-list li:last-child { border-bottom: 0; }
.activity-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--color-surface-muted); display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); flex-shrink: 0; }
.activity-main { font-weight: var(--fw-semibold); }
.activity-meta { font-size: var(--fs-sm); color: var(--color-text-muted); }

/* ---------- Auth -------------------------------------------------------- */
.auth-shell { min-height: calc(100vh - 6px); display: grid; grid-template-columns: minmax(340px, 44%) 1fr; }
.auth-brand { background: var(--sidebar-gradient); color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: 40px; }
.auth-brand .sidebar-logo { width: 300px; max-width: 100%; height: 220px; }
.auth-brand h1 { font-size: 2rem; font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: var(--tracking-tight); margin: 0 0 10px; }
.auth-brand p { color: rgba(255,255,255,.82); max-width: 460px; margin: 0; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--color-bg); }
.auth-card { width: 100%; max-width: 460px; }
.auth-card .ch-form-body { padding: 32px; }

/* ---------- Charts ------------------------------------------------------ */
.section-heading { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 14px; }
.section-heading .ch-card-title { margin: 0; }
.section-heading .section-note { font-size: var(--fs-sm); color: var(--color-text-muted); }
.chart-card { height: 100%; display: flex; flex-direction: column; }
.chart-card .ch-card-header { align-items: flex-start; }
.chart-subtitle { display: block; margin-top: 4px; font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--color-text-muted); text-transform: uppercase; }
.chart-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chart-body { padding: 18px 24px 20px; flex: 1 1 auto; display: flex; flex-direction: column; gap: 16px; }
.chart-canvas { position: relative; height: 240px; }
.chart-card.is-wide .chart-canvas { height: 280px; }
.chart-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.chart-card.is-donut .chart-legend { grid-template-columns: 1fr; }
.chart-card:not(.is-donut) .chart-legend { display: flex; flex-wrap: wrap; gap: 8px 22px; }
.chart-legend li { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); font-weight: var(--fw-semibold); text-transform: uppercase; }
.chart-key { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(11, 11, 11, 0.12); }
[data-theme="dark"] .chart-key { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28); }
.chart-key.is-line { height: 3px; width: 16px; border-radius: 2px; }
.chart-legend-name { color: var(--color-text); }
.chart-legend-value { margin-left: auto; color: var(--color-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-card:not(.is-donut) .chart-legend-value { margin-left: 4px; }
.chart-table-wrap { display: none; max-height: 300px; overflow: auto; }
.chart-card.show-table .chart-table-wrap { display: block; }
.chart-card.show-table .chart-canvas, .chart-card.show-table .chart-legend { display: none; }
.chart-table { width: 100%; font-size: var(--fs-sm); }
.chart-table th { text-transform: uppercase; font-weight: var(--fw-heavy); padding: 8px 10px; background: var(--color-surface-muted); border-bottom: 1px solid var(--color-border); text-align: left; }
.chart-table td { padding: 8px 10px; border-bottom: 1px solid var(--color-border); font-weight: var(--fw-medium); }
.chart-table .num, .chart-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.chart-empty { display: none; }
.chart-card.is-empty .chart-canvas { display: none; }
.chart-card.is-empty .chart-empty { display: block; }
.ch-badge-sample { background: transparent; color: var(--color-text); border: 1px dashed var(--color-text); }

/* ---------- Mobile ------------------------------------------------------ */
.sidebar-toggle { display: none; }
.topbar .sidebar-toggle { display: inline-flex; }
.sidebar-backdrop { display: none; }
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; top: 0; height: 100vh; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-pop); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1035; }
  .topbar { padding: 0 16px; gap: 8px; }
  .content { padding: 24px 16px 40px; }
  .nav-grid { grid-template-columns: repeat(2, 1fr); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px; gap: 20px; }
  .auth-brand .sidebar-logo { height: 150px; width: 220px; }
}
@media (max-width: 767.98px) {
  .user-meta { display: none; }
  .nav-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.5rem; }
  .ai-card { flex-wrap: wrap; }
  .ai-card .ai-text { flex: 1 1 calc(100% - 70px); }
  .ai-card input { flex-basis: 100%; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi { padding: 16px; gap: 12px; }
  .kpi-icon { width: 40px; height: 40px; }
  .form-actions { padding: 14px 16px; }
  .form-actions .btn-primary { min-width: 0; }
  .ch-form-body { padding: 18px; }
  .form-section { padding: 16px; }
  .system-name { font-size: var(--fs-sm); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Registers (Phase 2) ---------------------------------------- */
.search-box { position: relative; min-width: 240px; }
.search-box i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); }
.search-box .form-control { padding-left: 40px; }
.ch-toolbar .form-select, .ch-toolbar .form-control { min-height: 46px; text-transform: none; }
.ch-toolbar select.form-select { text-transform: uppercase; font-weight: var(--fw-medium); }
.ch-pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-top: 1px solid var(--color-border); }
.ch-table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.ch-table .col-status { width: 1%; white-space: nowrap; }
.ch-table .cell-sub { display: block; font-size: var(--fs-sm); color: var(--color-text-muted); text-transform: none; font-weight: var(--fw-regular); }
.ch-table .cell-lower { text-transform: none; }
.ch-table a.row-link { color: var(--color-text); font-weight: var(--fw-bold); text-decoration: underline; text-underline-offset: 3px; }
.ch-table-scroll { overflow-x: auto; }
.btn-split .dropdown-menu form { margin: 0; }
.btn-split .dropdown-item.text-danger, .btn-split .dropdown-item.text-danger i { color: var(--color-danger) !important; }
.htmx-request #register-table, #register-table.htmx-request { opacity: .55; transition: opacity .15s; }
.form-section-hint { margin: -8px 0 16px; color: var(--color-text-muted); font-size: var(--fs-sm); }

/* Permission matrix (D&A "Default Permissions") */
.perm-matrix { width: 100%; border-collapse: collapse; }
.perm-matrix th, .perm-matrix td { border: 1px solid var(--color-border); padding: 12px 10px; }
.perm-matrix thead th { background: var(--color-surface-muted); font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase; text-align: center; white-space: nowrap; }
.perm-matrix thead th:first-child { text-align: left; }
.perm-matrix .group-row td { background: var(--color-surface-muted); font-weight: var(--fw-heavy); text-transform: uppercase; font-size: var(--fs-sm); }
.perm-matrix td.area { text-transform: uppercase; font-weight: var(--fw-medium); }
.perm-matrix td.choice { text-align: center; width: 120px; }
.perm-matrix td.choice.narrow { width: 90px; }
.perm-matrix .form-check-input { margin: 0; float: none; cursor: pointer; }
.perm-matrix .sensitive { color: var(--color-text-muted); margin-left: 6px; font-size: .85em; }
.perm-matrix.is-disabled { opacity: .45; pointer-events: none; }
.audit-changes { width: 100%; }
.audit-changes td, .audit-changes th { padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: top; }
.audit-changes th { text-transform: uppercase; font-size: var(--fs-sm); background: var(--color-surface-muted); }
.audit-changes code { color: var(--color-text); white-space: pre-wrap; word-break: break-word; }

/* ---------- Command Centre panel (gear icon; D&A "System Core") -------- */
.topbar .icon-btn.is-active, .topbar .icon-btn.is-active:hover { background: var(--color-primary); color: #fff; }
.command-panel.offcanvas-end { width: min(1120px, calc(100vw - var(--sidebar-width) - 80px)); border-left: 0; background: var(--color-surface); color: var(--color-text); }
.offcanvas-backdrop.show { opacity: .35; }
.command-panel-header { display: flex; align-items: center; justify-content: space-between; margin: 28px 36px 0; padding-bottom: 22px; border-bottom: 1px solid var(--color-border); }
.command-panel-title { margin: 0; display: flex; align-items: center; gap: 12px; font-size: 1.5rem; font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: var(--tracking-tight); }
.command-panel .icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: var(--radius); background: transparent; color: var(--color-text); font-size: 1.35rem; }
.command-panel .icon-btn:hover { background: var(--color-surface-muted); }
.command-panel-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); padding: 24px 36px 36px; overflow-y: auto; align-content: start; }
.command-column { padding: 0 26px; border-left: 1px solid var(--color-border); }
.command-column:first-child { padding-left: 0; border-left: 0; }
.command-column-title { font-size: var(--fs-md); font-weight: var(--fw-heavy); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-muted); padding-bottom: 14px; margin: 0 0 14px; border-bottom: 1px solid var(--color-border); }
.command-column ul { list-style: none; margin: 0; padding: 0; }
.command-column a { display: flex; align-items: center; gap: 14px; padding: 10px 10px; margin: 0 -10px; border-radius: var(--radius); color: var(--color-text); text-decoration: none; font-size: var(--fs-lg); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: var(--tracking-tight); }
.command-column a i { width: 22px; text-align: center; font-size: 1.1rem; }
.command-column a:hover { background: var(--color-surface-muted); }
.command-column a:hover i { color: var(--color-primary); }
.command-column a.active, .command-column a.active:hover { background: var(--color-primary); color: #fff; }
.command-column a.active i { color: #fff; }
@media (max-width: 991.98px) {
  .command-panel.offcanvas-end { width: 100vw; }
  .command-panel-header { margin: 18px 20px 0; }
  .command-panel-body { grid-template-columns: 1fr; padding: 18px 20px 28px; gap: 22px; }
  .command-column { padding: 0; border-left: 0; }
}

/* ---------- Documents (Phase 3) ---------------------------------------- */
/* Status badges in theme colours only; the icon + label carry the meaning. */
.st { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase; white-space: nowrap; border: 1px solid transparent; }
.st-valid { background: var(--color-primary); color: #fff; }
.st-expiring_soon { background: var(--color-surface); color: var(--color-text); border-color: var(--color-text); }
.st-expired, .st-review_due { background: var(--color-text); color: var(--color-surface); }
.st-pending_renewal { background: var(--color-surface); color: var(--color-primary); border-color: var(--color-primary); }
.st-under_review { background: var(--color-surface); color: var(--color-text-muted); border-color: var(--color-input-border); }
.st-missing { background: var(--color-surface); color: var(--color-text); border: 1px dashed var(--color-text); }
.st-not_applicable { background: var(--color-surface-muted); color: var(--color-text-muted); }
.kpi-grid.kpi-6 { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
a.kpi { text-decoration: none; color: inherit; transition: border-color .15s; }
a.kpi:hover { border-color: var(--color-text); }
a.kpi.is-current { border: 2px solid var(--color-primary); }
.kpi-icon.dark { background: var(--color-text); color: var(--color-surface); }
.kpi-icon.outline { background: var(--color-surface); color: var(--color-text); border: 2px solid var(--color-text); }
.folder-count { margin-left: auto; font-size: var(--fs-sm); font-weight: var(--fw-heavy); color: var(--color-text-muted); }
a.nav-grid-item.is-current { background: var(--color-primary); color: #fff; }
a.nav-grid-item.is-current i, a.nav-grid-item.is-current .folder-count { color: #fff; }
.due-text { display: block; font-size: var(--fs-sm); text-transform: none; font-weight: var(--fw-semibold); color: var(--color-text-muted); }
.due-text.is-late { color: var(--color-text); font-weight: var(--fw-heavy); }
.key-date { text-align: center; padding: 22px 16px; }
.key-date .big { font-size: 2.6rem; font-weight: var(--fw-heavy); line-height: 1; letter-spacing: -0.02em; }
.key-date .label { text-transform: uppercase; font-weight: var(--fw-bold); color: var(--color-text-muted); font-size: var(--fs-sm); margin-top: 6px; }
.detail-list dt { text-transform: uppercase; font-size: var(--fs-sm); font-weight: var(--fw-bold); color: var(--color-text-muted); }
.detail-list dd { font-weight: var(--fw-medium); margin-bottom: 14px; }
.ch-card .ch-form-body.compact { padding: 18px 24px; }
.mini-list { list-style: none; padding: 0; margin: 0; }
.mini-list li { padding: 12px 24px; border-bottom: 1px solid var(--color-border); }
.mini-list li:last-child { border-bottom: 0; }
.tab-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-row .btn.is-current { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.progress-line { height: 10px; border-radius: 999px; background: var(--color-surface-muted); border: 1px solid var(--color-border); overflow: hidden; }
.progress-line > span { display: block; height: 100%; background: var(--color-primary); }
.date-hint { display: none; }
.date-hint.show { display: block; }

/* ---------- Children (Phase 4a) ---------------------------------------- */
.child-avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--color-primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: var(--fw-heavy); flex-shrink: 0; }
.child-avatar.lg { width: 112px; height: 112px; font-size: 2rem; }
.child-cell { display: flex; align-items: center; gap: 12px; }
.profile-head { display: flex; gap: 22px; align-items: center; padding: 22px 24px; }
.profile-head .meta { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 8px; color: var(--color-text-muted); font-weight: var(--fw-semibold); }
.profile-head .meta strong { color: var(--color-text); }
.tabbar { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--color-border); padding: 0 16px; }
.tabbar a { padding: 14px 14px 12px; text-decoration: none; color: var(--color-text-muted); font-weight: var(--fw-bold); text-transform: uppercase; font-size: var(--fs-sm); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabbar a:hover { color: var(--color-text); }
.tabbar a.active { color: var(--color-text); border-bottom-color: var(--color-primary); }
.tabbar a .fa-lock { font-size: .75em; margin-left: 4px; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--color-text); border-left-width: 4px; border-radius: var(--radius); background: var(--color-surface); margin-bottom: 16px; font-weight: var(--fw-semibold); }
.notice.subtle { border-color: var(--color-border); border-left-color: var(--color-primary); }
.note-card { padding: 18px 24px; border-bottom: 1px solid var(--color-border); }
.note-card:last-child { border-bottom: 0; }
.note-card .note-meta { font-size: var(--fs-sm); color: var(--color-text-muted); font-weight: var(--fw-semibold); text-transform: uppercase; }
.note-card .note-body { margin-top: 8px; white-space: pre-line; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--color-border); font-size: var(--fs-xs); font-weight: var(--fw-bold); text-transform: uppercase; }
.chip.dark { background: var(--color-text); color: var(--color-surface); border-color: var(--color-text); }
.chip.green { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
details.add-panel > summary { list-style: none; cursor: pointer; }
details.add-panel > summary::-webkit-details-marker { display: none; }
a.row-link { color: var(--color-text); font-weight: var(--fw-bold); text-decoration: underline; text-underline-offset: 3px; }
a.row-link:hover { color: var(--color-primary); }

/* ---------- Finance (Phase 4d) ------------------------------------------ */
.chip.outline-dark { border-color: var(--color-text); color: var(--color-text); }
.chip.dashed { border-style: dashed; border-color: var(--color-text-muted); color: var(--color-text-muted); }
.progress-line.is-over > span { background: var(--color-text); }
.ch-table tfoot th { border-top: 2px solid var(--color-text); padding-top: 12px; }

/* ---------- Food & Nutrition (Phase 4f) --------------------------------- */
.menu-grid th.is-today, .menu-grid td.is-today { box-shadow: inset 0 3px 0 var(--color-primary); }
.menu-grid td { min-width: 130px; font-size: .9rem; }

/* ---------- Activities calendar (Phase 4i) ------------------------------ */
.cal { table-layout: fixed; }
.cal td { vertical-align: top; height: 112px; padding: 6px !important; text-transform: none; }
.cal td.other { background: var(--color-canvas); color: var(--color-text-muted); }
.cal td.is-today { box-shadow: inset 0 3px 0 var(--color-primary); }
.cal .day { font-weight: var(--fw-heavy); }
.cal .add { color: var(--color-text-muted); font-size: .75rem; }
.cal .ev { display: block; font-size: .78rem; font-weight: 600; line-height: 1.25; padding: 3px 6px; margin-top: 4px;
           border-radius: 6px; background: var(--color-primary); color: #fff; text-decoration: none;
           overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.off { background: var(--color-text); color: var(--color-surface); }
.cal .ev.cancelled { background: transparent; color: var(--color-text-muted); border: 1px dashed var(--color-text-muted);
                     text-decoration: line-through; }
.cal .ev.bday { background: transparent; color: var(--color-text); border: 1px solid var(--color-border); }
p .ev.off { padding: 2px 6px; border-radius: 6px; font-size: .75rem; font-weight: 600; }

/* Disabled primary buttons: neutral grey, never a faded brand colour. */
.btn-primary:disabled, .btn-primary.disabled { background: var(--color-border) !important; border-color: var(--color-border) !important;
  color: var(--color-text-muted) !important; opacity: 1; cursor: not-allowed; }

/* ---------- Child Protection (Phase 4j) --------------------------------- */
.report-concern { border-color: var(--color-text); color: var(--color-text); font-weight: var(--fw-heavy); }
.report-concern:hover { background: var(--color-text); color: var(--color-surface); }
.sev-critical { background: var(--color-text); color: var(--color-surface); }
.case-locked { border-left: 4px solid var(--color-text); }

/* ---------- Reports (Phase 5) ------------------------------------------- */
.report-card { color: var(--color-text); transition: border-color .15s; }
.report-card:hover { border-color: var(--color-primary); }

/* ---------- Simplified look (round of changes after Phase 5) ------------
   KPI tiles: one joined grid, plain icons (no coloured squares), like the D&A registers grid. */
.kpi-grid, .kpi-grid.kpi-6 { gap: 0; background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); overflow: hidden; }
.kpi-grid > .kpi { border: 0; border-radius: 0; border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border); margin: 0 -1px -1px 0; padding: 18px 24px; gap: 18px; }
.kpi-icon, .kpi-icon.dark, .kpi-icon.outline { width: 30px; height: auto; background: none; border: 0; border-radius: 0;
  color: var(--color-text); font-size: 1.45rem; }
.kpi-value { font-size: 1.6rem; }
a.kpi:hover { border-color: var(--color-border); background: var(--color-surface-muted); }
a.kpi:hover .kpi-icon { color: var(--color-primary); }
a.kpi.is-current { border: 0; border-right: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
  background: var(--color-primary); color: #fff; }
a.kpi.is-current .kpi-icon, a.kpi.is-current .kpi-label { color: #fff; }
@media (max-width: 575.98px) { .kpi-grid > .kpi { padding: 14px 16px; gap: 12px; } }
.section-label { font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase; letter-spacing: .02em;
  margin: 0 0 10px; color: var(--color-text); }
.nav-grid-item .small-lock { width: auto; font-size: .85rem; color: var(--color-text-muted); }

/* ---------- Collapsible sidebar (desktop): icon rail ---------------------- */
.sidebar, .sidebar-logo, .sidebar-nav span, .main { transition: width .2s ease, flex-basis .2s ease, padding .2s ease; }
.nav-flyout-title { display: none; }
@media (min-width: 992px) {
  html.sb-collapsed { --sidebar-width: 84px; }
  html.sb-collapsed .sidebar { padding: 16px 12px 0; }
  html.sb-collapsed .sidebar-logo { height: 60px; padding: 6px; border-radius: 14px; margin-bottom: 18px; }
  html.sb-collapsed .sidebar-nav { overflow: visible; margin: 0; padding: 0 0 16px; }
  html.sb-collapsed .nav-link-top, html.sb-collapsed .nav-group-toggle { justify-content: center; padding-left: 0; padding-right: 0; gap: 0; }
  html.sb-collapsed .nav-link-top span, html.sb-collapsed .nav-group-toggle span,
  html.sb-collapsed .nav-group-toggle .chev { display: none; }
  html.sb-collapsed .nav-link-top i, html.sb-collapsed .nav-group-toggle > i:first-child { font-size: 1.2rem; width: auto; }
  html.sb-collapsed .nav-group { position: relative; }
  html.sb-collapsed .nav-group.has-active > .nav-group-toggle { background: rgba(0, 0, 0, 0.32); }
  /* Sub-menus become flyouts to the right of the rail. */
  html.sb-collapsed .nav-sub, html.sb-collapsed .nav-sub.show { display: none; }
  html.sb-collapsed .nav-group:hover > .nav-sub, html.sb-collapsed .nav-group:focus-within > .nav-sub,
  html.sb-collapsed .nav-group.flyout-open > .nav-sub {
    display: block; position: absolute; left: calc(100% + 10px); top: 0; margin: 0; min-width: 240px;
    padding: 8px; border: 0; border-radius: 12px; background: #063b20; box-shadow: var(--shadow-pop); z-index: 1100; }
  html.sb-collapsed .nav-group:hover > .nav-sub::before { content: ""; position: absolute; left: -12px; top: 0; bottom: 0; width: 12px; }
  html.sb-collapsed .nav-flyout-title { display: block; padding: 6px 12px 8px; font-size: .72rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: .04em; color: rgba(255, 255, 255, .6); }
  html.sb-collapsed .sidebar-footer .nav-link-top { width: 100%; }
}

/* ---------- Dashboard stat strips ---------------------------------------
   Large plain icon on the left, number and label beside it. Equal columns, one row per group. */
.stat-groups { display: grid; grid-template-columns: 1fr; gap: 18px; margin-bottom: 28px; }
.stat-group-title { font-size: var(--fs-sm); font-weight: var(--fw-heavy); text-transform: uppercase;
  letter-spacing: .04em; color: var(--color-text-muted); margin: 0 0 8px; }
.stat-strip { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.stat { display: flex; align-items: center; gap: 16px; min-height: 96px; padding: 18px 20px;
  border-left: 1px solid var(--color-border); color: var(--color-text); text-decoration: none;
  transition: background .15s; }
.stat:first-child { border-left: 0; }
a.stat:hover { background: var(--color-surface-muted); color: var(--color-text); }
.stat-icon { width: 34px; text-align: center; font-size: 1.6rem; color: var(--color-text); flex-shrink: 0; }
a.stat:hover .stat-icon { color: var(--color-primary); }
.stat-body { min-width: 0; }
.stat-value { font-size: 1.7rem; font-weight: var(--fw-heavy); line-height: 1; letter-spacing: -0.02em; }
.stat-label { margin-top: 6px; font-size: .8rem; font-weight: var(--fw-bold); text-transform: uppercase; line-height: 1.3;
  color: var(--color-text-muted); overflow-wrap: normal; }
@media (max-width: 767.98px) {
  .stat-strip { grid-template-columns: 1fr 1fr; }
  .stat { border-left: 0; border-bottom: 1px solid var(--color-border); }
  .stat:nth-child(odd) { border-right: 1px solid var(--color-border); }
}

/* ---------- Attention = professional red ---------------------------------
   Solid red for things that need action now; red outline for things coming up. */
:root { --color-alert: #b42318; --color-alert-dark: #912018; }
.chip.red { background: var(--color-alert); border-color: var(--color-alert); color: #fff; }
.chip.red-outline { background: var(--color-surface); border-color: var(--color-alert); color: var(--color-alert); }
.st-missing, .st-expired, .st-review_due { background: var(--color-alert); border: 1px solid var(--color-alert); color: #fff; }
.st-expiring_soon { background: var(--color-surface); border-color: var(--color-alert); color: var(--color-alert); }
.due-text.is-late { color: var(--color-alert); }
.sev-critical { background: var(--color-alert); color: #fff; }
.stat.is-alert .stat-icon, .stat.is-alert .stat-value { color: var(--color-alert); }
a.stat.is-alert:hover .stat-icon { color: var(--color-alert-dark); }
.kpi-icon.alert { color: var(--color-alert); }
.kpi:has(.kpi-icon.alert) .kpi-value { color: var(--color-alert); }
a.kpi.is-current .kpi-icon.alert, a.kpi.is-current:has(.kpi-icon.alert) .kpi-value { color: #fff; }
a.kpi.is-current:has(.kpi-icon.alert) { background: var(--color-alert); }
.kpi-grid, .kpi-grid.kpi-6 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi-grid > .kpi:last-child { border-right: 0; }
/* Icons stay plain black; only the number turns red. */
.kpi-icon.alert, .stat.is-alert .stat-icon, a.stat.is-alert:hover .stat-icon { color: var(--color-text); }
a.stat.is-alert:hover .stat-icon { color: var(--color-primary); }
.assign-row { display: grid; grid-template-columns: minmax(160px, 1fr) 150px auto; gap: 8px; align-items: center; }
@media (max-width: 767.98px) { .assign-row { grid-template-columns: 1fr; } }

/* ---------- AI (Phase 6) ------------------------------------------------- */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.seg-item { position: relative; margin: 0; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span { display: block; padding: 8px 16px; font-size: var(--fs-sm); font-weight: var(--fw-bold); text-transform: uppercase;
  border-left: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); }
.seg-item:first-child span { border-left: 0; }
.seg-item input:checked + span { background: var(--color-primary); color: #fff; }
.seg-item input:focus-visible + span { outline: 2px solid var(--color-text); outline-offset: -2px; }
.ai-output { white-space: pre-wrap; line-height: 1.6; font-size: 1rem; }
.ai-note { display: flex; gap: 8px; align-items: center; font-size: var(--fs-sm); font-weight: var(--fw-bold);
  text-transform: uppercase; color: var(--color-text-muted); padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--color-border); }
.ai-rules { list-style: none; padding: 0; margin: 18px 0 0; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface); }
.ai-rules li { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--color-border); font-weight: var(--fw-semibold); }
.ai-rules li:first-child { border-top: 0; }
.ai-rules i { width: 18px; text-align: center; }
.ch-table tr.is-selected td { background: var(--color-surface-muted); }

/* ---------- Toto: floating assistant ------------------------------------ */
.toto { position: fixed; right: 24px; bottom: 24px; z-index: 1080; display: flex; flex-direction: column; align-items: flex-end; gap: 14px; }
.toto-launcher { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; cursor: pointer; }
.toto-avatar { width: 68px; height: 68px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.22); border: 3px solid var(--color-primary); transition: transform .15s; }
.toto-avatar { overflow: hidden; } .toto-avatar img { width: 64px; height: 64px; }
.toto-launcher:hover .toto-avatar { transform: translateY(-2px) rotate(-4deg); }
.toto-launcher[aria-expanded="true"] .toto-hello { display: none; }
.toto-hello { background: #fff; color: var(--color-text); border: 1px solid var(--color-border); border-radius: 18px 18px 4px 18px;
  padding: 8px 14px; font-size: .9rem; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap;
  opacity: 0; transform: translateX(8px); transition: opacity .3s, transform .3s; pointer-events: none; }
.toto-launcher:hover .toto-hello, .toto-hello.show { opacity: 1; transform: none; }
.toto-panel { width: 430px; height: min(600px, calc(100vh - 140px)); background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 18px; box-shadow: 0 18px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; overflow: hidden; }
.toto-panel[hidden] { display: none; }
.toto-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: #fff;
  background: linear-gradient(135deg, #0b8a43 0%, #063b20 55%, #020b06 100%); }
.toto-head-img { width: 44px; height: 44px; background: #fff; border-radius: 50%; padding: 3px; }
.toto-head-text { display: flex; flex-direction: column; line-height: 1.15; margin-right: auto; }
.toto-head-text strong { font-size: 1.1rem; text-transform: uppercase; letter-spacing: .02em; }
.toto-head-text span { font-size: .78rem; opacity: .85; text-transform: uppercase; }
.toto-icon-btn { border: 0; background: rgba(255,255,255,.12); color: #fff; width: 34px; height: 34px; border-radius: 50%; }
.toto-icon-btn:hover { background: rgba(255,255,255,.25); }
.toto-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: var(--color-bg, #f3f4f7); }
.toto-msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; font-size: .95rem; line-height: 1.45; overflow-wrap: anywhere; }
.toto-msg p { margin: 0 0 6px; } .toto-msg p:last-child { margin: 0; }
.toto-msg ul, .toto-msg ol { margin: 4px 0 4px 18px; padding: 0; }
.toto-from-bot { align-self: flex-start; background: var(--color-surface); border: 1px solid var(--color-border); border-bottom-left-radius: 4px; }
.toto-from-user { align-self: flex-end; background: var(--color-primary); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.toto-from-bot.is-error { border-color: var(--color-alert); color: var(--color-alert); }
.toto-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.toto-chip { border: 1px solid var(--color-primary); color: var(--color-primary); background: var(--color-surface); border-radius: 999px;
  padding: 5px 11px; font-size: .82rem; font-weight: var(--fw-semibold); }
.toto-chip:hover { background: var(--color-primary); color: #fff; }
.toto-typing { display: inline-flex; gap: 4px; }
.toto-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--color-text-muted); animation: toto-dot 1s infinite; }
.toto-typing i:nth-child(2) { animation-delay: .15s; } .toto-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes toto-dot { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.toto-input { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-top: 1px solid var(--color-border); background: var(--color-surface); }
.toto-input textarea { flex: 1; resize: none; border: 1px solid var(--color-input-border); border-radius: 20px; padding: 9px 14px;
  max-height: 120px; font: inherit; background: var(--color-surface); color: var(--color-text); }
.toto-input textarea:focus { outline: 2px solid var(--color-primary); outline-offset: -1px; }
.toto-send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--color-primary); color: #fff; flex-shrink: 0; }
.toto-send:disabled { background: var(--color-border); color: var(--color-text-muted); }
.toto-foot { font-size: .72rem; color: var(--color-text-muted); text-align: center; padding: 0 12px 8px; background: var(--color-surface); }
@media (max-width: 575.98px) {
  .toto { right: 12px; bottom: 12px; }
  .toto-panel { width: calc(100vw - 24px); height: calc(100vh - 110px); }
  .toto-avatar { width: 58px; height: 58px; } .toto-avatar img { width: 48px; height: 48px; }
}
@media print { .toto { display: none !important; } }

/* Toto answer typography */
.toto-from-bot { line-height: 1.55; }
.toto-from-bot p { margin: 0 0 8px; }
.toto-from-bot ul, .toto-from-bot ol { margin: 2px 0 8px; padding-left: 20px; }
.toto-from-bot li { margin: 3px 0; padding-left: 2px; }
.toto-from-bot li::marker { color: var(--color-primary); }
.toto-from-bot strong { font-weight: var(--fw-heavy); color: var(--color-text); }
.toto-from-bot em { font-style: italic; color: var(--color-text-muted); }
.toto-from-bot code { font-size: .85em; background: var(--color-surface-muted); padding: 1px 5px; border-radius: 4px; }
.toto-from-bot > :last-child { margin-bottom: 0; }
.toto-h { font-weight: var(--fw-heavy); text-transform: uppercase; font-size: .8rem; letter-spacing: .03em;
  color: var(--color-primary); margin: 10px 0 4px; }
.toto-h:first-child { margin-top: 0; }

/* ---------- Page loader: a ring of dots, like QuickBooks ----------------- */
.page-loader { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.55); backdrop-filter: blur(1.5px); opacity: 0; visibility: hidden;
  transition: opacity .15s, visibility .15s; }
[data-theme="dark"] .page-loader { background: rgba(10,14,12,.55); }
.page-loader.is-on { opacity: 1; visibility: visible; }
.dot-spinner { position: relative; width: 56px; height: 56px; }
.dot-spinner i { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px;
  border-radius: 50%; background: var(--color-primary); opacity: .15; animation: dot-fade 1.1s linear infinite; }
.dot-spinner i:nth-child(1) { transform: rotate(0deg) translateY(-22px); animation-delay: -1.100s; }
.dot-spinner i:nth-child(2) { transform: rotate(30deg) translateY(-22px); animation-delay: -1.008s; }
.dot-spinner i:nth-child(3) { transform: rotate(60deg) translateY(-22px); animation-delay: -0.917s; }
.dot-spinner i:nth-child(4) { transform: rotate(90deg) translateY(-22px); animation-delay: -0.825s; }
.dot-spinner i:nth-child(5) { transform: rotate(120deg) translateY(-22px); animation-delay: -0.733s; }
.dot-spinner i:nth-child(6) { transform: rotate(150deg) translateY(-22px); animation-delay: -0.642s; }
.dot-spinner i:nth-child(7) { transform: rotate(180deg) translateY(-22px); animation-delay: -0.550s; }
.dot-spinner i:nth-child(8) { transform: rotate(210deg) translateY(-22px); animation-delay: -0.458s; }
.dot-spinner i:nth-child(9) { transform: rotate(240deg) translateY(-22px); animation-delay: -0.367s; }
.dot-spinner i:nth-child(10) { transform: rotate(270deg) translateY(-22px); animation-delay: -0.275s; }
.dot-spinner i:nth-child(11) { transform: rotate(300deg) translateY(-22px); animation-delay: -0.183s; }
.dot-spinner i:nth-child(12) { transform: rotate(330deg) translateY(-22px); animation-delay: -0.092s; }
@keyframes dot-fade { 0% { opacity: 1; transform-origin: center; } 100% { opacity: .15; } }
.dot-spinner.sm { width: 28px; height: 28px; }
@media (prefers-reduced-motion: reduce) { .dot-spinner i { animation-duration: 2.4s; } }
@media print { .page-loader { display: none !important; } }
/* Larger ring */
.dot-spinner { width: 80px; height: 80px; }
.dot-spinner i { width: 12px; height: 12px; margin: -6px 0 0 -6px; }
.dot-spinner i:nth-child(1) { transform: rotate(0deg) translateY(-32px); }
.dot-spinner i:nth-child(2) { transform: rotate(30deg) translateY(-32px); }
.dot-spinner i:nth-child(3) { transform: rotate(60deg) translateY(-32px); }
.dot-spinner i:nth-child(4) { transform: rotate(90deg) translateY(-32px); }
.dot-spinner i:nth-child(5) { transform: rotate(120deg) translateY(-32px); }
.dot-spinner i:nth-child(6) { transform: rotate(150deg) translateY(-32px); }
.dot-spinner i:nth-child(7) { transform: rotate(180deg) translateY(-32px); }
.dot-spinner i:nth-child(8) { transform: rotate(210deg) translateY(-32px); }
.dot-spinner i:nth-child(9) { transform: rotate(240deg) translateY(-32px); }
.dot-spinner i:nth-child(10) { transform: rotate(270deg) translateY(-32px); }
.dot-spinner i:nth-child(11) { transform: rotate(300deg) translateY(-32px); }
.dot-spinner i:nth-child(12) { transform: rotate(330deg) translateY(-32px); }

/* ---------- "Draft with Toto" (Phase 7) ---------------------------------- */
.toto-draft-btn { display: inline-flex; align-items: center; gap: 8px; }
.toto-btn-face { width: 26px; height: 26px; margin: -4px 0; }
.toto-draft { border: 0; border-radius: 18px; overflow: hidden; }
.toto-draft .modal-body { min-height: 220px; padding: 22px 26px; background: var(--color-surface); }
.toto-draft-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  min-height: 200px; color: var(--color-text-muted); font-weight: var(--fw-semibold); }
.toto-draft-loading[hidden] { display: none; }
.toto-draft-text { border: 0; padding: 0; max-width: none; font-size: 1rem; background: none; }
.toto-draft-actions { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--color-border);
  background: var(--color-surface); }
.toto-draft-actions .form-control { flex: 1; }
.toto-draft-actions .btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ---------- Notifications (Phase 8) -------------------------------------- */
.bell-btn { position: relative; }
.bell-count { position: absolute; top: 2px; right: 0; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--color-alert); color: #fff; font-size: .68rem; font-weight: var(--fw-heavy); line-height: 19px;
  text-align: center; border: 2px solid var(--color-surface); }
.bell-menu { width: 380px; padding: 0; overflow: hidden; border-radius: 14px; }
.bell-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--color-border); text-transform: uppercase; font-size: .85rem; }
.bell-link { border: 0; background: none; color: var(--color-primary); font-weight: var(--fw-bold); font-size: .8rem;
  text-transform: uppercase; padding: 0; }
.bell-all { display: block; text-align: center; padding: 10px; border-top: 1px solid var(--color-border);
  font-weight: var(--fw-bold); text-transform: uppercase; font-size: .8rem; color: var(--color-primary); text-decoration: none; }
.bell-empty { padding: 24px 16px; text-align: center; color: var(--color-text-muted); }
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list.compact { max-height: 360px; overflow-y: auto; }
.notif-list li + li { border-top: 1px solid var(--color-border); }
.notif-list a { display: flex; gap: 14px; align-items: flex-start; padding: 12px 16px; color: var(--color-text); text-decoration: none; }
.notif-list a:hover { background: var(--color-surface-muted); }
.notif-icon { width: 22px; text-align: center; font-size: 1.05rem; padding-top: 2px; color: var(--color-text); }
.notif-list li.lvl-attention .notif-icon { color: var(--color-text); }
.notif-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.notif-text strong { font-weight: var(--fw-semibold); }
.notif-text span { font-size: .82rem; color: var(--color-text-muted); }
.notif-list li.is-unread .notif-text strong { font-weight: var(--fw-heavy); }
.notif-list li.is-unread.lvl-attention a { box-shadow: inset 4px 0 0 var(--color-alert); }
.notif-list li.is-unread.lvl-info a { box-shadow: inset 4px 0 0 var(--color-primary); }
.notif-when { font-size: .8rem; color: var(--color-text-muted); white-space: nowrap; }

/* ---------- Offline bar (Phase 8) ---------------------------------------- */
.offline-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 2100; display: flex; gap: 10px; align-items: center;
  justify-content: center; padding: 10px 16px; background: var(--color-alert); color: #fff; font-weight: var(--fw-bold);
  font-size: .9rem; text-align: center; }
.offline-bar[hidden] { display: none; }
.offline-bar.shake { animation: offline-shake .4s; }
@keyframes offline-shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media print { .offline-bar { display: none !important; } }

/* ---------- Two-step sign-in (Phase 9) ----------------------------------- */
.code-input { font-size: 1.6rem; letter-spacing: .35em; font-weight: var(--fw-heavy); }
.steps-list { padding-left: 20px; margin-bottom: 20px; line-height: 1.7; }
.qr-box { background: #fff; border: 1px solid var(--color-border); border-radius: 12px; padding: 8px; line-height: 0; }
.qr-box svg { width: 200px; height: 200px; }
.setup-key { display: inline-block; font-size: 1.05rem; letter-spacing: .08em; padding: 8px 12px; border-radius: 8px;
  background: var(--color-surface-muted); color: var(--color-text); word-break: break-all; }
.backup-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; max-width: 760px; }
.backup-codes code { display: block; text-align: center; font-size: 1.15rem; letter-spacing: .1em; padding: 12px;
  border: 1px dashed var(--color-text); border-radius: 10px; color: var(--color-text); background: var(--color-surface); }
.text-alert { color: var(--color-alert); }
