/* ============================================================
   PARTE 3B — ARCHIVO: styles.css
   Estética: Industrial Dark — Acero, Grafito, Ámbar/Dorado
   Tipografía: Bebas Neue (display) + Barlow (cuerpo) + DM Mono (datos)
============================================================ */

/* ── Variables de diseño ─────────────────────────────────── */
:root {
  /* Paleta industrial */
  --bg-void:        #080909;
  --bg-base:        #0c0e10;
  --bg-surface:     #111418;
  --bg-raised:      #181d22;
  --bg-hover:       #1e252d;
  --bg-active:      #242c36;

  /* Bordes */
  --border-subtle:  rgba(255,255,255,0.05);
  --border-mid:     rgba(255,255,255,0.09);
  --border-strong:  rgba(255,255,255,0.15);

  /* Acento principal: Ámbar industrial */
  --accent:         #e8a923;
  --accent-dim:     rgba(232,169,35,0.15);
  --accent-glow:    rgba(232,169,35,0.35);
  --accent-dark:    #b87d0f;

  /* Semáforo financiero */
  --green:          #2ecc71;
  --green-dim:      rgba(46,204,113,0.12);
  --red:            #e74c3c;
  --red-dim:        rgba(231,76,60,0.12);
  --blue:           #3498db;
  --blue-dim:       rgba(52,152,219,0.12);
  --orange:         #f39c12;
  --orange-dim:     rgba(243,156,18,0.12);

  /* Texto */
  --text-primary:   #e8eaed;
  --text-secondary: #8a9099;
  --text-muted:     #4e5560;
  --text-accent:    var(--accent);

  /* Tipografía */
  --font-display:   'Bebas Neue', 'Impact', sans-serif;
  --font-body:      'Barlow', sans-serif;
  --font-mono:      'DM Mono', 'Courier New', monospace;

  /* Espaciado */
  --sidebar-w:      260px;
  --topbar-h:       56px;
  --radius:         3px;
  --radius-md:      5px;

  /* Sombras */
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,0.6);
  --glow-accent:0 0 20px var(--accent-glow);

  /* Transiciones */
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; scroll-behavior: smooth; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  /* Textura industrial sutil */
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255,255,255,0.012) 2px,
      rgba(255,255,255,0.012) 3px
    );
}

a { color: var(--accent); text-decoration: none; transition: opacity var(--transition); }
a:hover { opacity: 0.8; }

input, select, textarea, button { font-family: var(--font-body); }

/* ── Scrollbar industrial ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ════════════════════════════════════════════════════════════
   APP LOADER
════════════════════════════════════════════════════════════ */
.app-loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-void);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.app-loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }

.loader-logo svg { width: 80px; height: 80px; animation: loaderPulse 1.5s ease-in-out infinite; }
@keyframes loaderPulse {
  0%, 100% { filter: drop-shadow(0 0 8px var(--accent-glow)); }
  50%       { filter: drop-shadow(0 0 20px var(--accent-glow)); }
}

.loader-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.3em;
  color: var(--text-secondary);
}

.loader-bar {
  width: 200px; height: 2px;
  background: var(--bg-raised);
}
.loader-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  animation: loaderFill 1.8s ease forwards;
}
@keyframes loaderFill { to { width: 100%; } }

/* ════════════════════════════════════════════════════════════
   TOAST
════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 8000; display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1.2rem;
  background: var(--bg-raised);
  border: 1px solid var(--border-mid);
  border-left: 3px solid var(--accent);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease;
  max-width: 360px;
}
.toast.toast-success { border-left-color: var(--green); }
.toast.toast-error   { border-left-color: var(--red); }
.toast.toast-info    { border-left-color: var(--blue); }
@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-mid);
  display: flex; flex-direction: column;
  z-index: 1000;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar-logo svg { width: 32px; height: 32px; flex-shrink: 0; }
.sidebar-brand { flex: 1; min-width: 0; }
.brand-name {
  display: block;
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  color: var(--text-primary);
  line-height: 1;
}
.brand-sub {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-close {
  display: none; background: none; border: none;
  color: var(--text-secondary); cursor: pointer;
  padding: 4px;
}
.sidebar-close svg { width: 18px; height: 18px; }

/* WS Status */
.ws-status {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono); font-size: 0.7rem;
  color: var(--text-muted);
}
.ws-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.4s;
  flex-shrink: 0;
}
.ws-dot.connected    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.ws-dot.disconnected { background: var(--red); }
.ws-dot.connecting   { background: var(--orange); animation: wsPulse 1s ease-in-out infinite; }
@keyframes wsPulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Period Selector */
.period-selector {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}
.period-label {
  display: block;
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.12em; color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.period-controls { display: flex; gap: 0.5rem; }
.period-select {
  flex: 1;
  background: var(--bg-raised); color: var(--text-primary);
  border: 1px solid var(--border-mid);
  padding: 0.4rem 0.5rem;
  font-family: var(--font-mono); font-size: 0.75rem;
  border-radius: var(--radius);
  cursor: pointer; outline: none;
  transition: border-color var(--transition);
}
.period-select:focus { border-color: var(--accent); }

/* Nav */
.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.75rem 0; }
.nav-list { list-style: none; }
.nav-item { margin: 0.1rem 0.75rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: all var(--transition);
  position: relative;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}
.nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: rgba(232,169,35,0.3);
}
.nav-link.active .nav-icon svg { stroke: var(--accent); }

.nav-icon { display: flex; align-items: center; flex-shrink: 0; }
.nav-icon svg { width: 16px; height: 16px; stroke: var(--text-muted); transition: stroke var(--transition); }
.nav-link:hover .nav-icon svg { stroke: var(--text-primary); }

.nav-label { font-size: 0.82rem; letter-spacing: 0.06em; font-weight: 500; }

.nav-badge {
  margin-left: auto;
  background: var(--bg-active);
  color: var(--text-secondary);
  font-family: var(--font-mono); font-size: 0.65rem;
  padding: 1px 6px; border-radius: 10px;
  min-width: 22px; text-align: center;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}
.sidebar-footer-time {
  font-family: var(--font-mono); font-size: 1.1rem;
  color: var(--accent); letter-spacing: 0.1em;
}
.sidebar-footer-date {
  font-family: var(--font-mono); font-size: 0.65rem;
  color: var(--text-muted); margin-top: 2px; letter-spacing: 0.08em;
}

/* Overlay móvil */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,0.7);
}

/* ════════════════════════════════════════════════════════════
   MAIN CONTENT
════════════════════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ── TOPBAR ── */
.topbar {
  position: sticky; top: 0; z-index: 900;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-mid);
  backdrop-filter: blur(8px);
}
.topbar-menu-btn {
  display: none; background: none; border: none;
  color: var(--text-secondary); cursor: pointer; padding: 4px;
}
.topbar-menu-btn svg { width: 20px; height: 20px; }

.topbar-title {
  font-family: var(--font-display);
  font-size: 1.3rem; letter-spacing: 0.2em;
  color: var(--text-primary); flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }

.topbar-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised); border: 1px solid var(--border-mid);
  color: var(--text-secondary); cursor: pointer; border-radius: var(--radius);
  transition: all var(--transition);
}
.topbar-btn svg { width: 16px; height: 16px; }
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.topbar-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.topbar-period-pill {
  font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.1em; color: var(--accent);
  border: 1px solid rgba(232,169,35,0.4);
  padding: 4px 12px;
  background: var(--accent-dim);
}

/* ── VIEWS ── */
.view { display: none; padding: 1.5rem; flex-direction: column; gap: 1.5rem; }
.view.active { display: flex; animation: viewIn 0.2s ease; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem;
}
.view-title {
  font-family: var(--font-display);
  font-size: 1.6rem; letter-spacing: 0.15em;
  color: var(--text-primary);
}

/* ════════════════════════════════════════════════════════════
   KPI CARDS
════════════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  padding: 1.25rem 1.25rem 1rem;
  position: relative; overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.kpi-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.kpi-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.kpi-ingresos::before { background: var(--green); }
.kpi-gastos::before   { background: var(--red); }
.kpi-ganancia::before { background: var(--accent); }
.kpi-objetivo::before { background: var(--blue); }

.kpi-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 0.75rem; }
.kpi-label {
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.14em; color: var(--text-muted);
}
.kpi-icon svg { width: 18px; height: 18px; opacity: 0.4; }
.kpi-ingresos .kpi-icon svg { stroke: var(--green); }
.kpi-gastos   .kpi-icon svg { stroke: var(--red); }
.kpi-ganancia .kpi-icon svg { stroke: var(--accent); }
.kpi-objetivo .kpi-icon svg { stroke: var(--blue); }

.kpi-value {
  font-family: var(--font-display);
  font-size: 2rem; letter-spacing: 0.05em;
  line-height: 1; margin-bottom: 0.4rem;
  transition: color 0.3s;
}
.kpi-ingresos .kpi-value { color: var(--green); }
.kpi-gastos   .kpi-value { color: var(--red); }
.kpi-ganancia .kpi-value { color: var(--accent); }
.kpi-objetivo .kpi-value { color: var(--blue); }

.kpi-sub {
  font-family: var(--font-mono); font-size: 0.7rem;
  color: var(--text-muted); margin-bottom: 0.75rem;
}

.kpi-bar { height: 2px; background: var(--bg-active); overflow: hidden; }
.kpi-bar-fill { height: 100%; transition: width 0.8s cubic-bezier(0.4,0,0.2,1); }
.kpi-bar-ingreso  { background: var(--green); }
.kpi-bar-gasto    { background: var(--red); }
.kpi-bar-ganancia { background: var(--accent); }
.kpi-bar-objetivo { background: var(--blue); }

/* ════════════════════════════════════════════════════════════
   CHART CARDS
════════════════════════════════════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.chart-wide  { grid-column: span 2; }
.chart-narrow { grid-column: span 1; }

.chart-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.chart-card-header { display: flex; align-items: baseline; justify-content: space-between; }
.chart-title {
  font-family: var(--font-mono); font-size: 0.68rem;
  letter-spacing: 0.14em; color: var(--text-muted);
}
.chart-subtitle { font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted); opacity: 0.6; }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap-doughnut { height: 180px; }
.chart-wrap-tall { height: 320px; }

/* Leyenda custom */
.chart-legend {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
}
.legend-item {
  display: flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-mono); font-size: 0.65rem; color: var(--text-muted);
}
.legend-dot { width: 8px; height: 8px; flex-shrink: 0; }

/* ════════════════════════════════════════════════════════════
   TABLES
════════════════════════════════════════════════════════════ */
.tables-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  overflow: hidden;
}
.table-card-full { grid-column: span 2; }

.table-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}
.table-title {
  font-family: var(--font-mono); font-size: 0.68rem;
  letter-spacing: 0.14em; color: var(--text-muted);
}
.table-link { font-family: var(--font-mono); font-size: 0.65rem; color: var(--accent); }

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.8rem;
}
.data-table th {
  font-family: var(--font-mono); font-size: 0.62rem;
  letter-spacing: 0.1em; color: var(--text-muted);
  padding: 0.6rem 1rem; text-align: left;
  border-bottom: 1px solid var(--border-mid);
  background: var(--bg-raised);
  white-space: nowrap;
  font-weight: 500;
}
.data-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: var(--font-mono); font-size: 0.78rem;
  white-space: nowrap;
  transition: background var(--transition);
}
.data-table tr:hover td { background: var(--bg-raised); }
.data-table tr:last-child td { border-bottom: none; }

.text-right  { text-align: right !important; }
.text-center { text-align: center !important; }

.table-empty {
  text-align: center !important;
  color: var(--text-muted) !important;
  padding: 2rem !important;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

/* Totales footer tabla */
.table-foot td {
  background: var(--bg-raised) !important;
  border-top: 1px solid var(--border-mid) !important;
  border-bottom: none !important;
}
.foot-label {
  font-family: var(--font-mono) !important;
  font-size: 0.65rem !important;
  letter-spacing: 0.1em !important;
  color: var(--text-muted) !important;
}
.foot-val {
  font-family: var(--font-display) !important;
  font-size: 1rem !important;
  color: var(--accent) !important;
}

/* Badges de estado */
.badge {
  display: inline-block; padding: 2px 8px;
  font-family: var(--font-mono); font-size: 0.62rem;
  letter-spacing: 0.08em; border-radius: var(--radius);
  font-weight: 500;
}
.badge-green   { background: var(--green-dim);  color: var(--green); }
.badge-red     { background: var(--red-dim);    color: var(--red); }
.badge-orange  { background: var(--orange-dim); color: var(--orange); }
.badge-blue    { background: var(--blue-dim);   color: var(--blue); }
.badge-accent  { background: var(--accent-dim); color: var(--accent); }
.badge-muted   { background: var(--bg-active);  color: var(--text-secondary); }

/* Valores numéricos en tabla */
.val-positive { color: var(--green) !important; }
.val-negative { color: var(--red) !important; }
.val-neutral  { color: var(--text-secondary) !important; }

/* Toolbar de tabla */
.table-toolbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.table-search {
  flex: 1; min-width: 200px;
  background: var(--bg-raised); color: var(--text-primary);
  border: 1px solid var(--border-mid);
  padding: 0.45rem 0.75rem;
  font-family: var(--font-mono); font-size: 0.75rem;
  border-radius: var(--radius); outline: none;
  transition: border-color var(--transition);
}
.table-search:focus { border-color: var(--accent); }
.table-search::placeholder { color: var(--text-muted); }
.table-toolbar-right { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Paginación */
.table-pagination {
  display: flex; align-items: center; justify-content: flex-end; gap: 0.25rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
}
.page-btn {
  min-width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raised); border: 1px solid var(--border-mid);
  color: var(--text-secondary); cursor: pointer;
  font-family: var(--font-mono); font-size: 0.7rem;
  border-radius: var(--radius); padding: 0 6px;
  transition: all var(--transition);
}
.page-btn:hover, .page-btn.active {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-dim);
}

/* ════════════════════════════════════════════════════════════
   MINI KPI ROW
════════════════════════════════════════════════════════════ */
.mini-kpi-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.mini-kpi {
  flex: 1; min-width: 140px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  padding: 0.75rem 1rem;
}
.mini-kpi-label {
  font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.12em; color: var(--text-muted);
  display: block; margin-bottom: 4px;
}
.mini-kpi-value {
  font-family: var(--font-display); font-size: 1.3rem;
  letter-spacing: 0.05em;
}

/* ════════════════════════════════════════════════════════════
   BOTONES
════════════════════════════════════════════════════════════ */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  font-family: var(--font-mono); font-size: 0.75rem;
  letter-spacing: 0.1em; font-weight: 500;
  border: 1px solid; border-radius: var(--radius);
  cursor: pointer; outline: none;
  transition: all var(--transition);
}
.btn-primary svg, .btn-secondary svg, .btn-danger svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--accent); color: #000;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-secondary {
  background: var(--bg-raised); color: var(--text-secondary);
  border-color: var(--border-mid);
}
.btn-secondary:hover { border-color: var(--border-strong); color: var(--text-primary); }

.btn-danger {
  background: var(--red-dim); color: var(--red);
  border-color: rgba(231,76,60,0.4);
}
.btn-danger:hover { background: var(--red); color: #fff; }

/* ════════════════════════════════════════════════════════════
   ACCIONES EN TABLA (iconos)
════════════════════════════════════════════════════════════ */
.action-btns { display: flex; gap: 0.35rem; justify-content: center; }
.action-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-mid);
  background: var(--bg-raised); cursor: pointer;
  border-radius: var(--radius); transition: all var(--transition);
  color: var(--text-muted);
}
.action-btn svg { width: 13px; height: 13px; }
.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.delete:hover { border-color: var(--red); color: var(--red); }

/* ════════════════════════════════════════════════════════════
   MODAL
════════════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 5000;
  background: rgba(0,0,0,0.8);
  display: none; align-items: center; justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: modalIn 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-sm { max-width: 400px; }
@keyframes modalIn {
  from { transform: scale(0.96) translateY(-10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-mid);
}
.modal-title {
  font-family: var(--font-display); font-size: 1.1rem;
  letter-spacing: 0.15em; color: var(--text-primary);
}
.modal-close {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; line-height: 1;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text-primary); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-mid);
}

.confirm-text {
  color: var(--text-secondary);
  font-size: 0.85rem; line-height: 1.6;
}

/* ════════════════════════════════════════════════════════════
   FORMULARIOS (dentro de modal)
════════════════════════════════════════════════════════════ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group.full { grid-column: span 2; }

.form-label {
  font-family: var(--font-mono); font-size: 0.65rem;
  letter-spacing: 0.1em; color: var(--text-muted);
}
.form-input {
  background: var(--bg-raised); color: var(--text-primary);
  border: 1px solid var(--border-mid);
  padding: 0.55rem 0.75rem;
  font-family: var(--font-mono); font-size: 0.8rem;
  border-radius: var(--radius); outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }
.form-input[readonly] { opacity: 0.6; cursor: not-allowed; }

textarea.form-input { resize: vertical; min-height: 70px; }

/* ════════════════════════════════════════════════════════════
   CONFIGURACIÓN
════════════════════════════════════════════════════════════ */
.config-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.config-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.config-card-title {
  font-family: var(--font-mono); font-size: 0.68rem;
  letter-spacing: 0.14em; color: var(--text-muted);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}
.config-stat-list { display: flex; flex-direction: column; gap: 0.6rem; }
.config-stat {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-secondary);
}
.stat-badge {
  font-size: 0.65rem; padding: 2px 8px;
  background: var(--bg-active); border-radius: 2px;
  color: var(--text-muted);
}
.stat-badge.stat-ok { background: var(--green-dim); color: var(--green); }
.stat-badge.stat-err { background: var(--red-dim); color: var(--red); }

/* ════════════════════════════════════════════════════════════
   CATÁLOGOS
════════════════════════════════════════════════════════════ */
.cat-tabs {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--border-mid);
  padding-bottom: 0;
}
.cat-tab {
  padding: 0.5rem 1.1rem;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  transition: all var(--transition);
  position: relative; bottom: -1px;
}
.cat-tab:hover { color: var(--text-primary); border-color: var(--border-mid); }
.cat-tab.active {
  color: var(--accent);
  border-color: var(--border-mid);
  border-bottom-color: var(--bg-card);
  background: var(--bg-card);
}
.btn-sm {
  padding: 0.35rem 0.85rem !important;
  font-size: 0.72rem !important;
}
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer; color: var(--text-secondary);
  transition: all var(--transition);
}
.btn-icon:hover { border-color: var(--border-strong); color: var(--text-primary); }
.btn-icon-danger:hover { border-color: var(--red); color: var(--red); }
.row-inactivo td { opacity: 0.45; }
.text-muted { color: var(--text-muted); }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤ 1100px)
════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .config-grid { grid-template-columns: 1fr 1fr; }
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤ 768px)
════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-260px);
    width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .sidebar-overlay.open { display: block; }

  .topbar-menu-btn { display: flex; }
  .main-content { margin-left: 0; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .kpi-value { font-size: 1.5rem; }

  .charts-row { grid-template-columns: 1fr; }
  .chart-wide { grid-column: span 1; }

  .tables-row { grid-template-columns: 1fr; }
  .table-card-full { grid-column: span 1; }

  .config-grid { grid-template-columns: 1fr; }

  .view { padding: 1rem; gap: 1rem; }
  .view-header { flex-direction: column; align-items: flex-start; }

  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: span 1; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ════════════════════════════════════════════════════════════
   ANIMACIONES DE ENTRADA (stagger)
════════════════════════════════════════════════════════════ */
.kpi-card { animation: cardIn 0.35s ease both; }
.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.10s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.20s; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ════════════════════════════════════════════════════════════
   UTILIDADES
════════════════════════════════════════════════════════════ */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }

/* ════════════════════════════════════════════════════════════
   REPORTE MENSUAL
════════════════════════════════════════════════════════════ */

/* Resumen rápido */
.rm-summary {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.rm-summary-item {
  flex: 1;
  min-width: 140px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}
.rm-summary-label {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
}
.rm-summary-value {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-top: 0.25rem;
}
.rm-summary-value.is-green { color: var(--green); }
.rm-summary-value.is-red   { color: var(--red); }
.rm-summary-value.is-accent{ color: var(--accent); }

/* Tabs */
.rm-tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border-mid);
}
.rm-tab-btn {
  padding: 0.55rem 2.2rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.rm-tab-btn:hover  { color: var(--text-secondary); }
.rm-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Panels */
.rm-panel        { display: none; }
.rm-panel.active { display: block; }

/* Tabla */
.rm-table-wrap { overflow-x: auto; }

.rm-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

/* Encabezado */
.rm-table thead tr {
  background: var(--bg-void);
}
.rm-table thead th {
  padding: 0.65rem 1rem;
  text-align: center;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--text-primary);
  border: 1px solid var(--border-mid);
  white-space: nowrap;
}
.rm-th-cat   { text-align: left !important; min-width: 190px; }
.rm-th-num   { min-width: 130px; }
.rm-th-pct   { min-width: 70px; }
.rm-th-exist {
  background: var(--accent) !important;
  color: #000 !important;
  font-weight: 700;
  min-width: 150px;
}

/* Filas */
.rm-row-even { background: var(--bg-surface); }
.rm-row-odd  { background: var(--bg-raised); }
.rm-table tbody tr:hover { background: var(--bg-hover); transition: background var(--transition); }

.rm-table td {
  padding: 0.45rem 1rem;
  border-right: 1px dashed var(--border-subtle);
  border-bottom: 1px dashed var(--border-subtle);
}
.rm-cat {
  text-align: left;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}
.rm-num { text-align: right; color: var(--text-primary); }
.rm-pct { text-align: right; color: var(--text-muted); }

/* Columna existencia */
.rm-exist     { text-align: right; color: var(--text-muted); }
.rm-exist-pos { color: var(--green); font-weight: 500; }

/* Fila total */
.rm-tfoot-row { background: var(--bg-active); border-top: 2px solid var(--accent); }
.rm-table tfoot td { padding: 0.65rem 1rem; border-right: 1px solid var(--border-mid); }
.rm-tfoot-label {
  text-align: left;
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.rm-tfoot-num  { text-align: right; color: var(--accent); font-family: var(--font-mono); font-size: 0.9rem; }
.rm-tfoot-pct  { text-align: right; color: var(--text-secondary); font-family: var(--font-mono); }
.rm-tfoot-exist{
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--green);
  background: var(--green-dim);
}
