/* =============================================================================
 * TechnoSense-Wx — components.css
 * -----------------------------------------------------------------------------
 * Componentes reutilizables en todo el sistema.
 * Depende de theme.css y base.css.
 *
 * Firma visual: las .card llevan una línea "horizonte" superior que evoca
 * la lectura de un instrumento. Es el detalle recurrente del sistema.
 * ============================================================================= */

/* ---- App bar ---- */
.app-bar {
    background: var(--white);
    border-bottom: 1px solid var(--line);
    padding: var(--sp-4) var(--sp-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}
.app-bar .brand {
    font-family: var(--font-display);
    font-size: var(--fs-md);
    font-weight: var(--fw-black);
    color: var(--sky-900);
    letter-spacing: -0.02em;
}
.app-bar .brand .wx { color: var(--solar-500); }
.app-bar .bar-actions { display: flex; align-items: center; gap: var(--sp-3); }

/* ---- Contenedor ---- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--sp-6);
}

/* ---- Card con firma "horizonte" ---- */
.card {
    position: relative;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--sky-600), var(--solar-500));
}
.card.no-horizon::before { display: none; }

/* ---- Stat card ---- */
.stat-card { text-align: left; }
.stat-card .stat-num {
    font-family: var(--font-data);
    font-variant-numeric: tabular-nums;
    font-size: var(--fs-2xl);
    font-weight: var(--fw-bold);
    color: var(--sky-900);
    line-height: 1;
}
.stat-card .stat-label {
    font-size: var(--fs-sm);
    color: var(--muted);
    margin-top: var(--sp-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---- Grid ---- */
.grid { display: grid; gap: var(--sp-4); }
.grid-stats  { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-cards  { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.section-gap { margin-bottom: var(--sp-6); }

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    padding: 0.25rem 0.6rem;
    border-radius: var(--r-sm);
    background: var(--sky-100);
    color: var(--sky-700);
}
.badge-soft   { background: var(--paper);       color: var(--muted);      }
.badge-solar  { background: var(--solar-100);   color: var(--solar-600);  }
.badge-ok     { background: rgba(22,163,74,.10); color: #16a34a;          }
.badge-warn   { background: #fef3c7;            color: #92400e;           }
.badge-danger { background: #fee2e2;            color: #991b1b; font-weight: var(--fw-bold); }

/* ---- Status (online / offline) ---- */
.status {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    padding: 0.25rem 0.6rem;
    border-radius: var(--r-sm);
}
.status::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: currentColor;
}
.status-online  { color: var(--ok);    background: rgba(22,163,74,0.10);  }
.status-stale   { color: var(--warn);  background: rgba(245,158,11,0.10); }
.status-offline { color: var(--error); background: rgba(220,38,38,0.10);  }
.status-nodata  { color: var(--idle);  background: rgba(148,163,184,0.12);}

/* ---- Alerts ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
    border: 1px solid transparent;
}
.alert-error {
    background: rgba(220,38,38,0.06);
    border-color: rgba(220,38,38,0.25);
    color: var(--error);
}
.alert-ok {
    background: rgba(22,163,74,0.06);
    border-color: rgba(22,163,74,0.25);
    color: var(--ok);
}

/* ---- Page heading ---- */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: var(--sp-6);
}
.page-head h2 { color: var(--sky-900); }
.page-head p  { color: var(--muted); margin-top: var(--sp-1); }

/* ---- Field (label + input agrupados) ---- */
.field { margin-bottom: var(--sp-4); }

/* ---- Botón pequeño ---- */
.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: var(--fs-xs);
    width: auto;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Tabla de datos ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
}
.data-table thead th {
    text-align: left;
    padding: var(--sp-3) var(--sp-4);
    background: var(--sky-100);
    color: var(--sky-900);
    font-weight: var(--fw-bold);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--line);
}
.data-table tbody td {
    padding: var(--sp-3) var(--sp-4);
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover         { background: var(--paper); }
.data-table tfoot td {
    padding: var(--sp-3) var(--sp-4);
    border-top: 2px solid var(--line);
    font-size: var(--fs-sm);
}

/* ---- Modal ---- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(12, 74, 110, 0.45);
    backdrop-filter: blur(2px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
}
.modal-overlay.open { display: flex; }

/* Tamaños de modal */
.modal       { max-width: 460px; }   /* default — formularios simples  */
.modal-wide  { max-width: 820px; }   /* detalle / historial            */
.modal-full  { max-width: 1000px; }  /* si se necesita más adelante    */

/* Base compartida */
.modal, .modal-wide, .modal-full {
    background: var(--white);
    border-radius: var(--r-lg);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--white);
    z-index: 1;
}
.modal-head h3 { color: var(--sky-900); }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: auto;
    flex-shrink: 0;
}
.modal-close:hover { color: var(--ink); }
.modal-body { padding: var(--sp-5); }
.modal-body .field { margin-bottom: var(--sp-4); }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-5);
    border-top: 1px solid var(--line);
    position: sticky;
    bottom: 0;
    background: var(--white);
}
.modal-foot .btn { width: auto; }

/* ---- Listas de módulos y usuarios (admin de cuentas) ---- */
.modulos-list, .usuarios-list {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.modulo-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    cursor: pointer;
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--ink);
    transition: border-color var(--t-fast), background var(--t-fast);
}
.modulo-item:hover { border-color: var(--sky-600); background: var(--paper); }
.modulo-item input[type="checkbox"] {
    width: auto; margin: 0; cursor: pointer;
    accent-color: var(--solar-500);
}
.modulo-item input[type="checkbox"]:disabled { cursor: not-allowed; }
.modulo-item span { display: flex; align-items: center; gap: var(--sp-2); }

.usuario-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    font-size: var(--fs-sm);
}
.usuario-item strong { color: var(--ink); }

/* .module-card — estilos en modules/admin_panel.css (específicos del panel) */

/* ---- Cobranza: filas coloreadas por urgencia ---- */
.row-danger td { background: #fef2f2; }
.row-warn   td { background: #fffbeb; }

/* ---- Cobranza: stat cards con color ---- */
.stat-danger .stat-num { color: var(--error); }
.stat-warn   .stat-num { color: #d97706; }
.stat-ok     .stat-num { color: var(--ok); }

/* ---- Info box (cobranza detalle) ---- */
.info-box {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 0.75rem 1rem;
    line-height: 1.7;
    font-size: var(--fs-sm);
    margin-bottom: var(--sp-4);
}

/* ── Panel SMN fuera de servicio ─────────────────────────────────────────────*/
.smn-outage {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: var(--r-md);
    margin: 0.5rem 0;
}

/* ── Badge de tendencia de presión ───────────────────────────────────────────*/
.tend-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    padding: 2px 7px;
    border-radius: 99px;
    margin-top: 4px;
    white-space: nowrap;
}
.tend-warn {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}
.tend-bad {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}
.tend-good {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

/* ══════════════════════════════════════════════════════════════════════════════
 * TEMA OSCURO — components
 * ══════════════════════════════════════════════════════════════════════════════ */

/* Cards y paneles */
[data-theme="dark"] .wx-panel,
[data-theme="dark"] .hist-card,
[data-theme="dark"] .card {
    background: var(--surface-1);
    border-color: var(--line);
}

/* Tablas */
[data-theme="dark"] .hist-data-table thead th {
    background: var(--surface-3);
    color: var(--sky-900);
    border-bottom-color: var(--line);
}
[data-theme="dark"] .hist-data-table tbody tr { border-bottom-color: var(--line); }
[data-theme="dark"] .hist-data-table tbody tr:hover { background: var(--surface-3); }
[data-theme="dark"] .hist-td-time { color: var(--muted); }
[data-theme="dark"] .hist-td-val  { color: var(--ink); }

/* Range buttons históricos */
[data-theme="dark"] .hist-range-btn {
    background: var(--surface-3);
    color: var(--muted);
    border-color: var(--line);
}
[data-theme="dark"] .hist-range-btn.active {
    background: var(--sky-600);
    color: #fff;
    border-color: var(--sky-600);
}
[data-theme="dark"] .hist-range-btn:hover:not(.active) {
    border-color: var(--sky-600);
    color: var(--sky-900);
}

/* View switch (chart/tabla) */
[data-theme="dark"] .hist-view-switch {
    background: var(--surface-1);
    border-color: var(--line);
}
[data-theme="dark"] .hist-view-btn { color: var(--muted); }
[data-theme="dark"] .hist-view-btn:hover { background: var(--surface-3); color: var(--sky-900); }
[data-theme="dark"] .hist-view-btn.active { background: var(--sky-600); color: #fff; }

/* Station tabs históricos */
[data-theme="dark"] .hist-station-tabs { border-bottom-color: var(--line); }
[data-theme="dark"] .station-tab { color: var(--muted); border-bottom-color: transparent; }
[data-theme="dark"] .station-tab:hover { color: var(--ink-soft); }
[data-theme="dark"] .station-tab.active { color: var(--sky-600); border-bottom-color: var(--sky-600); }

/* Status badges */
[data-theme="dark"] .status-badge.online  { background: rgba(34,197,94,0.15); color: #4ade80; }
[data-theme="dark"] .status-badge.stale   { background: rgba(251,191,36,0.15); color: #fbbf24; }
[data-theme="dark"] .status-badge.offline { background: rgba(100,116,139,0.15); color: #94a3b8; }

/* SMN outage */
[data-theme="dark"] .smn-outage {
    background: rgba(251,191,36,0.1);
    border-color: rgba(251,191,36,0.25);
}

/* Badges de tendencia */
[data-theme="dark"] .tend-warn { background: rgba(251,191,36,0.15); color: #fbbf24; border-color: rgba(251,191,36,0.3); }
[data-theme="dark"] .tend-bad  { background: rgba(248,113,113,0.15); color: #f87171; border-color: rgba(248,113,113,0.3); }
[data-theme="dark"] .tend-good { background: rgba(74,222,128,0.15);  color: #4ade80; border-color: rgba(74,222,128,0.3); }