/* Shared admin visual tokens. Existing widgets retain their data and actions. */
:root {
    --keria-surface: #fff;
    --keria-soft: #f8fafc;
    --keria-border: #dbe4ef;
    --keria-ink: #172033;
    --keria-muted: #52637a;
    --keria-blue: #2563eb;
    --keria-focus: #2563eb;
    --keria-radius: .75rem;
    --keria-kpi-label: .8125rem;
    --keria-kpi-value: 1.625rem;
    --keria-kpi-detail: .75rem;
}
.dark {
    --keria-surface: #181b22;
    --keria-soft: #202530;
    --keria-border: #343d4d;
    --keria-ink: #f4f7fb;
    --keria-muted: #b5c0d1;
    --keria-focus: #93baff;
}
.fi-main :is(.atenea-customer-card,.fi-wi-stats-overview-stat,.atenea-order-kpi,.atenea-dispatch-stat,.atenea-task-kpi,.atenea-subs .sub-kpi) {
    box-sizing: border-box;
    background: var(--keria-surface) !important;
    color: var(--keria-ink);
    border: 1px solid var(--keria-border) !important;
    border-radius: var(--keria-radius);
    box-shadow: none !important;
    padding: 1rem;
    min-height: 7rem;
    font-family: inherit;
}
.fi-main :is(.atenea-customer-card h3,.fi-wi-stats-overview-stat-label,.atenea-order-kpi-label,.atenea-dispatch-stat > span,.atenea-task-kpi h3,.sub-kpi-label) {
    color: var(--keria-muted) !important;
    font-size: var(--keria-kpi-label) !important;
    font-weight: 650;
    line-height: 1.35;
    text-transform: none;
    letter-spacing: normal;
}
.fi-main :is(.atenea-customer-card > strong,.fi-wi-stats-overview-stat-value,.atenea-order-kpi-content > strong,.atenea-dispatch-stat > strong,.atenea-task-kpi strong,.sub-kpi-value) {
    color: var(--keria-ink) !important;
    font-size: var(--keria-kpi-value) !important;
    font-weight: 750;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}
.fi-main :is(.atenea-customer-card p,.fi-wi-stats-overview-stat-description,.atenea-order-kpi small,.atenea-dispatch-stat small,.atenea-task-kpi p,.sub-kpi-hint) {
    color: var(--keria-muted) !important;
    font-size: var(--keria-kpi-detail) !important;
    line-height: 1.4;
}
.fi-main :is(button.atenea-dispatch-stat,button.atenea-order-kpi):hover {
    border-color: var(--keria-focus) !important;
}
.fi-main :is(button.atenea-dispatch-stat,button.atenea-order-kpi,.sub-action):focus-visible {
    outline: 2px solid var(--keria-focus);
    outline-offset: 2px;
}
.fi-main .atenea-subs .sub-kpis {
    gap: .75rem;
    background: transparent;
    border: 0;
    border-radius: 0;
    overflow: visible;
}
.fi-main :is(.atenea-dispatch-operational-header,.atenea-dispatch-workflow-card,.atenea-subs .sub-card,.atenea-subs .sub-detail) {
    background: var(--keria-surface) !important;
    border-color: var(--keria-border) !important;
    color: var(--keria-ink) !important;
}
.fi-main :is(.atenea-dispatch-block-heading h2,.atenea-dispatch-workflow-card strong,.sub-card-head h2,.sub-detail-name) {
    color: var(--keria-ink) !important;
}
.fi-main :is(.atenea-dispatch-block-heading p,.atenea-dispatch-workflow-card small,.sub-kicker,.sub-muted) {
    color: var(--keria-muted) !important;
}
.fi-main .atenea-subs {
    --ink: var(--keria-ink);
    --muted: var(--keria-muted);
    --line: var(--keria-border);
    --soft: var(--keria-soft);
}
.fi-main .atenea-subs :is(.sub-table th,.sub-filters) {
    background: var(--keria-soft);
    color: var(--keria-muted);
}
.fi-main .atenea-subs :is(.sub-table td,.sub-card-head) {
    color: var(--keria-ink);
    border-color: var(--keria-border);
}
.fi-main .atenea-subs .sub-table tbody tr:hover {
    background: var(--keria-soft);
}
.fi-main :is(.fi-header-actions .fi-btn,.atenea-subs .sub-action) {
    font-family: inherit;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.25;
    min-height: 2.25rem;
    border-radius: .55rem;
}
.fi-main .atenea-subs .sub-action {
    background: var(--keria-surface);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}
.fi-main .atenea-subs .sub-action.primary {
    background: var(--keria-blue);
    border-color: var(--keria-blue);
    color: #fff;
}

.keria-product-overview header {
    margin-bottom: 1rem;
}
.keria-product-overview h2 {
    font-weight: 600;
}
.keria-product-overview p {
    margin-top: .25rem;
    color: var(--keria-muted);
    font-size: .875rem;
}
.keria-product-kpis {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}
.fi-main :is(.keria-product-kpis, .atenea-customers-ribbon, .atenea-tasks-ribbon, .atenea-dispatch-stats) {
    gap: .75rem;
}
.fi-main .keria-kpi {
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr);
    align-content: start;
    align-items: start;
    gap: .65rem;
    min-width: 0;
    min-height: 7rem;
    padding: 1rem;
    text-align: left;
    color: var(--keria-ink);
    background: var(--keria-surface);
    border: 1px solid var(--keria-border);
    border-radius: var(--keria-radius);
}
.keria-kpi-icon {
    display: grid;
    width: 2.25rem;
    height: 2.25rem;
    place-items: center;
    border-radius: .65rem;
    background: #e6f0ff;
    color: #2563eb;
}
.keria-kpi-icon svg {
    width: 1.125rem;
    height: 1.125rem;
}
.keria-kpi-alert .keria-kpi-icon {
    background: #feecef;
    color: #b91c1c;
}
.keria-kpi-body {
    display: grid;
    gap: .15rem;
    overflow-wrap: anywhere;
}
.keria-kpi-label {
    color: var(--keria-muted);
    font-size: var(--keria-kpi-label);
    font-weight: 650;
    line-height: 1.35;
}
.keria-kpi-body strong {
    font-size: var(--keria-kpi-value);
    font-weight: 750;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.keria-kpi-body small {
    color: var(--keria-muted);
    font-size: var(--keria-kpi-detail);
    line-height: 1.4;
}
.keria-kpi > :is(.active-breakdown, .other-breakdown) {
    grid-column: 1 / -1;
    container-type: inline-size;
}
.keria-kpi .atenea-customer-breakdown dt {
    overflow-wrap: anywhere;
}
.fi-main button.keria-kpi {
    width: 100%;
    cursor: pointer;
}
.fi-main button.keria-kpi:hover {
    border-color: var(--keria-focus);
}
.fi-main button.keria-kpi:focus-visible {
    outline: 2px solid var(--keria-focus);
    outline-offset: 2px;
}
@container (max-width: 250px) {
    .keria-kpi .other-breakdown .atenea-customer-breakdown {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 1100px) {
    .keria-product-kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
@media (max-width: 700px) {
    .keria-product-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 540px) {
    .keria-product-kpis {
        grid-template-columns: 1fr;
    }
}

.keria-address-primary .fi-section-header {
    background-color: #1e40af;
}
.keria-address-secondary .fi-section-header {
    background-color: #6b21a8;
}
:is(.keria-address-primary, .keria-address-secondary) .fi-section-header {
    border-start-start-radius: inherit;
    border-start-end-radius: inherit;
}
:is(.keria-address-primary, .keria-address-secondary) .fi-section-header-heading {
    color: #fff;
}

.fi-main :is(.keria-address-primary, .keria-address-secondary) > .fi-section {
    box-shadow: 0 2px 5px rgb(15 23 42 / .12), 0 9px 20px -4px rgb(15 23 42 / .22) !important;
}
.dark .fi-main :is(.keria-address-primary, .keria-address-secondary) > .fi-section {
    box-shadow: 0 2px 5px rgb(0 0 0 / .28), 0 9px 20px -4px rgb(0 0 0 / .55) !important;
}

/* Dark-mode contrast for custom headings and forms. */
.dark .home-title h2,
.dark .access-hero h2,
.dark .access-toolbar h3,
.dark .profile-home-welcome h2 {
    color: var(--keria-ink) !important;
}
.dark .home-title p,
.dark .access-hero p,
.dark .access-toolbar p,
.dark .profile-home-welcome p {
    color: var(--keria-muted) !important;
}
.dark .profile-home-welcome {
    background: var(--keria-soft);
    border-color: var(--keria-border);
}

.dark :is(.fi-main, .fi-modal) :is(.fi-fo-field-label, .fi-fo-field-wrp-label) {
    color: var(--keria-ink);
}
.dark :is(.fi-main, .fi-modal) :is(.fi-fo-field-helper-text, .fi-fo-field-wrp-helper-text, .fi-fo-field-hint-label) {
    color: var(--keria-muted);
}

/* Profile editor has custom surfaces and labels inside Filament's modal. */
.dark .permission-tree-group {
    background: var(--keria-surface) !important;
    border-color: var(--keria-border) !important;
}
.dark .permission-tree-group .fi-section-header {
    background: var(--keria-soft);
}
.dark .permission-tree-group .fi-section-header-heading,
.dark .permission-tree-row:has(input:checked) .permission-menu-label {
    color: var(--keria-ink) !important;
}
.dark .permission-menu-label,
.dark .permission-tree-header .fi-fo-placeholder {
    color: var(--keria-muted) !important;
}
.dark .permission-tree-row {
    border-color: var(--keria-border);
}
.dark .permission-tree-row input.fi-checkbox-input:not(:checked) {
    background-color: var(--keria-soft) !important;
    outline-color: var(--keria-muted) !important;
}

/* Subscription editing, including its product picker. */
.dark .atenea-subs :is(.sub-editor-title, .sub-editor label, .sub-editor-products-head b) {
    color: var(--keria-ink) !important;
}
.dark .atenea-subs .sub-editor-copy {
    color: var(--keria-muted);
}
.dark .atenea-subs .sub-editor-products {
    background: var(--keria-soft);
    border-color: var(--keria-border);
}
.dark .atenea-subs .sub-editor :is(input, select, textarea) {
    background: var(--keria-surface);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}

/* Settlement entry is a hand-built form rather than a Filament schema. */
.dark .settlement-create {
    color: var(--keria-ink);
}
.dark .settlement-create :is(.settlement-card, .settlement-selection-summary > div, .settlement-amount, .settlement-full-amount) {
    background: var(--keria-surface);
    border-color: var(--keria-border);
}
.dark .settlement-create :is(.settlement-head h2, .settlement-head strong, .settlement-selection-summary strong, .settlement-fields label, .settlement-footer label) {
    color: var(--keria-ink);
}
.dark .settlement-create :is(.settlement-head p, .settlement-selection-summary span, .settlement-quick-filter > span, .settlement-full-switch) {
    color: var(--keria-muted);
}
.dark .settlement-create :is(.settlement-fields input, .settlement-fields select, .settlement-footer textarea, .settlement-amount input) {
    background: var(--keria-soft);
    color: var(--keria-ink);
    border-color: var(--keria-border);
}
.dark .settlement-create :is(.settlement-orders-table th, .settlement-orders-table tbody tr:hover) {
    background: var(--keria-soft);
    color: var(--keria-ink);
}
.dark .settlement-create :is(.settlement-amount input:disabled, .settlement-quick-filter button:disabled) {
    background: var(--keria-soft);
    color: var(--keria-muted);
    border-color: var(--keria-border);
}

/* Custom search and filter controls used across the application. */
.dark :is(.financial-filters, .collections .cc-filters, .wa-test__card) {
    background: var(--keria-surface);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}
.dark :is(.financial-filter-group-title, .financial-filters label, .financial-filter-clear, .wa-test__field label) {
    color: var(--keria-muted);
}
.dark :is(.financial-filters input, .financial-filters select, .collections .cc-filters input, .collections .cc-filters select, .wa-test__input, .channel-settlements-toolbar select, .atenea-order-view-selector select, .atenea-wc-queue-row select) {
    background: var(--keria-soft);
    color: var(--keria-ink);
    border-color: var(--keria-border);
}
.dark :is(.financial-filter-presets button, .financial-filter-clear) {
    color: var(--keria-ink);
    border-color: var(--keria-border);
    background: var(--keria-soft);
}
.dark :is(.sub-editor, .settlement-create, .financial-filters, .cc-filters, .wa-test__card) :is(input, textarea)::placeholder {
    color: var(--keria-muted);
    opacity: 1;
}

/* Route, dispatch-origin and mobile-user custom dialogs. */
.dark :is(.atenea-dispatch-origin-modal, .atenea-route-assignment-modal, .atenea-route-duplicate-modal) {
    background: var(--keria-surface);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}
.dark :is(.atenea-dispatch-origin-fields label, .atenea-dispatch-origin-modal h2, .atenea-dispatch-origin-modal h3, .atenea-dispatch-origin-modal .atenea-geolocation-details strong, .atenea-route-assignment-label, .atenea-route-duplicate-form label, .atenea-mobile-user-checks label) {
    color: var(--keria-ink);
}
.dark :is(.atenea-dispatch-origin-modal .atenea-geolocation-details span, .atenea-route-assignment-options small, .atenea-mobile-publication-users .atenea-mobile-user-checks p) {
    color: var(--keria-muted);
}
.dark :is(.atenea-dispatch-origin-fields input[type=text], .atenea-dispatch-origin-fields input[type=number], .atenea-route-duplicate-form input, .atenea-route-assignment-chips, .atenea-mobile-publication-users .atenea-mobile-user-checks label) {
    background: var(--keria-soft);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}

/* Dispatch rows must use matching foreground/background colors in dark mode. */
.dark .fi-main :is(.atenea-dispatch-orders-block,.atenea-dispatch-route-day,.atenea-dispatch-preparation) {
    background: var(--keria-surface) !important;
    border-color: var(--keria-border) !important;
    color: var(--keria-ink);
}
.dark .atenea-dispatch-orders-block :is(.atenea-dispatch-section-description,.atenea-route-map-empty-message),
.dark .atenea-dispatch-workflow-copy > span {
    color: var(--keria-muted) !important;
}
.dark .atenea-dispatch-orders-block :is(.atenea-day-filter,.atenea-order-view-selector) {
    color: var(--keria-muted);
}
.dark .atenea-dispatch-orders-block :is(.atenea-day-filter select,.atenea-day-filter input,.atenea-order-view-selector select,.atenea-routing-input,.atenea-delivery-date-input) {
    background: var(--keria-soft);
    color: var(--keria-ink);
    border-color: var(--keria-border);
}
.dark .atenea-orders-table td { color: var(--keria-ink); }
.dark .atenea-orders-table tr.is-unplanned > td,
.dark .atenea-screen-order.is-unplanned .atenea-screen-order-summary {
    background: #422f16;
    color: #f4f7fb;
}
.dark .atenea-orders-table tr.is-unplanned:hover > td {
    background: #543e1b !important;
    color: #f4f7fb;
}
.dark .atenea-orders-table .atenea-order-link {
    color: #93c5fd;
}

/* Route proposal uses dark surfaces together with its light text. */
.dark .atenea-route-simulation-orders article {
    background: var(--keria-surface);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}
.dark .atenea-route-simulation-orders article.is-proposed {
    background: #17283f;
    border-color: #42658d;
}
.dark .atenea-route-simulation-orders h4,
.dark .atenea-route-stop-copy {
    color: var(--keria-ink);
}
.dark .atenea-route-sortable li {
    background: var(--keria-soft);
    border-color: var(--keria-border);
    color: var(--keria-ink);
}
.dark .atenea-route-sortable li:is(.is-dragging,.is-anchor) {
    background: #1e3a5f;
    border-color: #60a5fa;
}
.dark .atenea-route-sortable li.is-new {
    background: #143c2a;
    border-color: #4ade80;
}
.dark .atenea-route-proposal-head > span,
.dark .atenea-route-drag-handle {
    color: var(--keria-muted);
}

.atenea-route-proposal-head > span { color: var(--keria-muted); }
