/* ==========================================================================
   Sistema de Cálculo de Factura Eléctrica — hoja de estilos
   Identidad: panel de medidor digital. Navy profundo + acento ámbar (el
   color de un dial de consumo), tipografía monoespaciada tabular para las
   lecturas y los importes (igual que en un medidor real), Space Grotesk
   para títulos y Inter para el resto de la interfaz.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --bg: #F3F5F8;
    --surface: #FFFFFF;
    --surface-2: #EBEEF3;
    --ink: #10192B;
    --ink-soft: #5B6676;
    --ink-faint: #93A0B2;
    --border: #E1E6ED;
    --navy: #10263A;
    --navy-2: #16324A;
    --accent: #E29A2E;
    --accent-ink: #4A2E00;
    --accent-soft: #FBEBD2;
    --success: #22855A;
    --success-soft: #DFF3E9;
    --danger: #C6473F;
    --danger-soft: #FBE6E4;
    --info: #2E6FA6;
    --info-soft: #E1EDF7;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 25, 43, .06);
    --shadow-md: 0 6px 20px rgba(16, 25, 43, .08);
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

[data-theme="dark"] {
    --bg: #0B1220;
    --surface: #121B2C;
    --surface-2: #182338;
    --ink: #E7ECF5;
    --ink-soft: #9AA7BC;
    --ink-faint: #647089;
    --border: #253352;
    --navy: #0A1727;
    --navy-2: #0F2036;
    --accent: #F0AC45;
    --accent-ink: #1A1000;
    --accent-soft: #2E210A;
    --success: #3DBE85;
    --success-soft: #123322;
    --danger: #E4655C;
    --danger-soft: #3A1917;
    --info: #5B9BD8;
    --info-soft: #10233A;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--ink); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
a { color: inherit; }

/* ---------- Layout: shell con sidebar ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
    background: var(--navy);
    color: #DCE6F0;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 50%;
    background: conic-gradient(var(--accent) 0deg 260deg, rgba(255,255,255,.12) 260deg 360deg);
    display: flex; align-items: center; justify-content: center; flex: none;
}
.brand-mark::after {
    content: ''; width: 15px; height: 15px; border-radius: 50%;
    background: var(--navy); box-shadow: inset 0 0 0 2px rgba(255,255,255,.15);
}
.brand-text { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: #fff; line-height: 1.15; }
.brand-text small { display: block; font-family: var(--font-body); font-weight: 500; font-size: 11px; color: #8FA3B8; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 8px;
    color: #B7C4D4; text-decoration: none; font-size: 13.5px; font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.nav-link.active svg { opacity: 1; }
.nav-section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6C8098; margin: 16px 12px 6px; }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; }
.user-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12.5px; flex: none;
}
.user-meta { line-height: 1.25; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: #8FA3B8; }
.btn-logout { margin-left: auto; background: none; border: none; color: #8FA3B8; cursor: pointer; padding: 4px; border-radius: 6px; }
.btn-logout:hover { color: #fff; background: rgba(255,255,255,.08); }

.main { min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 19px; }
.topbar-sub { color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }
.content { padding: 26px 28px 60px; }

.theme-toggle {
    display: flex; align-items: center; gap: 8px; border: 1px solid var(--border);
    background: var(--surface-2); border-radius: 999px; padding: 4px; cursor: pointer;
}
.theme-toggle button {
    border: none; background: none; width: 30px; height: 26px; border-radius: 999px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; color: var(--ink-soft);
}
.theme-toggle button.active { background: var(--navy); color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; }

/* ---------- Componentes ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm); padding: 20px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 500; margin-bottom: 8px; }
.stat-value { font-family: var(--font-mono); font-size: 24px; font-weight: 600; }
.stat-delta { font-size: 12px; margin-top: 6px; color: var(--ink-faint); }

.btn {
    display: inline-flex; align-items: center; gap: 7px; border-radius: 8px; border: 1px solid transparent;
    padding: 9px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: var(--font-body);
    transition: filter .15s, background .15s;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { filter: brightness(0.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--accent-soft); color: var(--accent-ink); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: 11.5px; color: var(--ink-faint); }
input, select, textarea {
    font-family: var(--font-body); font-size: 13.5px; padding: 9px 11px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink);
    width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
input.mono, .field.mono input { font-family: var(--font-mono); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { background: var(--surface-2); color: var(--ink-faint); }
input.invalid { border-color: var(--danger); }
.error-text { color: var(--danger); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }
@media (max-width: 760px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }

/* ---------- Tablas ---------- */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search-box { position: relative; max-width: 320px; flex: 1; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-faint); }
.search-box input { padding-left: 33px; }

table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-soft); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border);
    cursor: pointer; white-space: nowrap; user-select: none;
}
thead th:hover { color: var(--ink); }
thead th .sort-arrow { opacity: .35; margin-left: 4px; font-size: 10px; }
thead th.sorted .sort-arrow { opacity: 1; color: var(--accent); }
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.table-empty { text-align: center; padding: 40px 20px; color: var(--ink-faint); }
.pagination { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 12.5px; color: var(--ink-soft); }
.pagination .pages { display: flex; gap: 4px; }
.pagination button { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; width: 28px; height: 28px; cursor: pointer; color: var(--ink); }
.pagination button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Factura: bloque de pasos numerados (fiel a las 13 secciones del Excel) ---------- */
.invoice-step { display: flex; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.invoice-step:last-child { border-bottom: none; }
.step-num {
    flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--ink-soft);
    display: flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-size: 12.5px; font-weight: 600;
}
.step-body { flex: 1; }
.step-title { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.step-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 3px 0; color: var(--ink-soft); }
.step-row b { color: var(--ink); font-family: var(--font-mono); font-weight: 600; }
.step-total { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; margin-top: 6px; }
.step-total b { font-family: var(--font-mono); }

.total-banner {
    background: var(--navy); color: #fff; border-radius: var(--radius-lg); padding: 22px 26px;
    display: flex; align-items: center; justify-content: space-between; margin-top: 18px;
}
.total-banner .label { font-size: 12.5px; color: #9DB2C6; text-transform: uppercase; letter-spacing: .06em; }
.total-banner .amount { font-family: var(--font-mono); font-size: 30px; font-weight: 700; color: var(--accent); margin-top: 4px; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(9, 14, 24, .5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 460px; box-shadow: var(--shadow-md); max-height: 90vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-close { border: none; background: var(--surface-2); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; color: var(--ink-soft); }

.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 8px; animation: toast-in .2s ease; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-faint); }
.empty-state svg { width: 46px; height: 46px; margin-bottom: 12px; opacity: .5; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .login-shell { grid-template-columns: 1fr; } .login-visual { display: none; } }
.login-visual { background: var(--navy); display: flex; flex-direction: column; justify-content: center; padding: 60px; color: #fff; position: relative; overflow: hidden; }
.login-visual::before {
    content: ''; position: absolute; width: 480px; height: 480px; border-radius: 50%;
    border: 1px solid rgba(255,255,255,.06); top: -120px; right: -160px;
}
.login-visual::after {
    content: ''; position: absolute; width: 340px; height: 340px; border-radius: 50%;
    border: 1px solid rgba(255,255,255,.08); bottom: -140px; right: -60px;
}
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-box { width: 100%; max-width: 360px; }
.login-error { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px; display: none; }

/* ---------- Utilidades ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .gap-14 { gap: 14px; }
.mt-8 { margin-top: 8px; } .mt-14 { margin-top: 14px; } .mt-20 { margin-top: 20px; } .mt-24 { margin-top: 24px; }
.mb-14 { margin-bottom: 14px; }
.text-soft { color: var(--ink-soft); }
.text-faint { color: var(--ink-faint); }
.text-sm { font-size: 12.5px; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Impresión (usada por factura-ver.html para exportar a PDF) ---------- */
@media print {
    .no-print { display: none !important; }
    .shell { display: block; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: none; }
}
