:root {
  /* Superficies y texto */
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e7ed;
  --border-strong: #cfd7e0;
  --text: #1a222b;
  --text-muted: #5f6c7a;
  /* Marca y acentos (uso controlado: acciones, activos, enlaces) */
  --accent: #1f6feb;
  --accent-hover: #1a5fd0;
  --accent-soft: #e9f1fd;
  --accent-ring: rgba(31, 111, 235, .13);
  /* Sidebar corporativo sobrio */
  --sidebar-bg: #131a24;
  --sidebar-bg-2: #0e141d;
  --sidebar-fg: #dbe2eb;
  --sidebar-muted: #8b97a8;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(255, 255, 255, .1);
  /* Estados (sobrios, nunca sólo color: se combinan con texto/icono) */
  --danger: #b42318;
  --danger-soft: #fdf0ef;
  --danger-border: #efc5c0;
  --success: #1e7e4c;
  --success-soft: #e9f5ee;
  --warning: #8a5a0b;
  --warning-soft: #faf3e2;
  /* Forma y elevación */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, .09);
  --shadow-pop: 0 10px 32px rgba(16, 24, 40, .18);
  /* Tipografía: una familia, pesos 400/500/600/700 */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Iconos del sprite único: 16 acciones / 18 navegación / 20 principales */
.icon { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: -3px; }
.icon--xs { width: 16px; height: 16px; }
.icon--sm { width: 16px; height: 16px; }
.icon--lg { width: 20px; height: 20px; }

/* Foco visible consistente (teclado) */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection { background: var(--accent-soft); }

/* Alto real de la ventana.
   `--app-height` lo fija JS con visualViewport (descuenta la barra del
   navegador y el teclado en móvil); dvh/vh quedan como respaldo. */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 288px;
  flex: 0 0 288px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 14px;
  gap: 12px;
  border-right: 1px solid rgba(255, 255, 255, .05);
}

.sidebar__header { padding: 2px 8px 0; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand__mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}

.brand__name { font-weight: 650; font-size: 16px; letter-spacing: .1px; }

.btn-new {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  color: var(--sidebar-fg);
  font: inherit;
  font-weight: 550;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn-new:hover { background: rgba(255, 255, 255, .11); border-color: rgba(255, 255, 255, .2); }
.btn-new:active { transform: translateY(1px); }

.sidebar__section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .9px;
  color: var(--sidebar-muted);
  padding: 10px 10px 2px;
}

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding-bottom: 4px; }

.conv-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px 2px 2px;
  border-radius: 9px;
  color: var(--sidebar-fg);
  transition: background .13s ease;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item--active { background: var(--sidebar-active); }
.conv-item--active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

.conv-item__icon { color: var(--sidebar-muted); margin-left: 8px; }
.conv-item--active .conv-item__icon { color: var(--sidebar-fg); }

.conv-item__link {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 2px;
  color: inherit;
  text-decoration: none;
}

.conv-item__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 450;
}
.conv-item--active .conv-item__title { font-weight: 600; color: #fff; }

.conv-item__action {
  opacity: 0;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  border-radius: 7px;
  transition: opacity .13s ease, background .13s ease, color .13s ease;
}
.conv-item:hover .conv-item__action,
.conv-item__action:focus-visible { opacity: 1; }
.conv-item__action:hover { color: #fff; background: rgba(255, 255, 255, .12); }
.conv-item__action--danger:hover { color: #ff9d97; background: rgba(180, 35, 42, .35); }

.conv-item__input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--sidebar-fg);
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 5px 8px;
  outline: none;
}

@media (hover: none) {
  .conv-item__action { opacity: 1; }
}

.conv-empty { color: var(--sidebar-muted); font-size: 13px; padding: 8px 10px; }

/* Tarjeta de usuario + acciones al pie del sidebar */
.sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, .09);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 11px;
  padding: 9px 10px;
}

.user-card__avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-size: 14px;
  font-weight: 650;
}

.user-card__info { min-width: 0; display: flex; flex-direction: column; }
.user-card__email {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--sidebar-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-card__role { font-size: 11px; color: var(--sidebar-muted); }

.sidebar__actions { display: flex; flex-direction: column; gap: 2px; }
.sidebar__logout-form { margin: 0; }

.sidebar__action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--sidebar-fg);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  transition: background .13s ease;
}
.sidebar__action:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar__action--secondary { color: var(--sidebar-muted); font-weight: 450; }
.sidebar__action--secondary:hover { color: var(--sidebar-fg); }

.sidebar__notice {
  font-size: 11.5px;
  color: #d9a521;
  padding: 0 10px;
}

.sidebar-backdrop { display: none; }

/* ---------- Chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}

.chat__heading { min-width: 0; }
.chat__eyebrow {
  margin: 0 0 1px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.chat__title {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 36px;
  height: 36px;
  place-items: center;
  cursor: pointer;
  color: var(--text);
  transition: background .13s ease, border-color .13s ease;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 28px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg { max-width: 760px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.msg__bubble {
  padding: 13px 17px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-size: 14.5px;
}

.msg--user { align-items: flex-end; }
.msg--user .msg__bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
  max-width: 80%;
  box-shadow: var(--shadow-sm);
}

.msg--assistant .msg__bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.msg--error .msg__bubble {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}

.msg__role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Fuentes y fragmentos */
.evidence { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.evidence__block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.evidence__toggle {
  width: 100%;
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.evidence__toggle:hover { background: var(--surface-2); color: var(--text); }
.evidence__caret { transition: transform .16s ease; display: inline-flex; color: var(--text-muted); }
.evidence__block[open] .evidence__caret { transform: rotate(90deg); }

.evidence__body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 10px; }

.source {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  font-size: 13.5px;
}
.source__doc { font-weight: 600; }
.source__link { font-weight: 600; color: var(--accent); }
.source__meta { color: var(--text-muted); font-size: 13px; }

.msg__bubble a { color: var(--accent); font-weight: 550; overflow-wrap: anywhere; text-decoration: none; }
.msg__bubble a:hover { text-decoration: underline; }
.msg--user .msg__bubble a { color: #e8efff; }

/* Markdown simple del agente */
.msg__bubble .md-h { font-weight: 700; margin: 12px 0 5px; line-height: 1.35; letter-spacing: -.1px; }
.msg__bubble .md-h:first-child { margin-top: 0; }
.msg__bubble .md-h1 { font-size: 1.1em; }
.msg__bubble .md-h2 { font-size: 1.03em; }
.msg__bubble .md-h3 { font-size: .97em; }
.msg__bubble .md-list { margin: 8px 0; padding-left: 22px; }
.msg__bubble .md-list li { margin: 4px 0; }
.msg__bubble .md-list li::marker { color: var(--text-muted); }
.msg__bubble code {
  font-family: var(--mono);
  font-size: .87em;
  background: rgba(0, 0, 0, .06);
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .05);
}
.msg--user code { background: rgba(255, 255, 255, .2); border-color: transparent; }

/* Contexto citado (líneas "> …") */
.msg__bubble .quote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  font-size: .94em;
  color: var(--text-muted);
}
.msg__bubble .quote:first-child { margin-top: 0; }
.msg__bubble .quote:last-child { margin-bottom: 0; }
.msg--user .quote {
  border-left-color: rgba(255,255,255,.65);
  background: rgba(255,255,255,.14);
}

/* Botón flotante para citar la selección */
.quote-popover {
  position: fixed;
  z-index: 50;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border: none;
  border-radius: 9px;
  background: var(--sidebar-bg);
  color: #fff;
  box-shadow: var(--shadow-pop);
  cursor: pointer;
  transition: background .13s ease;
}
.quote-popover[hidden] { display: none; }
.quote-popover:hover { background: var(--accent); }

/* Bandeja de citas en el composer */
.quote-tray {
  max-width: 760px;
  margin: 0 auto 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quote-tray[hidden] { display: none; }

.quote-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 8px 8px 8px 12px;
}
.quote-chip__icon { color: var(--text-muted); display: inline-flex; margin-top: 2px; }
.quote-chip__info { min-width: 0; flex: 1; }
.quote-chip__source { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); font-weight: 600; }
.quote-chip__text { font-size: 13px; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.quote-chip__remove {
  border: none; background: none; cursor: pointer;
  display: grid; place-items: center;
  width: 28px; height: 28px;
  color: var(--text-muted);
  border-radius: 7px;
  transition: background .13s ease, color .13s ease;
}
.quote-chip__remove:hover { background: var(--danger-soft); color: var(--danger); }

.chunk {
  border-left: 3px solid var(--border);
  padding: 2px 0 2px 10px;
  font-size: 13.5px;
  color: var(--text-muted);
  font-style: italic;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Estado de carga */
.typing { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); }
.typing__dots { display: inline-flex; gap: 3px; }
.typing__dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing__dots span:nth-child(2) { animation-delay: .2s; }
.typing__dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.empty-state {
  margin: auto;
  max-width: 460px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }
.empty-state p { margin: 0; font-size: 14px; }

/* ---------- Composer ---------- */
.composer {
  padding: 12px 24px 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  flex: 0 0 auto;
}

.composer__box {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 9px 9px 9px 12px;
  box-shadow: var(--shadow-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer__box:hover { border-color: #bcc7d2; }
.composer__box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring), var(--shadow-md);
}

.composer__input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  color: var(--text);
  background: transparent;
  max-height: 180px;
  padding: 6px 0;
}

.btn-send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: none;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .13s ease, transform .1s ease, opacity .13s ease;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:active { transform: scale(.96); }
.btn-send:disabled { background: #c3cbd6; cursor: not-allowed; transform: none; }
.btn-send--loading { position: relative; color: transparent; }
.btn-send--loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-attach {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background .13s ease, color .13s ease;
}
.btn-attach:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-attach:disabled { opacity: .45; cursor: not-allowed; }

.file-input { display: none; }

.file-preview {
  max-width: 760px;
  margin: 0 auto 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.file-preview[hidden] { display: none; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 7px 7px 7px 10px;
  max-width: 250px;
  box-shadow: var(--shadow-sm);
}
.file-chip__thumb {
  width: 36px; height: 36px;
  object-fit: cover;
  border-radius: 7px;
  flex: 0 0 36px;
}
.file-chip__icon { color: var(--text-muted); display: inline-flex; }
.file-chip__info { min-width: 0; flex: 1; }
.file-chip__name {
  font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 150px;
}
.file-chip__size { font-size: 11.5px; color: var(--text-muted); }
.file-chip__remove {
  border: none; background: none; cursor: pointer;
  display: grid; place-items: center;
  width: 28px; height: 28px;
  color: var(--text-muted);
  border-radius: 7px;
  transition: background .13s ease, color .13s ease;
}
.file-chip__remove:hover { background: var(--danger-soft); color: var(--danger); }

/* Adjuntos ya enviados (historial y mensajes nuevos) */
.attach-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.attach-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.msg--user .attach-item { justify-content: flex-end; }
.attach-item__thumb {
  max-width: 220px; max-height: 160px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
  box-shadow: var(--shadow-sm);
}
.attach-item__link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: inherit;
  font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 11px;
  text-decoration: none;
  transition: border-color .13s ease;
}
.attach-item__link:hover { border-color: var(--border-strong); text-decoration: none; }
.attach-item__link .icon { color: var(--text-muted); }
.msg--user .attach-item__link { color: #e8efff; background: rgba(255, 255, 255, .12); border-color: transparent; }
.msg--user .attach-item__link .icon { color: #e8efff; }

.composer__hint {
  max-width: 760px;
  margin: 9px auto 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.composer__error {
  max-width: 760px;
  margin: 0 auto 8px;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--danger);
  color: var(--danger);
}
.composer__error[hidden] { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar--open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 15;
  }
  .sidebar-backdrop[hidden] { display: none; }
  .icon-btn { display: grid; }
  .messages { padding: 20px 14px 8px; }
  .composer {
    padding: 10px 14px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .composer__hint { margin-top: 6px; font-size: 11.5px; }
  .chat__header { padding: 10px 14px; min-height: 58px; }
  .chat__title { font-size: 15.5px; }
  .console__body { padding: 16px 14px 40px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .msg--user .msg__bubble { max-width: 92%; }
}

/* Movimiento reducido: microinteracciones discretas, nunca decorativas */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Ocultar el marcador nativo de <details> en los bloques de evidencia */
.evidence__toggle { list-style: none; }
.evidence__toggle::-webkit-details-marker { display: none; }

/* ---------- Acceso (email + OTP) ---------- */
.auth {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.auth__card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}
.auth__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth__title { margin: 0 0 6px; font-size: 20px; font-weight: 650; letter-spacing: -.2px; }
.auth__subtitle { margin: 0 0 22px; font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.auth__field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.auth__label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.auth__input {
  font: inherit;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  transition: border-color .13s ease, box-shadow .13s ease;
}
.auth__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.auth__input--code { letter-spacing: .5em; text-align: center; font-size: 20px; }
.auth__submit {
  width: 100%;
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .13s ease;
}
.auth__submit:hover { background: var(--accent-hover); }
.auth__footer { margin-top: 18px; display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.auth__link {
  background: none; border: none; padding: 0;
  font: inherit; color: var(--accent); cursor: pointer; text-decoration: none;
}
.auth__errors { color: #b4232a; font-size: 13px; margin: 0 0 12px; }
.flash { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.flash li {
  font-size: 13px; padding: 10px 12px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); line-height: 1.45;
}
.flash li.error { background: rgba(180,35,42,.1); color: #8f1c22; }
.flash li.warning { background: rgba(200,140,20,.12); }

/* ---------- Usuario en la barra lateral ---------- */
.sidebar__user { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
.sidebar__user-email {
  font-size: 12px; color: var(--sidebar-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar__logout {
  background: none; border: none; padding: 4px 6px; border-radius: 6px;
  font: inherit; font-size: 12px; color: var(--sidebar-muted); cursor: pointer;
}
.sidebar__logout:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar__admin-link { font-size: 12px; color: var(--sidebar-muted); text-decoration: none; }
.sidebar__admin-link:hover { color: #fff; }

/* ---------- Consola de administración ---------- */
.console { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; background: var(--bg); }
.console .chat__header { position: sticky; top: 0; z-index: 5; }
.console__body { padding: 22px 24px 48px; max-width: 1120px; width: 100%; margin: 0 auto; box-sizing: border-box; }
.console__messages { margin-bottom: 12px; }
.console__flash { padding: 10px 14px; border-radius: 10px; font-size: 13px; margin: 0 0 8px; background: var(--accent-soft); border: 1px solid #c9dcfa; color: var(--text); }
.console__flash--error { background: var(--danger-soft); border-color: var(--danger-border); border-left: 3px solid var(--danger); color: var(--danger); }
.console__flash--success { background: var(--success-soft); border: 1px solid #c4e2c9; border-left: 3px solid var(--success); color: var(--success); }

.period-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.period-nav__link { padding: 7px 14px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; font-size: 13px; font-weight: 550; color: var(--text-muted); background: var(--surface); transition: border-color .13s ease, color .13s ease; }
.period-nav__link:hover { border-color: var(--border-strong); color: var(--text); }
.period-nav__link--active { background: var(--accent); border-color: var(--accent); color: #fff; }
.period-nav__link--active:hover { color: #fff; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px 16px; display: flex; gap: 12px; align-items: flex-start; box-shadow: var(--shadow-sm); }
.kpi > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi__icon { color: var(--accent); background: var(--accent-soft); border-radius: 9px; padding: 7px; width: 32px; height: 32px; }
.kpi__value { font-size: 23px; font-weight: 700; letter-spacing: -.3px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi__label { font-size: 12px; color: var(--text-muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm); overflow-x: auto; }
.panel--narrow { max-width: 560px; }
.panel__title { margin: 0 0 4px; font-size: 15.5px; font-weight: 650; letter-spacing: -.1px; }
.panel__subtitle { font-size: 13px; font-weight: 650; margin: 16px 0 6px; }
.panel__hint { font-size: 12.5px; color: var(--text-muted); }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 20px; }

.stat-list { margin: 8px 0; }
.stat-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.stat-list > div:last-child { border-bottom: none; }
.stat-list dt { color: var(--text-muted); }
.stat-list dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table thead th { font-size: 11px; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.data-table thead th a { color: inherit; text-decoration: none; }
.data-table thead th a:hover { color: var(--accent); }
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table__empty { color: var(--text-muted); text-align: center; padding: 22px; }
.muted { color: var(--text-muted); font-size: 12.5px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge--ok { background: var(--success-soft); color: var(--success); }
.badge--error { background: var(--danger-soft); color: var(--danger); }
.badge--muted { background: #eef1f4; color: var(--text-muted); }

.actions { white-space: nowrap; }
.inline-form { display: inline; }
.link-btn { background: none; border: none; padding: 0; font: inherit; font-size: 13px; font-weight: 550; color: var(--accent); cursor: pointer; text-decoration: none; margin-right: 12px; }
.link-btn:hover { text-decoration: underline; }
.link-btn--danger { color: var(--danger); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.filters label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.filters input, .filters select { font: inherit; font-size: 13px; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); transition: border-color .13s ease, box-shadow .13s ease; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

.form { display: flex; flex-direction: column; gap: 15px; }
.form__label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.form__input { font: inherit; font-size: 14px; padding: 10px 13px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); transition: border-color .13s ease, box-shadow .13s ease; }
.form__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.form__check { display: flex; gap: 9px; align-items: flex-start; font-size: 13.5px; line-height: 1.5; }
.form__check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--accent); }
.form__actions { display: flex; gap: 14px; align-items: center; }
.btn-new--inline { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; width: auto; background: var(--accent); border-color: var(--accent); color: #fff; font-size: 14px; padding: 9px 16px; }
.btn-new--inline:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 9px; padding: 10px 18px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: filter .13s ease; }
.btn-danger:hover { filter: brightness(.94); }

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; }
.chart__bar-label { font-size: 11px; fill: var(--text-muted); }
