:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #fafbfd;
  --border: #e3e8ef;
  --border-strong: #d3dae5;
  --text: #1b2434;
  --text-soft: #4a5568;
  --muted: #8492a6;
  --accent: #3b5bdb;
  --accent-soft: #eef2ff;
  --ok: #0f8a5f;
  --ok-soft: #e7f6ef;
  --warn: #a76a10;
  --warn-soft: #fff5e3;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 33, 54, .04), 0 6px 20px rgba(23, 33, 54, .045);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
button, input { font: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; background: #f0f3f8; padding: 1px 5px; border-radius: 4px; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.015em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); font-size: 12px; }

.app { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 22px 16px 18px; display: flex; flex-direction: column; gap: 26px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 17px;
}
.brand strong { display: block; font-size: 15px; letter-spacing: -.02em; }
.brand span { display: block; color: var(--muted); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-soft); text-align: left; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-icon { width: 17px; text-align: center; font-size: 15px; opacity: .85; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 16px 6px 0; }
.sidebar-foot p { color: var(--muted); font-size: 11.5px; margin: 10px 0 0; }
.phase-chip {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px;
}

/* ---------- Topbar ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 18px 30px; position: sticky; top: 0; z-index: 5;
}
.eyebrow { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .09em; margin-bottom: 3px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.version-badge {
  font-family: ui-monospace, Consolas, monospace; font-size: 11.5px;
  background: var(--surface-soft); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 7px; color: var(--text-soft);
}

.content { padding: 26px 30px 34px; flex: 1; }
.view { display: none; }
.view.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Cards & layout ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.pill { font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }

.notice {
  display: flex; gap: 12px; align-items: flex-start; background: var(--accent-soft);
  border: 1px solid #dbe3ff; color: #2b3c7a; border-radius: var(--radius);
  padding: 14px 16px; font-size: 12.5px; margin-bottom: 18px;
}
.notice-ok { background: var(--ok-soft); border-color: #c9ebdb; color: #106a4c; }
.notice-icon { font-size: 15px; line-height: 1.35; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 16px 14px;
}
.kpi .kpi-label { color: var(--muted); font-size: 11.5px; font-weight: 500; }
.kpi .kpi-value { font-size: 25px; font-weight: 680; letter-spacing: -.03em; margin-top: 7px; line-height: 1.1; }
.kpi .kpi-sub { color: var(--muted); font-size: 10.5px; margin-top: 5px; }

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 0; font-size: 12.5px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; color: var(--text); word-break: break-word; }
.detail-body { font-size: 12.5px; color: var(--text-soft); }
.detail-body .price-big { font-size: 24px; font-weight: 680; color: var(--text); letter-spacing: -.02em; }
.detail-body .disclaimer { margin-top: 12px; color: var(--warn); background: var(--warn-soft); padding: 9px 11px; border-radius: 8px; font-size: 11.5px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.compact { max-height: 300px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; padding: 9px 10px;
  border-bottom: 1px solid var(--border); background: var(--surface-soft);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid #eef1f6; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8faff; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .code { font-family: ui-monospace, Consolas, monospace; color: var(--accent); font-weight: 600; }
.table .desc { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .link { color: var(--accent); background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px !important; }
.badge { font-size: 10.5px; font-weight: 650; padding: 3px 8px; border-radius: 6px; display: inline-block; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-bad { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: #eef1f6; color: var(--text-soft); }
.hash { font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; color: var(--muted); }

/* ---------- Toolbar / tabs / pager ---------- */
.toolbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 280px; max-width: 380px; }
.search input {
  width: 100%; padding: 9px 12px 9px 32px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--surface); color: var(--text); outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input:disabled { background: #f1f3f7; color: var(--muted); cursor: not-allowed; }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 16px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); padding: 4px; border-radius: 9px; }
.tab { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; color: var(--text-soft); font-size: 12px; font-weight: 500; }
.tab:hover { background: var(--surface-soft); }
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn-ghost { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 7px; padding: 5px 11px; color: var(--text-soft); font-size: 12px; }
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled { opacity: .45; cursor: not-allowed; }
.pager span { color: var(--muted); font-size: 12px; }

.endpoint-list { list-style: none; margin: 0; padding: 0; }
.endpoint-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #eef1f6; font-size: 12.5px; }
.endpoint-list li:last-child { border-bottom: 0; }
.method { font-size: 10px; font-weight: 700; padding: 3px 7px; border-radius: 5px; min-width: 42px; text-align: center; }
.method-get { background: var(--ok-soft); color: var(--ok); }
.method-post { background: var(--warn-soft); color: var(--warn); }
.endpoint-list code { background: transparent; padding: 0; color: var(--text); }
.endpoint-list .ep-note { color: var(--muted); font-size: 11px; margin-left: auto; }
.rules { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.rule { display: flex; gap: 9px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 12px; color: var(--text-soft); }
.rule b { color: var(--accent); }

.footer { border-top: 1px solid var(--border); color: var(--muted); font-size: 11.5px; padding: 16px 30px; background: var(--surface); }
.footer span { color: var(--text-soft); }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  .topbar { padding: 14px 18px; }
  .content { padding: 18px; }
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .rules { grid-template-columns: 1fr; }
}

/* ---------- Fase 3: sesión ---------- */
.session-chip {
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--ok-soft); color: var(--ok);
  padding: 5px 10px; border-radius: 999px;
}
.session-chip b { font-weight: 700; }
.session-chip.sin-sesion { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(27, 36, 52, .48); backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 18px 60px rgba(18, 27, 45, .22); padding: 26px 28px 28px;
}
.login-card .brand { padding: 0; margin-bottom: 20px; }
.login-card h2 { font-size: 19px; margin-bottom: 8px; }
.login-card .form-help { margin: 0 0 18px; }
.field { display: block; color: var(--text-soft); font-size: 12px; font-weight: 600; margin-bottom: 12px; }
.field input {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: 8px; background: var(--surface); color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-hint {
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; color: var(--text-soft);
  font-size: 11.5px; margin: 4px 0 16px;
}
.login-error {
  background: var(--danger-soft); color: var(--danger); border-radius: 8px;
  padding: 9px 11px; font-size: 12px; margin-bottom: 14px;
}
.login-error[hidden] { display: none; }

/* ---------- Fase 3: pedidos ---------- */
.form-help { color: var(--text-soft); font-size: 12px; line-height: 1.6; margin: 0 0 12px; }
.btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-soft); border-radius: 8px; padding: 8px 12px;
  font-size: 12px; font-weight: 600; transition: border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #324fc4; color: #fff; }
.btn-block { width: 100%; padding: 11px; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.payload {
  width: 100%; resize: vertical; padding: 12px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface-soft); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px;
  line-height: 1.55; outline: none;
}
.payload:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.response-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 8px;
}
.response {
  margin: 0; padding: 13px; border-radius: 9px; overflow: auto; max-height: 260px;
  background: #f7f9fc; border: 1px solid var(--border); color: var(--text-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11.5px;
  line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
#card-auditoria { margin-top: 18px; }
#tabla-cola .pill { font-size: 10px; }

@media (max-width: 780px) {
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; }
  .btn-row { gap: 6px; }
}
