/* ============================================
   HIC Console — Design System
   Dark theme, data-heavy operational app
   ============================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors — base */
  --bg: #0b0f14;
  --panel: #141a22;
  --panel-2: #1c242f;
  --panel-hover: #222d3a;
  --border: #2a3441;
  --border-strong: #3a4656;

  /* Colors — text */
  --text: #e6edf3;
  --text-2: #b8c2cc;
  --muted: #7d8a99;
  --subtle: #5a6472;

  /* Colors — semantic */
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --accent-dim: rgba(56, 189, 248, 0.12);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.12);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.12);
  --highlight: #fbbf24;

  /* Spacing scale (8px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radius — unificado */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Shadows — dark theme */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.45);
  --shadow-glow: 0 0 0 3px rgba(56,189,248,0.18);

  /* Transitions */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-med:  180ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", Monaco, Consolas, monospace;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Custom scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================
   Sidebar
   ============================================ */
#sidebar {
  width: 248px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
#sidebar h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
  margin: var(--space-2) var(--space-3) var(--space-6);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
#sidebar h1::before {
  content: '';
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}
#sidebar nav {
  display: flex; flex-direction: column;
  gap: 2px;
  flex: 1;
}
.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  padding: 9px 12px;
  text-align: left;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  font-family: inherit;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
  display: flex;
  align-items: center;
}
.nav-btn:hover {
  background: var(--panel-hover);
  color: var(--text);
}
.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.nav-btn.active::before {
  content: '';
  position: absolute;
  left: -8px; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.nav-btn.highlight {
  border: 1px solid var(--highlight);
  color: var(--highlight);
}
.nav-btn.highlight.active {
  background: var(--highlight);
  color: #0b0f14;
  border-color: var(--highlight);
}
.nav-btn.highlight.active::before { background: #0b0f14; }

.sidebar-footer {
  display: flex; flex-direction: column;
  gap: var(--space-1);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.sidebar-footer button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 7px var(--space-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  transition: all var(--t-fast);
}
.sidebar-footer button:hover {
  background: var(--panel-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.sidebar-footer button.danger { color: var(--danger); }
.sidebar-footer button.danger:hover { border-color: var(--danger); background: var(--danger-dim); }

/* ============================================
   Main content
   ============================================ */
#main {
  flex: 1;
  padding: var(--space-8) var(--space-8);
  max-width: calc(100vw - 248px);
  overflow-x: auto;
}
.view { display: none; }
.view.active { display: block; animation: fadeIn var(--t-med); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.view h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin-bottom: var(--space-1);
  color: var(--text);
}
.view .subtitle {
  color: var(--muted);
  margin-bottom: var(--space-6);
  font-size: 13px;
  max-width: 800px;
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  transition: border-color var(--t-fast);
}
.card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.card h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-3);
}

/* ============================================
   Grid helpers
   ============================================ */
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

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

/* ============================================
   Stat cards (KPIs) — con jerarquía hero/normal/compact
   ============================================ */
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-4);
  position: relative;
  transition: transform var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.stat:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.stat .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.stat .value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 6px;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

/* Semantic accent (left bar) */
.stat.success { border-left: 3px solid var(--success); }
.stat.success .value { color: var(--success); }
.stat.warn    { border-left: 3px solid var(--warn); }
.stat.warn .value { color: var(--warn); }
.stat.danger  { border-left: 3px solid var(--danger); }
.stat.danger .value { color: var(--danger); }

/* Hero stat — para el KPI #1 de la pantalla */
.stat.hero {
  grid-column: span 2;
  padding: var(--space-6);
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
}
.stat.hero .label { font-size: 12px; }
.stat.hero .value { font-size: 40px; font-weight: 700; margin-top: var(--space-2); }

/* ============================================
   Tables
   ============================================ */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--panel-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  position: sticky;
  top: 0;
  z-index: 2;
}
tbody tr { transition: background var(--t-fast); }
tbody tr:hover td { background: rgba(56,189,248,0.04); }
tbody tr:last-child td { border-bottom: none; }

td.num, th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 13px;
}

td .brand-tag {
  display: inline-block;
  background: var(--panel-2);
  color: var(--text-2);
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 10.5px;
  font-weight: 500;
  margin-right: 4px;
  letter-spacing: 0.2px;
}

/* Clickable rows */
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--accent-dim); }
td.clickable, th.clickable-th {
  cursor: pointer;
  transition: filter var(--t-fast);
}
td.clickable:hover, th.clickable-th:hover { filter: brightness(1.3); }
th.clickable-th { text-transform: none; letter-spacing: 0; }

/* ============================================
   Buttons
   ============================================ */
button.primary, button.secondary {
  font-family: inherit;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  padding: 9px 16px;
  transition: all var(--t-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
button.primary {
  background: var(--accent-2);
  border: 1px solid var(--accent-2);
  color: white;
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset, 0 1px 2px rgba(0,0,0,0.2);
}
button.primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, 0 4px 10px rgba(14,165,233,0.3);
}
button.primary:active { transform: translateY(0); }
button.secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
}
button.secondary:hover {
  background: var(--panel-2);
  border-color: var(--muted);
}
button.icon {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13px;
  transition: all var(--t-fast);
}
button.icon:hover {
  background: var(--panel-2);
  color: var(--text);
}
button.icon.danger:hover {
  color: var(--danger);
  background: var(--danger-dim);
}

/* ============================================
   Toolbar / filter area
   ============================================ */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.toolbar .filters { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ============================================
   Form elements
   ============================================ */
input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: auto;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}
input[type="date"] { color-scheme: dark; }

label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 500;
}

/* ============================================
   Period presets (segmented control)
   ============================================ */
.period-presets {
  display: flex;
  gap: 0;
  background: var(--panel-2);
  padding: 3px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}
.preset {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--t-fast);
}
.preset:hover { color: var(--text); }
.preset.active {
  background: var(--accent-2);
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

/* ============================================
   Matriz (heatmap table)
   ============================================ */
.matrix-wrapper { overflow-x: auto; }
.matrix {
  border-collapse: separate;
  border-spacing: 0;
}
.matrix th, .matrix td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-width: 90px;
  font-size: 12.5px;
}
.matrix th:first-child, .matrix td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 2;
  min-width: 240px;
  font-weight: 500;
}
.matrix thead th {
  background: var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.matrix thead th:first-child { z-index: 3; }
.matrix .cell-toggle {
  width: 100%;
  height: 28px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  font-family: inherit;
  transition: all var(--t-fast);
}
.matrix .cell-toggle:hover {
  background: var(--border);
  transform: scale(1.05);
}
.matrix .cell-toggle.active {
  background: var(--success);
  color: white;
  border-color: var(--success);
}
.matrix .brand-row td {
  background: var(--panel-2);
  font-weight: 600;
  color: var(--accent);
  text-align: left !important;
  letter-spacing: 0.3px;
}

/* ============================================
   Modal
   ============================================ */
#modal-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  pointer-events: auto;
  animation: fadeIn var(--t-fast);
}
.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--space-6);
  width: min(580px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp var(--t-med);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal h3 {
  margin-bottom: var(--space-5);
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
}
.modal .form-row { margin-bottom: var(--space-3); }
.modal .form-row input,
.modal .form-row select,
.modal .form-row textarea { width: 100%; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

/* ============================================
   Toast
   ============================================ */
#toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 13.5px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(12px);
  transition: all var(--t-med);
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow-md);
}
#toast.show {
  opacity: 1;
  transform: translateY(0);
}
#toast.success { border-left-color: var(--success); }
#toast.success::before { content: '✓ '; color: var(--success); font-weight: 700; }
#toast.error { border-left-color: var(--danger); }
#toast.error::before { content: '⚠ '; color: var(--danger); font-weight: 700; }

/* ============================================
   Tags (badges)
   ============================================ */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.tag.ok       { background: var(--success-dim); color: var(--success); }
.tag.low      { background: var(--warn-dim);    color: var(--warn); }
.tag.out      { background: var(--danger-dim);  color: var(--danger); }
.tag.expired  { background: var(--danger-dim);  color: var(--danger); }
.tag.expiring { background: var(--warn-dim);    color: var(--warn); }
.tag.up       { background: var(--success-dim); color: var(--success); }
.tag.down     { background: var(--danger-dim);  color: var(--danger); }
.tag.flat     { background: var(--panel-2);     color: var(--muted); }
.tag.new      { background: var(--accent-dim);  color: var(--accent); }

/* ============================================
   Empty state — siempre con CTA
   ============================================ */
.empty-state {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}
.empty-state::before {
  content: '—';
  display: block;
  font-size: 32px;
  color: var(--subtle);
  margin-bottom: var(--space-3);
  opacity: 0.5;
}

/* ============================================
   Filter chips (breadcrumb)
   ============================================ */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 4px 4px 4px 10px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid rgba(56,189,248,0.25);
}
.filter-chip b { font-weight: 600; color: var(--text); }
.filter-chip button {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  transition: background var(--t-fast);
}
.filter-chip button:hover { background: rgba(56,189,248,0.2); }

/* ============================================
   Bar chart (tendencia)
   ============================================ */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 200px;
  padding: var(--space-3) var(--space-1) 44px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.bar-wrap {
  flex: 1;
  min-width: 14px;
  max-width: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  position: relative;
}
.bar {
  width: 100%;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: filter var(--t-fast);
}
.bar-wrap:hover .bar { filter: brightness(1.3); }
.bar-label {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  white-space: nowrap;
  position: absolute;
  bottom: -28px;
  transform: rotate(-35deg);
  transform-origin: center top;
}
.bar-value {
  font-size: 10px;
  color: var(--muted);
  position: absolute;
  top: -18px;
  white-space: nowrap;
}
.bar-wrap:hover .bar-value { color: var(--accent); font-weight: 600; }

/* ============================================
   Inline bar (sparkline en tabla)
   ============================================ */
.inline-bar {
  width: 100%;
  height: 6px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
}
.inline-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: 3px;
  transition: width var(--t-med);
}

/* Sparkline blocky */
.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 22px; }
.spark-bar {
  width: 5px;
  min-height: 2px;
  background: var(--accent);
  border-radius: 1px;
  display: inline-block;
  opacity: 0.85;
}

/* ============================================
   Misc helpers
   ============================================ */
.muted { color: var(--muted); }
hr { border: none; border-top: 1px solid var(--border); margin: var(--space-4) 0; }

/* Links inline */
a { color: var(--accent); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--text); text-decoration: underline; }

/* Checkbox inline labels */
label:has(input[type="checkbox"]) {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-transform: none;
  letter-spacing: 0;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-2);
  cursor: pointer;
}

/* Code inline */
code {
  font-family: var(--font-mono);
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent);
  border: 1px solid var(--border);
}

/* ============================================
   Print-friendly (para exportar a PDF)
   ============================================ */
@media print {
  #sidebar { display: none !important; }
  #main { max-width: 100% !important; padding: 16px !important; }
  .view { display: none; }
  .view.active { display: block !important; }
  body { background: white !important; color: black !important; }
  .card, .stat {
    background: white !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }
  .card h3, .stat .value, h2, h3 { color: black !important; }
  .toolbar button, button.icon, button.primary, button.secondary,
  #dash-print, #dash-whatsapp, #dash-email, #pc-print, #pc-whatsapp, #pc-email { display: none !important; }
  table { font-size: 10.5px; }
  th { background: #eee !important; color: black !important; }
  tr:hover td { background: white !important; }
  .tag { border: 1px solid #999 !important; color: black !important; background: white !important; }
  a { color: black !important; text-decoration: none !important; }
  .bar { background: #666 !important; }
  .inline-bar > div { background: #666 !important; }
}
