/* ============ Reset + Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-feature-settings: "cv02","cv03","cv04","cv11";
  background: #0a0a0b;
  color: #f4f4f5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; cursor: pointer; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
ul { list-style: none; }
.mono { font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace; }
.num  { font-variant-numeric: tabular-nums; }
.muted { color: #6b6b76; }

/* ============ Colors (custom props) ============ */
:root {
  --sultana-100: #d6f5c9;
  --sultana-200: #b1ea99;
  --sultana-300: #84db61;
  --sultana-400: #5fc83a;
  --sultana-500: #43ad21;
  --sultana-600: #338a17;
  --sultana-700: #296a15;
  --sultana-800: #235416;
  --sultana-900: #1f4716;
  --cherry-500: #dc2626;
  --cherry-600: #b91c1c;
  --amber-500: #f59e0b;
  --ink-950: #0a0a0b;
  --ink-900: #101012;
  --ink-850: #141417;
  --ink-800: #17171a;
  --ink-700: #1f1f23;
  --ink-600: #2a2a30;
  --ink-500: #3a3a42;
  --ink-400: #6b6b76;
  --ink-300: #a1a1aa;
  --ink-200: #d4d4d8;
  --ink-100: #f4f4f5;
}

/* ============ Layout ============ */
.layout { display: flex; min-height: 100vh; }

/* ============ Sidebar ============ */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: rgba(16, 16, 18, 0.85);
  backdrop-filter: blur(8px);
  border-right: 1px solid rgba(31, 31, 35, 0.6);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(31, 31, 35, 0.6);
}
.brand-logo {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--sultana-500);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 18px;
  box-shadow: 0 0 24px -4px rgba(67, 173, 33, 0.45);
}
.brand-title { font-size: 14px; font-weight: 600; line-height: 1.1; }
.brand-sub {
  font-size: 10px; color: var(--ink-400);
  text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px;
}

.nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-group {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-400); padding: 12px 12px 8px;
  font-weight: 500;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 6px;
  color: var(--ink-300); font-size: 13px;
  transition: background 0.12s ease;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(31, 31, 35, 0.5); }
.nav-item.active {
  background: rgba(67, 173, 33, 0.1);
  color: var(--sultana-300);
  font-weight: 500;
}
.nav-item .badge { margin-left: auto; }

.user-card {
  padding: 12px;
  border-top: 1px solid rgba(31, 31, 35, 0.6);
  display: flex; align-items: center; gap: 12px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--sultana-500), var(--sultana-700));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.user-name { font-size: 12px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--ink-400); }

/* ============ Main + Topbar ============ */
.main { flex: 1; min-width: 0; }
.topbar {
  height: 64px;
  border-bottom: 1px solid rgba(31, 31, 35, 0.6);
  background: rgba(16, 16, 18, 0.6);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-right { margin-left: auto; }

.btn-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 6px;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  color: var(--ink-100); font-size: 13px;
  transition: background 0.12s;
}
.btn-pill:hover { background: var(--ink-700); }
.btn-pill strong { font-weight: 600; }

.btn-icon {
  width: 36px; height: 36px; border-radius: 6px;
  background: var(--ink-800); border: 1px solid var(--ink-700);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.btn-icon:hover { background: var(--ink-700); }
.badge-bell {
  position: absolute; top: -4px; right: -4px;
  width: 16px; height: 16px;
  background: var(--cherry-500);
  border-radius: 50%;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.live-indicator {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--ink-300);
}

/* ============ Page ============ */
.page {
  padding: 32px;
  max-width: 1600px;
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 24px;
}
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.eyebrow {
  font-size: 11px; color: var(--sultana-400);
  font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.page-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.page-sub { color: var(--ink-400); font-size: 13px; margin-top: 4px; }

.filters { display: flex; gap: 8px; }
.btn-filter {
  padding: 6px 12px; border-radius: 6px;
  background: transparent;
  border: 1px solid var(--ink-700);
  color: var(--ink-300); font-size: 12px;
}
.btn-filter:hover { background: var(--ink-800); }
.btn-filter.active {
  background: rgba(67, 173, 33, 0.1);
  color: var(--sultana-300);
  border-color: rgba(67, 173, 33, 0.3);
  font-weight: 500;
}

/* ============ Grid ============ */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }

@media (max-width: 1024px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
  .span-2 { grid-column: span 2; }
  .sidebar { display: none; }
}
@media (max-width: 640px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .page { padding: 16px; }
}

/* ============ Card ============ */
.card {
  background:
    radial-gradient(ellipse at top, rgba(67,173,33,0.06), transparent 60%),
    var(--ink-800);
  border-radius: 12px;
  padding: 20px;
  box-shadow:
    inset 0 1px 0 0 rgba(255,255,255,0.04),
    0 0 0 1px rgba(255,255,255,0.04);
  position: relative;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-sub { font-size: 11px; color: var(--ink-400); margin-top: 2px; }

/* ============ KPI ============ */
.kpi-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.kpi-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-400); font-weight: 500;
}
.kpi-value-row { display: flex; align-items: baseline; gap: 8px; }
.kpi-value {
  font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.kpi-value-sm { font-size: 22px; font-weight: 400; color: var(--ink-400); }
.kpi-delta { font-size: 13px; font-weight: 500; }
.kpi-delta.up { color: var(--sultana-400); }
.kpi-delta.down { color: var(--cherry-500); }
.kpi-sub { font-size: 11px; color: var(--ink-400); margin-top: 4px; }
.spark { height: 40px !important; margin-top: 12px; width: 100% !important; }

.bars-row { display: flex; gap: 4px; margin-top: 12px; }
.bar { flex: 1; height: 8px; border-radius: 4px; background: var(--ink-700); }
.bar.on { background: var(--sultana-500); }

/* ============ Pill / Badge ============ */
.pill {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  font-weight: 500; display: inline-block;
}
.pill-sultana { background: rgba(67, 173, 33, 0.2); color: var(--sultana-300); }
.pill-cherry  { background: rgba(220, 38, 38, 0.2); color: var(--cherry-500); }
.pill-amber   { background: rgba(245, 158, 11, 0.2); color: var(--amber-500); }

.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  font-weight: 500; font-family: 'JetBrains Mono', monospace;
}
.badge-cherry { background: rgba(220, 38, 38, 0.2); color: var(--cherry-500); }

/* ============ Dot / Pulse ============ */
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--sultana-400);
  display: inline-block;
}
.dot.small { width: 6px; height: 6px; }
.dot.cherry { background: var(--cherry-500); }
.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ============ Icons ============ */
.icon, .icon-xs, .icon-muted, .icon-sultana {
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.icon { width: 16px; height: 16px; }
.icon-xs { width: 12px; height: 12px; }
.icon-muted { color: var(--ink-400); }
.icon-sultana { color: var(--sultana-400); }

/* ============ Heatmap ============ */
.heatmap { overflow-x: auto; }
.heatmap-grid {
  display: grid;
  grid-template-columns: 36px repeat(18, minmax(20px, 1fr));
  gap: 3px;
  align-items: center;
  margin-bottom: 3px;
}
.heatmap-grid > .label {
  font-size: 10px; color: var(--ink-400);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
}
.heatmap-grid > .row-label {
  font-size: 10px; color: var(--ink-400);
  font-family: 'JetBrains Mono', monospace;
  text-align: left;
}
.heatmap-cell {
  aspect-ratio: 1; border-radius: 3px;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.heatmap-cell:hover { transform: scale(1.2); z-index: 10; position: relative; }
.h-0 { background: var(--ink-700); }
.h-1 { background: var(--sultana-900); }
.h-2 { background: var(--sultana-700); }
.h-3 { background: var(--sultana-500); }
.h-4 { background: var(--sultana-400); }
.h-5 { background: var(--sultana-300); }

.legend { display: flex; align-items: center; gap: 8px; font-size: 10px; color: var(--ink-400); }
.legend-swatches { display: flex; gap: 2px; }
.legend-swatches i {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}
.sw-1 { background: var(--sultana-900); }
.sw-2 { background: var(--sultana-700); }
.sw-3 { background: var(--sultana-500); }
.sw-4 { background: var(--sultana-400); }
.sw-5 { background: var(--sultana-300); }

.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-300); margin-right: 12px;
}
.sw {
  width: 10px; height: 10px; border-radius: 2px; display: inline-block;
}
.sw-solid { background: var(--sultana-500); }
.sw-dashed {
  background: rgba(67,173,33,0.4);
  border: 1px dashed var(--sultana-500);
}

/* ============ Alerts ============ */
.alerts {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 360px; overflow-y: auto; padding-right: 4px;
}
.alerts::-webkit-scrollbar { width: 6px; }
.alerts::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 999px; }

.alert {
  display: flex; gap: 12px;
  padding: 12px; border-radius: 8px;
  border: 1px solid transparent;
}
.alert.critical { background: rgba(220, 38, 38, 0.05); border-color: rgba(220, 38, 38, 0.2); }
.alert.warn     { background: rgba(245, 158, 11, 0.05); border-color: rgba(245, 158, 11, 0.2); }
.alert.info:hover { background: rgba(255,255,255,0.02); }

.alert-icon {
  width: 32px; height: 32px; border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.alert.critical .alert-icon { background: rgba(220, 38, 38, 0.2); color: var(--cherry-500); }
.alert.warn .alert-icon { background: rgba(245, 158, 11, 0.2); color: var(--amber-500); }
.alert .icon-ok { background: rgba(67, 173, 33, 0.2); color: var(--sultana-400); }
.alert .icon-neutral { background: var(--ink-700); color: var(--ink-300); }

.alert-body { min-width: 0; flex: 1; }
.alert-title {
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.alert-body p { font-size: 12px; color: var(--ink-300); margin-top: 2px; }
.alert-time { font-size: 10px; color: var(--ink-500); margin-top: 4px; }

.link {
  color: var(--sultana-400); font-size: 12px; font-weight: 500;
}
.link:hover { color: var(--sultana-300); }

/* ============ Charts ============ */
.chart-container { position: relative; width: 100%; }
.chart-tall { height: 280px; }
.chart-mid { height: 260px; }
.donut-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 200px; margin-bottom: 16px;
}
.donut-wrap canvas { max-width: 200px !important; max-height: 200px !important; }

.legend-list { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.legend-list li {
  display: flex; align-items: center; gap: 8px;
}
.legend-list .num { margin-left: auto; color: var(--ink-200); font-weight: 500; }

/* ============ Cameras ============ */
.cams { display: flex; flex-direction: column; gap: 8px; }
.cams li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border-radius: 8px;
  background: rgba(23, 23, 26, 0.4);
}
.cam-icon {
  width: 36px; height: 36px; border-radius: 6px;
  background: rgba(67, 173, 33, 0.15);
  color: var(--sultana-400);
  display: flex; align-items: center; justify-content: center;
}
.cam-body { flex: 1; min-width: 0; }
.cam-name { font-size: 13px; font-weight: 500; }
.cam-meta { font-size: 11px; color: var(--ink-400); margin-top: 2px; }

/* ============ Inteligencia operativa ============ */
.ops-table-wrap { overflow-x: auto; }
.ops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ops-table th {
  text-align: left;
  padding: 8px 12px;
  color: var(--ink-400);
  font-weight: 500;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--ink-700);
  background: rgba(255,255,255,0.02);
}
.ops-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--ink-800);
  color: var(--ink-200);
  font-variant-numeric: tabular-nums;
}
.ops-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.ops-table .ops-time {
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink-300);
}
.ops-table .ops-day {
  font-weight: 500;
  color: var(--sultana-300);
}
.ops-table .ops-hours {
  font-weight: 600;
}
.ops-table .ops-delta-up   { color: var(--sultana-400); font-weight: 500; }
.ops-table .ops-delta-down { color: var(--cherry-500); font-weight: 500; }
.ops-table .ops-delta-flat { color: var(--ink-400); }

.dow-rank {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dow-rank-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(23,23,26,0.4);
  font-size: 12px;
}
.dow-rank-item.top { background: rgba(67,173,33,0.08); border-left: 3px solid var(--sultana-500); }
.dow-rank-position {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-400);
  min-width: 24px;
}
.dow-rank-item.top .dow-rank-position { color: var(--sultana-400); }
.dow-rank-name {
  flex: 1;
  font-weight: 500;
  color: var(--ink-100);
}
.dow-rank-bar {
  flex: 2;
  height: 6px;
  background: var(--ink-700);
  border-radius: 3px;
  overflow: hidden;
}
.dow-rank-bar-fill {
  height: 100%;
  background: var(--sultana-500);
  border-radius: 3px;
}
.dow-rank-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-300);
  min-width: 50px;
  text-align: right;
}

/* ============ Events grid (Planta) ============ */
.events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.event-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--ink-900);
  border: 1px solid var(--ink-700);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.event-card:hover { transform: translateY(-2px); border-color: var(--sultana-500); }
.event-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  background: var(--ink-800);
}
.event-meta {
  padding: 10px 12px;
  font-size: 11px;
}
.event-meta .row-1 {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.event-time {
  color: var(--ink-300); font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
}
.event-conf {
  font-size: 10px; font-family: 'JetBrains Mono', monospace;
  padding: 2px 6px; border-radius: 4px;
  background: rgba(67,173,33,0.2); color: var(--sultana-300);
}
.event-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.event-tag {
  font-size: 9px; padding: 2px 5px; border-radius: 3px;
  background: var(--ink-700); color: var(--ink-300);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.event-tag.violation { background: rgba(220,38,38,0.2); color: var(--cherry-500); }
.event-tag.vehicle   { background: rgba(245,158,11,0.2); color: var(--amber-500); }
.event-tag.person    { background: rgba(67,173,33,0.15); color: var(--sultana-300); }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 40px;
}
.modal-backdrop.visible { display: flex; }
.modal-body {
  position: relative;
  max-width: 90vw; max-height: 90vh;
  background: var(--ink-800);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-body img {
  max-width: 90vw; max-height: 80vh;
  display: block;
  object-fit: contain;
}
.modal-meta {
  padding: 12px 16px;
  background: var(--ink-900);
  color: var(--ink-300);
  font-size: 12px;
  border-top: 1px solid var(--ink-700);
}
.modal-close {
  position: absolute; top: 8px; right: 8px;
  width: 32px; height: 32px;
  background: rgba(0,0,0,0.6);
  border-radius: 50%;
  color: white;
  font-size: 20px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
}
.modal-close:hover { background: var(--cherry-500); }

.hidden { display: none !important; }

/* ============ Footer ============ */
.footer {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--ink-500);
  padding-top: 16px; margin-top: 16px;
  border-top: 1px solid var(--ink-800);
}
