:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f0f3f9; --border: #dde3ee;
  --text: #17202f; --muted: #5d6b82; --primary: #2563eb; --primary-ink: #ffffff;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --info: #1d4ed8; --info-bg: #dbeafe;
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b; --surface: #161d29; --surface-2: #1d2634; --border: #2b3648;
    --text: #e6ebf3; --muted: #97a4ba; --primary: #4b83f0; --primary-ink: #0b1220;
    --ok: #4ade80; --ok-bg: #12301f; --warn: #fbbf24; --warn-bg: #33270a;
    --bad: #f87171; --bad-bg: #3a1515; --info: #8ab4ff; --info-bg: #14233f;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--primary); }
code, pre, textarea.mono, input.mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Estructura */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: .25rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.1rem; margin-bottom: 1.25rem; }
.brand svg { width: 28px; height: 28px; }
.nav a { display: block; padding: .55rem .75rem; border-radius: 8px; color: var(--text); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--info-bg); color: var(--info); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: .85rem; color: var(--muted); padding: 0 .75rem; word-break: break-all; }
main { padding: 1.75rem clamp(1rem, 3vw, 2.5rem); max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.card > h2 { margin-bottom: .75rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .45rem .85rem; border-radius: 8px; }
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.small { padding: .25rem .6rem; font-size: .85rem; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; }
textarea { resize: vertical; min-height: 6rem; }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: .6rem .9rem; color: var(--muted); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.log { background: #0b1220; color: #d7e1f2; padding: .9rem 1rem; border-radius: 8px; max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: .85rem; margin: 0; }
.notice { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; background: var(--info-bg); color: var(--info); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice ul { margin: .25rem 0 0; padding-left: 1.2rem; }

/* Ventana modal */
.overlay { position: fixed; inset: 0; background: rgba(8, 12, 20, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 1rem; overflow: auto; z-index: 20; }
.modal { background: var(--surface); border-radius: 14px; padding: 1.4rem; width: min(560px, 100%); border: 1px solid var(--border); }
.modal.wide { width: min(760px, 100%); }
.modal .foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.kv { display: grid; grid-template-columns: 110px 1fr auto; gap: .35rem .6rem; align-items: center; margin-bottom: .5rem; }
.kv input { font-family: var(--mono); }

#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 40; max-width: min(420px, 90vw); }
.toast { background: var(--text); color: var(--bg); padding: .65rem .9rem; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.toast.bad { background: var(--bad); color: #fff; }

/* Acceso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: min(380px, 100%); margin: 0; padding: 1.75rem; }
.login .brand { justify-content: center; margin-bottom: 1.25rem; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); padding: .6rem 1rem; }
  .brand { margin: 0 1rem 0 0; }
  .sidebar .spacer, .sidebar .who { display: none; }
}
