/* Consulta Ciudadana 2.0: panel con tableros estilo Monday. Etiquetas de estatus de color sólido,
   grupos con franja de color, superficies blancas sobre fondo gris azulado. */

:root {
  color-scheme: light;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Poppins", var(--font);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #f1f3f9;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --surface-3: #eceef5;
  --hover: #dcdfec66;
  --border: #d0d4e4;
  --border-soft: #e6e9ef;
  --text: #323338;
  --text-2: #4b4e69;
  --muted: #676879;
  --faint: #9699a6;

  --primary: #0073ea;
  --primary-hover: #0060b9;
  --primary-soft: #cce5ff;
  --primary-ink: #0060b9;

  /* Paleta de estatus (identidad, no magnitud) */
  --st-green: #00c875;
  --st-grass: #037f4c;
  --st-orange: #fdab3d;
  --st-yellow: #ffcb00;
  --st-red: #df2f4a;
  --st-darkred: #bb3354;
  --st-purple: #a25ddc;
  --st-blue: #579bfc;
  --st-sky: #66ccff;
  --st-navy: #225091;
  --st-pink: #ff5ac4;
  --st-gray: #c4c4c4;
  --st-steel: #808080;
  --st-ink-dark: #323338; /* texto sobre amarillo */

  --series-1: #579bfc;
  --series-2: #00c875;
  --series-3: #a25ddc;
  --series-4: #fdab3d;

  --warn-bg: #fff3dc;
  --warn-border: #ffd88a;
  --warn-text: #7a4d00;
  --bad-bg: #ffe5e9;
  --bad-text: #a1102b;
  --ok-bg: #dcf8ea;
  --ok-text: #03683e;
  --info-bg: #e5f1ff;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.06);
  --shadow: 0 4px 12px rgb(0 0 0 / 0.08);
  --shadow-lg: 0 12px 40px rgb(0 0 0 / 0.18);
  --sidebar-w: 248px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #181b34;
    --surface: #292f4c;
    --surface-2: #30355a;
    --surface-3: #363b62;
    --hover: #4b4e6966;
    --border: #4b4e69;
    --border-soft: #3d4166;
    --text: #e6e9ef;
    --text-2: #c5c7d4;
    --muted: #a8abc0;
    --faint: #7f83a0;
    --primary: #2b8af6;
    --primary-hover: #4a9cf7;
    --primary-soft: #133774;
    --primary-ink: #8cc1ff;
    --warn-bg: #4a3a12;
    --warn-border: #7a5b12;
    --warn-text: #ffd88a;
    --bad-bg: #4d1a26;
    --bad-text: #ff9fb0;
    --ok-bg: #0f3d2a;
    --ok-text: #7ef0b8;
    --info-bg: #1b2f55;
    --shadow-sm: none;
    --shadow: 0 4px 16px rgb(0 0 0 / 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #181b34;
  --surface: #292f4c;
  --surface-2: #30355a;
  --surface-3: #363b62;
  --hover: #4b4e6966;
  --border: #4b4e69;
  --border-soft: #3d4166;
  --text: #e6e9ef;
  --text-2: #c5c7d4;
  --muted: #a8abc0;
  --faint: #7f83a0;
  --primary: #2b8af6;
  --primary-hover: #4a9cf7;
  --primary-soft: #133774;
  --primary-ink: #8cc1ff;
  --warn-bg: #4a3a12;
  --warn-border: #7a5b12;
  --warn-text: #ffd88a;
  --bad-bg: #4d1a26;
  --bad-text: #ff9fb0;
  --ok-bg: #0f3d2a;
  --ok-text: #7ef0b8;
  --info-bg: #1b2f55;
  --shadow-sm: none;
  --shadow: 0 4px 16px rgb(0 0 0 / 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-family: var(--font-head); font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12.5px var(--mono); background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

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

/* ================================================================ shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border-soft); padding: 14px 10px;
  overflow-y: auto; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-family: var(--font-head); font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: #fff;
  background: conic-gradient(from 210deg, var(--st-red), var(--st-orange), var(--st-yellow), var(--st-green), var(--st-blue), var(--st-purple), var(--st-red));
}
.brand-logo .icon { width: 17px; height: 17px; stroke-width: 2.2; filter: drop-shadow(0 1px 1px rgb(0 0 0 / .25)); }
.brand .ver { color: var(--primary); }
.brand small { display: block; font: 400 11.5px var(--font); color: var(--muted); }

.nav-label { font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; padding: 14px 12px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-radius: 6px; color: var(--text-2);
  font-weight: 500; text-decoration: none; position: relative;
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary-ink); }
.nav a .count { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--surface-3); border-radius: 10px; padding: 0 7px; }
.nav a .dot { width: 8px; height: 8px; border-radius: 50%; margin-left: auto; background: var(--st-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--st-green) 25%, transparent); }

.side-foot { margin-top: auto; padding-top: 12px; display: grid; gap: 8px; }
/* Revisión del sistema: siempre a la vista, en el pie de la barra y en el login. */
.rev { margin: 0; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side-foot .rev { padding: 0 4px; }
.login-card .rev { text-align: center; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius); background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--st-purple); color: #fff; font-weight: 600; flex: none; }
.user-card .who { min-width: 0; flex: 1; }
.user-card .who b { display: block; font-weight: 600; font-size: 13px; }
.user-card .who span { font-size: 11.5px; color: var(--muted); }

.nav-scrim { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
}
.topbar .menu-btn { display: none; }
.crumbs { display: flex; align-items: center; gap: 8px; font-family: var(--font-head); font-size: 20px; font-weight: 500; min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs .sep { color: var(--faint); }
.crumbs span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.view { padding: 4px 28px 48px; display: grid; gap: 20px; align-content: start; }

/* ================================================================ controles */
.btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-weight: 500;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 14px; cursor: pointer; min-height: 36px; white-space: nowrap; text-decoration: none;
  transition: background-color .12s, border-color .12s, transform .06s;
}
.btn:hover, .icon-btn:hover { background: var(--hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .icon-btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--st-red); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-success { background: var(--st-green); border-color: var(--st-green); color: #fff; }
.btn-success:hover { background: var(--st-grass); border-color: var(--st-grass); }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.icon-btn { padding: 0; width: 36px; }
.icon-btn.sm { width: 30px; min-height: 30px; }
.btn-ghost.icon-btn { border-color: transparent; background: transparent; }
.btn-ghost.icon-btn:hover { background: var(--hover); }

.field { display: grid; gap: 6px; }
.field > label, .label { font-weight: 500; font-size: 13px; color: var(--text-2); }
.field > label .opt { font-weight: 400; color: var(--faint); }
.hint { font-size: 12.5px; color: var(--muted); }
input[type=text], input[type=number], input[type=password], input[type=tel], input[type=search], input[type=email], input:not([type]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 11px; width: 100%; min-height: 38px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; line-height: 1.5; }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.invalid { border-color: var(--st-red) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--st-red) 15%, transparent) !important; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { font: inherit; font-weight: 500; font-size: 13px; color: var(--muted); background: transparent; border: 0; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; padding: 8px 12px; }

.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { padding-left: 34px; min-width: 220px; }

/* ================================================================ tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .sub { font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.grid-main > aside { position: sticky; top: 76px; display: grid; gap: 16px; }
.stack { display: grid; gap: 16px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.kpi { display: flex; gap: 14px; align-items: flex-start; }
.kpi-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: none; background: var(--c, var(--primary)); }
.kpi-icon .icon { width: 20px; height: 20px; }
.kpi-label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi-value { font-family: var(--font-head); font-size: 28px; font-weight: 500; line-height: 1.15; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-value small { font: 500 13px var(--font); color: var(--muted); margin-left: 4px; }
.kpi-foot { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.hero .kpi-value { font-size: 40px; }

/* Avisos */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius); border: 1px solid var(--warn-border); background: var(--warn-bg); color: var(--warn-text); }
.banner.info { background: var(--info-bg); border-color: color-mix(in srgb, var(--primary) 35%, transparent); color: var(--text); }
.banner.bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--st-red) 35%, transparent); color: var(--bad-text); }
.banner.ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--st-green) 35%, transparent); color: var(--ok-text); }
.banner .icon { margin-top: 1px; }
.banner > div { flex: 1; }
.banner a { color: inherit; text-decoration: underline; font-weight: 600; }
.banner button { margin-left: auto; background: transparent; border: 0; color: inherit; cursor: pointer; padding: 0; }

.empty { text-align: center; padding: 48px 20px; display: grid; justify-items: center; gap: 10px; }
.empty-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-ink); }
.empty-icon .icon { width: 26px; height: 26px; }
.empty h2 { font-size: 18px; }
.empty p { max-width: 440px; color: var(--muted); }
.empty .actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }

/* ================================================================ etiquetas de estatus (estilo Monday) */
.status {
  --c: var(--st-gray);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 112px; height: 30px; padding: 0 12px;
  background: var(--c); color: #fff; font-weight: 500; font-size: 13px; border-radius: var(--radius-sm); white-space: nowrap;
  border: 0; font-family: inherit;
}
button.status { cursor: pointer; }
button.status:hover { filter: brightness(.94); }
.status.dark-ink { color: var(--st-ink-dark); }
.status.sm { min-width: 0; height: 24px; font-size: 12px; padding: 0 9px; }
.status.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.tag .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--st-gray)); }

/* Menú contextual (cambiar estatus) */
.menu {
  position: fixed; z-index: 60; min-width: 200px; background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; display: grid; gap: 4px;
}
.menu button { display: flex; align-items: center; gap: 8px; width: 100%; font: inherit; text-align: left; padding: 6px 8px; border: 0; border-radius: 4px; background: transparent; color: var(--text); cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu button:disabled { opacity: .4; cursor: default; }
.menu .status { width: 100%; }
.menu .menu-note { font-size: 12px; color: var(--muted); padding: 4px 8px; }

/* ================================================================ tableros */
.board-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.group { --g: var(--st-blue); display: grid; gap: 8px; }
.group-head { display: flex; align-items: center; gap: 8px; }
.group-head button { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 0; padding: 2px 4px; color: var(--g); font: 500 16px var(--font-head); cursor: pointer; border-radius: 4px; }
.group-head button:hover { background: var(--hover); }
.group-head .icon { transition: transform .15s; }
.group[data-collapsed] .group-head .icon { transform: rotate(-90deg); }
.group[data-collapsed] .board-wrap { display: none; }
.group-head .count { color: var(--muted); font-size: 13px; }

.board-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border-soft); }
table.board { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.board th {
  font-weight: 500; font-size: 12.5px; color: var(--muted); text-align: center; padding: 9px 10px; white-space: nowrap;
  border-bottom: 1px solid var(--border-soft); background: var(--surface);
}
.board th:first-child, .board td:first-child { text-align: left; }
.board td { padding: 5px 10px; border-bottom: 1px solid var(--border-soft); border-left: 1px solid var(--border-soft); text-align: center; height: 42px; white-space: nowrap; }
.board td:first-child { border-left: 0; position: relative; padding-left: 18px; white-space: normal; min-width: 220px; }
.board td:first-child::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--g); }
.board tbody tr:last-child td { border-bottom: 0; }
.board tbody tr[data-href], .board tbody tr[data-sid], .board tbody tr.clickable { cursor: pointer; }
.board tbody tr:hover td { background: var(--hover); }
.board td.cell-status { padding: 0; position: relative; min-width: 130px; }
.board td.cell-status .status { position: absolute; inset: 0; width: auto; height: auto; border-radius: 0; min-width: 0; }
table.board.fixed { table-layout: fixed; min-width: 640px; }
table.board.fixed td:first-child { min-width: 0; }
.board .title { font-weight: 500; }
.board .sub { font-size: 12px; color: var(--muted); }
.board .num { text-align: right; }
.board-foot td { background: var(--surface-2); font-weight: 500; }
.board-foot td:first-child::before { opacity: .4; }

/* batería de avance (segmentos por estatus) */
.battery { display: flex; height: 22px; border-radius: 4px; overflow: hidden; background: var(--surface-3); min-width: 140px; }
.battery > div { height: 100%; transition: flex-grow .3s; }
.battery.lg { height: 30px; border-radius: 6px; }
.battery-label { font-size: 12px; color: var(--muted); margin-top: 3px; }
.legend { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-2); }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.legend .amt { color: var(--muted); margin-left: 4px; }

/* ================================================================ gráficas */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 12px; align-items: center; }
.hbar-label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-label .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.hbar-track { display: flex; align-items: center; gap: 8px; height: 24px; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--c, var(--primary)); min-width: 3px; transition: width .3s; }
.hbar-fill.zero { min-width: 0; }
.hbar-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hbar-value span { color: var(--muted); font-weight: 400; margin-left: 3px; }

.columns { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 18px; border-bottom: 1px solid var(--border-soft); overflow-x: auto; }
.col-group { flex: 1 0 28px; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 28px; }
.col-bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.col { width: min(16px, 42%); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.col.s1 { background: var(--series-1); }
.col.s2 { background: var(--series-2); }
.col-top { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); padding-bottom: 2px; }
.col-label { font-size: 11px; color: var(--muted); padding-top: 6px; white-space: nowrap; }

.stackbar { display: flex; height: 30px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface-3); }
.stackbar > div { min-width: 3px; }
.table-view { margin-top: 12px; font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--muted); }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table-view td, .table-view th { padding: 5px 8px; border-bottom: 1px solid var(--border-soft); text-align: left; }
.table-view .num { text-align: right; }

/* ================================================================ pestañas */
.page-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button { font: inherit; font-weight: 500; color: var(--muted); background: transparent; border: 0; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 7px; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { font-size: 11.5px; background: var(--surface-3); color: var(--muted); padding: 0 7px; border-radius: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 13px; padding: 4px 11px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: default; }
button.chip { cursor: pointer; }
button.chip:hover { background: var(--hover); }
.chip b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--st-gray)); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-ink); }
.chip.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-text); }
.chip.bad { background: var(--bad-bg); border-color: transparent; color: var(--bad-text); }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border-soft); }

/* ================================================================ preguntas y editor */
.q-card .q-text { font-weight: 500; font-size: 15px; }
.q-card .q-meta { color: var(--muted); font-size: 12.5px; margin: 4px 0 14px; }
.quotes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.quotes li { padding: 9px 12px; border-radius: 6px; background: var(--surface-2); border-left: 3px solid var(--st-purple); }

.step { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff; font: 600 13px var(--font); margin-right: 10px; flex: none; }
.form-section h2 { display: flex; align-items: center; margin-bottom: 16px; }
.form-section .fields { display: grid; gap: 16px; }

.q-list { display: grid; gap: 12px; margin-bottom: 14px; }
.q-item { border: 1px solid var(--border-soft); border-left: 6px solid var(--qc, var(--st-blue)); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; background: var(--surface-2); }
.q-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.q-num { font-weight: 600; font-size: 13px; color: var(--text-2); display: flex; gap: 8px; align-items: center; }
.q-tools { display: flex; gap: 2px; }
.q-row { display: grid; grid-template-columns: 180px 1fr; gap: 10px; }
.q-row label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.opt-pills { display: flex; flex-wrap: wrap; gap: 6px; }

.templates { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.template { text-align: left; font: inherit; background: var(--surface); border: 1px solid var(--border-soft); border-top: 4px solid var(--c); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; color: var(--text); }
.template:hover { box-shadow: var(--shadow); }
.template b { display: block; font-weight: 600; margin-bottom: 2px; }
.template span { font-size: 12.5px; color: var(--muted); }

/* Conversación */
.transcript { display: grid; gap: 10px; }
.turn { max-width: 86%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; }
.turn small { display: block; font-size: 11px; font-weight: 600; opacity: .75; margin-bottom: 2px; }
.turn.bot { background: var(--surface-3); border-bottom-left-radius: 4px; justify-self: start; }
.turn.ciudadano { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; justify-self: end; }
.turn.herramienta { justify-self: center; font: 12px var(--mono); color: var(--muted); background: transparent; padding: 2px 8px; border: 1px dashed var(--border); border-radius: 12px; max-width: 100%; }
.turn.error { justify-self: center; background: var(--bad-bg); color: var(--bad-text); font-size: 12.5px; }
.turn .opts { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.turn.typing { color: var(--muted); }
.turn.typing::after { content: "…"; animation: pulse 1s infinite; }
.note { justify-self: center; font-size: 12px; color: var(--muted); text-align: center; }
.script { max-height: 560px; overflow-y: auto; padding-right: 4px; }

.chat { display: grid; grid-template-rows: 1fr auto; min-height: 420px; max-height: 620px; }
.chat .transcript { overflow-y: auto; padding: 4px 4px 12px; align-content: start; }
.chat-input { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.chat-input form { display: flex; gap: 8px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { font: inherit; font-size: 12.5px; padding: 3px 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; }
.quick button:hover { background: var(--hover); }

.timeline { font: 12.5px/1.75 var(--mono); display: grid; }
.timeline .ev { display: grid; grid-template-columns: 56px 92px 1fr; gap: 8px; }
.timeline .ev .t { color: var(--faint); }
.timeline .ev .k { color: var(--c, var(--primary)); font-weight: 600; }
.timeline .ev .x { color: var(--text-2); word-break: break-word; }

.mini-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.mini-tile { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.mini-tile .l { font-size: 12px; color: var(--muted); }
.mini-tile .v { font: 500 14px var(--mono); margin-top: 2px; word-break: break-word; }

.answers { display: grid; gap: 10px; }
.answers .a { padding: 10px 12px; border-radius: 6px; background: var(--surface-2); }
.answers .a .q { font-size: 12px; color: var(--muted); }
.answers .a .v { font-weight: 600; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 13.5px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; }
.checklist li { display: flex; gap: 8px; align-items: flex-start; }
.checklist .icon { color: var(--st-green); margin-top: 1px; }
.estimate { display: grid; gap: 8px; font-size: 13.5px; }
.estimate div { display: flex; justify-content: space-between; gap: 10px; }
.estimate b { font-variant-numeric: tabular-nums; font-family: var(--mono); font-weight: 500; }
.estimate .total { border-top: 1px solid var(--border-soft); padding-top: 8px; font-weight: 600; }

/* Pasos (inicio) */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.step-card { display: flex; gap: 12px; padding: 14px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text); text-decoration: none; }
.step-card:hover { text-decoration: none; box-shadow: var(--shadow); }
.step-card b { display: block; font-weight: 600; }
.step-card span { font-size: 12.5px; color: var(--muted); }
.step-card .n { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: 13px; flex: none; }
.step-card.done .n { background: var(--st-green); border-color: var(--st-green); color: #fff; }

.live-list { display: grid; gap: 14px; }
.live-item { display: grid; gap: 6px; text-decoration: none; color: var(--text); padding: 10px; margin: -10px; border-radius: 6px; }
.live-item:hover { background: var(--hover); text-decoration: none; }
.live-item .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 500; }
.live-item .top span { color: var(--muted); font-weight: 400; font-size: 12.5px; white-space: nowrap; }

.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.count-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.count-card:hover { text-decoration: none; border-color: var(--border); box-shadow: var(--shadow); }
.count-card .kpi-icon { width: 36px; height: 36px; border-radius: 9px; }
.count-card b { font: 500 22px var(--font-head); display: block; line-height: 1.1; }
.count-card span { font-size: 12.5px; color: var(--muted); }

.connectors { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.connector { display: grid; gap: 10px; }
.connector .top { display: flex; gap: 12px; align-items: center; }
.connector .top b { font-weight: 600; display: block; }
.connector .top span { font-size: 12.5px; color: var(--muted); }

/* Contactos (carga) */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 24px; display: grid; justify-items: center; gap: 6px; text-align: center; cursor: pointer; background: var(--surface-2); transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--info-bg); }
.dropzone .icon { width: 26px; height: 26px; color: var(--primary); }
.dropzone .link { color: var(--primary); font-weight: 600; }
.paste { margin-top: 10px; }
.paste summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.paste textarea { margin-top: 8px; font-family: var(--mono); font-size: 13px; }
.parse-summary { margin-top: 14px; display: grid; gap: 10px; }
.parse-summary table { width: 100%; border-collapse: collapse; font-size: 13px; }
.parse-summary td, .parse-summary th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.bad-rows { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--bad-text); }

/* ================================================================ capas */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 50;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); gap: 10px; }
.drawer-body { padding: 20px; overflow-y: auto; display: grid; gap: 20px; align-content: start; }
.scrim { position: fixed; inset: 0; background: rgb(15 18 40 / .45); z-index: 40; }
.modal {
  position: fixed; z-index: 55; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(440px, calc(100% - 32px));
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 22px; display: grid; gap: 14px;
}
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 8px; background: #323338; color: #fff; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: min(560px, calc(100vw - 32px)); animation: toast-in .2s ease-out; }
.toast .icon { color: var(--st-green); }
.toast.bad .icon { color: #ff8a9c; }
.toast.warn .icon { color: var(--st-orange); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }
.tooltip { position: fixed; z-index: 80; pointer-events: none; background: #323338; color: #fff; font-size: 12.5px; padding: 6px 9px; border-radius: 6px; max-width: 280px; box-shadow: var(--shadow); }
.error { color: var(--st-red); font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background:
  radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--st-purple) 18%, transparent), transparent),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--st-blue) 22%, transparent), transparent), var(--bg); }
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 32px; display: grid; gap: 14px; }
.login-card .brand { padding: 0 0 6px; }

.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ================================================================ permisos (el servidor los aplica; esto solo oculta) */
body:not([data-role="administrador"]) .owner-only { display: none !important; }
body[data-role="lector"] .act { display: none !important; }
body[data-role="lector"] button.status { pointer-events: none; }
.avatar { text-decoration: none; }
.avatar:hover { text-decoration: none; filter: brightness(1.08); }
.link-box { display: flex; gap: 8px; }
.link-box input { font-family: var(--mono); font-size: 12.5px; }

/* ================================================================ responsivo */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: 1fr; }
  .grid-main > aside { position: static; }
  .counts { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .shell[data-nav-open] .sidebar { transform: none; }
  .shell[data-nav-open] .nav-scrim { display: block; }
  .nav-scrim { position: fixed; inset: 0; z-index: 15; background: rgb(15 18 40 / .4); }
  .topbar { padding: 12px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar-actions .btn span { display: none; }
  .view { padding: 4px 16px 40px; }
  .grid-2, .row-2, .row-3, .steps { grid-template-columns: 1fr; }
  .q-row { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 1fr; gap: 4px; }
  .crumbs { font-size: 17px; }
  .search input { min-width: 0; }
  .kpi.hero .kpi-value { font-size: 32px; }
}
@media (max-width: 520px) {
  .counts { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 16px; }
  .timeline .ev { grid-template-columns: 48px 1fr; }
  .timeline .ev .x { grid-column: 1 / -1; padding-left: 56px; margin-top: -6px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
