:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #1c2321;
  --muted: #5d6965;
  --line: #dde2df;
  --accent: #0f766e;
  --accent-strong: #0b5c56;
  --accent-soft: #d9f0ec;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --done: #15803d;
  --done-soft: #dcf5e4;
  --callback: #a15c00;
  --callback-soft: #fdefd0;
  --attempted: #a3361b;
  --attempted-soft: #fde6df;
  --claimed: #1d4ed8;
  --claimed-soft: #e0e9fd;
  --pending: #55605c;
  --pending-soft: #e8ebe9;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #1a211f;
    --surface-2: #232b29;
    --text: #e8eeeb;
    --muted: #9aa8a3;
    --line: #2f3936;
    --accent: #2dd4bf;
    --accent-strong: #5eead4;
    --accent-soft: #123a35;
    --on-accent: #062a26;
    --danger: #ff8a80;
    --danger-soft: #3b1d1a;
    --done: #6ee7a0;
    --done-soft: #14351f;
    --callback: #fbbf5a;
    --callback-soft: #3a2b0b;
    --attempted: #ff9d84;
    --attempted-soft: #3b1f18;
    --claimed: #8fb0ff;
    --claimed-soft: #1a2747;
    --pending: #a7b3ae;
    --pending-soft: #252d2b;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent-strong); }
.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Botones y campos ---------- */
button, input, textarea, select { font: inherit; color: inherit; }
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 44px; padding: 0.5rem 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 36px; padding: 0.25rem 0.75rem; font-size: 0.9rem; }
.btn.block { width: 100%; }

label.field { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.925rem; }
input[type="text"], input[type="password"], input[type="date"], input[type="search"], textarea, select {
  width: 100%; min-height: 44px; padding: 0.55rem 0.75rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-weight: 400;
}
textarea { resize: vertical; min-height: 96px; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 880px; margin: 0 auto; padding: 0.6rem 1rem;
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; margin-right: auto; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 0.95rem;
}
.tabs { display: flex; gap: 0.25rem; }
.tab { padding: 0.45rem 0.8rem; border-radius: 8px; border: 0; background: none; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 40px; }
.tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }
.userbox { display: flex; align-items: center; gap: 0.25rem; }

main { max-width: 880px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.stack { display: grid; gap: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login { width: min(400px, 100%); display: grid; gap: 1rem; }
.login .brand { margin: 0; font-size: 1.2rem; }

/* ---------- Mes y progreso ---------- */
.monthnav { display: flex; align-items: center; gap: 0.5rem; }
.monthnav h2 { flex: 1; text-align: center; font-size: 1.25rem; }
.monthnav h2::first-letter { text-transform: uppercase; }
.progress-top { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.big { font-size: 1.6rem; font-weight: 700; }
.bar { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 0.6rem 0; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--done); border-radius: 99px; transition: width 0.4s ease; }
.counts { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0.6rem; border-radius: 99px;
  font-size: 0.8rem; font-weight: 700; white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.done { color: var(--done); background: var(--done-soft); }
.badge.callback { color: var(--callback); background: var(--callback-soft); }
.badge.attempted { color: var(--attempted); background: var(--attempted-soft); }
.badge.claimed { color: var(--claimed); background: var(--claimed-soft); }
.badge.pending { color: var(--pending); background: var(--pending-soft); }

.banner { padding: 0.75rem 1rem; border-radius: var(--radius); background: var(--callback-soft); color: var(--callback); font-weight: 600; }
.banner.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Filtros y lista ---------- */
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0.3rem 0.85rem; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.person {
  width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; align-items: center;
  padding: 0.8rem 1rem; min-height: 64px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer;
}
.person:hover { border-color: var(--accent); }
.person .txt { display: grid; gap: 0.1rem; min-width: 0; }
.person .tags { display: grid; gap: 0.25rem; justify-items: end; }
.person .name { font-weight: 700; overflow-wrap: anywhere; }
.person .sub { color: var(--muted); font-size: 0.875rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* ---------- Ventana de persona ---------- */
dialog {
  width: min(560px, 100%); max-height: 100dvh; padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--bg); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}
dialog::backdrop { background: rgb(8 12 11 / 55%); }
@media (max-width: 600px) {
  dialog { width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; margin: 0; }
}
.dlg-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 0.5rem; padding: 0.9rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.dlg-head h2 { flex: 1; }
.dlg-body { padding: 1rem; display: grid; gap: 1rem; }
.phones { display: grid; gap: 0.5rem; }
.phone-btn { justify-content: flex-start; font-size: 1.1rem; }
.phone-btn small { font-weight: 400; color: var(--muted); }
.outcomes { display: grid; gap: 0.5rem; border: 0; padding: 0; margin: 0; }
.outcomes legend { font-weight: 600; font-size: 0.925rem; margin-bottom: 0.4rem; padding: 0; }
.outcome { position: relative; display: block; }
.outcome input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.outcome span { display: block; padding: 0.65rem 0.85rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.outcome b { display: block; }
.outcome small { color: var(--muted); }
.outcome input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.outcome input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.history li { padding: 0.7rem 0.85rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); display: grid; gap: 0.3rem; }
.history .meta { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); }
.history .note { white-space: pre-wrap; overflow-wrap: anywhere; }
.sync-warn { color: var(--callback); font-weight: 600; font-size: 0.85rem; }

/* ---------- Administración ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.grid2 { display: grid; gap: 0.75rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Avisos ---------- */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(1rem + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 0.5rem; pointer-events: none; z-index: 100; padding: 0 1rem; }
.toast { pointer-events: auto; max-width: 480px; padding: 0.75rem 1rem; border-radius: 10px; background: #1c2321; color: #fff; box-shadow: var(--shadow); font-weight: 600; }
.toast.warn { background: #92400e; }
.toast.error { background: #991b1b; }

@media (prefers-reduced-motion: reduce) { .bar > span { transition: none; } }

/* ---------- Asignaciones ---------- */
.tab { position: relative; }
.dot {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 99px; background: var(--danger); color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 1;
}
.dot[hidden] { display: none; }
.badge.new { color: var(--claimed); background: var(--claimed-soft); }
.badge.tiny { font-size: 0.7rem; padding: 0.05rem 0.45rem; margin-left: 0.4rem; }
.greet { margin-bottom: 0.4rem; }
.warn-text { color: var(--callback); }
.events { margin: 0.4rem 0 0; padding-left: 1.2rem; display: grid; gap: 0.2rem; max-height: 260px; overflow: auto; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent-strong); min-height: 32px; display: flex; align-items: center; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }

.switch { display: grid; grid-template-columns: auto 1fr; gap: 0.75rem; align-items: start; cursor: pointer; }
.switch input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); }
.switch b { display: block; }
.switch small { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }
.weekly { padding-top: 0.5rem; border-top: 1px solid var(--line); }

.request { padding: 0.75rem 0; border-top: 1px solid var(--line); }
.request:first-of-type { border-top: 0; padding-top: 0; }
.request select { width: auto; min-width: 140px; }

input.cap { width: 96px; min-height: 36px; padding: 0.25rem 0.5rem; }
td input[type="checkbox"], .arow input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

.bulk { position: sticky; top: 64px; z-index: 3; padding: 0.5rem; margin: 0 -0.5rem; background: var(--surface); border-radius: 10px; }
.bulk select { width: auto; min-width: 150px; min-height: 36px; padding: 0.2rem 0.5rem; }
.arows { list-style: none; margin: 0; padding: 0; display: grid; }
.arow { display: grid; grid-template-columns: auto 1fr minmax(130px, 200px); gap: 0.6rem; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--line); }
.arow select { min-height: 38px; padding: 0.25rem 0.5rem; }
.arow select.unassigned { border-color: var(--callback); color: var(--callback); font-weight: 600; }
.linklike { appearance: none; background: none; border: 0; padding: 0.4rem 0; text-align: left; cursor: pointer; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.linklike:hover { color: var(--accent-strong); text-decoration: underline; }
@media (max-width: 480px) {
  .arow { grid-template-columns: auto 1fr; }
  .arow select { grid-column: 2; }
}

/* Tabla de carga: en móvil cada voluntario es una tarjeta */
@media (max-width: 600px) {
  table.stackable thead { display: none; }
  table.stackable, table.stackable tbody { display: block; }
  table.stackable tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 0.75rem; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
  table.stackable td { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; border: 0; padding: 0.1rem 0; }
  table.stackable td.who { grid-column: 1 / -1; font-weight: 600; }
  table.stackable td[data-label]::before { content: attr(data-label); font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
  table.stackable td.num { text-align: right; }
  table.stackable td:last-child:empty { display: none; }
  table.stackable td:last-child { grid-column: 1 / -1; }
}
