:root {
    color-scheme: light;
    --ec-canvas: #f1f6f8;
    --ec-surface: #ffffff;
    --ec-surface-soft: #e8f1f4;
    --ec-text-primary: #003d50;
    --ec-text-secondary: #526b74;
    --ec-text-muted: #526b74;
    --ec-muted: var(--ec-text-muted);
    --ec-line: #b7d0d9;
    --ec-line-soft: #dcebf0;
    --ec-action-primary: #003d50;
    --ec-action-primary-hover: #00536b;
    --ec-action-primary-active: #002c3a;
    --ec-action-on-primary: #ffffff;
    --ec-accent: #0b6f8d;
    --ec-focus: #0b6f8d;
    --ec-success-bg: #d7f4e4;
    --ec-success-ink: #155f39;
    --ec-success-border: #91cfad;
    --ec-success-surface: #effaf4;
    --ec-neutral-bg: #e9eff1;
    --ec-neutral-ink: #526b74;
    --ec-disabled-bg: #eaf0f2;
    --ec-danger: #a62b23;
    --ec-danger-bg: #fff2f0;
    --ec-danger-border: #e7aaa5;
    --ec-danger-action: #a62b23;
    --ec-warning-bg: #fff2ce;
    --ec-warning-ink: #6e4b00;
    --ec-sun: #b56b00;
    --ec-overlay: rgb(0 32 42 / 0.46);
    --ec-shadow-color: rgb(0 45 58 / 0.14);
    --ec-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --public-primary: #530e0e;
    --public-secondary: #ffffff;

    /* Compatibility aliases while the legacy styles are migrated to semantic tokens. */
    --ec-ink: var(--ec-text-primary);
    --ec-ink-hover: var(--ec-action-primary-hover);
    --primary: var(--ec-action-primary);
    --primary-hover: var(--ec-action-primary-hover);
    --primary-active: var(--ec-action-primary-active);
    --accent: var(--ec-accent);
    --secondary: var(--ec-action-on-primary);
    --tertiary: var(--ec-line-soft);
    --quaternary: var(--ec-line);
    --surface: var(--ec-surface);
    --surface-soft: var(--ec-canvas);
    --text-muted: var(--ec-text-secondary);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --ec-canvas: #071419;
    --ec-surface: #0d2229;
    --ec-surface-soft: #12303a;
    --ec-text-primary: #eaf5f7;
    --ec-text-secondary: #a9c0c7;
    --ec-text-muted: #809ba3;
    --ec-line: #2b4a54;
    --ec-line-soft: #1c3740;
    --ec-action-primary: #1c7895;
    --ec-action-primary-hover: #248aa9;
    --ec-action-primary-active: #155f77;
    --ec-action-on-primary: #f4fbfc;
    --ec-accent: #54b9d7;
    --ec-focus: #75d0e8;
    --ec-success-bg: #123d2d;
    --ec-success-ink: #74d6a4;
    --ec-success-border: #2e7a50;
    --ec-success-surface: #102f24;
    --ec-neutral-bg: #1c3740;
    --ec-neutral-ink: #a9c0c7;
    --ec-disabled-bg: #142c34;
    --ec-danger: #ff9b94;
    --ec-danger-bg: #431b1b;
    --ec-danger-border: #8b4642;
    --ec-danger-action: #8b3a36;
    --ec-warning-bg: #432f13;
    --ec-warning-ink: #f3c571;
    --ec-sun: #f3c571;
    --ec-overlay: rgb(0 7 10 / 0.72);
    --ec-shadow-color: rgb(0 0 0 / 0.34);
}

body.public-site {
    --primary: var(--public-primary);
    --secondary: var(--public-secondary);
}

html {
    background: var(--ec-canvas);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--ec-canvas);
    color: var(--ec-text-primary);
}

::selection {
    background: var(--ec-accent);
    color: var(--ec-action-on-primary);
}

input,
select,
textarea {
    color-scheme: inherit;
}

.ec-theme-setting {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.ec-theme-toggle,
.ec-theme-system {
    border: 0;
    font: inherit;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.ec-theme-toggle {
    display: grid;
    width: 100%;
    min-height: 54px;
    grid-template-columns: 52px minmax(0, 1fr);
    align-items: center;
    gap: 11px;
    padding: 7px 9px;
    border-radius: 12px;
    background: transparent;
    color: var(--ec-text-primary);
    text-align: left;
    transition: background-color 160ms ease, transform 140ms var(--ec-ease-out);
}

.ec-theme-toggle:hover,
.ec-theme-toggle:focus-visible {
    background: var(--ec-surface-soft);
}

.ec-theme-toggle:active {
    transform: scale(0.98);
}

.ec-theme-toggle__track {
    position: relative;
    display: block;
    width: 48px;
    height: 28px;
    border: 1px solid var(--ec-line);
    border-radius: 999px;
    background: var(--ec-line-soft);
    transition: background-color 180ms ease, border-color 180ms ease;
}

.ec-theme-toggle__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    display: grid;
    width: 20px;
    height: 20px;
    place-items: center;
    border-radius: 50%;
    background: var(--ec-surface);
    color: var(--ec-sun);
    box-shadow: 0 2px 7px var(--ec-shadow-color);
    transform: translateX(0);
    transition: transform 180ms var(--ec-ease-out), background-color 180ms ease, color 180ms ease;
}

/* Sol y luna en la misma celda: centrados exactos, con su propio tamaño y alto de línea (antes heredaban los del
   botón y el glifo quedaba desplazado hacia abajo). */
.ec-theme-toggle__thumb :is(.fas, .fab, .far) {
    grid-area: 1 / 1;
    display: block;
    font-size: 11px;
    line-height: 1;
    transition: opacity 140ms ease, transform 180ms var(--ec-ease-out);
}

.ec-theme-toggle__moon {
    opacity: 0;
    transform: rotate(-45deg) scale(0.8);
}

[data-theme="dark"] .ec-theme-toggle__track {
    border-color: var(--ec-accent);
    background: color-mix(in srgb, var(--ec-accent) 30%, var(--ec-surface));
}

[data-theme="dark"] .ec-theme-toggle__thumb {
    color: var(--ec-accent);
    transform: translateX(20px);
}

[data-theme="dark"] .ec-theme-toggle__sun {
    opacity: 0;
    transform: rotate(45deg) scale(0.8);
}

[data-theme="dark"] .ec-theme-toggle__moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

.ec-theme-toggle__copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
}

.ec-theme-toggle__copy small {
    color: var(--ec-text-secondary);
    font-size: 0.78rem;
}

.ec-theme-toggle__copy strong {
    overflow: hidden;
    color: var(--ec-text-primary);
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ec-theme-system {
    display: inline-flex;
    width: fit-content;
    min-height: 32px;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border-radius: 11px;
    background: transparent;
    color: var(--ec-accent);
    font-size: 0.78rem;
    font-weight: 700;
}

.ec-theme-system[hidden] {
    display: none;
}

.ec-theme-system:hover,
.ec-theme-system:focus-visible {
    background: var(--ec-surface-soft);
}

/* Shared shell and current EbeneCenter modules. */
[data-theme="dark"] .dashboard-page {
    --dashboard-surface: var(--ec-surface);
    --dashboard-border: var(--ec-line);
    --dashboard-text-soft: var(--ec-text-secondary);
    --dashboard-accent: var(--ec-accent);
    --dashboard-accent-soft: var(--ec-surface-soft);
    --dashboard-shadow: 0 10px 35px var(--ec-shadow-color);
}

[data-theme="dark"] .tp-page {
    --tp-ink: var(--ec-text-primary);
    --tp-accent: var(--ec-accent);
    --tp-canvas: var(--ec-canvas);
    --tp-surface: var(--ec-surface);
    --tp-line: var(--ec-line);
    --tp-line-soft: var(--ec-line-soft);
    --tp-muted: var(--ec-text-secondary);
}

[data-theme="dark"] .ec-mobile-header,
[data-theme="dark"] .ec-sidebar,
[data-theme="dark"] .ec-bottom-nav,
[data-theme="dark"] .ec-sidebar-account,
[data-theme="dark"] .dashboard-panel,
[data-theme="dark"] .metric-card:not(.metric-card--primary),
[data-theme="dark"] .tp-directory,
[data-theme="dark"] .tp-detail-card,
[data-theme="dark"] .tp-next-actions,
[data-theme="dark"] .tp-nav,
[data-theme="dark"] .tp-wizard-step,
[data-theme="dark"] .tp-metric:not(.tp-metric--primary),
[data-theme="dark"] .tp-flow-grid article {
    background: var(--ec-surface);
}

[data-theme="dark"] .ec-nav-link,
[data-theme="dark"] .ec-sidebar-user strong,
[data-theme="dark"] .dashboard-welcome h1,
[data-theme="dark"] .panel-heading h2,
[data-theme="dark"] .metric-card:not(.metric-card--primary),
[data-theme="dark"] .officer-breakdown b {
    color: var(--ec-text-primary);
}

[data-theme="dark"] .dashboard-welcome p,
[data-theme="dark"] .metric-label,
[data-theme="dark"] .metric-breakdown,
[data-theme="dark"] .metric-hint,
[data-theme="dark"] .officer-breakdown span {
    color: var(--ec-text-secondary);
}

[data-theme="dark"] .ec-nav-link.active,
[data-theme="dark"] .metric-card--primary,
[data-theme="dark"] .tp-metric--primary,
[data-theme="dark"] .tp-header__icon,
[data-theme="dark"] .tp-nav a.is-active,
[data-theme="dark"] .ec-button--primary {
    background: var(--ec-action-primary);
    color: var(--ec-action-on-primary);
}

[data-theme="dark"] .ec-crud-heading__icon {
    background: var(--ec-action-primary);
    color: var(--ec-action-on-primary);
}

[data-theme="dark"] .dashboard-secondary-action,
[data-theme="dark"] .tp-team-switcher select,
[data-theme="dark"] .tp-inline-form input,
[data-theme="dark"] .tp-inline-form select,
[data-theme="dark"] .tp-inline-form textarea,
[data-theme="dark"] .tp-form-grid input,
[data-theme="dark"] .tp-form-grid select,
[data-theme="dark"] .tp-notes textarea,
[data-theme="dark"] .tp-branch-fields input,
[data-theme="dark"] .tp-branch-fields select,
[data-theme="dark"] .tp-type-grid button {
    background: var(--ec-surface);
    color: var(--ec-text-primary);
}

[data-theme="dark"] .ec-sidebar-overlay {
    background: var(--ec-overlay);
}

[data-theme="dark"] .ec-directory-item__chevron {
    color: var(--ec-text-muted);
}

[data-theme="dark"] .footer {
    border-top: 1px solid var(--ec-line);
    background: var(--ec-surface);
}

[data-theme="dark"] .footer .ec-footer__copy,
[data-theme="dark"] .footer .ec-footer__copy > span {
    color: var(--ec-text-secondary);
}

[data-theme="dark"] img[src*="positive.png"] {
    filter: brightness(0) invert(1);
}

@media (prefers-reduced-motion: reduce) {
    .ec-theme-toggle,
    .ec-theme-toggle__track,
    .ec-theme-toggle__thumb,
    .ec-theme-toggle__thumb :is(.fas, .fab, .far) {
        transition: background-color 100ms linear, color 100ms linear, opacity 100ms linear;
    }

    .ec-theme-toggle:active,
    .ec-theme-toggle__thumb,
    .ec-theme-toggle__thumb :is(.fas, .fab, .far) {
        transform: none;
    }
}
