/* ==========================================================================
   CaXi design tokens
   A finance ledger, not a SaaS dashboard: paper surfaces, hairline rules,
   a serif for money figures, tabular mono for line-item numbers.
   ========================================================================== */

:root {
    --ink-900: #12161F;
    --ink-700: #333A48;
    --ink-500: #6B7280;
    --ink-300: #A8AEB8;

    --paper-0: #F5F3EE;
    --paper-50: #FFFFFF;
    --line: #DEDACE;
    --line-strong: #C7C1B1;

    --blue-600: #2E96C8;
    --blue-700: #1B6F99;
    --blue-100: #E4F1F8;

    --harbor-900: #0E4C6B;
    --harbor-tint-1: #6EC6E8;
    --harbor-tint-2: #9DC4D6;
    --harbor-tint-3: #BEE4F3;
    --mint: #8FE0B4;
    --coral: #FFB4A6;

    --positive-700: #1F7A4D;
    --positive-100: #E4F3EA;
    --negative-700: #B23A2E;
    --negative-100: #FBEAE8;
    --warning-700: #A66317;
    --warning-100: #FBF0DE;

    --font-display: "Fraunces", "Iowan Old Style", "Georgia", serif;
    --font-body: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
    --font-mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --shadow-card: 0 1px 2px rgba(18, 22, 31, 0.06), 0 1px 0 rgba(18, 22, 31, 0.03);
    --shadow-card-hover: 0 6px 18px rgba(18, 22, 31, 0.12);

    color-scheme: light;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--paper-0);
    color: var(--ink-900);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .cx-figure {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink-900);
    margin: 0;
}

a {
    color: var(--blue-600);
}

:focus-visible {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
}

.cx-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Guaranteed baseline size for every icon, regardless of context.
   Contextual rules below (.cx-nav-link svg etc.) override this via specificity. */
.cx-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

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

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

.cx-sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--harbor-900);
    color: var(--paper-0);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.18s ease;
}

.cx-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    padding: 18px 20px 16px;
    letter-spacing: -0.01em;
}

.cx-sidebar-brand img {
    height: 26px;
    width: auto;
    flex-shrink: 0;
}

.cx-sidebar-brand span {
    color: var(--harbor-tint-1);
}

.cx-sidebar-tagline {
    font-size: 11.5px;
    color: var(--harbor-tint-2);
    padding: 0 20px 14px;
    margin-top: -12px;
}

.cx-nav {
    list-style: none;
    margin: 0;
    padding: 4px 10px;
    flex: 1;
}

.cx-nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-300);
    padding: 16px 10px 6px;
}

.cx-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: #C7CCDA;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
}

.cx-nav-link svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.cx-nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.cx-nav-link.active {
    background: var(--blue-600);
    color: #fff;
}

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

/* Book tabs — the signature element: flip between ledgers like index tabs */
.cx-booktabs {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 14px 24px 0;
    background: var(--paper-50);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}

.cx-booktab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px 8px 0 0;
    background: var(--paper-0);
    border: 1px solid var(--line);
    border-bottom: none;
    color: var(--ink-500);
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    position: relative;
    top: 1px;
}

.cx-booktab .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cx-booktab.active {
    background: var(--paper-50);
    border-color: var(--line);
    color: var(--ink-900);
    font-weight: 600;
}

.cx-booktab-add {
    padding: 9px 12px;
    color: var(--ink-500);
    text-decoration: none;
    font-size: 18px;
    line-height: 1;
}

.cx-booktab-add:hover {
    color: var(--blue-600);
}

.cx-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--paper-50);
    border-bottom: 1px solid var(--line);
}

.cx-topbar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--ink-700);
}

.cx-content {
    padding: 28px 24px 60px;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
}

@media (max-width: 900px) {
    .cx-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        margin-left: -232px;
    }

    .cx-sidebar.open {
        margin-left: 0;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }

    .cx-topbar-toggle {
        display: inline-flex;
    }

    .cx-scrim {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(18, 22, 31, 0.4);
        z-index: 30;
    }

    .cx-scrim.open {
        display: block;
    }
}

/* ------------------------------ Primitives ------------------------------- */

.cx-page-title {
    font-size: 26px;
    margin-bottom: 4px;
}

.cx-page-sub {
    color: var(--ink-500);
    font-size: 14px;
    margin: 0 0 24px;
}

/* Page header band — dark harbor strip above every page's content */

.cx-header-band {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--harbor-900);
    color: #fff;
    padding: 14px 24px;
}

.cx-header-band-group {
    font-size: 11px;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--harbor-tint-2);
    margin-bottom: 2px;
}

.cx-header-band-title {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: #fff;
    margin: 0;
}

.cx-header-band-sub {
    font-size: 13px;
    color: var(--harbor-tint-2);
    margin: 3px 0 0;
}

.cx-header-band .cx-btn-primary {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
}

.cx-header-band .cx-btn-primary:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* KPI row — equal-width stat cards at the top of the Dashboard */

.cx-kpi-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 16px;
    margin-bottom: 24px;
}

.cx-kpi-row > * {
    flex: 1 1 260px;
    min-width: 260px;
    max-width: 380px;
    box-sizing: border-box;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.cx-kpi-row > *:hover {
    transform: translateY(-2px);
}

/* The hero balance leads the row, so let it run wider than the stat cards. */
.cx-kpi-row > .cx-hero-card {
    flex: 1.5 1 300px;
    max-width: 420px;
}

@media (max-width: 560px) {
    .cx-kpi-row > *,
    .cx-kpi-row > .cx-hero-card {
        flex-basis: 100%;
        min-width: 0;
        max-width: none;
    }
}

/* KPI stat card — label / figure / sub, with a colour-coded left edge */

.cx-kpi-card {
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-left: 3px solid var(--line-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: 14px 16px;
}

/* A card that links somewhere — the whole card is the hit target. */
a.cx-kpi-card {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

a.cx-kpi-card:hover {
    border-left-color: var(--blue-600);
    box-shadow: var(--shadow-card-hover);
    transform: translateY(-1px);
}

.cx-kpi-card.positive { border-left-color: var(--positive-700); }
.cx-kpi-card.negative { border-left-color: var(--negative-700); }
.cx-kpi-card.accent { border-left-color: var(--blue-600); }
.cx-kpi-card.warning { border-left-color: var(--warning-700); }

.cx-kpi-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-500);
}

.cx-kpi-value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-top: 4px;
}

.cx-kpi-value.positive { color: var(--positive-700); }
.cx-kpi-value.negative { color: var(--negative-700); }

.cx-kpi-sub {
    font-size: 12px;
    color: var(--ink-500);
    margin-top: 3px;
}

/* Dashboard panels — a card with a titled header, holding a chart or a breakdown */

.cx-panel {
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    padding: 16px 18px 18px;
}

.cx-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-size: 15.5px;
    font-weight: 600;
}

.cx-panel-title .accent-bar {
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--blue-600);
    flex-shrink: 0;
}

.cx-panel-sub {
    font-size: 12.5px;
    color: var(--ink-500);
    margin: 2px 0 14px 11px;
}

.cx-dash-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 860px) {
    .cx-dash-grid {
        grid-template-columns: 1fr;
    }
}

/* Horizontal bar breakdown */

.cx-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cx-bar-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 5px;
}

.cx-bar-name {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    color: var(--ink-700);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cx-bar-name .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cx-bar-value {
    font-size: 13px;
    color: var(--ink-900);
    flex-shrink: 0;
}

.cx-bar-track {
    height: 7px;
    background: var(--paper-0);
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
}

.cx-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

/* Pick list — scrollable multi-select rows (attaching an invoice to transactions) */

.cx-picklist {
    /* Its own scroll sits inside the modal's — keep it short so both stay usable. */
    max-height: min(220px, 32dvh);
    overflow-y: auto;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--paper-50);
}

.cx-picklist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 11px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
    cursor: pointer;
}

.cx-picklist-row:last-child {
    border-bottom: none;
}

.cx-picklist-row:hover {
    background: var(--paper-0);
}

.cx-picklist-row.selected {
    background: var(--blue-100);
}

.cx-picklist-row input {
    flex-shrink: 0;
    margin: 0;
    accent-color: var(--blue-600);
}

.cx-picklist-date {
    font-size: 12px;
    color: var(--ink-500);
    flex-shrink: 0;
}

.cx-picklist-payee {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cx-picklist-amount {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

/* Range selector — 30D / 90D / 12M */

.cx-range {
    display: inline-flex;
    gap: 3px;
    padding: 3px;
    background: var(--paper-0);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.cx-range-btn {
    border: none;
    background: none;
    padding: 5px 11px;
    border-radius: 6px;
    font-family: var(--font-body);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-500);
    cursor: pointer;
}

.cx-range-btn.active {
    background: var(--paper-50);
    color: var(--harbor-900);
    box-shadow: var(--shadow-card);
}

/* Hero balance card — dark card used at the top of the Dashboard */

.cx-hero-card {
    border-radius: var(--radius-md);
    background: var(--harbor-900);
    color: #fff;
    padding: 22px 22px 18px;
    position: relative;
    overflow: hidden;
}

.cx-hero-label {
    font-size: 11.5px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--harbor-tint-2);
}

.cx-hero-figure {
    font-family: var(--font-display);
    font-size: 42px;
    font-weight: 600;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    line-height: 1.05;
    margin-top: 8px;
}

.cx-hero-figure.negative { color: var(--coral); }

.cx-callout {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    text-align: left;
    width: 100%;
    padding: 14px 16px;
    background: var(--blue-100);
    border: 1px solid var(--harbor-tint-3);
    border-radius: 12px;
    box-sizing: border-box;
}

.cx-callout-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--blue-700);
    border: 1px solid var(--harbor-tint-2);
    border-radius: 4px;
    padding: 2px 5px;
    flex-shrink: 0;
    margin-top: 2px;
}

.cx-callout-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--harbor-900);
}

.cx-callout-sub {
    display: block;
    font-size: 13px;
    color: var(--blue-700);
    margin-top: 2px;
}

.cx-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.cx-btn svg {
    width: 16px;
    height: 16px;
}

.cx-btn-primary {
    background: var(--blue-600);
    color: #fff;
}

.cx-btn-primary:hover {
    background: var(--blue-700);
}

.cx-btn-ghost {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--ink-700);
}

.cx-btn-ghost:hover {
    background: var(--paper-0);
}

.cx-btn-danger {
    background: transparent;
    color: var(--negative-700);
    border-color: var(--negative-100);
}

.cx-btn-danger:hover {
    background: var(--negative-100);
}

.cx-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--paper-50);
    color: var(--ink-700);
    cursor: pointer;
}

.cx-icon-btn:hover {
    background: var(--paper-0);
}

.cx-icon-btn svg {
    width: 16px;
    height: 16px;
}

.cx-card {
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

.cx-card-body {
    padding: 18px 20px;
}

.cx-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}

.cx-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.cx-figure {
    font-size: 34px;
}

.cx-figure.positive { color: var(--positive-700); }
.cx-figure.negative { color: var(--negative-700); }

.cx-empty {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-md);
    padding: 32px 24px;
    text-align: center;
    color: var(--ink-500);
    background: var(--paper-50);
}

.cx-empty svg {
    width: 30px;
    height: 30px;
    color: var(--ink-300);
    margin-bottom: 10px;
}

.cx-alert {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    margin-bottom: 18px;
}

.cx-alert-info { background: var(--blue-100); color: var(--blue-700); }
.cx-alert-success { background: var(--positive-100); color: var(--positive-700); }
.cx-alert-warning { background: var(--warning-100); color: var(--warning-700); }

/* Forms */

.cx-field {
    margin-bottom: 16px;
}

.cx-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-700);
    margin-bottom: 6px;
}

.cx-hint {
    font-size: 12.5px;
    color: var(--ink-500);
    margin-top: 5px;
}

.cx-input, .cx-select {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: var(--paper-50);
    color: var(--ink-900);
    font-family: var(--font-body);
    font-size: 14px;
}

.cx-input:focus, .cx-select:focus {
    outline: none;
    border-color: var(--blue-600);
    box-shadow: 0 0 0 3px var(--blue-100);
}

.cx-swatches {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.cx-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
}

.cx-swatch.selected {
    border-color: var(--ink-900);
}

.validation-message {
    color: var(--negative-700);
    font-size: 12.5px;
    display: block;
    margin-top: 4px;
}

/* Tables (Accounts, Transactions) */

.cx-table-wrap {
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: auto;
    box-shadow: var(--shadow-card);
}

.cx-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.cx-table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-500);
    font-weight: 600;
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.cx-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.cx-table tbody tr:last-child td {
    border-bottom: none;
}

.cx-table tbody tr:hover {
    background: var(--paper-0);
}

.cx-table .num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.cx-table .num.positive { color: var(--positive-700); }
.cx-table .num.negative { color: var(--negative-700); }

.cx-table-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

.cx-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 16px;
    margin-top: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--paper-50);
    box-shadow: var(--shadow-card);
}

.cx-pager-label {
    font-size: 13px;
    color: var(--ink-500);
}

.cx-pager-actions {
    display: flex;
    gap: 8px;
}

.cx-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: var(--paper-0);
    border: 1px solid var(--line);
    color: var(--ink-700);
}

.cx-pill .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.cx-kind-badge {
    display: inline-flex;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.cx-kind-badge.income { background: var(--positive-100); color: var(--positive-700); }
.cx-kind-badge.expense { background: var(--negative-100); color: var(--negative-700); }
.cx-kind-badge.transfer { background: var(--blue-100); color: var(--blue-700); }

/* Cards used for entity list items (e.g. Books) */

.cx-entity-card {
    border-top: 4px solid var(--blue-600);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cx-entity-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.cx-entity-name {
    font-weight: 600;
    font-size: 15.5px;
}

.cx-entity-meta {
    color: var(--ink-500);
    font-size: 13px;
    margin-top: 2px;
}

.cx-menu {
    position: relative;
}

.cx-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(18,22,31,0.14);
    min-width: 140px;
    z-index: 20;
    overflow: hidden;
}

.cx-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    background: none;
    border: none;
    font-size: 13.5px;
    color: var(--ink-700);
    cursor: pointer;
}

.cx-menu-item:hover {
    background: var(--paper-0);
}

.cx-menu-item.danger {
    color: var(--negative-700);
}

/* Modal */

.cx-modal-scrim {
    position: fixed;
    inset: 0;
    background: rgba(18, 22, 31, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    animation: cx-fade 0.15s ease;
}

@media (max-width: 560px) {
    .cx-modal-scrim {
        padding: 10px;
    }
}

.cx-modal {
    background: var(--paper-50);
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 60px rgba(18,22,31,0.3);
    animation: cx-rise 0.16s ease;
    /* Never taller than the viewport (minus the scrim's 20px padding) — a long form
       scrolls inside the body instead of pushing its buttons off-screen. */
    max-height: calc(100dvh - 40px);
    display: flex;
    flex-direction: column;
}

.cx-modal-wide {
    max-width: 640px;
}

.cx-field-row {
    display: flex;
    gap: 12px;
}

.cx-field-row > .cx-field {
    flex: 1;
    min-width: 0;
}

@media (max-width: 560px) {
    .cx-field-row {
        flex-direction: column;
        gap: 0;
    }

    /* Matches the scrim's tighter padding at this width. */
    .cx-modal {
        max-height: calc(100dvh - 20px);
    }
}

.cx-modal-header {
    padding: 18px 20px 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;
}

.cx-modal-title {
    font-family: var(--font-display);
    font-size: 19px;
    font-weight: 600;
}

.cx-modal-body {
    /* No bottom padding: a sticky form footer would otherwise float above the edge. */
    padding: 12px 20px 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.cx-modal-footer {
    padding: 16px 20px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex: 0 0 auto;
}

/* Forms that carry their own buttons (they must sit inside the EditForm to submit)
   render them in the scrolling body — pin them to its bottom edge so they stay reachable. */
.cx-modal-body .cx-form-footer {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 0 12px;
    margin-top: 4px;
    background: var(--paper-50);
    border-top: 1px solid var(--line);
}

/* The wrapper still renders when a modal supplies no Footer; don't pay for its padding. */
.cx-modal-footer:empty {
    display: none;
}

@keyframes cx-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes cx-rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Toasts */

.cx-toast-stack {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 200;
}

.cx-toast {
    background: var(--ink-900);
    color: #fff;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    animation: cx-rise 0.18s ease;
    min-width: 220px;
}

.cx-toast.success { background: var(--positive-700); }
.cx-toast.error { background: var(--negative-700); }

/* ------------------------------ Sign-in ---------------------------------- */
/* Standalone pages: no sidebar, no book tabs, nothing but the form.
   Padded for the notch and the on-screen keyboard on a phone. */

.cx-auth {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper-0);
    padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.cx-auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--paper-50);
    border: 1px solid var(--line);
    border-top: 3px solid var(--blue-600);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card-hover);
    padding: 26px 26px 28px;
}

.cx-auth-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 22px;
}

.cx-auth-brand img {
    height: 34px;
    width: 34px;
    object-fit: contain;
    flex-shrink: 0;
}

.cx-auth-wordmark {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--harbor-900);
    letter-spacing: -0.01em;
}

.cx-auth-wordmark span {
    color: var(--blue-600);
}

.cx-auth-tagline {
    font-size: 11.5px;
    color: var(--ink-500);
}

.cx-auth-title {
    font-size: 19px;
    margin: 0 0 16px;
}

.cx-auth-remember {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    color: var(--ink-700);
    margin: 4px 0 18px;
    cursor: pointer;
}

.cx-auth-remember input {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: var(--blue-600);
    flex-shrink: 0;
}

.cx-auth-submit {
    width: 100%;
    justify-content: center;
    padding: 11px;
    font-size: 15px;
}

.cx-auth-error {
    color: var(--negative-700);
    font-size: 13px;
}

.cx-auth-error ul {
    margin: 0 0 12px;
    padding-left: 18px;
}

/* The card is centred by the flex parent; the install row sits under it, not beside it. */
.cx-auth {
    flex-direction: column;
}

.cx-auth-install,
.cx-auth-install-hint {
    margin-top: 16px;
    text-align: center;
    max-width: 380px;
    width: 100%;
}

.cx-auth-install-hint {
    font-size: 12.5px;
    color: var(--ink-500);
    line-height: 1.5;
}
