/* ==========================================================================
   FairChoice CRM — workspace shell            added 2026-07-31
   Loaded AFTER style.css. Everything here is additive: remove this file and
   its <link> in base.html and the previous interface returns unchanged.

   What it does
     · sidebar collapses to a 68px icon rail, and can dock left or right
     · sticky app bar with New / Tools / View / account dropdown menus
     · comfortable + compact density modes
     · sticky table headers so long tables stay readable
     · off-canvas sidebar drawer below 1000px instead of stacking on top
   ========================================================================== */

:root {
    --rail-w: 264px;
    --appbar-h: 52px;
    --d-panel-pad: 16px;
    --d-gap: 14px;
    --d-cell-y: 9px;
    --d-cell-x: 12px;
    --d-cell-fs: 0.92rem;
    --d-metric-num: 1.7rem;
    --d-h2: 1.7rem;
    /* tall enough for a 22px action chip plus cell padding and border, so a
       row carrying a button is never taller than one that isn't */
    --d-row-h: 42px;
    --d-chip-h: 26px;
    --menu-shadow: 0 18px 44px rgba(4, 51, 71, 0.18);
}

html[data-density="compact"] {
    font-size: 15px;
    --d-panel-pad: 11px;
    --d-gap: 9px;
    --d-cell-y: 5px;
    --d-cell-x: 9px;
    --d-cell-fs: 0.86rem;
    --d-metric-num: 1.35rem;
    --d-h2: 1.35rem;
    --d-row-h: 34px;
    --d-chip-h: 20px;
}

/* --------------------------------------------------------------- shell --- */

/* No transition on this track: Chromium will not re-run a transition that was
   started from a var() when only the custom property changed, which leaves the
   rail stuck at its old width. Snapping is instant and always correct. */
.app-auth .shell {
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
}

html[data-side="right"] .app-auth .shell {
    grid-template-columns: minmax(0, 1fr) var(--rail-w);
}

html[data-side="right"] .app-auth .sidebar {
    order: 2;
}

.app-auth .content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 0;
}

.app-auth .content-body {
    min-width: 0;
    padding: 14px clamp(12px, 1.6vw, 24px) 56px;
}

.app-public .content-body {
    display: contents;
}

/* ------------------------------------------------------------- sidebar --- */

.app-auth .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    gap: 12px;
    padding: 14px 12px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.app-auth .sidebar::-webkit-scrollbar {
    width: 8px;
}

.app-auth .sidebar::-webkit-scrollbar-thumb {
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.22);
}

.app-auth .sidebar-top {
    display: grid;
    gap: 10px;
}

.app-auth .brand-lockup {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    margin-bottom: 2px;
}

.app-auth .brand-logo-wrap {
    padding: 7px 9px;
    border-radius: 12px;
    box-shadow: none;
}

.app-auth .brand-logo-wrap img {
    width: 132px;
}

.app-auth .brand-copy strong {
    font-size: 1rem;
    line-height: 1.2;
}

.app-auth .sidebar .brand-kicker {
    font-size: 0.6rem;
    letter-spacing: 0.14em;
}

.app-auth .sidebar-nav {
    gap: 3px;
    margin-top: 2px;
}

.app-auth .sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    font-size: 0.92rem;
    white-space: nowrap;
}

.app-auth .sidebar-nav a:hover {
    transform: none;
    border-color: transparent;
    background: rgba(255, 255, 255, 0.09);
}

.app-auth .sidebar-nav a.is-active {
    transform: none;
    border-color: rgba(4, 148, 165, 0.5);
    background: linear-gradient(90deg, rgba(4, 148, 165, 0.4), rgba(4, 148, 165, 0.1));
    box-shadow: inset 3px 0 0 var(--brand);
}

.app-auth .sidebar-nav svg {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    opacity: 0.85;
}

.app-auth .sidebar-nav a.is-active svg {
    opacity: 1;
}

.app-auth .sidebar-section {
    margin: 10px 4px 2px;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.42);
}

.app-auth .sidebar-footer {
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.82rem;
}

/* -------------------------------------------------- collapsed icon rail --- */

@media (min-width: 1001px) {
    html[data-rail="1"] {
        --rail-w: 68px;
    }

    html[data-rail="1"] .app-auth .sidebar {
        padding: 14px 10px;
        overflow: visible;
    }

    html[data-rail="1"] .app-auth .rail-hide {
        display: none !important;
    }

    html[data-rail="1"] .app-auth .brand-lockup {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    html[data-rail="1"] .app-auth .brand-logo-wrap {
        padding: 5px;
        border-radius: 10px;
    }

    html[data-rail="1"] .app-auth .brand-logo-wrap img {
        width: 38px;
        height: 30px;
        object-fit: cover;
        object-position: left center;
    }

    html[data-rail="1"] .app-auth .sidebar-nav a {
        justify-content: center;
        padding: 10px 0;
    }

    html[data-rail="1"] .app-auth .sidebar-nav svg {
        width: 20px;
        height: 20px;
    }

    /* label revealed on hover, since the text itself is hidden */
    html[data-rail="1"] .app-auth .sidebar-nav a::after {
        content: attr(data-label);
        position: absolute;
        left: calc(100% + 10px);
        top: 50%;
        z-index: 80;
        padding: 6px 10px;
        border-radius: 8px;
        background: #0d2b35;
        color: #ffffff;
        font-size: 0.78rem;
        font-weight: 600;
        white-space: nowrap;
        opacity: 0;
        transform: translateY(-50%);
        pointer-events: none;
        transition: opacity 0.12s ease;
    }

    html[data-rail="1"] .app-auth .sidebar-nav a:hover::after,
    html[data-rail="1"] .app-auth .sidebar-nav a:focus-visible::after {
        opacity: 1;
    }

    html[data-side="right"][data-rail="1"] .app-auth .sidebar-nav a::after {
        left: auto;
        right: calc(100% + 10px);
    }
}

/* -------------------------------------------------------------- app bar --- */

.appbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--appbar-h);
    padding: 7px clamp(10px, 1.4vw, 20px);
    border-bottom: 1px solid rgba(4, 148, 165, 0.18);
    background: rgba(247, 251, 252, 0.88);
    backdrop-filter: blur(12px);
}

.appbar-title {
    display: flex;
    align-items: baseline;
    gap: 9px;
    min-width: 0;
    margin-right: auto;
}

.appbar-title strong {
    font-size: 1.02rem;
    font-weight: 700;
    white-space: nowrap;
}

.appbar-title .appbar-org {
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--brand-dark);
    opacity: 0.7;
    white-space: nowrap;
}

.appbar-actions {
    display: flex;
    align-items: center;
    gap: 7px;
}

/* style.css gives every bare <button> the filled brand treatment — undo it */
.appbar button,
.menu-pop button,
.icon-button {
    padding: 0;
    border-radius: 9px;
    background: transparent;
    color: inherit;
    font: inherit;
    box-shadow: none;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(4, 148, 165, 0.22);
    background: rgba(255, 255, 255, 0.7);
    color: var(--brand-dark);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-button:hover {
    border-color: rgba(4, 148, 165, 0.5);
    background: rgba(4, 148, 165, 0.12);
    transform: none;
}

.icon-button svg {
    width: 18px;
    height: 18px;
}

/* ------------------------------------------------------- dropdown menus --- */

.menu {
    position: relative;
}

.menu > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid rgba(4, 148, 165, 0.22);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.7);
    color: var(--brand-dark);
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    list-style: none;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.menu > summary::-webkit-details-marker,
.menu > summary::marker {
    display: none;
    content: "";
}

.menu > summary:hover,
.menu[open] > summary {
    border-color: rgba(4, 148, 165, 0.5);
    background: rgba(4, 148, 165, 0.12);
}

.menu > summary svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
}

.menu > summary .caret {
    width: 11px;
    height: 11px;
    opacity: 0.6;
}

.menu--primary > summary {
    border-color: transparent;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #ffffff;
}

.menu--primary > summary:hover,
.menu--primary.menu[open] > summary {
    border-color: transparent;
    background: linear-gradient(180deg, #05a6b9 0%, #075164 100%);
}

.menu--avatar > summary {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(145deg, #075164, #087987);
    border-color: transparent;
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 800;
}

.menu-pop {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 70;
    display: grid;
    gap: 2px;
    min-width: 224px;
    padding: 6px;
    border: 1px solid rgba(4, 148, 165, 0.2);
    border-radius: 12px;
    background: #ffffff;
    box-shadow: var(--menu-shadow);
}

.menu-pop--left {
    right: auto;
    left: 0;
}

.menu-pop a,
.menu-pop button {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    color: var(--ink);
    font-size: 0.87rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.menu-pop a:hover,
.menu-pop button:hover {
    background: rgba(4, 148, 165, 0.1);
    transform: none;
}

.menu-pop svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    opacity: 0.7;
}

.menu-pop button[aria-pressed="true"] {
    background: rgba(4, 148, 165, 0.14);
    color: var(--brand-dark);
}

.menu-label {
    padding: 8px 10px 3px;
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted);
}

.menu-note {
    padding: 2px 10px 8px;
    font-size: 0.82rem;
    color: var(--muted);
}

.menu-note strong {
    display: block;
    color: var(--ink);
}

.menu-sep {
    height: 1px;
    margin: 5px 2px;
    background: rgba(4, 148, 165, 0.16);
}

.menu-key {
    margin-left: auto;
    padding: 1px 7px;
    border: 1px solid rgba(4, 148, 165, 0.25);
    border-radius: 5px;
    background: rgba(4, 148, 165, 0.07);
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--muted);
}

/* ------------------------------------------------------------ densities --- */

.app-auth .page-head {
    align-items: center;
    margin-bottom: var(--d-gap);
    padding: 14px 18px;
    border-radius: 16px;
    box-shadow: 0 8px 22px rgba(4, 51, 71, 0.07);
}

.app-auth .page-head h2 {
    margin: 3px 0 0;
    font-size: var(--d-h2);
    line-height: 1.15;
}

.app-auth .page-head p {
    display: -webkit-box;
    margin-top: 5px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
    font-size: 0.85rem;
    line-height: 1.5;
}

.app-auth .page-head:hover p,
.app-auth .page-head:focus-within p {
    -webkit-line-clamp: 5;
}

.app-auth .page-head::after {
    height: 4px;
}

.app-auth .page-actions .button {
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 0.87rem;
}

html[data-density="compact"] .app-auth .page-head p,
html[data-density="compact"] .app-auth .page-head .brand-kicker {
    display: none;
}

.app-auth .sync-banner {
    margin: 0 0 var(--d-gap);
    padding: 9px 14px;
    border-radius: 12px;
    font-size: 0.88rem;
}

/* .card-grid also matches these, so keep the specificity above it or the
   wider gap wins and the eighth metric wraps onto a second row */
.app-auth .card-grid.metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(124px, 1fr));
    gap: 9px;
    margin-bottom: var(--d-gap);
}

.app-auth .metric-card {
    padding: 10px 12px 10px 15px;
    border-radius: 12px;
    box-shadow: 0 6px 16px rgba(4, 51, 71, 0.06);
}

.app-auth .metric-card::before {
    width: 4px;
}

.app-auth .metric-card span {
    margin-bottom: 2px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.app-auth .metric-card strong {
    font-size: var(--d-metric-num);
}

.app-auth .panel {
    padding: var(--d-panel-pad);
    border-radius: 16px;
    box-shadow: 0 8px 22px rgba(4, 51, 71, 0.07);
}

.app-auth .form-panel {
    padding: var(--d-panel-pad);
}

.app-auth .panel-head {
    margin-bottom: 10px;
}

.app-auth .panel-head h3 {
    font-size: 1.02rem;
}

.app-auth .card-grid {
    gap: var(--d-gap);
}

.app-auth .filter-bar {
    grid-template-columns: minmax(200px, 1fr) 170px 200px 120px;
    gap: 9px;
    margin-bottom: var(--d-gap);
}

@media (max-width: 900px) {
    .app-auth .filter-bar {
        grid-template-columns: 1fr;
    }
}

/* ------------------------------------------------- sortable headers --- */

.app-auth th.is-sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.app-auth th.is-sortable a {
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
}

.app-auth th.is-sortable::after {
    content: "↕";
    margin-left: 5px;
    font-size: 0.85em;
    opacity: 0.32;
}

.app-auth th.is-sortable:hover {
    background: #dcedef;
}

.app-auth th.is-sortable:hover::after {
    opacity: 0.6;
}

.app-auth th[aria-sort="ascending"]::after {
    content: "↑";
    opacity: 1;
}

.app-auth th[aria-sort="descending"]::after {
    content: "↓";
    opacity: 1;
}

.app-auth th[aria-sort="ascending"],
.app-auth th[aria-sort="descending"] {
    background: #d7ebee;
    color: var(--brand-dark);
}

.app-auth th.is-sortable:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
}

/* ------------------------------------------------------ filter chips --- */

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border: 1px solid rgba(4, 148, 165, 0.26);
    border-radius: 999px;
    background: #ffffff;
    color: var(--brand-dark);
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.chip span {
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(4, 148, 165, 0.12);
    font-size: 0.68rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.chip span:empty {
    display: none;
}

.chip:hover {
    border-color: rgba(4, 148, 165, 0.6);
    background: rgba(4, 148, 165, 0.1);
}

.chip.is-active {
    border-color: transparent;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #ffffff;
}

.chip.is-active span {
    background: rgba(255, 255, 255, 0.24);
}

/* Text inputs came out at 44px, date inputs at 46px, and the Linked referral
   select at 64px because of its very long option text — the create/edit form
   read as ragged. One height for every control on the row. */
.app-auth .form-grid input:not([type="hidden"]),
.app-auth .form-grid select,
.app-auth .filter-bar input,
.app-auth .filter-bar select,
.app-auth .filter-bar button {
    height: 46px;
}

.app-auth .form-grid select,
.app-auth .filter-bar select {
    /* long option labels must not push the closed control taller */
    text-overflow: ellipsis;
}

.app-auth .form-actions .button,
.app-auth .form-actions button {
    min-height: 44px;
}

/* ---------------------------------------------------------- data tables --- */

.app-auth .table-wrap {
    overflow: auto;
    max-height: calc(100vh - 190px);
    border-radius: 10px;
    scrollbar-width: thin;
}

.app-auth th,
.app-auth td {
    padding: var(--d-cell-y) var(--d-cell-x);
    font-size: var(--d-cell-fs);
}

.app-auth th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #e7f3f5;
    box-shadow: inset 0 -1px 0 rgba(4, 148, 165, 0.28);
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

/* One line per cell, in both densities. This is what makes rows a uniform
   height — and uniform rows are the only reason two panels side by side can
   ever line up. Nothing is lost: ui-shell.js copies the full text into a
   title tooltip on every cell that actually overflows. */
.app-auth td,
.app-auth th {
    max-width: 260px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

html[data-density="compact"] .app-auth td,
html[data-density="compact"] .app-auth th {
    max-width: 220px;
}

/* summary tables sit two or three across, so they get a tighter cap */
.app-auth .two-up td,
.app-auth .milestone-summary-grid td {
    max-width: 170px;
}

/* Panels sitting side by side only read as aligned if their rows are the
   same height — and a row carrying a Notes button is naturally taller than
   one that isn't. Pin the height so both columns march in step. */
.app-auth .two-up tbody td,
.app-auth .milestone-summary-grid tbody td {
    height: var(--d-row-h);
}

.app-auth td,
.app-auth th {
    vertical-align: middle;
}

.app-auth .two-up tbody td a,
.app-auth .two-up .inline-note-button {
    min-height: 22px;
    padding: 0 8px;
    font-size: 0.72rem;
}

.app-auth tbody tr:nth-child(even) td {
    background: rgba(4, 148, 165, 0.022);
}

.app-auth tbody tr:hover td {
    background: rgba(4, 148, 165, 0.07);
}

.app-auth tbody tr:last-child td {
    border-bottom: 0;
}

/* ------------------------------------------------- in-table action cells --- */

/* style.css sets display:flex on these cells. On a <td> that drops the cell
   out of the table's formatting context, so the column stops aligning with
   its header. Put them back and lay the controls out inline instead. */
.app-auth td.action-row,
.app-auth td.row-actions {
    display: table-cell;
    max-width: none;
    overflow: visible;
    white-space: nowrap;
    text-align: right;
    /* No text here, only controls, so drop the line strut and the vertical
       padding. Button height + padding + border was overshooting the fixed
       row height by a pixel, and that pixel compounded row after row until
       the two panels visibly drifted apart. */
    line-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.app-auth td.action-row form,
.app-auth td.row-actions form {
    display: inline-block;
    margin: 0;
    vertical-align: middle;
}

/* Row actions were bare links inheriting body colour — they read as plain
   text until you hovered. These are controls, so they look like controls.
   Matched on every in-table link, because only some of the templates wrap
   their actions in an .action-row / .row-actions cell. */
.app-auth tbody td a,
.app-auth td.action-row .link-button,
.app-auth .inline-note-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: var(--d-chip-h);
    margin: 0 0 0 5px;
    padding: 0 10px;
    border: 1px solid rgba(4, 148, 165, 0.32);
    border-radius: 7px;
    background: #ffffff;
    color: var(--brand-dark);
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(4, 51, 71, 0.06);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.app-auth tbody td a:first-child {
    margin-left: 0;
}

.app-auth tbody td a:hover,
.app-auth td.action-row .link-button:hover {
    border-color: rgba(4, 148, 165, 0.7);
    background: rgba(4, 148, 165, 0.14);
    transform: none;
    box-shadow: 0 1px 2px rgba(4, 51, 71, 0.06);
}

/* "Complete" commits something, so it reads as the affirmative action */
.app-auth td.action-row .link-button {
    border-color: rgba(31, 123, 95, 0.35);
    background: rgba(31, 123, 95, 0.08);
    color: var(--success);
}

.app-auth td.action-row .link-button:hover {
    border-color: rgba(31, 123, 95, 0.65);
    background: rgba(31, 123, 95, 0.16);
    color: var(--success);
}

/* Notes chip: amber so a file carrying commentary is visible at a glance */
.app-auth .inline-note-button {
    border-color: rgba(152, 101, 27, 0.38);
    background: rgba(152, 101, 27, 0.09);
    color: var(--warn);
}

.app-auth .inline-note-button::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.app-auth .inline-note-button:hover {
    border-color: rgba(152, 101, 27, 0.7);
    background: rgba(152, 101, 27, 0.18);
    box-shadow: 0 1px 2px rgba(4, 51, 71, 0.06);
}

/* Cells that reveal a note on hover advertise it rather than hiding it.
   The marker is a text decoration, not a border: a border adds a pixel of box
   height, which compounds row by row and pulls side-by-side panels crooked. */
.app-auth .note-hover-target {
    /* plain inline text: an inline-block or inline-flex box here sits on the
       baseline and grows the line box by a pixel, which compounds row by row
       until side-by-side panels visibly drift apart. The cell already clips
       and ellipsises, so this element does not need a box of its own. */
    display: inline;
    max-width: none;
    border-bottom: 0;
    text-decoration: underline dashed rgba(152, 101, 27, 0.75);
    text-underline-offset: 3px;
}

.app-auth .note-hover-target:hover {
    color: var(--warn);
    text-decoration-color: var(--warn);
}

/* ------------------------------------------------------- status badges --- */

/* Fixed height, so a row with a status badge is exactly as tall as one
   without — otherwise a handful of populated rows sit proud of the rest. */
.app-auth .status {
    display: inline-block;
    height: 20px;
    max-width: 150px;
    overflow: hidden;
    padding: 0 9px;
    border: 1px solid rgba(4, 51, 71, 0.12);
    font-size: 0.66rem;
    line-height: 18px;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* 798 of 812 referrals carry no status, and an empty capsule read as a bug.
   Keep the box so heights still match, but show a plain dash instead. */
.app-auth .status:empty {
    border-color: transparent;
    background: none;
}

.app-auth .status:empty::before {
    content: "—";
    color: var(--muted);
    font-size: inherit;
}

.app-auth .appointment-item {
    padding: 10px 0;
}

/* Milestone comments run long — without a cap this panel grew past 1500px and
   stretched whatever sat beside it. Scroll the list, clamp each note. */
.app-auth .notes-list {
    display: grid;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.app-auth .note-card {
    padding: 11px 13px;
}

.app-auth .note-card p {
    display: -webkit-box;
    margin: 6px 0;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ------------------------------------------------- insight bar panels --- */

.stat-bars {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.stat-bars li {
    display: grid;
    grid-template-columns: minmax(90px, 152px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.stat-bar-label {
    overflow: hidden;
    font-size: 0.8rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-bar-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(4, 148, 165, 0.11);
}

.stat-bar-fill {
    display: block;
    height: 100%;
    min-width: 3px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
}

.stat-bar-fill--warn {
    background: linear-gradient(90deg, #c78a24, var(--warn));
}

.stat-bar-value {
    min-width: 30px;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--brand-dark);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.stat-bar-value small {
    display: block;
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--muted);
}

.panel-hint {
    margin: 0 0 10px;
    font-size: 0.78rem;
    color: var(--muted);
}

/* referral source bars: total behind, converted-to-file in front */
.stat-bar-fill--muted {
    background: rgba(4, 148, 165, 0.28);
}

.stat-bar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
}

.source-bars .stat-bar-track,
.aging-list .stat-bar-track {
    position: relative;
}

.aging-list .stat-bar-label,
.source-bars .stat-bar-label {
    display: block;
    white-space: normal;
}

.aging-list .stat-bar-label a {
    color: var(--brand-dark);
    font-weight: 700;
}

.aging-list .stat-bar-label a:hover {
    text-decoration: underline;
}

.aging-list .stat-bar-label small,
.source-bars .stat-bar-label small {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
}

.aging-list li,
.source-bars li {
    grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) auto;
}

.pager-info--solo {
    margin: 10px 0 0;
    padding-top: 10px;
    border-top: 1px solid rgba(4, 148, 165, 0.16);
}

.empty-note {
    margin: 0;
    padding: 14px 0;
    color: var(--muted);
    font-size: 0.86rem;
    text-align: center;
}

/* ---------------------------------------------------------- charts --- */

.chart-panel {
    display: flex;
    flex-direction: column;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin-bottom: 6px;
}

.chart-key {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}

.chart-key i {
    width: 9px;
    height: 9px;
    border-radius: 3px;
}

.chart-key b {
    color: var(--ink);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.chart-svg {
    width: 100%;
    height: auto;
    margin-top: auto;
}

.chart-grid {
    stroke: rgba(4, 148, 165, 0.18);
    stroke-width: 1;
}

.chart-axis {
    fill: var(--muted);
    font-size: 10px;
    font-weight: 600;
}

.chart-area {
    opacity: 0.08;
}

.chart-line {
    fill: none;
    stroke-width: 2.2;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-dot {
    stroke: #ffffff;
    stroke-width: 1.5;
    cursor: help;
    transition: r 0.12s ease;
}

.chart-dot:hover {
    r: 5.5;
}

.donut-wrap {
    display: grid;
    grid-template-columns: 148px minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    margin-top: auto;
}

.donut {
    width: 148px;
    height: 148px;
}

.donut circle {
    cursor: help;
    transition: stroke-width 0.14s ease;
}

.donut circle:hover {
    stroke-width: 24;
}

.donut-total {
    fill: var(--brand-dark);
    font-size: 26px;
    font-weight: 800;
}

.donut-sub {
    fill: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.donut-legend {
    display: grid;
    gap: 5px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.donut-legend li {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 9px;
    font-size: 0.8rem;
}

.donut-legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.donut-legend span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.donut-legend b {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.donut-legend small {
    min-width: 38px;
    color: var(--muted);
    font-weight: 700;
    text-align: right;
}

/* ------------------------------------------------------ pagination --- */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(4, 148, 165, 0.16);
}

.pager-info {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
}

.pager-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 30px;
    padding: 0 9px;
    border: 1px solid rgba(4, 148, 165, 0.28);
    border-radius: 8px;
    background: #ffffff;
    color: var(--brand-dark);
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.pager-btn:hover {
    border-color: rgba(4, 148, 165, 0.6);
    background: rgba(4, 148, 165, 0.12);
}

.pager-btn.is-current {
    border-color: transparent;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #ffffff;
}

.pager-btn.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.pager-gap {
    padding: 0 3px;
    color: var(--muted);
}

.panel-head-tools {
    display: flex;
    align-items: center;
    gap: 12px;
}

.panel-count {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.app-auth .table-wrap--tall {
    max-height: calc(100vh - 250px);
    min-height: 300px;
}

/* ------------------------------------------------- live sheet grid --- */

.source-switch {
    display: inline-flex;
    gap: 3px;
    margin-bottom: var(--d-gap);
    padding: 3px;
    border: 1px solid rgba(4, 148, 165, 0.22);
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.72);
}

.source-btn {
    padding: 7px 14px;
    border-radius: 8px;
    color: var(--brand-dark);
    font-size: 0.85rem;
    font-weight: 700;
}

.source-btn:hover {
    background: rgba(4, 148, 165, 0.1);
}

.source-btn.is-active {
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #ffffff;
}

.sheet-panel {
    padding: 0;
    overflow: hidden;
}

.sheet-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 13px;
    border-bottom: 1px solid rgba(4, 148, 165, 0.18);
}

.sheet-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.sheet-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    border: 1px solid rgba(4, 148, 165, 0.26);
    border-radius: 8px;
    background: #ffffff;
    color: var(--brand-dark);
    font-size: 0.83rem;
    font-weight: 700;
}

.sheet-tab span {
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(4, 148, 165, 0.13);
    font-size: 0.68rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.sheet-tab:hover {
    border-color: rgba(4, 148, 165, 0.6);
    background: rgba(4, 148, 165, 0.1);
}

.sheet-tab.is-active {
    border-color: transparent;
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #ffffff;
}

.sheet-tab.is-active span {
    background: rgba(255, 255, 255, 0.24);
}

.sheet-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-auth .sheet-search {
    width: 210px;
    height: 34px;
    padding: 0 12px;
    border-radius: 9px;
    font-size: 0.85rem;
}

.sheet-count {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--muted);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.sheet-formula {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 13px;
    border-bottom: 1px solid rgba(4, 148, 165, 0.18);
    background: rgba(4, 148, 165, 0.045);
}

.sheet-ref {
    min-width: 58px;
    padding: 3px 8px;
    border: 1px solid rgba(4, 148, 165, 0.3);
    border-radius: 6px;
    background: #ffffff;
    color: var(--brand-dark);
    font-size: 0.75rem;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.sheet-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet-value.is-empty {
    color: var(--muted);
    font-style: italic;
}

.sheet-scroll {
    overflow: auto;
    max-height: calc(100vh - 290px);
    min-height: 360px;
}

.sheet-grid {
    border-collapse: separate;
    border-spacing: 0;
}

.app-auth .sheet-grid th,
.app-auth .sheet-grid td {
    border-right: 1px solid rgba(4, 51, 71, 0.1);
    border-bottom: 1px solid rgba(4, 51, 71, 0.1);
}

.app-auth .sheet-letters th {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 22px;
    padding: 0 8px;
    background: #d8e8ec;
    color: var(--brand-dark);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-align: center;
}

.app-auth .sheet-headers th {
    position: sticky;
    top: 22px;
    z-index: 5;
    max-width: 220px;
    padding: 6px 8px;
    background: #eaf4f6;
    font-size: 0.7rem;
    text-align: left;
}

.app-auth .sheet-corner {
    position: sticky;
    left: 0;
    z-index: 7;
    width: 54px;
    min-width: 54px;
    background: #cadfe4;
}

.app-auth .sheet-rownum {
    position: sticky;
    left: 0;
    z-index: 3;
    width: 54px;
    min-width: 54px;
    padding: 0 8px;
    background: #eef5f6;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
}

.app-auth .sheet-grid td {
    max-width: 240px;
    height: 26px;
    padding: 0 8px;
    background: #ffffff;
    font-size: 0.79rem;
}

.app-auth .sheet-grid tbody tr:nth-child(even) td {
    background: #f7fbfc;
}

.app-auth .sheet-grid tbody tr:hover td {
    background: rgba(4, 148, 165, 0.07);
}

.app-auth .sheet-grid td.is-selected {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
    background: rgba(4, 148, 165, 0.12);
}

.app-auth .sheet-empty {
    padding: 26px;
    color: var(--muted);
    text-align: center;
}

.sheet-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 13px;
    border-top: 1px solid rgba(4, 148, 165, 0.18);
    font-size: 0.76rem;
    color: var(--muted);
}

.sheet-hint {
    font-weight: 600;
    opacity: 0.85;
}

/* ------------------------------------------- funnel and cycle times --- */

.funnel,
.cycle-bars {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.funnel li {
    display: grid;
    grid-template-columns: minmax(84px, 118px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.funnel-label,
.cycle-label {
    overflow: hidden;
    font-size: 0.8rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.funnel-track {
    position: relative;
    display: block;
    height: 22px;
    overflow: hidden;
    border-radius: 6px;
    background: rgba(4, 148, 165, 0.09);
}

.funnel-fill {
    display: block;
    height: 100%;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
}

.funnel-pct {
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.funnel li.is-empty .funnel-pct {
    left: auto;
    right: 8px;
    color: var(--muted);
    text-shadow: none;
}

.funnel-value {
    min-width: 54px;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--brand-dark);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.funnel-value small {
    display: block;
    font-size: 0.66rem;
    font-weight: 700;
    color: var(--danger);
}

.panel-note {
    margin: 10px 0 0;
    padding: 9px 11px;
    border-left: 3px solid var(--warn);
    border-radius: 0 8px 8px 0;
    background: rgba(152, 101, 27, 0.08);
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--ink);
}

.cycle-bars li {
    display: grid;
    grid-template-columns: minmax(110px, 170px) minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.cycle-track {
    position: relative;
    display: block;
    height: 18px;
    border-radius: 6px;
    background: rgba(4, 148, 165, 0.08);
}

.cycle-range {
    position: absolute;
    top: 4px;
    bottom: 4px;
    border-radius: 4px;
    background: rgba(4, 148, 165, 0.28);
}

.cycle-median {
    position: absolute;
    top: 1px;
    bottom: 1px;
    width: 3px;
    margin-left: -1px;
    border-radius: 2px;
    background: var(--brand-dark);
}

.cycle-none {
    padding-left: 8px;
    font-size: 0.72rem;
    line-height: 18px;
    color: var(--muted);
}

.cycle-value {
    min-width: 56px;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--brand-dark);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.cycle-value small {
    display: block;
    font-size: 0.64rem;
    font-weight: 700;
    color: var(--muted);
}

/* ------------------------------------------------ file timeline --- */

.timeline-panel .panel-head {
    margin-bottom: 8px;
}

.timeline-stage {
    display: inline-block;
    padding: 4px 11px;
    border-radius: 999px;
    background: rgba(4, 148, 165, 0.13);
    color: var(--brand-dark);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.timeline-summary {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

.timeline-progress {
    flex: 1 1 200px;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(4, 148, 165, 0.12);
}

.timeline-progress span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), var(--brand-dark));
}

.timeline-next {
    font-size: 0.82rem;
    color: var(--muted);
}

.timeline-next strong {
    color: var(--ink);
}

.timeline {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.timeline li {
    position: relative;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    font-size: 0.85rem;
    color: var(--muted);
}

/* the connecting rail, drawn between consecutive dots */
.timeline li::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 12px;
    width: 2px;
    background: rgba(4, 148, 165, 0.16);
}

.timeline li:first-child::before {
    top: 50%;
}

.timeline li:last-child::before {
    bottom: 50%;
}

.timeline-dot {
    position: relative;
    z-index: 1;
    justify-self: center;
    width: 11px;
    height: 11px;
    border: 2px solid rgba(4, 148, 165, 0.35);
    border-radius: 50%;
    background: #ffffff;
}

.timeline li.is-done {
    color: var(--ink);
}

.timeline li.is-done .timeline-dot {
    border-color: var(--brand-dark);
    background: linear-gradient(180deg, var(--brand), var(--brand-dark));
    box-shadow: 0 0 0 3px rgba(4, 148, 165, 0.14);
}

.timeline li.is-done .timeline-label {
    font-weight: 700;
}

.timeline-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-date {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.timeline-gap {
    min-width: 52px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--brand-dark);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

@media (max-width: 620px) {
    .timeline li {
        grid-template-columns: 26px minmax(0, 1fr) auto;
    }

    .timeline-gap {
        display: none;
    }
}

/* --------------------------------------------- narrow screens: drawer --- */

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 85;
    background: rgba(6, 32, 42, 0.5);
    backdrop-filter: blur(2px);
}

.drawer-backdrop[hidden] {
    display: none;
}

@media (min-width: 1001px) {
    .drawer-backdrop {
        display: none;
    }
}

@media (max-width: 1000px) {
    .app-auth .shell {
        grid-template-columns: minmax(0, 1fr);
    }

    /* Deliberately not transitioned. Animating this transform leaves the drawer
       stranded on-screen after the viewport crosses the breakpoint, because the
       interrupted transition never settles on its end value. */
    .app-auth .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 90;
        width: 268px;
        transform: translateX(-100%);
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.45);
    }

    html[data-side="right"] .app-auth .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }

    html[data-drawer="1"] .app-auth .sidebar {
        transform: none;
    }

    .app-auth .table-wrap {
        max-height: calc(100vh - 150px);
    }
}

@media (max-width: 760px) {
    .appbar-title .appbar-org {
        display: none;
    }

    .hide-sm {
        display: none !important;
    }

    .menu-pop {
        min-width: 200px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-auth .sidebar-nav a::after {
        transition: none;
    }
}
