:root {
  color-scheme: light;
  --bg: #F1F4F9;
  --surface: #FFFFFF;
  --sidebar: #12295A;
  --sidebar-ink: #E6ECF8;
  --sidebar-muted: #9FB0D3;
  --ink: #15233F;
  --muted: #5A6782;
  --line: #D6DDEA;
  --blue: #1E4DB7;
  --gold: #E8B10C;
  --gold-soft: #FFF3C8;
  --ok: #1D7F4E;
  --warn: #9A6A00;
  --bad: #B3362C;
  --user-bubble: #E3EAF8;
  --focus: #1E4DB7;
  --radius-s: 6px;
  --radius-m: 12px;
  --sans: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0E1A33;
    --surface: #15244A;
    --sidebar: #0A1428;
    --sidebar-ink: #E6ECF8;
    --sidebar-muted: #8C9CC0;
    --ink: #E8EDF7;
    --muted: #A2AFCB;
    --line: #283B66;
    --blue: #93B2FF;
    --gold: #F4C63D;
    --gold-soft: #3A3317;
    --ok: #5BD08F;
    --warn: #F4C63D;
    --bad: #FF8C80;
    --user-bubble: #22366A;
    --focus: #F4C63D;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
button, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 272px 1fr; height: 100vh; height: 100dvh; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 28px 20px;
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px 9px 9px 2px;
  background: var(--gold);
  box-shadow: inset -10px -10px 0 rgba(10, 20, 40, .18);
}
.brand-name { margin: 0; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-client { margin: 0; color: var(--sidebar-muted); font-size: .9rem; }
.side-title { margin: 0 0 4px; padding-left: 15px; font-size: .85rem; font-weight: 600; color: var(--sidebar-muted); }
.domain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.domain-list li.muted { color: var(--sidebar-muted); font-size: .9rem; }
.domain-btn {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 10px 12px; border-radius: var(--radius-s); color: var(--sidebar-ink);
  border-left: 3px solid transparent;
}
.domain-btn:hover { background: rgba(255, 255, 255, .07); border-left-color: var(--gold); }
.domain-btn strong { display: block; font-weight: 600; }
.domain-btn span { display: block; font-size: .82rem; color: var(--sidebar-muted); }
.side-foot { margin-top: auto; padding-left: 15px; font-size: .82rem; color: var(--sidebar-muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.menu-btn { display: none; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: none; cursor: pointer; padding: 8px 14px;
  border-radius: var(--radius-s); color: var(--muted); font-weight: 600;
}
.tabs button[aria-selected="true"] { color: var(--ink); background: var(--bg); box-shadow: inset 0 -2px 0 var(--gold); }
.status { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status[data-state="ok"] .dot { background: var(--ok); }
.status[data-state="error"] .dot { background: var(--bad); }
.status[data-state="error"] { color: var(--bad); }

/* ---------- chat ---------- */
.panel { flex: 1; min-height: 0; }
.panel-chat { display: flex; flex-direction: column; }
.thread { flex: 1; overflow-y: auto; padding: 32px 28px 16px; display: flex; flex-direction: column; gap: 22px; }
.thread > * { width: 100%; max-width: 760px; margin-inline: auto; }

.empty { margin-top: 6vh; }
.empty h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 12px; max-width: 18ch; }
.empty p { color: var(--muted); max-width: 60ch; margin: 0 0 24px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; }
.suggestions button {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  padding: 10px 14px; border-radius: 999px; text-align: left; font-size: .93rem;
}
.suggestions button:hover { border-color: var(--blue); color: var(--blue); }

.turn-user { display: flex; justify-content: flex-end; }
.msg-user {
  max-width: min(620px, 90%);
  background: var(--user-bubble); padding: 12px 16px; border-radius: var(--radius-m) var(--radius-m) 3px var(--radius-m);
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.msg-bot { border-left: 3px solid var(--gold); padding: 2px 0 2px 20px; }
.answer { font-family: var(--serif); font-size: 1.12rem; line-height: 1.62; max-width: 68ch; overflow-wrap: anywhere; }
.answer p { margin: 0 0 .8em; }
.answer h4 { font-family: var(--sans); font-size: 1rem; margin: 1.1em 0 .4em; }
.answer ul, .answer ol { margin: 0 0 .8em; padding-left: 1.3em; }
.answer li { margin-bottom: .25em; }
.answer code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .85em; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.answer table { border-collapse: collapse; font-family: var(--sans); font-size: .9rem; margin: .4em 0 1em; display: block; overflow-x: auto; }
.answer th, .answer td { border-bottom: 1px solid var(--line); padding: 6px 12px 6px 0; text-align: left; vertical-align: top; }
.answer th { font-weight: 600; }

.trace { margin-top: 12px; font-size: .86rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.trace-text { margin-right: 4px; }
.chip { background: var(--gold-soft); color: var(--ink); padding: 2px 10px; border-radius: 999px; font-size: .82rem; }

.msg-error { border-left: 3px solid var(--bad); padding: 4px 0 4px 20px; color: var(--bad); }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer-wrap { padding: 12px 28px 18px; background: linear-gradient(to bottom, transparent, var(--bg) 30%); }
.composer {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 8px 8px 8px 16px;
}
.composer:focus-within { border-color: var(--blue); }
.composer textarea {
  flex: 1; border: 0; background: none; resize: none; padding: 8px 0; max-height: 180px;
  line-height: 1.45; outline: none;
}
.send {
  border: 0; cursor: pointer; padding: 10px 18px; border-radius: var(--radius-s);
  background: var(--blue); color: var(--surface); font-weight: 600;
}
.send:disabled { opacity: .5; cursor: not-allowed; }
.hint { max-width: 760px; margin: 8px auto 0; font-size: .8rem; color: var(--muted); }

/* ---------- explorador ---------- */
.panel-explore { overflow-y: auto; padding: 32px 28px 48px; }
.panel-explore > * { max-width: 900px; margin-inline: auto; }
.explore-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; }
.explore-head h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.02em; }
.filter { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.filter select { padding: 8px 10px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface); min-width: 220px; }
.explore-intro { color: var(--muted); margin: 10px auto 20px; }

.component-list { border-top: 1px solid var(--line); }
.component { border-bottom: 1px solid var(--line); }
.component-row {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center;
  padding: 14px 4px; background: none; border: 0; cursor: pointer; text-align: left;
}
.component-row:hover .component-name { color: var(--blue); }
.component-name { font-weight: 600; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .95rem; }
.component-desc { grid-column: 1 / -1; color: var(--muted); font-size: .92rem; }
.component-meta { display: flex; gap: 8px; align-items: center; font-size: .85rem; color: var(--muted); }
.badge { padding: 2px 9px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid currentColor; }
.badge-activo { color: var(--ok); }
.badge-beta { color: var(--warn); }
.badge-deprecado { color: var(--bad); }

.coverage { padding: 4px 4px 18px; display: grid; gap: 10px; max-width: 520px; }
.cov-row { display: grid; grid-template-columns: 130px 1fr 48px; gap: 12px; align-items: center; font-size: .9rem; }
.cov-bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.cov-fill { height: 100%; background: var(--blue); width: 0; }
.cov-fill.low { background: var(--bad); }
.cov-fill.mid { background: var(--gold); }
.cov-pct { text-align: right; font-variant-numeric: tabular-nums; }
.cov-date { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); margin-top: -6px; }

.rules-title { font-size: 1.2rem; margin: 36px auto 8px; }
.rule { padding: 12px 0; border-bottom: 1px solid var(--line); }
.rule h3 { margin: 0 0 4px; font-size: 1rem; }
.rule p { margin: 0; color: var(--muted); max-width: 70ch; }
.rule .rule-meta { font-size: .82rem; margin-top: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(5, 10, 25, .45); z-index: 20; }
  .menu-btn {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 38px; height: 38px; padding: 0 9px; border: 1px solid var(--line); border-radius: var(--radius-s);
    background: none; cursor: pointer;
  }
  .menu-btn span { display: block; height: 2px; background: var(--ink); border-radius: 2px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .tabs button { padding: 8px 10px; }
  .status .status-text { display: none; }
  .thread, .panel-explore { padding-inline: 16px; }
  .composer-wrap { padding-inline: 12px; }
  .cov-row { grid-template-columns: 100px 1fr 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- fase 3: sesión y administración ---------- */
:root { --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; --serif: Georgia, "Times New Roman", serif; }
.carga { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: var(--muted); }
.carga.error { color: var(--bad); }
.carga p { margin: 0; max-width: 46ch; text-align: center; }
.side-foot { display: flex; flex-direction: column; gap: 4px; }
.user-email { margin: 0; color: var(--sidebar-ink); font-size: .85rem; overflow-wrap: anywhere; }
.user-group { margin: 0 0 8px; color: var(--sidebar-muted); font-size: .8rem; }
.logout { align-self: flex-start; background: none; border: 1px solid var(--sidebar-muted); color: var(--sidebar-ink); border-radius: var(--radius-s); padding: 6px 12px; cursor: pointer; font-size: .85rem; }
.logout:hover { border-color: var(--gold); }
.badge-planeado { color: var(--blue); }
.admin-estado { border-top: 1px solid var(--line); }
.admin-fila { display: grid; grid-template-columns: 220px 1fr; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.admin-fila dt { color: var(--muted); }
.admin-fila dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.admin-ok { color: var(--ok); font-weight: 600; }
.admin-mal { color: var(--bad); font-weight: 600; }
