:root {
  --bg: #0f0f14;
  --surface: #1a1a23;
  --surface-2: #22222d;
  --text: #f0f0f5;
  --muted: #8a8a9a;
  --border: #2a2a35;
  --on: #22c55e;
  --off: #ef4444;
  --accent: #3987e5;
  --series-bot: #3987e5;
  --series-manual: #d95926;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.3px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }

/* ---- navegacion ---- */
.nav {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.nav .brand { font-weight: 700; margin-right: auto; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.nav a.active, .nav a:hover { color: var(--text); }
.nav .user { color: var(--muted); font-size: 13px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px; margin-bottom: 16px;
}

/* ---- formularios ---- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 10px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #fca5a5; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.error { color: #fca5a5; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---- control ---- */
.big-toggle {
  width: 100%; padding: 20px; font-size: 18px; font-weight: 700; border: none;
  border-radius: var(--radius); cursor: pointer; color: #fff;
}
.big-toggle.on { background: var(--on); }
.big-toggle.off { background: var(--off); }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px;
  border-radius: 999px; font-size: 13px; font-weight: 600;
}
.pill.on { background: rgba(34, 197, 94, 0.15); color: var(--on); }
.pill.off { background: rgba(239, 68, 68, 0.15); color: var(--off); }
.pill.warn { background: rgba(250, 178, 25, 0.15); color: #fab219; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot.pulse { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr img { display: block; width: 260px; height: 260px; }

/* ---- reportes ---- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.shortcuts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend span::before {
  content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  margin-right: 6px; vertical-align: -1px; background: var(--c);
}
.chart { position: relative; overflow-x: auto; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 180px; min-width: 100%; border-bottom: 1px solid var(--border); }
.bar {
  flex: 1 0 14px; height: 100%; display: flex; flex-direction: column-reverse; gap: 2px;
  cursor: default; position: relative;
}
.bar:hover { background: rgba(255, 255, 255, 0.04); }
.seg { width: 100%; }
.seg.bot { background: var(--series-bot); }
.seg.manual { background: var(--series-manual); }
.bar .seg:last-child { border-radius: 4px 4px 0 0; }
.axis { display: flex; gap: 4px; min-width: 100%; font-size: 11px; color: var(--muted); margin-top: 4px; }
.axis div { flex: 1 0 14px; text-align: center; overflow: hidden; white-space: nowrap; }
.tooltip {
  position: fixed; pointer-events: none; z-index: 20; display: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
td { font-size: 13px; }
td.nowrap { white-space: nowrap; }
td.msg { max-width: 320px; overflow-wrap: anywhere; color: var(--muted); }
tr.is-error td { opacity: 0.6; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.bot { background: rgba(57, 135, 229, 0.18); color: #86b6ef; }
.tag.manual { background: rgba(217, 89, 38, 0.18); color: #f0a07e; }
.tag.error { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }
.row-actions { display: flex; gap: 6px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* ---- modal ---- */
dialog {
  width: min(460px, calc(100vw - 32px)); padding: 20px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.form-grid { display: grid; gap: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 600px) {
  .kpi .value { font-size: 22px; }
  .nav { gap: 12px; }
}
