/* ════════════════════════════════════════════════════════════════════════════
   APP.CSS — Sistema de Facturación
   Layout: Sidebar fijo + Topbar + Área de contenido
   Las variables :root son los DEFAULTS; el módulo Diseño las sobreescribe
   cargando /diseno/tema.css después de este archivo.
════════════════════════════════════════════════════════════════════════════ */

/* ── Variables por defecto ───────────────────────────────────────────────── */
:root {
    --color-primario:        #1e3a5f;
    --color-acento:          #2563eb;
    --color-acento-hover:    #1d4ed8;
    --color-exito:           #10b981;
    --color-peligro:         #ef4444;
    --color-advertencia:     #f59e0b;
    --color-fondo:           #f1f5f9;
    --color-superficie:      #ffffff;
    --color-borde:           #e2e8f0;
    --color-texto:           #1e293b;
    --color-texto-suave:     #94a3b8;
    --color-sidebar-texto:   #94a3b8;
    --color-sidebar-hover:   rgba(255,255,255,0.08);
    --color-sidebar-active:  rgba(255,255,255,0.15);
    --fuente-principal:      'Inter', system-ui, sans-serif;
    --fuente-titulos:        'Inter', system-ui, sans-serif;
    --fuente-codigo:         'JetBrains Mono', monospace;
    --tamano-base:           15px;
    --peso-titulos:          700;
    --radio-borde:           8px;
    --radio-borde-lg:        12px;
    --sombra-card:           0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
    --sombra-sidebar:        2px 0 16px rgba(0,0,0,.12);
    --sidebar-ancho:         256px;
    --navbar-alto:           56px;
    --contenido-max-ancho:   1200px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { font-family: var(--fuente-principal); font-size: var(--tamano-base); line-height: 1.6; background: var(--color-fondo); color: var(--color-texto); min-height: 100vh; }

/* Forzar herencia de tipografía en elementos nativos que el navegador no hereda */
input, select, textarea, button, optgroup, option {
    font-family: var(--fuente-principal);
    font-size: inherit;
    color: inherit;
}
a { color: var(--color-acento); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4,h5,h6 { font-family: var(--fuente-titulos); font-weight: var(--peso-titulos); color: var(--color-texto); line-height: 1.3; }
code, pre { font-family: var(--fuente-codigo); }

/* ════════════════════════════════════════════════════════════════════════════
   SIDEBAR LAYOUT
════════════════════════════════════════════════════════════════════════════ */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-ancho);
    background: var(--color-primario);
    display: flex; flex-direction: column;
    z-index: 200;
    box-shadow: var(--sombra-sidebar);
    transition: transform .25s ease;
    overflow-y: auto; overflow-x: hidden;
}
.sidebar-brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.1rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-brand-icon { font-size: 1.35rem; line-height: 1; }
.sidebar-brand-name { font-weight: 700; font-size: .95rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { flex: 1; padding: .75rem .75rem 0; display: flex; flex-direction: column; gap: .15rem; }
.sidebar-nav-label { font-size: .62rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: rgba(255,255,255,.3); padding: .5rem .5rem .35rem; margin-bottom: .15rem; }
.sidebar-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .85rem; border-radius: var(--radio-borde); color: var(--color-sidebar-texto); font-size: .875rem; font-weight: 500; transition: background .15s, color .15s; text-decoration: none; white-space: nowrap; }
.sidebar-link:hover { background: var(--color-sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-link.active { background: var(--color-sidebar-active, rgba(255,255,255,.15)); color: #fff; }
.sidebar-link-icon { font-size: 1rem; width: 1.25rem; text-align: center; flex-shrink: 0; }
.sidebar-footer { padding: .85rem 1rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.sidebar-user { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.sidebar-user-avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; font-weight: 700; font-size: .85rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { font-size: .82rem; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: .7rem; color: rgba(255,255,255,.45); text-transform: capitalize; }
.sidebar-logout { font-size: 1.1rem; color: rgba(255,255,255,.35); transition: color .15s; text-decoration: none; flex-shrink: 0; padding: .25rem; }
.sidebar-logout:hover { color: var(--color-peligro); text-decoration: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 199; backdrop-filter: blur(1px); }

/* ── Main wrapper ────────────────────────────────────────────────────────── */
.main-wrapper { margin-left: var(--sidebar-ancho); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .25s ease; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 100; height: var(--navbar-alto); background: var(--color-superficie); border-bottom: 1px solid var(--color-borde); display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; }
.topbar-toggle { display: none; flex-direction: column; justify-content: center; gap: 4px; width: 28px; height: 28px; background: none; border: none; cursor: pointer; padding: 2px; flex-shrink: 0; }
.topbar-toggle span { display: block; height: 2px; background: var(--color-texto); border-radius: 2px; }
.topbar-title { flex: 1; font-size: 1rem; font-weight: 700; color: var(--color-texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: .85rem; flex-shrink: 0; }
.topbar-version { font-size: .75rem; color: var(--color-texto-suave); font-family: var(--fuente-codigo); }
.topbar-logout-btn { font-size: .8rem; color: var(--color-texto-suave); padding: .3rem .75rem; border-radius: 20px; border: 1px solid var(--color-borde); transition: all .15s; text-decoration: none; }
.topbar-logout-btn:hover { color: var(--color-peligro); border-color: var(--color-peligro); text-decoration: none; }

/* ── Contenido / Footer ──────────────────────────────────────────────────── */
.page-content { flex: 1; padding: 2rem; max-width: var(--contenido-max-ancho); width: 100%; }
.footer { padding: .85rem 2rem; font-size: .78rem; color: var(--color-texto-suave); border-top: 1px solid var(--color-borde); background: var(--color-superficie); }

/* Sin auth */
.no-sidebar .container { max-width: 480px; margin: 0 auto; padding: 2rem 1.25rem; }
.auth-page-wrap { min-height: 100vh; display: flex; flex-direction: column; }

/* ════════════════════════════════════════════════════════════════════════════
   COMPONENTES
════════════════════════════════════════════════════════════════════════════ */

/* Alertas */
.alert { padding: .85rem 1.1rem; border-radius: var(--radio-borde); margin-bottom: 1.25rem; font-size: .9rem; border-left: 4px solid transparent; }
.alert-success { background: #ecfdf5; border-color: var(--color-exito);       color: #065f46; }
.alert-danger   { background: #fef2f2; border-color: var(--color-peligro);     color: #991b1b; }
.alert-warning  { background: #fffbeb; border-color: var(--color-advertencia); color: #92400e; }
.alert-info     { background: #eff6ff; border-color: var(--color-acento);      color: #1e40af; }

/* Auth box */
.auth-box { background: var(--color-superficie); border-radius: var(--radio-borde-lg); box-shadow: var(--sombra-card); max-width: 420px; margin: 3rem auto; padding: 2.5rem 2rem; }
.auth-box h1 { font-size: 1.4rem; margin-bottom: 1.5rem; color: var(--color-primario); text-align: center; }

/* Formularios */
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: .78rem; font-weight: 600; margin-bottom: .35rem; color: var(--color-texto-suave); text-transform: uppercase; letter-spacing: .04em; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: .6rem .9rem; border: 1.5px solid var(--color-borde); border-radius: var(--radio-borde); font-size: .92rem; font-family: var(--fuente-principal); transition: border-color .15s, box-shadow .15s; background: var(--color-superficie); color: var(--color-texto); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--color-acento); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-acento) 18%, transparent); }

/* Botones */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1.1rem; border-radius: var(--radio-borde); border: none; font-size: .875rem; font-weight: 600; font-family: var(--fuente-principal); cursor: pointer; transition: background .15s, box-shadow .15s, transform .1s; text-decoration: none; line-height: 1; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.12); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn-primary   { background: var(--color-acento); color: #fff; }
.btn-primary:hover { background: var(--color-acento-hover); }
.btn-secondary { background: #e2e8f0; color: var(--color-texto); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success   { background: var(--color-exito);   color: #fff; }
.btn-danger    { background: var(--color-peligro); color: #fff; }
.btn-warning   { background: var(--color-advertencia); color: #fff; }
.btn-outline   { background: transparent; color: var(--color-acento); border: 1.5px solid var(--color-acento); }
.btn-outline:hover { background: var(--color-acento); color: #fff; }
.btn-sm    { padding: .3rem .75rem; font-size: .8rem; }
.btn-lg    { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; margin-top: .5rem; }

/* Tablas */
.table-wrapper { overflow-x: auto; border-radius: var(--radio-borde-lg); box-shadow: var(--sombra-card); border: 1px solid var(--color-borde); }
table { width: 100%; border-collapse: collapse; background: var(--color-superficie); font-size: .875rem; }
thead th { background: var(--color-primario); color: rgba(255,255,255,.9); padding: .8rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--color-borde); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: color-mix(in srgb, var(--color-acento) 4%, transparent); }
tbody td { padding: .75rem 1rem; color: var(--color-texto); vertical-align: middle; }

/* Cards */
.card { background: var(--color-superficie); border-radius: var(--radio-borde-lg); box-shadow: var(--sombra-card); border: 1px solid var(--color-borde); padding: 1.5rem; margin-bottom: 1.25rem; }
.card-title { font-size: 1rem; font-weight: 700; color: var(--color-primario); margin-bottom: .85rem; padding-bottom: .7rem; border-bottom: 1px solid var(--color-borde); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-header h1, .page-header h2 { font-size: 1.35rem; margin: 0; }
.page-header-actions { display: flex; gap: .5rem; align-items: center; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: .2rem .6rem; border-radius: 20px; font-size: .72rem; font-weight: 700; }
.badge-success   { background: #dcfce7; color: #166534; }
.badge-danger    { background: #fee2e2; color: #991b1b; }
.badge-warning   { background: #fef9c3; color: #92400e; }
.badge-info      { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: var(--color-borde); color: var(--color-texto-suave); }

/* Dashboard módulos */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.module-card { display: flex; flex-direction: column; align-items: center; gap: .6rem; background: var(--color-superficie); border-radius: var(--radio-borde-lg); padding: 1.5rem 1rem; box-shadow: var(--sombra-card); border: 1px solid var(--color-borde); font-weight: 600; font-size: .875rem; color: var(--color-primario); transition: box-shadow .15s, transform .15s, border-color .15s; text-decoration: none; text-align: center; }
.module-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.12); transform: translateY(-3px); border-color: var(--color-acento); text-decoration: none; }
.module-icon { font-size: 2.2rem; line-height: 1; }

/* Stats */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-card { background: var(--color-superficie); border-radius: var(--radio-borde-lg); padding: 1.1rem 1.5rem; box-shadow: var(--sombra-card); border: 1px solid var(--color-borde); text-align: center; min-width: 130px; flex: 1; }
.stat-num   { display: block; font-size: 2rem; font-weight: 800; color: var(--color-primario); }
.stat-label { display: block; font-size: .78rem; color: var(--color-texto-suave); margin-top: .2rem; }

/* Errores */
.error-page { text-align: center; padding: 4rem 1rem; }
.error-page h1 { font-size: 5rem; color: var(--color-borde); margin-bottom: .5rem; font-weight: 900; }
.error-page p  { color: var(--color-texto-suave); margin-bottom: 1.5rem; }

/* Utilidades */
.mt-1{margin-top:.25rem}.mt-2{margin-top:.5rem}.mt-3{margin-top:1rem}.mt-4{margin-top:1.5rem}
.mb-1{margin-bottom:.25rem}.mb-2{margin-bottom:.5rem}.mb-3{margin-bottom:1rem}.mb-4{margin-bottom:1.5rem}
.text-center{text-align:center}.text-right{text-align:right}
.text-muted{color:var(--color-texto-suave);font-size:.875rem}.text-small{font-size:.8rem}
.d-flex{display:flex}.flex-wrap{flex-wrap:wrap}
.justify-between{justify-content:space-between}.justify-end{justify-content:flex-end}.align-center{align-items:center}
.gap-1{gap:.25rem}.gap-2{gap:.5rem}.gap-3{gap:1rem}.w-100{width:100%}

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-ancho))); box-shadow: none; }
    .sidebar.open { transform: translateX(0); box-shadow: var(--sombra-sidebar); }
    .sidebar-overlay.open { display: block; }
    .main-wrapper { margin-left: 0; }
    .topbar-toggle { display: flex; }
    .page-content { padding: 1.25rem 1rem; }
    .page-header { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 480px) {
    .stats-row { flex-direction: column; }
    .stat-card { min-width: 0; }
    .module-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
