/* PolicIApp · Panel de administración
   Tokens de assets/brand/tokens.json v0.4 (tema claro). Sin dependencias externas:
   Lexend y Source Sans 3 se usan si están instaladas; si no, la pila del sistema. */

:root {
  --bg: #F4F5F0;
  --surface: #FFFFFF;
  --text: #142D2D;
  --text-2: #526663;
  --primary: #145C54;
  --on-primary: #FFFFFF;
  --primary-pressed: #0E453F;
  --outline: #6F837D;
  --accent: #C78B4B;
  --subtle: #E4EEE7;
  --error: #B42318;
  --error-bg: #FDEBE8;
  --warning: #8C5200;
  --warning-bg: #FFF1D6;
  --success: #1F6B46;
  --success-bg: #E5F1E8;
  --info: #245E87;
  --info-bg: #E8F1F8;

  /* Identidad oscura (tema oscuro de tokens) para la barra superior */
  --ink: #142D2D;
  --ink-2: #0F2321;
  --on-ink: #F3F6EE;
  --on-ink-2: #BCCDC3;
  --ink-ia: #9BD6BC;

  --line: #DCE3DE;
  --line-strong: #C5D0CA;
  --row-hover: #F7F9F6;

  --font-head: "Lexend", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-body: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --r-chip: 8px;
  --r-control: 12px;
  --r-panel: 16px;
  --ctl-h: 38px;
  --focus: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
  --t-press: 100ms;
  --t-state: 180ms;
  --rail-w: 240px;
  --top-h: 56px;
}

@media (pointer: coarse) {
  :root { --ctl-h: 46px; }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

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

[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--font-head); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
strong { font-weight: 600; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

.mono { font-family: var(--font-mono); font-size: 0.92em; letter-spacing: 0; }

:focus-visible { outline: none; box-shadow: var(--focus); }
[tabindex="-1"]:focus { outline: none; box-shadow: none; }

/* ---------- Marca ---------- */

.wordmark {
  font-family: var(--font-head); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; margin: 0;
}
.wordmark-dark { color: var(--text); font-size: 22px; line-height: 1.1; }
.wordmark-dark .wm-ia { color: var(--primary); }
.wordmark-light { color: var(--on-ink); font-size: 18px; }
.wordmark-light .wm-ia { color: var(--ink-ia); }
.brand-logo { object-fit: contain; border-radius: 6px; }

/* ---------- Carga inicial ---------- */

.boot {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  color: var(--text-2);
}

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--primary);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Acceso ---------- */

.auth {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: flex-start; justify-content: center;
  padding: clamp(20px, 8vh, 96px) 20px 40px;
  background:
    linear-gradient(180deg, var(--ink) 0, var(--ink) 168px, var(--bg) 168px);
}

.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: var(--r-panel);
  box-shadow: 0 12px 32px rgba(20, 45, 45, 0.10);
  padding: 28px 28px 24px;
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-brand-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-title { font-size: 22px; line-height: 30px; }
.auth-lead { color: var(--text-2); }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--r-control);
  background: var(--info-bg); color: var(--info);
  margin-bottom: 16px; font-size: 14px;
}
.notice p { color: var(--text); }
.notice .icon { margin-top: 2px; }
.notice-success { background: var(--success-bg); color: var(--success); }
.notice-warning { background: var(--warning-bg); color: var(--warning); margin-bottom: 0; }
.notice-error { background: var(--error-bg); color: var(--error); }

/* ---------- Campos ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
.field > label, .field > legend { font-weight: 600; font-size: 14px; }
.optional { font-weight: 400; color: var(--text-2); font-size: 13px; margin-left: 4px; }
.help { color: var(--text-2); font-size: 13px; line-height: 1.4; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: var(--ctl-h);
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--r-control);
  transition: border-color var(--t-state), box-shadow var(--t-state);
}
textarea { resize: vertical; min-height: 76px; line-height: 1.4; }
input:hover, select:hover, textarea:hover { border-color: var(--text-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--primary); }
input[readonly] { background: var(--bg); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--error); }
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.form-error {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--error-bg); color: var(--error);
  border-radius: var(--r-control); padding: 10px 12px; font-size: 14px;
}
.form-error p { color: #7A1A12; }

.copy-field { display: flex; gap: 8px; }
.copy-field input { flex: 1; min-width: 0; }

.radio-group { gap: 8px; }
.radio-group legend { margin-bottom: 6px; padding: 0; }
.radio {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-control);
  cursor: pointer; transition: border-color var(--t-state), background var(--t-state);
}
.radio:hover { background: var(--row-hover); }
.radio:has(input:checked) { border-color: var(--primary); background: #F1F7F4; }
.radio input { margin: 3px 0 0; accent-color: var(--primary); width: 16px; height: 16px; flex: none; }
.radio span { display: flex; flex-direction: column; gap: 1px; }
.radio small { color: var(--text-2); font-size: 13px; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--ctl-h); padding: 0 14px;
  border-radius: var(--r-control); border: 1px solid transparent;
  font-weight: 600; font-size: 14px; line-height: 1.2; white-space: nowrap;
  cursor: pointer; text-decoration: none;
  transition: background var(--t-press), border-color var(--t-press), color var(--t-press);
}
.btn:disabled { cursor: not-allowed; }
.btn-block { width: 100%; min-height: 44px; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: #105048; }
.btn-primary:active { background: var(--primary-pressed); }
.btn-primary:disabled { background: var(--subtle); color: var(--text-2); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--outline); background: var(--row-hover); }
.btn-secondary:active { background: var(--subtle); }
.btn-danger { background: var(--error); color: #FFFFFF; }
.btn-danger:hover { background: #9A1D14; }
.btn-danger-outline { background: var(--surface); color: var(--error); border-color: #E4B4AE; }
.btn-danger-outline:hover { background: var(--error-bg); }
.btn-on-dark { background: transparent; color: var(--on-ink); border-color: rgba(243, 246, 238, 0.28); min-height: 34px; padding: 0 12px; }
.btn-on-dark:hover { background: rgba(243, 246, 238, 0.08); }
@media (pointer: coarse) { .btn-on-dark { min-height: 44px; } }
.btn-on-dark:focus-visible { box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--ink-ia); }
.btn[aria-busy="true"] { position: relative; color: transparent !important; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--line-strong); border-top-color: var(--primary);
  animation: spin 800ms linear infinite;
}
.btn-primary[aria-busy="true"]::after, .btn-danger[aria-busy="true"]::after { border-color: rgba(255,255,255,0.35); border-top-color: #FFFFFF; }

.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; gap: 6px; }
.btn-sm .icon { width: 15px; height: 15px; }
@media (pointer: coarse) { .btn-sm { min-height: 40px; padding: 0 12px; } }

.link-btn {
  background: none; border: 0; padding: 6px 2px; align-self: center;
  color: var(--primary); font-weight: 600; font-size: 14px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
  border-radius: 6px;
}
.link-btn:hover { color: var(--primary-pressed); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--subtle); color: var(--text); }
@media (pointer: coarse) { .icon-btn { width: 44px; height: 44px; } }
.icon-btn-xs { width: 26px; height: 26px; }
.icon-btn-xs .icon { width: 14px; height: 14px; }
@media (pointer: coarse) { .icon-btn-xs { width: 40px; height: 40px; } }

/* ---------- Estructura ---------- */

.shell {
  min-height: 100vh; min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  grid-template-areas: "top top" "rail main";
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 50;
  background: var(--surface); color: var(--primary); padding: 8px 12px; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 10px; }

.topbar {
  grid-area: top; position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px 0 18px;
  background: var(--ink); color: var(--on-ink);
  border-bottom: 2px solid var(--accent);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-brand .brand-logo { border-radius: 4px; }
.topbar-tag {
  font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--on-ink-2); border: 1px solid rgba(188, 205, 195, 0.35);
  padding: 2px 7px; border-radius: 6px;
}
.topbar-end { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-user {
  color: var(--on-ink-2); font-size: 14px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px;
}

.rail {
  grid-area: rail;
  position: sticky; top: var(--top-h); align-self: start;
  height: calc(100vh - var(--top-h)); height: calc(100dvh - var(--top-h));
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px 24px;
}
.rail ul { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rail-group {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  padding: 8px 10px 6px; letter-spacing: 0.02em;
}
.rail-link {
  display: flex; align-items: center; gap: 10px;
  min-height: 38px; padding: 0 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
  position: relative;
  transition: background var(--t-press), color var(--t-press);
}
.rail-link .icon { color: var(--text-2); }
.rail-link:hover { background: var(--row-hover); }
.rail-link[aria-current="page"] { background: #E8F2EE; color: var(--primary-pressed); }
.rail-link[aria-current="page"] .icon { color: var(--primary); }
.rail-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--primary);
}
.rail-count {
  margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px;
  background: var(--warning-bg); color: var(--warning); font-size: 12px; text-align: center;
}

.main {
  grid-area: main; min-width: 0;
  padding: 18px 28px 48px;
  max-width: 1320px; width: 100%;
}
.main:focus { outline: none; }

.crumbs ol {
  list-style: none; margin: 0 0 10px; padding: 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  font-size: 13px; color: var(--text-2);
}
.crumbs li { display: inline-flex; align-items: center; gap: 4px; }
.crumbs li + li::before {
  content: "/"; color: var(--line-strong); margin-right: 4px;
}
.crumbs a { color: var(--text-2); text-decoration: none; border-radius: 4px; }
.crumbs a:hover { color: var(--primary); text-decoration: underline; }
.crumbs [aria-current="page"] { color: var(--text); font-weight: 600; }

.view-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.view-titles { min-width: 0; flex: 1 1 360px; }
.view-title { font-size: 24px; line-height: 32px; }
.view-sub { color: var(--text-2); margin-top: 2px; font-size: 14px; max-width: 72ch; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 8px;
}
.toolbar-end { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.chips {
  display: flex; gap: 6px; flex-wrap: wrap; min-width: 0;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 0 10px; border-radius: var(--r-chip);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background var(--t-press), border-color var(--t-press);
}
@media (pointer: coarse) { .chip { min-height: 40px; } }
.chip:hover { border-color: var(--outline); }
.chip-count { color: var(--text-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.chip[aria-pressed="true"] .chip-count { color: var(--ink-ia); }

.search { position: relative; flex: 0 1 280px; min-width: 200px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-2); width: 16px; height: 16px; pointer-events: none; }
.search input { padding-left: 32px; min-height: 34px; }
.select-wrap select { min-height: 34px; min-width: 180px; }
@media (pointer: coarse) { .search input, .select-wrap select { min-height: 44px; } }

.result-count { font-size: 13px; color: var(--text-2); margin: 0 0 8px; min-height: 18px; font-variant-numeric: tabular-nums; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  overflow: hidden;
}

.more { display: flex; justify-content: center; margin-top: 12px; }

/* ---------- Estados de panel ---------- */

.state {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
  padding: 40px 20px;
  color: var(--text-2);
}
.state .icon { width: 28px; height: 28px; stroke-width: 1.6; }
.state-title { font-family: var(--font-head); font-weight: 600; color: var(--text); font-size: 16px; }
.state-text { max-width: 52ch; font-size: 14px; }
.state-error .icon { color: var(--error); }
.state .btn { margin-top: 6px; }

.skeleton { padding: 6px 0; }
.skeleton-row { display: flex; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.skeleton-row:last-child { border-bottom: 0; }
.skeleton-bar { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--subtle), #F1F5F2, var(--subtle)); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.skeleton-bar.w1 { flex: 0 0 22%; } .skeleton-bar.w2 { flex: 0 0 12%; } .skeleton-bar.w3 { flex: 0 0 18%; } .skeleton-bar.w4 { flex: 1; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Tablas ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: auto; }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2);
  padding: 9px 14px; background: #FAFBF8; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--row-hover); }
.table .col-actions { text-align: right; width: 1%; white-space: nowrap; }
.cell-main { font-weight: 600; overflow-wrap: anywhere; }
.cell-sub { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.cell-stack { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.muted { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

.id {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
}
.id-text {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12ch;
}
.id .icon-btn { color: var(--text-2); }

.actions { display: inline-flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 18px; white-space: nowrap;
  background: var(--subtle); color: var(--text-2);
  font-family: var(--font-body); letter-spacing: 0; vertical-align: middle;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge:empty { display: none; }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-brand { background: #E8F2EE; color: var(--primary-pressed); }

.when { display: flex; flex-direction: column; gap: 1px; }
.when-rel { font-size: 12.5px; color: var(--text-2); }
.when-rel.is-soon { color: var(--warning); font-weight: 600; }
.when-rel.is-past { color: var(--text-2); }

/* ---------- Listas de actividad y revisión ---------- */

.feed { list-style: none; margin: 0; padding: 0; }
.feed-item {
  display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; gap: 4px 16px; align-items: baseline;
  padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.feed-item:last-child { border-bottom: 0; }
.feed-time { color: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.feed-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.feed-action { font-weight: 600; overflow-wrap: anywhere; }
.feed-refs { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--text-2); font-size: 13px; }
.feed-ref { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.feed-actor { color: var(--text-2); font-size: 13px; text-align: right; overflow-wrap: anywhere; max-width: 220px; }
.feed-detail { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }

.review-list { list-style: none; margin: 0; padding: 0; }
.review-item {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px 20px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.review-item:last-child { border-bottom: 0; }
.review-who { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.review-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kv { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: 14px; }
.kv-label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.reason { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); overflow-wrap: anywhere; }

/* ---------- Ajustes ---------- */

.settings { display: flex; flex-direction: column; gap: 12px; max-width: 880px; }
.setting {
  display: flex; gap: 16px; justify-content: space-between; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel);
  padding: 18px 20px;
}
.setting-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 380px; }
.setting-title { font-size: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-text { overflow-wrap: anywhere; }
.setting-side { display: flex; gap: 8px; }

/* ---------- Diálogos ---------- */

.dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-panel);
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 64px rgba(15, 35, 33, 0.28);
  overflow: auto;
}
.dialog-sm { width: min(440px, calc(100vw - 24px)); }
.dialog-lg { width: min(620px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(15, 35, 33, 0.52); }
.dialog[open] { animation: dlg-in var(--t-state) ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 16px 0 20px;
}
.dialog-title { font-size: 18px; line-height: 26px; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 14px 20px 20px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

.meta-list {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px;
  margin: 0; padding: 12px 14px; background: var(--bg); border-radius: var(--r-control); font-size: 14px;
}
.meta-list:empty { display: none; }
.meta-list dt { color: var(--text-2); font-weight: 600; font-size: 13px; }
.meta-list dd { margin: 0; overflow-wrap: anywhere; }

.steps {
  list-style: none; display: flex; gap: 6px; margin: 12px 20px 0; padding: 0; counter-reset: step;
  font-size: 12.5px; color: var(--text-2); flex-wrap: wrap;
}
.step { counter-increment: step; display: flex; align-items: center; gap: 6px; }
.step::before {
  content: counter(step); display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line-strong); font-weight: 600; font-size: 11.5px;
}
.step + .step::after { content: none; }
.step[aria-current="step"] { color: var(--text); font-weight: 600; }
.step[aria-current="step"]::before { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.step.is-done::before { background: var(--success-bg); color: var(--success); border-color: var(--success-bg); }

.codes {
  list-style: none; margin: 0; padding: 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px;
  background: var(--bg); border-radius: var(--r-control); font-size: 14px;
}
.codes li { overflow-wrap: anywhere; }

/* ---------- Avisos flotantes ---------- */

.toasts {
  position: fixed; z-index: 60; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--r-control);
  background: var(--ink); color: var(--on-ink); font-size: 14px;
  box-shadow: 0 8px 24px rgba(15, 35, 33, 0.24);
  pointer-events: auto; animation: dlg-in var(--t-state) ease-out;
}
.toast .icon { color: var(--ink-ia); }
.toast-error .icon { color: #FFB4AB; }

/* ---------- Adaptación ---------- */

@media (max-width: 960px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--top-h) auto minmax(0, 1fr);
    grid-template-areas: "top" "rail" "main";
  }
  .rail {
    position: sticky; top: var(--top-h); z-index: 15; height: auto;
    display: flex; align-items: center; gap: 4px;
    padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-group { display: none; }
  .rail ul { flex-direction: row; margin: 0; gap: 4px; }
  .rail-link { white-space: nowrap; min-height: 40px; }
  .rail-link[aria-current="page"]::before { left: 10px; right: 10px; top: auto; bottom: -6px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
  .main { padding: 14px 20px 40px; }
  .review-item { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .review-item > .review-who { grid-column: 1 / -1; }
  .review-item > .actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 720px) {
  body { font-size: 15px; }
  .topbar { padding: 0 12px; }
  .topbar-user { display: none; }
  .btn-on-dark span { display: none; }
  .btn-on-dark { width: 44px; min-height: 44px; padding: 0; }
  .main { padding: 12px 14px 32px; }
  .view-title { font-size: 21px; line-height: 28px; }
  .view-head { align-items: flex-start; }
  .btn-icon-only-sm .btn-label { display: none; }
  .btn-icon-only-sm { width: var(--ctl-h); padding: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-end { flex-direction: column; align-items: stretch; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
  .chips::-webkit-scrollbar { display: none; }
  .search { flex: 1 1 auto; min-width: 0; }
  .select-wrap select { width: 100%; }

  /* Tablas en tarjetas apiladas */
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 10px; align-items: baseline; }
  .table td::before { content: attr(data-label); color: var(--text-2); font-size: 12px; font-weight: 600; }
  .table td.td-primary { grid-template-columns: minmax(0, 1fr); padding-bottom: 6px; }
  .table td.td-primary::before { content: none; }
  .table .col-actions { width: 100%; text-align: left; grid-template-columns: minmax(0, 1fr); padding-top: 8px; }
  .table .col-actions::before { content: none; }
  .actions { justify-content: flex-start; }
  .id-text { max-width: 22ch; }

  .feed-item { grid-template-columns: minmax(0, 1fr); gap: 3px; }
  .feed-actor { text-align: left; max-width: none; }
  .review-item { grid-template-columns: minmax(0, 1fr); }

  .field-row { grid-template-columns: 1fr; }
  .codes { grid-template-columns: 1fr; }
  .dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .dialog-foot { flex-direction: column-reverse; }
  .dialog-foot .btn { width: 100%; }
  .meta-list { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .meta-list dd { margin-bottom: 6px; }

  .auth { padding-top: 24px; background: linear-gradient(180deg, var(--ink) 0, var(--ink) 120px, var(--bg) 120px); }
  .auth-card { padding: 22px 18px 18px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .spinner, .btn[aria-busy="true"]::after { animation: spin 1.6s linear infinite !important; }
}

@media (forced-colors: active) {
  .badge, .chip[aria-pressed="true"], .rail-link[aria-current="page"] { border: 1px solid CanvasText; }
  :focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
}

@media print {
  .topbar, .rail, .view-actions, .toolbar, .actions, .toasts { display: none !important; }
  .shell { display: block; }
}

/* Keep operational lists compact on desktops; phones get full-width labelled rows. */
@media (min-width: 1100px) {
  .table .col-actions .actions { flex-wrap: nowrap; }
}
.table .badge { justify-self: start; align-self: start; }

.case-details { margin: 12px 0; border: 1px solid var(--border, #bccdc3); background: white; border-radius: 8px; }
.case-details summary { cursor: pointer; padding: 12px 16px; font-weight: 600; }
.case-body { display: grid; gap: 12px; max-width: 42rem; padding: 0 16px 16px; }
.case-body .btn { justify-self: start; }
@media (max-width: 720px) {
  .toolbar, .toolbar-end { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; }
  .chips { max-width: 100%; margin: 0; }
}
