/* ============================================================================
   CountrPro — UI primitives
   The custom design system that replaces MudBlazor. Everything here is plain
   HTML/CSS driven by tokens; no framework classes, no !important overrides.

   Dark values are declared under [data-theme="dark"] only — deliberately NOT
   prefers-color-scheme, because pages still on MudBlazor would not follow the
   OS setting and the app would render half-dark mid-migration.

   Chart colors come from the validated palette in the dataviz reference,
   re-validated against THESE surfaces (#ffffff light, #1c1c1e dark):
   light + dark both pass lightness, chroma, CVD separation and normal-vision
   floors. Light-mode aqua/yellow/magenta sit under 3:1, so any chart using
   slots 3-5 must ship visible labels or the table view (the relief rule).
   ============================================================================ */

:root {
    /* Surfaces & ink */
    --cp-plane: #F4F5F7;
    --cp-surface: #FFFFFF;
    --cp-surface-2: #F7F8FA;
    --cp-text: #15181E;
    --cp-text-2: #545B69;
    --cp-muted: #858B99;
    --cp-line: rgba(16, 24, 40, 0.10);
    --cp-line-strong: rgba(16, 24, 40, 0.16);

    /* Chart chrome */
    --cp-grid: #ECEEF2;
    --cp-axis: #D5D9E2;

    /* Brand */
    --cp-accent: #4F5BD5;
    --cp-accent-hover: #4550c4;
    --cp-accent-soft: rgba(79, 91, 213, 0.10);

    /* Status — fixed, never themed. Always paired with an icon + label. */
    --cp-good: #0ca30c;
    --cp-warning: #fab219;
    --cp-serious: #ec835a;
    --cp-critical: #d03b3b;
    --cp-good-text: #006300;
    --cp-critical-text: #b02c2c;

    /* Categorical series (validated order — never cycle, never generate a 9th) */
    --cp-s1: #2a78d6;
    --cp-s2: #eb6834;
    --cp-s3: #1baf7a;
    --cp-s4: #eda100;
    --cp-s5: #e87ba4;
    --cp-s6: #008300;
    --cp-s7: #4a3aa7;
    --cp-s8: #e34948;

    /* Shape & type */
    --cp-r-sm: 8px;
    --cp-r: 12px;
    --cp-r-lg: 16px;
    --cp-pill: 999px;
    --cp-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

:root[data-theme="dark"] {
    --cp-plane: #0B0D12;
    --cp-surface: #1C1C1E;
    --cp-surface-2: #232428;
    --cp-text: #F2F4F8;
    --cp-text-2: #A8AEBD;
    --cp-muted: #7A8194;
    --cp-line: rgba(255, 255, 255, 0.10);
    --cp-line-strong: rgba(255, 255, 255, 0.16);

    --cp-grid: #2A2C31;
    --cp-axis: #3A3D45;

    --cp-accent: #7C8CFF;
    --cp-accent-hover: #8f9cff;
    --cp-accent-soft: rgba(124, 140, 255, 0.16);

    --cp-good-text: #0ca30c;
    --cp-critical-text: #e66767;

    --cp-s1: #3987e5;
    --cp-s2: #d95926;
    --cp-s3: #199e70;
    --cp-s4: #c98500;
    --cp-s5: #d55181;
    --cp-s6: #008300;
    --cp-s7: #9085e9;
    --cp-s8: #e66767;

    --cp-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ---- Base ---------------------------------------------------------------- */
.cp-main { background: var(--cp-plane); color: var(--cp-text); }

.cp-icon {
    font-family: 'Material Icons Outlined';
    font-size: 20px;
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

.cp-icon--sm { font-size: 16px; }
.cp-icon--lg { font-size: 28px; }

/* ---- Page header --------------------------------------------------------- */
.cp-page-head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.cp-page-title {
    margin: 0;
    color: var(--cp-text);
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -0.02em;
}

/* One filter row above everything it scopes — never per-card filters. */
.cp-filterbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---- Card ---------------------------------------------------------------- */
.cp-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r);
    background: var(--cp-surface);
    box-shadow: var(--cp-shadow);
}

.cp-card__head {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 0;
}

.cp-card__title {
    margin: 0;
    color: var(--cp-text);
    font-size: 14.5px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.cp-card__body { padding: 14px 16px 16px; }
.cp-card__body--flush { padding: 8px 0 0; }

/* ---- Grid ---------------------------------------------------------------- */
.cp-grid { display: grid; gap: 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.cp-col-2 { grid-column: span 2; }
.cp-col-3 { grid-column: span 3; }
.cp-col-4 { grid-column: span 4; }
.cp-col-5 { grid-column: span 5; }
.cp-col-6 { grid-column: span 6; }
.cp-col-7 { grid-column: span 7; }
.cp-col-8 { grid-column: span 8; }
.cp-col-12 { grid-column: span 12; }

@media (max-width: 1400px) {
    .cp-col-2 { grid-column: span 4; }
}

@media (max-width: 1100px) {
    .cp-col-3, .cp-col-4, .cp-col-5 { grid-column: span 6; }
    .cp-col-7, .cp-col-8 { grid-column: span 12; }
}

@media (max-width: 640px) {
    .cp-grid > * { grid-column: span 12; }
    .cp-col-2 { grid-column: span 6; }
}

/* ---- Stat tile ----------------------------------------------------------- */
.cp-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
}

.cp-stat__label {
    display: flex;
    gap: 6px;
    align-items: center;
    color: var(--cp-text-2);
    font-size: 12.5px;
    font-weight: 500;
}

.cp-stat__label .cp-icon { color: var(--cp-muted); font-size: 16px; }

/* Proportional figures on purpose — tabular-nums makes large numbers loose. */
.cp-stat__value {
    color: var(--cp-text);
    font-size: 25px;
    font-weight: 650;
    letter-spacing: -0.025em;
    line-height: 1.15;
}

.cp-stat__delta {
    display: flex;
    gap: 3px;
    align-items: center;
    font-size: 12px;
    font-weight: 550;
}

.cp-stat__delta--up { color: var(--cp-good-text); }
.cp-stat__delta--down { color: var(--cp-critical-text); }
.cp-stat__delta--flat { color: var(--cp-muted); }
.cp-stat__delta .cp-icon { font-size: 14px; }

/* ---- Buttons ------------------------------------------------------------- */
.cp-btn {
    display: inline-flex;
    gap: 7px;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--cp-r-sm);
    background: none;
    color: var(--cp-text);
    font: inherit;
    font-size: 13.5px;
    font-weight: 570;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.cp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cp-btn .cp-icon { font-size: 18px; }

.cp-btn--primary { background: var(--cp-accent); color: #fff; }
.cp-btn--primary:hover:not(:disabled) { background: var(--cp-accent-hover); }

.cp-btn--secondary { border-color: var(--cp-line-strong); background: var(--cp-surface); color: var(--cp-text); }
.cp-btn--secondary:hover:not(:disabled) { background: var(--cp-surface-2); }

.cp-btn--ghost { color: var(--cp-text-2); }
.cp-btn--ghost:hover:not(:disabled) { background: var(--cp-accent-soft); color: var(--cp-accent); }

.cp-btn--danger { background: var(--cp-critical); color: #fff; }

.cp-btn--icon { width: 34px; height: 34px; padding: 0; }
.cp-btn--block { width: 100%; }

/* Two-column label/value list used by detail summaries. */
.cp-summary {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 12px;
    font-size: 13px;
}

/* ---- Select / inputs ----------------------------------------------------- */
.cp-field { display: inline-flex; flex-direction: column; gap: 4px; }

.cp-field__label {
    color: var(--cp-text-2);
    font-size: 11.5px;
    font-weight: 550;
}

.cp-field__hint {
    color: var(--cp-text-2);
    font-size: 11px;
    line-height: 1.35;
}

.cp-input,
.cp-select {
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--cp-line-strong);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    color: var(--cp-text);
    font: inherit;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.cp-input:focus,
.cp-select:focus {
    border-color: var(--cp-accent);
    box-shadow: 0 0 0 3px var(--cp-accent-soft);
}

.cp-select { cursor: pointer; }

.cp-input:disabled,
.cp-select:disabled {
    background: var(--cp-surface-2);
    color: var(--cp-text-2);
    cursor: not-allowed;
}

.cp-field--full { display: flex; width: 100%; }
.cp-field--full .cp-input, .cp-field--full .cp-select { width: 100%; }

/* Row-layout helpers for fields sitting inside a .cp-filterbar. */
.cp-field--grow { display: flex; flex: 1 1 220px; min-width: 180px; }
.cp-field--sm { display: flex; width: 140px; }
.cp-field--grow .cp-input, .cp-field--sm .cp-input { width: 100%; }

textarea.cp-input { resize: vertical; font-family: inherit; }

/* Two-column form body; collapses to one on narrow dialogs. */
.cp-form { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.cp-form__full { grid-column: 1 / -1; }

@media (max-width: 560px) {
    .cp-form { grid-template-columns: 1fr; }
}

.cp-check {
    display: inline-flex;
    gap: 7px;
    align-items: center;
    color: var(--cp-text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.cp-check input { width: 15px; height: 15px; accent-color: var(--cp-accent); cursor: pointer; }

.cp-search {
    display: flex;
    gap: 7px;
    align-items: center;
    min-width: 220px;
    padding: 7px 10px;
    border: 1px solid var(--cp-line-strong);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    color: var(--cp-muted);
}

.cp-search:focus-within { border-color: var(--cp-accent); box-shadow: 0 0 0 3px var(--cp-accent-soft); }

.cp-search input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: none;
    color: var(--cp-text);
    font: inherit;
    font-size: 13.5px;
    outline: none;
}

/* ---- Autocomplete -------------------------------------------------------- */
.cp-ac { position: relative; }
.cp-ac__wrap { position: relative; }
.cp-ac__wrap .cp-input { width: 100%; }

.cp-ac__list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 40;
    max-height: 240px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--cp-line-strong);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16);
}

.cp-ac__item {
    display: block;
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--cp-text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.cp-ac__item:hover, .cp-ac__item.is-active { background: var(--cp-accent-soft); color: var(--cp-accent); }

/* ---- Row actions --------------------------------------------------------- */
.cp-row-actions { display: flex; gap: 2px; justify-content: flex-end; }

.cp-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: none;
    color: var(--cp-muted);
    cursor: pointer;
}

.cp-iconbtn:hover:not(:disabled) { background: var(--cp-accent-soft); color: var(--cp-accent); }
.cp-iconbtn:disabled { opacity: 0.35; cursor: not-allowed; }
.cp-iconbtn--danger:hover:not(:disabled) { background: rgba(208, 59, 59, 0.10); color: var(--cp-critical); }
.cp-iconbtn .cp-icon { font-size: 17px; }

/* ---- Menu ---------------------------------------------------------------- */
.cp-menu { position: relative; display: inline-flex; }

.cp-menu__scrim { position: fixed; inset: 0; z-index: 60; }

.cp-menu__list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 61;
    min-width: 190px;
    padding: 4px;
    border: 1px solid var(--cp-line-strong);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16);
}

.cp-menu__list--right { left: auto; right: 0; }

/* Rail menus sit at the bottom-left of the viewport, so they open upward and
   out to the right rather than downward off the screen. */
.cp-menu__list--rail {
    top: auto;
    bottom: 0;
    left: calc(100% + 8px);
    right: auto;
}

.cp-menu__sep {
    height: 1px;
    margin: 4px 0;
    background: var(--cp-line);
}

.cp-menu__item {
    display: flex;
    gap: 9px;
    align-items: center;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--cp-text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.cp-menu__item:hover { background: var(--cp-accent-soft); color: var(--cp-accent); }
.cp-menu__item:disabled { opacity: 0.45; cursor: not-allowed; }
.cp-menu__item .cp-icon { color: var(--cp-muted); }
.cp-menu__item:hover .cp-icon { color: var(--cp-accent); }

/* ---- Pager --------------------------------------------------------------- */
.cp-pager {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 10px 14px;
    border-top: 1px solid var(--cp-line);
    color: var(--cp-text-2);
    font-size: 12.5px;
}

.cp-pager__controls { display: flex; gap: 6px; align-items: center; }
.cp-pager__controls .cp-select { padding: 4px 8px; font-size: 12px; }
.cp-pager__page { font-variant-numeric: tabular-nums; min-width: 54px; text-align: center; }

/* ---- Thumbnail ----------------------------------------------------------- */
.cp-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    overflow: hidden;
    border-radius: 7px;
    background: var(--cp-surface-2);
    color: var(--cp-muted);
}

.cp-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---- Loading bar --------------------------------------------------------- */
.cp-loading {
    height: 2px;
    overflow: hidden;
    border-radius: 2px;
    background: var(--cp-accent-soft);
}

.cp-loading__bar {
    width: 35%;
    height: 100%;
    border-radius: 2px;
    background: var(--cp-accent);
    animation: cp-indeterminate 1.1s ease-in-out infinite;
}

@keyframes cp-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(340%); }
}

@media (prefers-reduced-motion: reduce) {
    .cp-loading__bar { animation: none; width: 100%; opacity: 0.5; }
}

/* ---- Chip ---------------------------------------------------------------- */
.cp-chip {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    padding: 2px 9px;
    border-radius: var(--cp-pill);
    background: var(--cp-surface-2);
    color: var(--cp-text-2);
    font-size: 11.5px;
    font-weight: 570;
    white-space: nowrap;
}

.cp-chip__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.cp-chip__close {
    margin: 0 -3px 0 1px;
    padding: 0 2px;
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
    font-size: 10px;
    line-height: 1;
    opacity: 0.65;
}

.cp-chip__close:hover { opacity: 1; }

/* ---- Switch -------------------------------------------------------------- */
.cp-switch { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; user-select: none; }
.cp-switch.is-disabled { opacity: 0.5; cursor: not-allowed; }
.cp-switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.cp-switch__track {
    position: relative;
    flex: 0 0 auto;
    width: 34px;
    height: 20px;
    border-radius: var(--cp-pill);
    background: var(--cp-line-strong);
    transition: background-color 0.16s ease;
}

.cp-switch__thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.3);
    transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cp-switch input:checked + .cp-switch__track { background: var(--cp-accent); }
.cp-switch input:checked + .cp-switch__track .cp-switch__thumb { transform: translateX(14px); }
.cp-switch__label { color: var(--cp-text); font-size: 13px; }

/* ---- File upload --------------------------------------------------------- */
.cp-upload { position: relative; display: inline-flex; }
.cp-upload input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.cp-imagebox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 160px;
    height: 160px;
    overflow: hidden;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r);
    background: var(--cp-surface-2);
    color: var(--cp-muted);
}

.cp-imagebox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cp-chip--good { background: rgba(12, 163, 12, 0.12); color: var(--cp-good-text); }
.cp-chip--warning { background: rgba(250, 178, 25, 0.16); color: #8a6100; }
.cp-chip--critical { background: rgba(208, 59, 59, 0.12); color: var(--cp-critical-text); }

:root[data-theme="dark"] .cp-chip--warning { background: rgba(250, 178, 25, 0.18); color: #fab219; }

/* ---- Alert --------------------------------------------------------------- */
.cp-alert {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 14px;
    border: 1px solid var(--cp-line);
    border-left: 3px solid var(--cp-warning);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    color: var(--cp-text);
    font-size: 13px;
}

.cp-alert .cp-icon { color: var(--cp-warning); }
.cp-alert a { color: var(--cp-accent); font-weight: 570; }

/* ---- Chart of accounts --------------------------------------------------- */
.cp-coa__head { font-weight: 620; }
.cp-coa__child { padding-left: 18px; }

.cp-coa__desc {
    font-size: 11.5px;
    color: var(--cp-text-2);
    margin-top: 2px;
}

.cp-coa__desc--child { padding-left: 18px; }

.cp-coa__badge {
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--cp-surface-2);
    color: var(--cp-muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: 1px;
}

/* ---- Variant attribute editor ------------------------------------------- */
.cp-attr {
    padding: 10px 0;
    border-bottom: 1px solid var(--cp-line);
}

.cp-attr:last-of-type { border-bottom: 0; }

.cp-attr__head {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.cp-attr__kind { min-width: 180px; }

.cp-attr__hint {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--cp-text-2);
}

.cp-attr__choices {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.cp-attr__add {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
}

.cp-attr__newvalue { max-width: 240px; }

/* A suggested value: click to include it in the variant grid. */
.cp-choice {
    padding: 4px 10px;
    border: 1px solid var(--cp-line-strong);
    border-radius: 999px;
    background: var(--cp-surface);
    color: var(--cp-text-2);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.cp-choice:hover { border-color: var(--cp-accent); color: var(--cp-accent); }

.cp-choice--on {
    border-color: var(--cp-accent);
    background: var(--cp-accent);
    color: #FFFFFF;
}

/* Unit symbol trailing a quantity — present but subordinate to the number. */
.cp-unit {
    margin-left: 3px;
    color: var(--cp-muted);
    font-size: 11px;
}

/* Full-viewport centring for standalone messages (404, not-authorised). */
.cp-centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--cp-plane);
}

.cp-centered > * { width: 100%; max-width: 420px; }

/* Two columns of supporting detail that collapse to one on narrow screens. */
.cp-download-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--cp-line);
}

.cp-subhead {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 620;
}

.cp-list {
    margin: 0;
    padding-left: 18px;
    font-size: 12.5px;
    color: var(--cp-text-2);
    line-height: 1.7;
}

/* A labelled URL / secret the user needs to copy out of the page. */
.cp-endpoint {
    padding: 8px 0;
    border-bottom: 1px solid var(--cp-line);
}

.cp-endpoint:last-child { border-bottom: 0; }

.cp-endpoint__name {
    font-size: 12px;
    font-weight: 600;
    color: var(--cp-text-2);
    margin-bottom: 3px;
}

.cp-endpoint__url {
    display: block;
    font-size: 12.5px;
    word-break: break-all;
}

/* Stack of toggles inside a card — one per row, comfortable tap target. */
.cp-switch-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Native file picker, styled to sit with the rest of the form controls. */
.cp-fileinput {
    display: block;
    width: 100%;
    padding: 10px;
    border: 1px dashed var(--cp-line);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface-2, var(--cp-surface));
    color: var(--cp-text-2);
    font-size: 13px;
}

.cp-fileinput::file-selector-button {
    margin-right: 12px;
    padding: 7px 12px;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    color: var(--cp-text);
    font: inherit;
    cursor: pointer;
}

.cp-fileinput::file-selector-button:hover { border-color: var(--cp-accent); }

/* ---- Table --------------------------------------------------------------- */
.cp-table-wrap { overflow-x: auto; }

.cp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.cp-table th {
    padding: 9px 12px;
    border-bottom: 1px solid var(--cp-line);
    color: var(--cp-text-2);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.cp-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--cp-line);
    color: var(--cp-text);
}

/* Scroll body, pin header — for long tables inside a dialog. Pair with an
   explicit max-height on .cp-table-wrap. */
.cp-table--sticky thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--cp-surface);
}

.cp-table tbody tr:last-child td { border-bottom: 0; }
.cp-table tbody tr:hover { background: var(--cp-surface-2); }

/* Columns of numbers align vertically — tabular figures belong here. */
.cp-num { font-variant-numeric: tabular-nums; text-align: right; }

/* A total that has been partly or wholly refunded: the gross is struck through
   above the net, so the row shows both what was rung up and what was kept. */
.cp-amount-void {
    display: block;
    text-decoration: line-through;
    color: var(--cp-text-3);
    font-size: 11.5px;
}

.cp-amount-net { display: block; }

/* Inline proportion bar for a 0–100% figure inside a table cell. Always pair
   it with the number — the bar shows shape, the number carries the value. */
.cp-meter {
    height: 4px;
    border-radius: 2px;
    background: var(--cp-line);
    overflow: hidden;
}

.cp-meter__fill { height: 100%; border-radius: 2px; background: var(--cp-accent); }

.cp-table a { color: var(--cp-accent); font-weight: 550; text-decoration: none; }
.cp-table a:hover { text-decoration: underline; }

/* ---- Tabs ---------------------------------------------------------------- */
.cp-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--cp-line); padding: 0 4px; }

.cp-tab {
    padding: 9px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--cp-text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 570;
    cursor: pointer;
}

.cp-tab:hover { color: var(--cp-text); }
.cp-tab--active { border-bottom-color: var(--cp-accent); color: var(--cp-accent); }

/* ---- Empty state --------------------------------------------------------- */
.cp-empty {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
    padding: 28px 16px;
    color: var(--cp-muted);
    text-align: center;
}

.cp-empty .cp-icon { font-size: 30px; opacity: 0.7; }
.cp-empty__text { font-size: 13px; }

/* ============================================================================
   CHARTS — HTML/CSS marks (no canvas, no SVG scaling artefacts)
   Specs: bars ≤24px thick, 4px rounded data-end square at the baseline, 2px
   surface gaps between touching marks, hairline solid gridlines, recessive
   axes, selective direct labels, hover tooltip, and a table-view twin.
   ============================================================================ */

.cp-chart { position: relative; }

.cp-chart__toolbar { display: flex; justify-content: flex-end; margin-bottom: 2px; }

.cp-chart__toggle {
    padding: 3px 8px;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-pill);
    background: none;
    color: var(--cp-muted);
    font: inherit;
    font-size: 11px;
    font-weight: 550;
    cursor: pointer;
}

.cp-chart__toggle:hover { color: var(--cp-accent); border-color: var(--cp-accent); }

/* -- Column chart ---------------------------------------------------------- */
.cp-col-chart { display: flex; gap: 8px; }

.cp-col-chart__yaxis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 0 0 auto;
    padding-bottom: 22px; /* the x-axis band — never let it clip the labels */
    color: var(--cp-muted);
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.cp-col-chart__plotwrap { position: relative; flex: 1 1 auto; min-width: 0; }

.cp-col-chart__grid {
    position: absolute;
    inset: 0 0 22px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.cp-col-chart__gridline { height: 1px; background: var(--cp-grid); }
.cp-col-chart__gridline:last-child { background: var(--cp-axis); }

.cp-col-chart__bands {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px; /* the surface gap between adjacent bars */
    height: 100%;
}

.cp-col-chart__band {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    padding-bottom: 22px;
    cursor: default;
}

.cp-col-chart__bar {
    width: 100%;
    max-width: 24px;
    min-height: 2px;
    border-radius: 4px 4px 0 0; /* rounded data-end, square at the baseline */
    background: var(--cp-s1);
    transition: opacity 0.12s ease;
}

.cp-col-chart__bar--zero { min-height: 0; }
.cp-col-chart__band:hover .cp-col-chart__bar { opacity: 0.78; }

.cp-col-chart__tick {
    position: absolute;
    bottom: 0;
    width: 100%;
    overflow: hidden;
    color: var(--cp-muted);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* -- Diverging columns (CpTrendChart) -------------------------------------- */
.cp-trend__zerowrap {
    position: absolute;
    inset: 0 0 22px 0;
    pointer-events: none;
}

.cp-trend__zero {
    position: absolute;
    right: 0;
    left: 0;
    height: 1px;
    background: var(--cp-axis);
}

.cp-trend__bands {
    position: relative;
    display: flex;
    gap: 2px; /* the surface gap between adjacent bars */
    height: 100%;
}

.cp-trend__band { position: relative; flex: 1 1 0; min-width: 0; height: 100%; cursor: default; }

/* The plot area stops short of the x-axis band so bars never overlap labels. */
.cp-trend__plot { position: absolute; inset: 0 0 22px 0; }

.cp-trend__bar {
    position: absolute;
    left: 50%;
    width: 100%;
    max-width: 24px;
    transform: translateX(-50%);
    transition: opacity 0.12s ease;
}

/* Rounded at the data end, square where the bar meets zero. */
.cp-trend__bar--pos { border-radius: 4px 4px 0 0; }
.cp-trend__bar--neg { border-radius: 0 0 4px 4px; }
.cp-trend__band:hover .cp-trend__bar { opacity: 0.78; }

/* -- Horizontal ranked bars ------------------------------------------------ */
.cp-bars { display: flex; flex-direction: column; gap: 10px; }
.cp-bars__row { display: grid; grid-template-columns: minmax(70px, 26%) 1fr auto; gap: 10px; align-items: center; }

.cp-bars__label {
    overflow: hidden;
    color: var(--cp-text-2);
    font-size: 12.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cp-bars__track { height: 100%; min-height: 14px; display: flex; align-items: center; }

.cp-bars__fill {
    height: 14px;
    min-width: 2px;
    border-radius: 0 4px 4px 0;
    background: var(--cp-s1);
}

.cp-bars__fill--zero { min-width: 0; }

.cp-bars__value {
    color: var(--cp-text);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    font-weight: 550;
}

/* -- Stacked part-to-whole bar --------------------------------------------- */
.cp-stack { display: flex; flex-direction: column; gap: 12px; }

.cp-stack__bar {
    display: flex;
    gap: 2px; /* surface gap between segments */
    height: 26px;
    overflow: hidden;
    border-radius: 6px;
}

.cp-stack__seg {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 3px;
    height: 100%;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
}

.cp-stack__seg:first-child { border-radius: 6px 0 0 6px; }
.cp-stack__seg:last-child { border-radius: 0 6px 6px 0; }

.cp-legend { display: flex; flex-wrap: wrap; gap: 12px; }
.cp-legend__item { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--cp-text-2); }
.cp-legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.cp-legend__value { color: var(--cp-text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* -- Tooltip --------------------------------------------------------------- */
.cp-tip {
    position: absolute;
    z-index: 5;
    padding: 6px 9px;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    box-shadow: 0 6px 20px rgba(16, 24, 40, 0.14);
    color: var(--cp-text);
    font-size: 12px;
    pointer-events: none;
    transform: translate(-50%, -100%);
    white-space: nowrap;
}

.cp-tip__label { color: var(--cp-text-2); font-size: 11px; }
.cp-tip__value { font-weight: 620; font-variant-numeric: tabular-nums; }

/* ---- Dialog -------------------------------------------------------------- */
.cp-dialog-scrim {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 16px 24px;
    overflow-y: auto;
    background: rgba(12, 16, 24, 0.45);
    backdrop-filter: blur(2px);
}

.cp-dialog {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r-lg);
    background: var(--cp-surface);
    box-shadow: 0 24px 64px rgba(12, 16, 24, 0.28);
}

.cp-dialog--xs { max-width: 400px; }
.cp-dialog--sm { max-width: 540px; }
.cp-dialog--md { max-width: 760px; }
.cp-dialog--lg { max-width: 1040px; }

.cp-dialog__head {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    border-bottom: 1px solid var(--cp-line);
}

.cp-dialog__title {
    margin: 0;
    color: var(--cp-text);
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.cp-dialog__close {
    border: 0;
    background: none;
    color: var(--cp-muted);
    cursor: pointer;
    font: inherit;
    line-height: 1;
}

.cp-dialog__close:hover { color: var(--cp-text); }

.cp-dialog__body { padding: 16px 18px; }

.cp-dialog__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 18px 16px;
    border-top: 1px solid var(--cp-line);
}

/* ---- Toasts -------------------------------------------------------------- */
.cp-toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(380px, calc(100vw - 36px));
}

.cp-toast {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 11px 13px;
    border: 1px solid var(--cp-line);
    border-left: 3px solid var(--cp-accent);
    border-radius: var(--cp-r-sm);
    background: var(--cp-surface);
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
    color: var(--cp-text);
    font-size: 13px;
}

.cp-toast--success { border-left-color: var(--cp-good); }
.cp-toast--warning { border-left-color: var(--cp-warning); }
.cp-toast--error { border-left-color: var(--cp-critical); }
.cp-toast--success .cp-icon { color: var(--cp-good); }
.cp-toast--warning .cp-icon { color: var(--cp-warning); }
.cp-toast--error .cp-icon { color: var(--cp-critical); }

.cp-toast__close {
    margin-left: auto;
    border: 0;
    background: none;
    color: var(--cp-muted);
    cursor: pointer;
    font: inherit;
    line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
    .cp-btn, .cp-col-chart__bar, .cp-trend__bar, .cp-input, .cp-select { transition: none; }
}

/* ── Global search overlay ───────────────────────────────────────────────────
   Shaped after Zoho POS's: a scope picker welded to the left of the input, and
   a visible esc affordance so the way out is never guessed at. Sits above the
   dialog layer so search can be opened from inside a dialog. */

.cp-gsearch__scrim {
    position: fixed;
    inset: 0;
    z-index: 1600;
    background: rgba(12, 16, 24, 0.5);
    backdrop-filter: blur(2px);
}

.cp-gsearch {
    position: fixed;
    z-index: 1601;
    top: 6vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(760px, calc(100vw - 32px));
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--cp-surface);
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r-lg);
    box-shadow: var(--cp-shadow);
    overflow: hidden;
}

.cp-gsearch__bar {
    display: flex;
    align-items: stretch;
    gap: 0;
    border-bottom: 1px solid var(--cp-line);
    background: var(--cp-surface);
}

/* ── Scope picker ── */

.cp-gsearch__scope { position: relative; flex: 0 0 auto; }

.cp-gsearch__scope-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 100%;
    min-height: 52px;
    padding: 0 12px 0 14px;
    border: 0;
    border-right: 1px solid var(--cp-line);
    background: transparent;
    color: var(--cp-text);
    font: inherit;
    font-size: 13px;
    white-space: nowrap;
    cursor: pointer;
}

.cp-gsearch__scope-btn:hover { background: var(--cp-surface-2); }

.cp-gsearch__scope-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 8px;
    z-index: 2;
    min-width: 240px;
    max-height: min(60vh, 420px);
    overflow-y: auto;
    padding: 4px;
    background: var(--cp-surface);
    border: 1px solid var(--cp-line);
    border-radius: var(--cp-r);
    box-shadow: var(--cp-shadow);
}

.cp-gsearch__scope-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--cp-r-sm);
    background: transparent;
    color: var(--cp-text);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}

.cp-gsearch__scope-item:hover { background: var(--cp-surface-2); }
.cp-gsearch__scope-item.active { color: var(--cp-accent); font-weight: 500; }

/* ── Input ── */

.cp-gsearch__input {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 52px;
    padding: 0 12px;
    border: 0;
    background: transparent;
    color: var(--cp-text);
    font: inherit;
    font-size: 15px;
    outline: none;
}

.cp-gsearch__input::placeholder { color: var(--cp-muted); }
.cp-gsearch__input::-webkit-search-cancel-button { display: none; }

.cp-gsearch__spinner {
    align-self: center;
    width: 14px;
    height: 14px;
    margin-right: 4px;
    border: 2px solid var(--cp-line-strong);
    border-top-color: var(--cp-accent);
    border-radius: 50%;
    animation: cp-gsearch-spin 0.7s linear infinite;
}

@keyframes cp-gsearch-spin { to { transform: rotate(360deg); } }

.cp-gsearch__esc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    flex: 0 0 auto;
    width: 54px;
    border: 0;
    border-left: 1px solid var(--cp-line);
    background: transparent;
    color: var(--cp-text-2);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.cp-gsearch__esc:hover { background: var(--cp-surface-2); color: var(--cp-text); }
.cp-gsearch__esc-key { font-size: 10px; color: var(--cp-muted); }

/* ── Results ── */

.cp-gsearch__body { overflow-y: auto; padding: 6px; }

.cp-gsearch__group + .cp-gsearch__group { margin-top: 4px; }

.cp-gsearch__group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--cp-text-2);
}

.cp-gsearch__more {
    margin-left: auto;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    color: var(--cp-muted);
}

.cp-gsearch__hit {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: var(--cp-r-sm);
    background: transparent;
    color: var(--cp-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

/* Keyboard cursor and hover share one state, so arrowing and pointing look
   the same and the two never disagree about what Enter would open. */
.cp-gsearch__hit.active { background: var(--cp-accent-soft); }

.cp-gsearch__hit-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 auto; }
.cp-gsearch__hit-title { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-gsearch__hit-sub { font-size: 11.5px; color: var(--cp-text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cp-gsearch__hit-meta {
    flex: 0 0 auto;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--cp-text-2);
}

/* ── Empty / hint states ── */

.cp-gsearch__hint { padding: 28px 16px 32px; text-align: center; color: var(--cp-text-2); font-size: 13px; }
.cp-gsearch__hint p { margin: 0 0 12px; }
.cp-gsearch__hint ul { display: flex; gap: 16px; justify-content: center; margin: 0; padding: 0; list-style: none; font-size: 12px; }
.cp-gsearch__hint li { display: flex; align-items: center; gap: 4px; color: var(--cp-muted); }

.cp-gsearch__hint kbd {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    border: 1px solid var(--cp-line-strong);
    border-radius: 4px;
    background: var(--cp-surface-2);
    font-family: inherit;
    font-size: 11px;
    color: var(--cp-text-2);
}

.cp-gsearch__widen {
    padding: 6px 12px;
    border: 1px solid var(--cp-line-strong);
    border-radius: var(--cp-r-sm);
    background: transparent;
    color: var(--cp-accent);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
}

@media (max-width: 640px) {
    .cp-gsearch { top: 0; width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; border: 0; }
    .cp-gsearch__scope-btn span:not(.cp-gsearch__esc-key) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .cp-gsearch__spinner { animation-duration: 2s; }
}
