:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #171a1f;
  --muted: #5d6573;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --ok: #157347;
  --ok-soft: #e5f4ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --code: #f3f4f7;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #9aa3b2;
    --accent: #8b85ff;
    --accent-text: #0f1115;
    --accent-soft: #24234a;
    --ok: #4cc38a;
    --ok-soft: #133024;
    --warn: #f0b354;
    --warn-soft: #3a2a10;
    --bad: #ff7b6e;
    --bad-soft: #3d1714;
    --code: #12151a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.boot { padding: 40px; color: var(--muted); }

/* Estructura */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; padding: 4px 8px 18px; }
.brand img { width: 26px; height: 26px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.side .who { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; }
.side .who strong { display: block; color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; color: var(--muted); }

/* Piezas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px 20px; }
.stack > * + * { margin-top: 14px; }
.grid-kpi { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; }
.kpi .n { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; }
.kpi.alert .n { color: var(--bad); }
.kpi.attn .n { color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.prod { background: var(--text); color: var(--surface); }
.count { background: var(--accent); color: var(--accent-text); border-radius: 999px; font-size: 11.5px; padding: 0 7px; font-weight: 650; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); padding: 7px 13px;
  border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:focus-visible, .nav a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabs { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
td .sub { color: var(--muted); font-size: 12.5px; }
td.actions { text-align: right; white-space: nowrap; }

.list > a, .list > div.row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 14px 18px;
  border-bottom: 1px solid var(--border); color: var(--text);
}
.list > a:last-child, .list > div.row:last-child { border-bottom: 0; }
.list > a:hover { background: var(--surface-2); text-decoration: none; }
.list .meta { color: var(--muted); font-size: 12.5px; grid-column: 1 / -1; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

/* Diferencias */
.diff { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.diff-row { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; border-bottom: 1px solid var(--border); }
.diff-row:last-child { border-bottom: 0; }
.diff-row > div { padding: 8px 12px; min-width: 0; }
.diff-path { background: var(--surface-2); font-weight: 550; word-break: break-all; }
.del, .add { display: block; padding: 1px 6px; border-radius: 4px; white-space: pre-wrap; word-break: break-word; }
.del { background: var(--bad-soft); color: var(--bad); text-decoration: line-through; text-decoration-thickness: 1px; }
.add { background: var(--ok-soft); color: var(--ok); }
.del + .add { margin-top: 4px; }
.wf { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.wf + .wf { margin-top: 8px; }
.wf-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wf ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
pre.json { background: var(--code); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; max-height: 420px; margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-weight: 550; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }

.decide { display: flex; flex-direction: column; gap: 10px; }
textarea, input[type=email], input[type=password] {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 70px; resize: vertical; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.note.ok { background: var(--ok-soft); color: var(--ok); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }

/* Salud */
.health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.hcard { padding: 16px 18px; }
.hcard .top { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.hcard .title { font-weight: 600; }
.hcard .errs { margin-top: 12px; border-top: 1px solid var(--border); }
.err-item { padding: 9px 0; border-bottom: 1px solid var(--border); }
.err-item:last-child { border-bottom: 0; }
.err-item button { all: unset; cursor: pointer; display: flex; justify-content: space-between; width: 100%; gap: 8px; }
.err-item button:focus-visible { outline: 2px solid var(--accent); }
.err-detail { margin-top: 8px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 28px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; }

/* Modal */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { width: 100%; max-width: 620px; max-height: 88vh; overflow: auto; padding: 22px; }
.modal .row-btns { justify-content: flex-end; margin-top: 16px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 9px;
  opacity: 0; pointer-events: none; transition: 0.2s; max-width: calc(100% - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.muted { color: var(--muted); }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Asistente Nuevo bot */
.stepper { list-style: none; display: flex; gap: 6px; padding: 0; margin: 0 0 16px; flex-wrap: wrap; }
.stepper li { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-weight: 550; font-size: 13px; }
.stepper li span { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 12px; }
.stepper li.on { color: var(--accent); border-color: var(--accent); }
.stepper li.on span { background: var(--accent); color: var(--accent-text); }
.stepper li.done span { background: var(--ok-soft); color: var(--ok); }
.wiz h2 { font-size: 17px; }
.wiz-nav { justify-content: space-between; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); }
.form { display: flex; flex-direction: column; gap: 4px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; max-width: 560px; }
.field label { font-weight: 550; font-size: 13.5px; }
.field .key { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.field input[type=text], .field input[type=number], .field input:not([type]), .field select, .secret input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 11px;
}
.field input[aria-invalid=true], .field select[aria-invalid=true] { border-color: var(--bad); }
.hint { color: var(--muted); font-size: 12.5px; min-height: 1em; }
.err { color: var(--bad); font-weight: 550; }
.fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px 2px; margin: 4px 0 14px; max-width: 600px; }
.fieldset legend { font-weight: 600; padding: 0 6px; }
details.fieldset { padding-bottom: 12px; }
details.fieldset summary { margin-bottom: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 20px; margin-top: 16px; }
.grid-2.review { gap: 20px; }
.tpl-list { display: flex; flex-direction: column; gap: 10px; }
.tpl { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; cursor: pointer; }
.tpl:hover { background: var(--surface-2); }
.tpl.on { border-color: var(--accent); background: var(--accent-soft); }
.tpl input { margin-top: 4px; accent-color: var(--accent); }
.secret { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.secret-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.tabs button:disabled { opacity: 0.45; cursor: not-allowed; }
.checklist { margin: 8px 0 0; padding-left: 22px; display: flex; flex-direction: column; gap: 12px; }
.checklist li::marker { color: var(--accent); font-weight: 650; }
.copy { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.copy pre.sql { flex: 1 1 100%; white-space: pre-wrap; word-break: break-all; max-height: none; }
.copy code { background: var(--code); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; word-break: break-all; }
.note ul { margin: 6px 0 0; padding-left: 18px; }

@media (max-width: 900px) {
  .two { grid-template-columns: 1fr; }
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 0; }
  .brand span { display: none; }
  .nav { display: flex; gap: 2px; }
  .side .who { display: none; }
  main { padding: 20px 16px 48px; }
  .diff-row { grid-template-columns: 1fr; }
  .health-grid { grid-template-columns: 1fr; }
}
