/**
 * UNEMAX — capa visual moderna (móvil, tablet y escritorio).
 * Tema claro/oscuro. Superficies sólidas (sin transparencia glass).
 * No altera la lógica del menú lateral (clases is-open, sidebar__group, JS).
 */

:root {
    --brand-navy: #0c1e42;
    --brand-blue: #1a3a6e;
    --brand-accent: #0ea5e9;
    --brand-accent-hover: #0284c7;
    --surface: #f4f6fb;
    --surface-elevated: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
    --header-h: 52px;
    --sidebar-w: 260px;
    --main-offset: calc(var(--header-h) + 16px);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --text-heading: #0c1e42;
    --btn-bg: #f1f5f9;
    --btn-bg-hover: #e2e8f0;
    --btn-primary-bg: #0ea5e9;
    --btn-primary-hover: #0284c7;
    --header-bg: #0c1e42;
    --focus-ring: rgba(14, 165, 233, 0.18);
    --scrollbar-size: 10px;
    --scrollbar-track: #e8edf3;
    --scrollbar-thumb: #b8c5d6;
    --scrollbar-thumb-hover: #94a3b8;
    --scrollbar-thumb-active: #0ea5e9;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --brand-navy: #e8edf3;
    --brand-blue: #1e3a5f;
    --brand-accent: #38bdf8;
    --brand-accent-hover: #7dd3fc;
    --surface: #0a0e14;
    --surface-elevated: #1e293b;
    --text: #e8edf3;
    --text-muted: #94a3b8;
    --text-heading: #f1f5f9;
    --border: #334155;
    --border-strong: #475569;
    --btn-bg: #334155;
    --btn-bg-hover: #475569;
    --btn-primary-bg: #0284c7;
    --btn-primary-hover: #0369a1;
    --header-bg: #0a0e14;
    --focus-ring: rgba(56, 189, 248, 0.24);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
    --scrollbar-track: #141c28;
    --scrollbar-thumb: #3d4f66;
    --scrollbar-thumb-hover: #5a6f8a;
    --scrollbar-thumb-active: #38bdf8;
}

*, *::before, *::after {
    -webkit-tap-highlight-color: transparent;
}

html {
    scroll-behavior: smooth;
    overflow-x: clip;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body {
    font-family: var(--font-sans);
    overflow-x: clip;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color 0.35s ease, color 0.25s ease;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* Barras de desplazamiento integradas (Firefox + WebKit) */
.sidebar,
.main,
.table-card,
.table-wrap,
.card,
.form__field textarea,
.ts-dropdown,
.egresos-recurrentes__table-wrap,
.node-traffic-chart,
.dataTables_scrollBody {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

@supports selector(::-webkit-scrollbar) {
    *::-webkit-scrollbar {
        width: var(--scrollbar-size);
        height: var(--scrollbar-size);
    }

    *::-webkit-scrollbar-track {
        background: var(--scrollbar-track);
        border-radius: 999px;
    }

    *::-webkit-scrollbar-thumb {
        background: var(--scrollbar-thumb);
        border-radius: 999px;
        border: 2px solid var(--scrollbar-track);
        background-clip: padding-box;
        min-height: 32px;
        min-width: 32px;
        transition: background 0.2s ease;
    }

    *::-webkit-scrollbar-thumb:hover {
        background: var(--scrollbar-thumb-hover);
        border-color: var(--scrollbar-track);
        background-clip: padding-box;
    }

    *::-webkit-scrollbar-thumb:active {
        background: var(--scrollbar-thumb-active);
        border-color: var(--scrollbar-track);
        background-clip: padding-box;
    }

    *::-webkit-scrollbar-corner {
        background: var(--scrollbar-track);
    }

    .table-card::-webkit-scrollbar-thumb,
    .egresos-recurrentes__table-wrap::-webkit-scrollbar-thumb,
    .sidebar::-webkit-scrollbar-thumb {
        border-width: 3px;
    }

    .table-card:not(:hover)::-webkit-scrollbar-thumb,
    .egresos-recurrentes__table-wrap:not(:hover)::-webkit-scrollbar-thumb {
        background: color-mix(in srgb, var(--scrollbar-thumb) 72%, var(--scrollbar-track));
    }
}

a {
    color: var(--brand-accent);
}

a:hover {
    color: var(--brand-accent-hover);
}

/* ——— Cabecera ——— */
.header {
    background: var(--header-bg);
    border-bottom: 1px solid #1e3a5f;
    box-shadow: var(--shadow-sm);
    gap: 10px;
}

.header__tools {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex-shrink: 0;
    min-width: 0;
}

.header__tools .header-user-menu {
    margin-left: 0;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid #2a4a8b;
    border-radius: 999px;
    background: #1a3a6e;
    color: #fff;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform 0.12s ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: #234878;
    border-color: #3b5f9a;
    outline: none;
}

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

.theme-toggle__icon {
    font-size: 1rem;
    line-height: 1;
}

html[data-theme="light"] .theme-toggle__icon--light {
    display: none;
}

html[data-theme="light"] .theme-toggle__icon--dark {
    display: inline-block;
}

html[data-theme="dark"] .theme-toggle__icon--dark {
    display: none;
}

html[data-theme="dark"] .theme-toggle__icon--light {
    display: inline-block;
}

.menu-toggle {
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    min-height: 36px;
    min-width: 36px;
    padding: 4px 8px;
    transition: background var(--transition);
    min-width: 0;
}

.menu-toggle:hover,
.menu-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.12);
    outline: none;
}

.menu-toggle__icon {
    font-size: 1.15rem;
    line-height: 1;
}

.menu-toggle__logo {
    max-height: 28px;
    max-width: 88px;
    object-fit: contain;
    vertical-align: middle;
}

.menu-toggle__label {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.card--highlight {
    border-color: var(--brand-accent, #00b8ff);
    background: var(--surface-elevated);
}

/* ——— Sidebar (solo apariencia) ——— */
.sidebar {
    background: linear-gradient(180deg, #122a52 0%, var(--brand-blue) 55%, #1e4478 100%);
    box-shadow: 4px 0 24px rgba(9, 20, 40, 0.18);
    overflow-x: hidden;
}

.sidebar__link {
    margin: 3px 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--transition), color var(--transition);
}

.sidebar__link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar__link.is-active {
    background: rgba(14, 165, 233, 0.22);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--brand-accent);
}

.sidebar__group {
    border-top-color: rgba(255, 255, 255, 0.1);
}

.sidebar__group-toggle {
    padding: 10px 12px;
    margin: 0;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.75);
    transition: background var(--transition), color var(--transition);
}

.sidebar__group-toggle:hover,
.sidebar__group-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar__group.is-open .sidebar__group-toggle {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.sidebar__subnav .sidebar__link {
    margin: 2px 0;
    font-size: 0.875rem;
}

.sidebar__group,
.sidebar__subnav {
    max-width: 100%;
    overflow-x: hidden;
}

.sidebar__subnav .sidebar__link.is-active {
    background: rgba(14, 165, 233, 0.2);
    box-shadow: inset 3px 0 0 #7dd3fc;
}

.sidebar-backdrop.is-visible {
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

/* ——— Transiciones de módulos ——— */
@keyframes unemax-module-enter {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-progress {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1300;
    height: 3px;
    width: 0;
    background: linear-gradient(90deg, var(--brand-accent), var(--brand-accent-hover));
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, width 0.25s ease;
}

.page-progress.is-active {
    opacity: 1;
}

.main.page-content {
    animation: unemax-module-enter 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
    will-change: opacity, transform;
}

body.page-leaving .main.page-content {
    animation: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    .main.page-content {
        animation: none;
    }

    body.page-leaving .main.page-content {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .page-progress {
        display: none;
    }
}

/* ——— Contenido principal ——— */
.main {
    padding-top: calc(var(--header-h) + 16px);
    padding-right: clamp(14px, 2.5vw, 28px);
    padding-bottom: 28px;
    padding-left: clamp(14px, 2.5vw, 28px);
    max-width: 1680px;
}

.main > h1:first-child {
    margin: 0 0 0.35rem;
    font-size: clamp(1.35rem, 2.5vw, 1.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-heading);
}

.page-head {
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.page-head h1 {
    font-size: clamp(1.25rem, 2.2vw, 1.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-heading);
}

.page-head__subtitle {
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

.footer {
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 400;
    border-top: 1px solid var(--border);
}

.footer p {
    margin: 0;
    text-align: center;
    line-height: 1.35;
}

/* ——— Tarjetas y bloques ——— */
.card,
.table-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.card {
    padding: clamp(16px, 2vw, 24px);
}

.table-card {
    padding: clamp(14px, 2vw, 20px);
    overflow-x: auto;
}

.table-wrap {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: none;
    overflow: hidden;
}

.card__title,
.card__subtitle,
.form__subtitle {
    color: var(--text-heading);
    font-weight: 700;
    letter-spacing: -0.01em;
}

/* ——— Botones ——— */
.btn {
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.875rem;
    border: 1px solid var(--border-strong);
    background: var(--btn-bg);
    color: var(--text);
    box-shadow: var(--shadow-sm);
    transition: background var(--transition), border-color var(--transition), transform 0.12s ease;
}

.btn:hover {
    background: var(--btn-bg-hover);
}

.btn:active {
    transform: scale(0.98);
}

.btn--primary {
    border: 1px solid var(--btn-primary-hover);
    background: var(--btn-primary-bg);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

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

.btn--ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.btn--ghost:hover {
    background: var(--btn-bg);
}

.btn--danger {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.btn--danger:hover {
    background: #fee2e2;
}

html[data-theme="dark"] .btn--danger {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

html[data-theme="dark"] .btn--danger:hover {
    background: #7f1d1d;
}

/* ——— Formularios ——— */
.form__field label,
.form__label-block {
    color: #334155;
    font-size: 0.85rem;
    line-height: 1.35;
}

.form__field input,
.form__field select,
.form__field textarea,
.search-form input {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-elevated);
    transition: border-color var(--transition), box-shadow var(--transition);
    color: var(--text);
}

.form__field input:focus,
.form__field select:focus,
.form__field textarea:focus,
.search-form input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form__intro {
    background: linear-gradient(90deg, #eff6ff 0%, #f8fafc 100%);
    border-left: 4px solid var(--brand-accent);
    border-radius: var(--radius-sm);
}

.form__section,
.form__fieldset {
    border-color: var(--border);
    border-radius: var(--radius-md);
    background: #fafbfc;
}

.form__actions {
    border-top-color: var(--border);
    gap: 12px;
}

/* ——— Tablas ——— */
.table th,
.table-card table.dataTable thead th {
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-color: var(--border);
    white-space: nowrap;
}

.table th,
.table td {
    border-color: var(--border);
    padding: 0.7rem 0.85rem;
    vertical-align: middle;
}

.table-card table,
.table-card table.dataTable {
    min-width: 760px;
}

.table-card .dataTables_filter input {
    min-height: 42px;
}

.table-card .dataTables_length select {
    min-height: 38px;
}

.table tbody tr:nth-child(odd),
.table-card table.dataTable tbody tr:nth-child(odd) {
    background: #fafbfc;
}

.table tbody tr:hover,
.table-card table.dataTable tbody tr:hover {
    background: #f0f9ff;
}

.table-card .dt-toolbar,
.table-card .dt-footer {
    border-color: var(--border);
}

.table-card .dataTables_filter input,
.table-card .dataTables_length select {
    border-radius: var(--radius-sm);
    border-color: var(--border-strong);
}

/* ——— Alertas y badges ——— */
.alert {
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.badge {
    padding: 4px 10px;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

/* ——— Detalle / stats ——— */
.detail-row {
    border-bottom-color: var(--border);
}

.detail-row dt {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
}

.stat-card {
    background: var(--surface-elevated);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card__value {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-heading);
}

.stat-card__link {
    color: var(--brand-accent);
}

/* ——— Dashboard nodos ——— */
.dashboard-nodos,
.dashboard-nodos__body,
.nodes-dashboard,
.node-row {
    max-width: 100%;
    min-width: 0;
}

.node-col {
    overflow: visible;
    max-height: none;
}

.node-col--chart {
    overflow: hidden;
}

.node-row {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.node-col {
    background: var(--btn-bg);
    border-color: var(--border);
}

.node-row,
.node-card--live {
    border-radius: var(--radius-md);
}

.dashboard-nodos__head h2 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ——— Menú usuario cabecera ——— */
.header-user-menu__toggle {
    border-radius: 999px;
    background: #1a3a6e;
    border-color: #2a4a8b;
    min-height: 36px;
    padding: 4px 10px 4px 4px;
    font-size: 0.82rem;
}

.header-user-menu__avatar {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

.header-user-menu__panel {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    background: var(--surface-elevated);
}

/* ——— Login ——— */
.login-page {
    position: relative;
    overflow: hidden;
    background-color: var(--surface);
    background-image:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(14, 165, 233, 0.22), transparent 55%),
        radial-gradient(ellipse 70% 50% at 100% 100%, rgba(16, 185, 129, 0.12), transparent 50%),
        radial-gradient(ellipse 60% 40% at 0% 80%, rgba(30, 58, 110, 0.1), transparent 45%),
        linear-gradient(180deg, var(--surface) 0%, color-mix(in srgb, var(--surface) 92%, var(--brand-accent) 8%) 100%);
    min-height: 100dvh;
    padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.login-page::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 20%, transparent 75%);
    pointer-events: none;
}

html[data-theme="dark"] .login-page {
    background-image:
        radial-gradient(ellipse 80% 60% at 50% -10%, rgba(56, 189, 248, 0.18), transparent 55%),
        radial-gradient(ellipse 70% 50% at 100% 100%, rgba(16, 185, 129, 0.08), transparent 50%),
        linear-gradient(180deg, #0a0e14 0%, #0f172a 100%);
}

html[data-theme="dark"] .login-page::before {
    background-image:
        linear-gradient(rgba(51, 65, 85, 0.35) 1px, transparent 1px),
        linear-gradient(90deg, rgba(51, 65, 85, 0.35) 1px, transparent 1px);
}

.login-page .theme-toggle--login {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    z-index: 2;
    border-color: var(--border-strong);
    background: var(--surface-elevated);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

html[data-theme="dark"] .login-page .theme-toggle--login {
    background: var(--btn-bg);
    border-color: var(--border-strong);
    color: var(--text);
}

.login-shell {
    position: relative;
    z-index: 1;
}

.login-card {
    position: relative;
    overflow: hidden;
    border-radius: calc(var(--radius-lg) + 4px);
    padding: clamp(28px, 5vw, 40px) clamp(24px, 4vw, 36px);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
}

.login-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--brand-accent), #10b981, var(--brand-accent));
    background-size: 200% 100%;
}

.login-card__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 1.75rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.login-card__logo {
    display: block;
    max-height: 72px;
    max-width: min(220px, 100%);
    margin: 0 auto 1rem;
    object-fit: contain;
}

.login-card__mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--btn-primary-bg), #10b981);
    color: #fff;
    font-size: 1.5rem;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
}

.login-card__title {
    margin: 0;
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.25;
    color: var(--text-heading);
}

.login-card__nit {
    display: inline-block;
    margin: 0.5rem 0 0;
    padding: 0.2rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--btn-bg);
    border: 1px solid var(--border);
    border-radius: 999px;
}

.login-card__tag {
    margin: 0.75rem 0 0;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--brand-accent);
}

html[data-theme="dark"] .login-card__tag {
    color: var(--brand-accent-hover);
}

.login-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 1.25rem;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.login-alert i {
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 1rem;
}

html[data-theme="dark"] .login-alert {
    background: rgba(127, 29, 29, 0.35);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.35);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.login-field__label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.01em;
}

.login-field__control {
    position: relative;
    display: flex;
    align-items: stretch;
}

.login-field__icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
    transition: color var(--transition);
}

.login-field__input {
    width: 100%;
    min-height: 48px;
    padding: 0 44px 0 42px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9375rem;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

html[data-theme="dark"] .login-field__input {
    background: color-mix(in srgb, var(--surface-elevated) 85%, #0a0e14 15%);
}

.login-field__input::placeholder {
    color: var(--text-muted);
    opacity: 0.75;
}

.login-field__input:hover {
    border-color: color-mix(in srgb, var(--border-strong) 70%, var(--brand-accent) 30%);
}

.login-field__input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
    background: var(--surface-elevated);
}

.login-field__control:focus-within .login-field__icon {
    color: var(--brand-accent);
}

.login-field__toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}

.login-field__toggle:hover {
    color: var(--text);
    background: var(--btn-bg);
}

.login-form__submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 50px;
    margin-top: 0.35rem;
    padding: 0 1.25rem;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--btn-primary-bg) 0%, color-mix(in srgb, var(--btn-primary-bg) 70%, #10b981 30%) 100%);
    color: #fff;
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
    transition: transform 0.15s ease, box-shadow var(--transition), filter var(--transition);
}

.login-form__submit:hover {
    filter: brightness(1.06);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.42);
}

.login-form__submit:active {
    transform: scale(0.98);
}

.login-form__submit i {
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

.login-form__submit:hover i {
    transform: translateX(3px);
}

html[data-theme="dark"] .login-form__submit {
    box-shadow: 0 4px 18px rgba(2, 132, 199, 0.45);
}

.flash {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    font-weight: 500;
}

.flash--error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ——— Tom Select ——— */
.form__field .ts-wrapper.focus .ts-control {
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

.form__field .ts-control {
    border-radius: var(--radius-sm);
    border-color: var(--border-strong);
}

/* ——— Tablet ——— */
@media (min-width: 600px) and (max-width: 1023px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 14px;
    }

    .form__grid {
        gap: 18px;
    }

    .toolbar {
        gap: 12px;
    }
}

/* ——— Móvil ——— */
@media (max-width: 768px) {
    :root {
        --header-h: 50px;
        --main-offset: calc(var(--header-h) + 16px);
    }

    .header {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        gap: 6px;
    }

    .menu-toggle {
        font-size: 0.88rem;
        padding: 8px 10px;
        flex: 1 1 auto;
        justify-content: flex-start;
        overflow: hidden;
    }

    .sidebar {
        width: min(100%, 320px);
    }

    .sidebar.is-open {
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
    }

    .main {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .card,
    .table-card {
        border-radius: var(--radius-sm);
    }

    .table-card {
        padding: 12px;
    }

    .page-head {
        gap: 12px;
    }

    .btn,
    .sidebar__link,
    .sidebar__group-toggle,
    .menu-toggle {
        min-height: 44px;
    }

    .header-user-menu__toggle {
        max-width: min(190px, 48vw);
        padding: 5px 8px 5px 5px;
    }

    .header-user-menu__name {
        font-size: 0.8rem;
    }

    .header-user-menu__panel {
        right: max(8px, env(safe-area-inset-right));
        left: auto;
        min-width: min(280px, calc(100vw - 16px));
    }

    .table th,
    .table td {
        font-size: 0.82rem;
    }

    .table-card table,
    .table-card table.dataTable {
        min-width: 680px;
    }

    .home-actions {
        gap: 10px;
    }
}

@media (max-width: 380px) {
    .menu-toggle__label {
        max-width: 64px;
    }

    .theme-toggle {
        width: 36px;
        height: 36px;
    }

    .header-user-menu__toggle {
        max-width: 148px;
    }

    .header-user-menu__name {
        max-width: 82px;
    }
}

@media (max-width: 340px) {
    .menu-toggle__label {
        display: none;
    }

    .header-user-menu__label {
        display: none;
    }

    .header-user-menu__toggle {
        width: 42px;
        padding-right: 5px;
        justify-content: center;
    }

    .header-user-menu__caret {
        display: none;
    }
}

/* ——— Escritorio ancho ——— */
@media (min-width: 1024px) {
    .sidebar {
        border-right: 1px solid rgba(255, 255, 255, 0.08);
    }
}

/* ——— Accesibilidad táctil ——— */
@media (hover: none) and (pointer: coarse) {
    .btn--sm {
        min-height: 42px;
        padding: 9px 14px;
    }

    .sidebar__group-toggle {
        min-height: 48px;
    }
}

/* ——— Tema oscuro: tablas, formularios, nodos ——— */
html[data-theme="dark"] .table th,
html[data-theme="dark"] .table-card table.dataTable thead th {
    background: rgba(30, 41, 59, 0.65);
    color: var(--text-muted);
}

html[data-theme="dark"] .table tbody tr:nth-child(odd),
html[data-theme="dark"] .table-card table.dataTable tbody tr:nth-child(odd) {
    background: rgba(15, 23, 42, 0.35);
}

html[data-theme="dark"] .table tbody tr:hover,
html[data-theme="dark"] .table-card table.dataTable tbody tr:hover {
    background: rgba(30, 58, 95, 0.35);
}

/* DataTables: toolbar, búsqueda, paginación */
html[data-theme="dark"] .table-card .dataTables_filter label,
html[data-theme="dark"] .table-card .dataTables_length label {
    color: var(--text-muted);
}

html[data-theme="dark"] .table-card .dataTables_filter input,
html[data-theme="dark"] .table-card .dataTables_length select {
    background: #0f172a;
    border-color: var(--border-strong);
    color: var(--text);
}

html[data-theme="dark"] .table-card .dataTables_filter input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

html[data-theme="dark"] .table-card .dataTables_info {
    color: var(--text-muted);
}

html[data-theme="dark"] .table-card .dataTables_paginate {
    color: var(--text-muted);
}

html[data-theme="dark"] .table-card .dataTables_paginate .paginate_button {
    color: var(--text-muted) !important;
    background: var(--btn-bg) !important;
    border: 1px solid var(--border) !important;
}

html[data-theme="dark"] .table-card .dataTables_paginate .paginate_button:hover:not(.disabled):not(.current) {
    color: var(--text) !important;
    background: var(--btn-bg-hover) !important;
    border-color: var(--border-strong) !important;
}

html[data-theme="dark"] .table-card .dataTables_paginate .paginate_button.current {
    color: #f8fafc !important;
    background: var(--btn-primary-bg) !important;
    border-color: var(--btn-primary-bg) !important;
}

html[data-theme="dark"] .table-card .dataTables_paginate .paginate_button.disabled,
html[data-theme="dark"] .table-card .dataTables_paginate .paginate_button.disabled:hover {
    color: #64748b !important;
    background: transparent !important;
    border-color: var(--border) !important;
    opacity: 0.65;
}

html[data-theme="dark"] .table-card .dt-toolbar,
html[data-theme="dark"] .table-card .dt-footer {
    border-color: var(--border);
}

html[data-theme="dark"] .table-card .dataTables_empty,
html[data-theme="dark"] .table-card table.dataTable tbody td {
    color: var(--text);
}

html[data-theme="dark"] .form__field input,
html[data-theme="dark"] .form__field select,
html[data-theme="dark"] .form__field textarea,
html[data-theme="dark"] .search-form input {
    background: #0f172a;
    border-color: var(--border-strong);
    color: var(--text);
}

html[data-theme="dark"] .form__field label,
html[data-theme="dark"] .form__label-block,
html[data-theme="dark"] .form__section legend,
html[data-theme="dark"] .form__fieldset legend {
    color: #cbd5e1;
}

html[data-theme="dark"] .req,
html[data-theme="dark"] .form__error {
    color: #f87171;
}

html[data-theme="dark"] .form__section,
html[data-theme="dark"] .form__fieldset {
    background: rgba(15, 23, 42, 0.32);
    border-color: var(--border);
}

html[data-theme="dark"] .card__title,
html[data-theme="dark"] .card__subtitle,
html[data-theme="dark"] .form__subtitle {
    color: var(--text-heading);
}

html[data-theme="dark"] .form__intro {
    background: #1e3a5f;
    color: var(--text);
}

html[data-theme="dark"] .form__hint {
    color: var(--text-muted);
}

html[data-theme="dark"] .dashboard-nodos__head h2,
html[data-theme="dark"] .dashboard-nodos__status {
    color: var(--text-muted);
}

html[data-theme="dark"] .live-badge {
    background: #334155;
    color: var(--text-muted);
}

html[data-theme="dark"] .live-badge--on {
    background: #14532d;
    color: #86efac;
}

/* Monitoreo de nodos (inicio) */
html[data-theme="dark"] .node-row {
    background: var(--surface-elevated);
    border-color: var(--border);
}

html[data-theme="dark"] .node-row__header {
    border-bottom-color: var(--border);
}

html[data-theme="dark"] .node-col {
    background: #0f172a;
    border-color: var(--border);
}

html[data-theme="dark"] .node-col--chart {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
}

html[data-theme="dark"] .node-col__title,
html[data-theme="dark"] .node-card__title,
html[data-theme="dark"] .node-uptime strong {
    color: var(--text-heading);
}

html[data-theme="dark"] .node-card__meta,
html[data-theme="dark"] .node-card__app,
html[data-theme="dark"] .node-uptime,
html[data-theme="dark"] .node-metric span,
html[data-theme="dark"] .node-bar__head,
html[data-theme="dark"] .node-bar__hint,
html[data-theme="dark"] .node-chart__legend {
    color: var(--text-muted);
}

html[data-theme="dark"] .node-spec-table th,
html[data-theme="dark"] .node-spec-table td {
    border-color: var(--border);
}

html[data-theme="dark"] .node-spec-table th {
    background: #1e293b;
    color: var(--text-muted);
}

html[data-theme="dark"] .node-spec-table td {
    background: #0f172a;
    color: var(--text);
}

html[data-theme="dark"] .node-traffic {
    background: #1e293b;
}

html[data-theme="dark"] .node-traffic__label {
    color: var(--text-muted);
}

html[data-theme="dark"] .node-traffic__value,
html[data-theme="dark"] .node-metric strong {
    color: var(--text-heading);
}

html[data-theme="dark"] .node-bar__track {
    background: #334155;
}

html[data-theme="dark"] .node-card__app {
    border-top-color: var(--border);
}

html[data-theme="dark"] .main code,
html[data-theme="dark"] .node-card__meta code {
    background: #0f172a;
    color: #7dd3fc;
    border: 1px solid var(--border);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

html[data-theme="dark"] .stat-card {
    background: var(--surface-elevated);
    border-color: var(--border);
}

html[data-theme="dark"] .stat-card__label {
    color: var(--text-muted);
}

html[data-theme="dark"] .header-user-menu__panel {
    background: var(--surface-elevated);
    border-color: var(--border);
    color: var(--text);
}

html[data-theme="dark"] .header-user-menu__meta strong {
    color: var(--text-heading);
}

html[data-theme="dark"] .header-user-menu__list a,
html[data-theme="dark"] .header-user-menu__logout {
    color: var(--text);
}

html[data-theme="dark"] .header-user-menu__list a:hover,
html[data-theme="dark"] .header-user-menu__logout:hover {
    background: rgba(51, 65, 85, 0.5);
}

html[data-theme="dark"] .alert--success {
    background: rgba(22, 101, 52, 0.35);
    color: #86efac;
    border-color: rgba(74, 222, 128, 0.35);
}

html[data-theme="dark"] .alert--error {
    background: rgba(127, 29, 29, 0.35);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.35);
}

html[data-theme="dark"] .alert--warning {
    background: rgba(120, 53, 15, 0.35);
    color: #fcd34d;
    border-color: rgba(251, 191, 36, 0.35);
}

html[data-theme="dark"] .footer {
    background: var(--surface);
    color: var(--text-muted);
    border-top-color: var(--border);
}

.home-actions .btn--primary {
    flex: 1 1 auto;
}

/* ——— Egresos mensuales (finanzas) ——— */
.egresos-recurrentes__top {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
    width: 100%;
}

@media (min-width: 900px) {
    .egresos-recurrentes__top {
        grid-template-columns: minmax(220px, 280px) 1fr;
        align-items: stretch;
    }
}

.egresos-recurrentes__period.card {
    margin-bottom: 0;
    padding: 1rem 1.15rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.egresos-recurrentes__period .form--inline-toolbar {
    margin: 0;
    flex-wrap: nowrap;
    gap: 12px;
}

.egresos-recurrentes__period-title {
    margin: 0 0 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.stats-grid--recurrentes {
    margin-top: 0;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}

@media (min-width: 1100px) {
    .stats-grid--recurrentes {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-card--recurrente {
    padding: 1rem 1.15rem;
    min-height: 108px;
    border-radius: var(--radius-md);
    background: var(--surface-elevated);
    box-shadow: var(--shadow-sm);
}

.stat-card--recurrente .stat-card__value {
    font-size: clamp(1.35rem, 2.5vw, 1.75rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 0.35rem 0 0.5rem;
}

.stat-card--recurrente .stat-card__meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-card--ok .stat-card__value { color: #16a34a; }
.stat-card--warn .stat-card__value { color: #b45309; }
.stat-card--neutral .stat-card__value { color: var(--text-heading); }

.stat-card__progress {
    height: 6px;
    margin-top: auto;
    border-radius: 999px;
    background: var(--btn-bg);
    overflow: hidden;
}

.stat-card__progress-bar {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #16a34a, #22c55e);
    transition: width 0.35s ease;
}

.egresos-recurrentes__mes.card {
    overflow: hidden;
}

.egresos-recurrentes__mes-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #f8fafc 0%, var(--surface-elevated) 100%);
}

html[data-theme="dark"] .egresos-recurrentes__mes-head {
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.5) 0%, var(--surface-elevated) 100%);
}

.egresos-recurrentes__mes-head h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-heading);
}

.egresos-recurrentes__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.egresos-recurrentes__table .table {
    min-width: 960px;
}

.egresos-recurrentes__table .col-tercero {
    min-width: 160px;
}

.egresos-recurrentes__table .col-contacto {
    min-width: 140px;
    max-width: 220px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.egresos-recurrentes__table .col-monto {
    white-space: nowrap;
    font-weight: 600;
    color: #b91c1c;
}

.egresos-recurrentes__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 6px 8px;
    min-width: 200px;
}

.egresos-recurrentes__confirm {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 140px;
    min-width: 120px;
}

.egresos-recurrentes__confirm input[type="text"] {
    width: 100%;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--surface-elevated);
    color: var(--text);
}

.egresos-recurrentes__plantillas {
    margin-top: 1.25rem;
}

.egresos-recurrentes__plantillas summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-heading);
    padding: 0.25rem 0;
    list-style: none;
}

.egresos-recurrentes__plantillas summary::-webkit-details-marker {
    display: none;
}

.egresos-recurrentes__plantillas summary::before {
    content: "\f054";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    display: inline-block;
    margin-right: 8px;
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.egresos-recurrentes__plantillas[open] summary::before {
    transform: rotate(90deg);
}

.egresos-recurrentes__plantillas .egresos-recurrentes__table-wrap {
    margin-top: 1rem;
}

/* ——— Diálogos de confirmación / aviso ——— */
.app-dialog {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
        max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.app-dialog[hidden] {
    display: none !important;
}

.app-dialog__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.62);
}

html[data-theme="dark"] .app-dialog__backdrop {
    background: rgba(0, 0, 0, 0.72);
}

.app-dialog__panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 1.35rem 1.35rem 1.15rem;
    animation: app-dialog-in 0.18s ease;
}

@keyframes app-dialog-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.app-dialog__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.75rem;
    border-radius: 999px;
    background: rgba(14, 165, 233, 0.12);
    color: var(--brand-accent);
    font-size: 1.15rem;
}

.app-dialog--danger .app-dialog__icon {
    background: rgba(239, 68, 68, 0.14);
    color: #ef4444;
}

.app-dialog__title {
    margin: 0 0 0.45rem;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-heading);
}

.app-dialog__message {
    margin: 0 0 1.15rem;
    color: var(--text);
    line-height: 1.55;
    white-space: pre-line;
}

.app-dialog__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

body.app-dialog-open {
    overflow: hidden;
}

@media (max-width: 480px) {
    .app-dialog__panel {
        padding: 1.15rem;
    }

    .app-dialog__actions {
        flex-direction: column-reverse;
    }

    .app-dialog__actions .btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
