:root {
  --ground:   #F5F9F9;
  --surface:  #FFFFFF;
  --surface-2:#EDF3F3;
  --ink:      #0F1E1D;
  --ink-2:    #4B5D5E;
  --ink-3:    #7C8F8F;
  --line:     #DBE6E5;
  --accent:   #0B8B86;
  --accent-2: #0A6E6A;
  --accent-wash:#E3F1F0;
  --good:     #1C9C6A;
  --good-wash:#E1F4EB;
  --warn:     #B0761A;
  --warn-wash:#FBF0DD;
  --crit:     #CB4234;
  --crit-wash:#FBE7E4;
  --shadow:   0 1px 2px rgba(15,30,29,.04), 0 8px 24px -12px rgba(15,30,29,.14);
  --radius:   14px;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", "Menlo", "Cascadia Mono", "Roboto Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --bubble-in: var(--surface-2);
  --bubble-out: var(--accent-wash);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:   #091312;
    --surface:  #0E1B1A;
    --surface-2:#152726;
    --ink:      #E8F2F0;
    --ink-2:    #9BAFAE;
    --ink-3:    #6A7E7D;
    --line:     #203634;
    --accent:   #2BC0B7;
    --accent-2: #6FE1D8;
    --accent-wash:#12302D;
    --good:     #33C088;
    --good-wash:#12302A;
    --warn:     #DCA33B;
    --warn-wash:#2E2210;
    --crit:     #EE6A59;
    --crit-wash:#2E1614;
    --shadow:   0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
    --bubble-in: var(--surface-2);
    --bubble-out: #123330;
  }
}
:root[data-theme="dark"] {
  --ground:#091312; --surface:#0E1B1A; --surface-2:#152726; --ink:#E8F2F0;
  --ink-2:#9BAFAE; --ink-3:#6A7E7D; --line:#203634; --accent:#2BC0B7;
  --accent-2:#6FE1D8; --accent-wash:#12302D; --good:#33C088; --good-wash:#12302A;
  --warn:#DCA33B; --warn-wash:#2E2210; --crit:#EE6A59; --crit-wash:#2E1614;
  --shadow:0 1px 2px rgba(0,0,0,.3),0 10px 30px -14px rgba(0,0,0,.6);
  --bubble-in: var(--surface-2); --bubble-out: #123330;
}
:root[data-theme="light"] {
  --ground:#F5F9F9; --surface:#FFFFFF; --surface-2:#EDF3F3; --ink:#0F1E1D;
  --ink-2:#4B5D5E; --ink-3:#7C8F8F; --line:#DBE6E5; --accent:#0B8B86;
  --accent-2:#0A6E6A; --accent-wash:#E3F1F0; --good:#1C9C6A; --good-wash:#E1F4EB;
  --warn:#B0761A; --warn-wash:#FBF0DD; --crit:#CB4234; --crit-wash:#FBE7E4;
  --shadow:0 1px 2px rgba(15,30,29,.04),0 8px 24px -12px rgba(15,30,29,.14);
  --bubble-in: var(--surface-2); --bubble-out: var(--accent-wash);
}

* { box-sizing: border-box; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  margin: 0;
}
.wrap { max-width: 1320px; margin: 0 auto; padding: 24px 20px 48px; }
button { font-family: var(--sans); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; }
.glyph {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-size: 20px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
h1 { font-size: 20px; font-weight: 640; letter-spacing: -.02em; margin: 0; text-wrap: balance; }
.sub { font-size: 12.5px; color: var(--ink-2); margin-top: 1px; }
.controls { display: flex; align-items: center; gap: 10px; }
select, .tbtn, input[type="search"], input[type="text"] {
  font-family: var(--sans); font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 12px;
}
select, .tbtn { cursor: pointer; }
.tbtn { width: 38px; height: 37px; padding: 0; display: grid; place-items: center; font-size: 15px; }
.revisor-badge {
  font-size: 12.5px; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; cursor: pointer;
}
.revisor-badge:before { content: "👤 "; }

.banner {
  margin: 20px 0 18px; display: flex; align-items: center; gap: 9px;
  font-size: 12.5px; color: var(--ink-2);
  background: var(--accent-wash); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 13px;
}
.banner b { color: var(--accent-2); font-weight: 620; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab-btn {
  background: none; border: none; cursor: pointer; padding: 10px 16px;
  font-size: 13.5px; font-weight: 600; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn[aria-selected="true"] { color: var(--accent-2); border-bottom-color: var(--accent); }
.tab-btn:hover { color: var(--ink); }

.panel-loading { padding: 60px 0; text-align: center; color: var(--ink-3); font-size: 13.5px; }

/* Empty / error state */
.empty-state {
  margin-top: 20px; text-align: center; padding: 48px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty-state .empty-icon { font-size: 34px; margin-bottom: 10px; }
.empty-state h2 { font-size: 17px; font-weight: 620; margin: 0 0 6px; }
.empty-state p { font-size: 13.5px; color: var(--ink-2); margin: 0 0 14px; max-width: 420px; margin-inline: auto; }

/* Buttons */
.btn {
  font-size: 13px; font-weight: 620; border-radius: 9px; padding: 9px 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: opacity .12s ease, transform .05s ease;
}
.btn:hover { opacity: .88; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(150deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn.good { background: var(--good); border-color: transparent; color: #fff; }
.btn.danger { background: var(--crit); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 11px; font-size: 12px; }

/* ============ Layout maestro-detalle ============ */
.review-layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }

.list-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  max-height: calc(100vh - 220px); min-height: 400px; overflow: hidden;
}
.list-filters { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip-btn {
  font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; cursor: pointer;
  display: flex; align-items: center; gap: 5px;
}
.chip-btn .cnt { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.chip-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-btn[aria-pressed="true"] .cnt { color: rgba(255,255,255,.85); }
.filters-row { display: flex; gap: 8px; }
.filters-row select { flex: none; }
.search-box { flex: 1; min-width: 0; }
.search-box input { width: 100%; }

.list-scroll { flex: 1; overflow-y: auto; padding: 6px; }
.conv-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.list-loading, .list-empty { padding: 30px 16px; text-align: center; color: var(--ink-3); font-size: 12.5px; }

.conv-item {
  width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 10px;
  padding: 10px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 5px;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item[aria-current="true"] { background: var(--accent-wash); border-color: var(--accent); }
.conv-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-item-who { font-size: 13px; font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-item-who .src-ico { flex: none; }
.conv-item-time { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; flex: none; }
.conv-item-preview { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.conv-item-badges { display: flex; flex-wrap: wrap; gap: 5px; }

.badge { font-size: 10.5px; font-weight: 640; border-radius: 999px; padding: 2px 8px; letter-spacing: .01em; white-space: nowrap; }
.badge.estado-pendiente_revision { background: var(--warn-wash); color: var(--warn); }
.badge.estado-error_generacion { background: var(--crit-wash); color: var(--crit); }
.badge.estado-aprobado { background: var(--good-wash); color: var(--good); }
.badge.estado-rechazado { background: var(--crit-wash); color: var(--crit); }
.badge.estado-ignorado { background: var(--surface-2); color: var(--ink-3); }
.badge.intencion { background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.latencia { background: transparent; color: var(--ink-3); border: 1px solid var(--line); font-variant-numeric: tabular-nums; font-weight: 560; }
.badge.cobertura-si { background: var(--good-wash); color: var(--good); }
.badge.cobertura-no { background: var(--crit-wash); color: var(--crit); }
.badge.cobertura-ambigua { background: var(--warn-wash); color: var(--warn); }

.list-pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2);
}
.list-pagination .pg-btns { display: flex; gap: 6px; }

/* Detalle */
.detail-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); min-height: 400px; max-height: calc(100vh - 220px); overflow-y: auto;
  display: flex; flex-direction: column;
}
.detail-empty, .detail-loading, .detail-error { margin: auto; text-align: center; padding: 48px 20px; color: var(--ink-2); }
.detail-empty .empty-icon, .detail-error .empty-icon { font-size: 34px; margin-bottom: 10px; }
.detail-empty h2, .detail-error h2 { font-size: 16px; margin: 0 0 6px; color: var(--ink); }
.detail-empty p, .detail-error p { font-size: 13px; margin: 0; max-width: 360px; margin-inline: auto; }

.detail-content { display: flex; flex-direction: column; }

.detail-header {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.detail-header-who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.detail-header-who .nm { font-size: 15px; font-weight: 650; }
.detail-header-who .meta { font-size: 12px; color: var(--ink-2); }
.detail-header-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.detail-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 20px; }

/* Hilo tipo chat */
.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; display: flex; flex-direction: column; gap: 3px; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg-bubble { border-radius: 14px; padding: 9px 13px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.msg.in .msg-bubble { background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.out .msg-bubble { background: var(--bubble-out); border: 1px solid var(--line); border-bottom-right-radius: 4px; }
.msg-meta { font-size: 10.5px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; padding: 0 3px; }
.msg-meta .auto-tag { background: var(--surface-2); border-radius: 999px; padding: 1px 6px; }

/* Borrador vigente */
.draft-card {
  border: 1.5px solid var(--accent); border-radius: var(--radius);
  background: var(--accent-wash); padding: 16px;
}
.draft-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.draft-card-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--accent-2); }
.draft-meta { font-size: 11.5px; color: var(--ink-2); display: flex; gap: 10px; flex-wrap: wrap; }
.draft-textarea {
  width: 100%; min-height: 140px; resize: vertical; font-family: var(--sans); font-size: 13.5px;
  padding: 12px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  line-height: 1.55;
}
.draft-textarea:disabled { opacity: .7; }
.char-count { font-size: 11px; color: var(--ink-3); text-align: right; margin-top: 4px; }
.char-count.over { color: var(--crit); font-weight: 600; }

.notas-revisor {
  margin-top: 10px; font-size: 12.5px; color: var(--ink-2); background: var(--surface);
  border: 1px dashed var(--line); border-radius: 9px; padding: 9px 11px; display: flex; gap: 7px;
}
.notas-revisor .ico { flex: none; }

.cobertura-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 620; border-radius: 999px; padding: 4px 11px; margin-top: 10px; }
.cobertura-chip.si { background: var(--good-wash); color: var(--good); }
.cobertura-chip.no { background: var(--crit-wash); color: var(--crit); }
.cobertura-chip.ambigua { background: var(--warn-wash); color: var(--warn); }

/* Acciones */
.actions-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.cobertura-check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); margin-top: 12px; }
.cobertura-check input { width: 16px; height: 16px; }

/* Estado especial: error_generacion */
.error-box {
  border: 1.5px solid var(--crit); background: var(--crit-wash); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.error-box .et { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; color: var(--crit); }
.error-box pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; color: var(--ink-2); margin: 0; }

/* Solo lectura (aprobado/rechazado) */
.readonly-box { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.readonly-box .rt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.readonly-box .rt.aprobado { color: var(--good); }
.readonly-box .rt.rechazado { color: var(--crit); }
.readonly-box .txt { font-size: 13.5px; white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; }
.readonly-box .comentario { font-size: 12.5px; color: var(--ink-2); font-style: italic; }
.readonly-box .rf-meta { font-size: 11.5px; color: var(--ink-3); }

/* Modales */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(9,19,18,.5); display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 22px; width: 100%; max-width: 420px;
}
.modal h2 { font-size: 16px; margin: 0 0 8px; }
.modal-hint { font-size: 12.5px; color: var(--ink-2); margin: 0 0 14px; }
.modal label { font-size: 12px; font-weight: 620; color: var(--ink-2); display: block; margin-bottom: 6px; }
.modal textarea, .modal input[type="text"] { width: 100%; }
.modal textarea { min-height: 90px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Toasts */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: 340px; }
.toast {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; box-shadow: var(--shadow); padding: 11px 14px; font-size: 13px; color: var(--ink);
  animation: toast-in .18s ease;
}
.toast.error { border-left-color: var(--crit); }
.toast.success { border-left-color: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Métricas */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px 13px; box-shadow: var(--shadow);
}
.kpi .lab { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); font-weight: 600; }
.kpi .val { font-family: var(--mono); font-size: 25px; font-weight: 600; letter-spacing: -.02em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.kpi .foot { font-size: 11.5px; color: var(--ink-2); margin-top: 6px; }

.grid { display: grid; gap: 14px; margin-top: 14px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 19px; box-shadow: var(--shadow);
}
.card h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); font-weight: 620; margin: 0 0 14px; }

.serie-chart { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 8px; }
.serie-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.serie-bars { width: 100%; display: flex; flex-direction: column-reverse; gap: 2px; height: 100%; justify-content: flex-start; }
.serie-bar { width: 100%; border-radius: 3px 3px 0 0; }
.serie-bar.total { background: var(--surface-2); border: 1px solid var(--line); }
.serie-bar.sin-edicion { background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.serie-label { font-size: 10px; color: var(--ink-3); white-space: nowrap; }
.serie-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 11.5px; color: var(--ink-2); }
.serie-legend .li { display: flex; align-items: center; gap: 5px; }
.serie-legend .sw { width: 9px; height: 9px; border-radius: 2px; }

/* Estado (operador) */
.runs-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.runs-table th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.runs-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.runs-table tr:last-child td { border-bottom: none; }
.status-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 620; }
.status-pill .dot2 { width: 8px; height: 8px; border-radius: 50%; }
.status-pill.ok .dot2 { background: var(--good); }
.status-pill.bad .dot2 { background: var(--crit); }
.quota-bar { height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin-top: 8px; }
.quota-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* Responsive */
@media (max-width: 980px) {
  .review-layout { grid-template-columns: 1fr; }
  .list-panel, .detail-panel { max-height: none; }
  .review-layout.showing-detail .list-panel { display: none; }
  .review-layout:not(.showing-detail) .detail-panel { display: none; }
  .back-to-list { display: inline-flex !important; }
}
.back-to-list { display: none; margin-bottom: 10px; }

@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .cols-2 { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .filters-row { flex-direction: column; }
}

/* ── Prompt de token (401) ─────────────────────────────────────────── */
.token-form {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}
.token-form input {
  min-width: 260px;
  padding: 9px 12px;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 8px;
  background: var(--panel, #fff);
  color: inherit;
  font: inherit;
}
.token-error { color: var(--danger, #d92d20); margin-top: 8px; }
.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;
}
