:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #e3e7ee;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #dc2626;
  --idle: #f59e0b;
  --active: #16a34a;
  --off: #cbd5e1;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --card: #171e27;
    --text: #e6ebf2;
    --muted: #93a0b3;
    --border: #273241;
    --off: #3b4757;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 16px; color: var(--text); }
.topbar-right { display: flex; gap: 12px; align-items: center; color: var(--muted); }

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 15px; }

.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn:disabled { opacity: .6; cursor: default; }

input, select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); font-size: 13px;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }

/* Login */
.login { max-width: 360px; margin: 80px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--bad); font-size: 13px; }

/* Lista de agentes */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.agent-card { cursor: pointer; transition: border-color .15s; }
.agent-card:hover { border-color: var(--accent); }
.agent-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.agent-head .name { font-weight: 600; font-size: 15px; flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex-shrink: 0; }
.dot.online { background: var(--ok); }
.dot.idle { background: var(--warn); }
.thumb {
  width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px;
  background: var(--border); display: block; margin: 8px 0;
}
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: flex; gap: 12px; margin-top: 8px; font-size: 12px; }
.stats b { display: block; font-size: 14px; color: var(--text); }
.stats span { color: var(--muted); }

/* Detalle */
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head h1 { margin: 0; font-size: 20px; }
.detail-head .spacer { flex: 1; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
  background: var(--border); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--bg); border-radius: 8px; padding: 12px; }
.kpi .v { font-size: 22px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 12px; }

.timeline { display: flex; height: 28px; border-radius: 6px; overflow: hidden; background: var(--off); margin: 8px 0 4px; }
.timeline div { height: 100%; }
.timeline .a { background: var(--active); }
.timeline .i { background: var(--idle); }
.timeline .l { background: var(--bad); opacity: .7; }
.timeline-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.trunc { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.shot img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--border); }
.shot .cap { font-size: 12px; color: var(--muted); margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.hint { color: var(--muted); font-size: 12px; }

dl.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 88vh; border-radius: 6px; }
.lightbox-caption { color: #fff; margin-top: 10px; font-size: 13px; }

.empty { color: var(--muted); padding: 30px; text-align: center; }

/* Pestaña Ventanas */
.wintable td.trunc { max-width: 520px; }
.wbar { height: 4px; margin-top: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.wbar i { display: block; height: 100%; background: var(--active); border-radius: 3px; }
tr.seg-idle td { color: var(--muted); }

/* Barra de categorías de productividad */
.catbar { display: flex; height: 18px; border-radius: 5px; overflow: hidden; background: var(--border); margin: 6px 0 10px; }
.catbar div { height: 100%; }
h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); }

/* Timelapse de capturas */
.tl-player { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.tl-stage { width: 100%; margin-top: 8px; }
.tl-stage img { width: 100%; border-radius: 6px; border: 1px solid var(--border); }

/* Botones pequeños en tablas */
.btn-sm { padding: 3px 8px; font-size: 12px; }
