:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c222b;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --panel: #ffffff; --panel-2: #f3f5f7; --line: #d8dee4;
    --text: #1f2328; --muted: #59636e; --accent: #0969da;
    --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 10px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.brand .dot.warn { background: var(--warn); } .brand .dot.bad { background: var(--bad); }
.nav button {
  all: unset; cursor: pointer; padding: 8px 10px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between;
  color: var(--muted);
}
.nav button:hover { background: var(--panel-2); color: var(--text); }
.nav button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.nav .spacer { flex: 1; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.badge:empty { display: none; }

main { padding: 24px; min-width: 0; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 10px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.grid { display: grid; gap: 12px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 12px; }

.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

.chart-box { position: relative; height: 220px; }

/* ---------- Tablas / listas ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.ok::before { background: var(--ok); } .pill.bad::before { background: var(--bad); } .pill.warn::before { background: var(--warn); }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.alert + .alert { margin-top: 8px; }
.alert.critical { border-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.alert.warning { border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.alert .t { font-weight: 600; }
.empty { color: var(--muted); padding: 10px 0; }

.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { all: unset; cursor: pointer; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.seg button.active { background: var(--panel-2); color: var(--text); }
select, input[type=text], input[type=password], textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
pre.log { background: var(--panel-2); border-radius: 8px; padding: 10px; max-height: 420px; overflow: auto; font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; margin: 0; }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 260px 1fr; gap: 12px; height: calc(100vh - 48px); }
.chat-list { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.chat-list .items { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.chat-item { all: unset; cursor: pointer; padding: 8px 10px; border-radius: 8px; border: 1px solid transparent; }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); border-color: var(--line); }
.chat-item .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.chat-item .s { color: var(--muted); font-size: 12px; }
.chat-main { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.chat-head { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 900px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap; }
.msg.assistant { line-height: 1.55; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant pre { background: var(--panel-2); padding: 10px; border-radius: 8px; overflow-x: auto; font: 12px/1.4 var(--mono); }
.msg.assistant code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.msg.assistant pre code { background: none; padding: 0; }
.tool { font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.tool summary { cursor: pointer; padding: 6px 10px; list-style: none; display: flex; gap: 8px; align-items: center; }
.tool summary::-webkit-details-marker { display: none; }
.tool .name { font-weight: 600; }
.tool .arg { color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); max-height: 320px; overflow: auto; font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; }
.tool.err .name { color: var(--bad); }
.approval { border: 1px solid var(--warn); border-radius: 8px; padding: 10px 12px; background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.approval pre { font: 12px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; background: var(--panel-2); padding: 8px; border-radius: 6px; margin: 8px 0; }
.sys { color: var(--muted); font-size: 12.5px; text-align: center; }
.sys.err { color: var(--bad); white-space: pre-wrap; text-align: left; }
.checkpoint { border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }
.checkpoint ul { margin: 6px 0; padding-left: 18px; font-family: var(--mono); }
.chat-input { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; resize: none; min-height: 42px; max-height: 200px; }
.typing { color: var(--muted); font-size: 12.5px; }
.typing::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Diálogo ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(1000px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog .head { display: flex; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 10px; }
dialog .body { padding: 14px; }
dialog pre.log { max-height: 70vh; }

.toast { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; max-width: 380px; }
.toast .alert { box-shadow: 0 6px 20px rgba(0,0,0,.35); background: var(--panel); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login input { width: 100%; margin: 16px 0 10px; padding: 10px 12px; }
.login .btn { width: 100%; padding: 10px; }
.login .error { color: var(--bad); min-height: 20px; margin-top: 10px; font-size: 13px; }

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: sticky; top: 0; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; z-index: 5; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav .brand { padding: 4px 8px; }
  .nav .brand span:last-child { display: none; }
  .nav button { white-space: nowrap; gap: 6px; }
  .nav .spacer { display: none; }
  main { padding: 16px; }
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.k2 { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list .items { max-height: 180px; }
  .chat-main { height: 75vh; }
}
