:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16181d;
  --muted: #5f6672;
  --border: #dde1e7;
  --primary: #1d4ed8;
  --primary-ink: #ffffff;
  --primary-soft: #e3eafc;
  --danger: #c62828;
  --danger-soft: #fde8e8;
  --warn: #b45309;
  --warn-soft: #fdf1df;
  --ok: #15803d;
  --ok-soft: #e2f4e8;
  --wait: #6d28d9;
  --wait-soft: #efe8fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --nav-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #2c313a;
    --primary: #6b93f5;
    --primary-ink: #0b1020;
    --primary-soft: #1c2742;
    --danger: #f17171;
    --danger-soft: #3a1c1c;
    --warn: #f0a640;
    --warn-soft: #3a2a14;
    --ok: #4ccf7d;
    --ok-soft: #173023;
    --wait: #b197fc;
    --wait-soft: #2a2140;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* evita el zoom automático en iPhone */
button { cursor: pointer; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Pantallas simples ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.panel { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.panel h1 { font-size: 20px; margin: 0 0 4px; }
.panel p { margin: 0 0 16px; }

/* ---------- Formularios ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { min-height: 80px; resize: vertical; }
.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* ---------- Estructura ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.top .brand { font-weight: 700; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; border: 0;
}
main { padding: 14px 16px calc(var(--nav-h) + 90px); max-width: 1100px; margin: 0 auto; }
.view-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 2px 0 12px; }
.view-title h2 { font-size: 20px; margin: 0; }

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom button {
  flex: 1; height: var(--nav-h); border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 600;
  position: relative;
}
.bottom button svg { width: 22px; height: 22px; }
.bottom button.on { color: var(--primary); }
.badge-dot {
  position: absolute; top: 6px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 6px 16px rgba(29, 78, 216, .35); display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .bottom { top: 61px; bottom: 0; right: auto; width: 92px; flex-direction: column; border-top: 0; border-right: 1px solid var(--border); justify-content: flex-start; padding-top: 8px; }
  .bottom button { flex: 0 0 72px; }
  main { padding: 20px 24px 100px 116px; max-width: none; }
  .fab { bottom: 28px; right: 28px; }
}

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; flex-wrap: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: 0 0 auto; min-height: 38px; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.chip.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.chip .n { opacity: .7; margin-left: 4px; }

/* ---------- Tarjetas de tarea ---------- */
.group { margin-bottom: 22px; }
.group-h { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.group-h .count { font-weight: 600; background: var(--surface-2); border-radius: 999px; padding: 1px 8px; letter-spacing: 0; }
.group-h.danger { color: var(--danger); }
.list { display: grid; gap: 8px; }
@media (min-width: 900px) { .list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow); cursor: pointer; display: block; text-align: left; width: 100%;
}
.card:active { transform: scale(.995); }
.card h3 { font-size: 15px; font-weight: 600; margin: 6px 0 8px; line-height: 1.3; word-break: break-word; }
.card.is-done h3 { text-decoration: line-through; color: var(--muted); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.tipo { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.estado { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.e-pendiente { background: var(--surface-2); color: var(--muted); }
.e-en_curso { background: var(--primary-soft); color: var(--primary); }
.e-esperando { background: var(--wait-soft); color: var(--wait); }
.e-hecha { background: var(--ok-soft); color: var(--ok); }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; transition: width .2s; }
.card.is-done .bar > span { background: var(--ok); }
.card-meta { display: flex; gap: 10px; align-items: center; margin-top: 8px; font-size: 13px; color: var(--muted); }
.card-meta .resp { margin-left: auto; font-weight: 600; }
.venc.vencida { color: var(--danger); font-weight: 700; }
.venc.hoy { color: var(--warn); font-weight: 700; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; }

/* ---------- Tablero ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: 84%; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.board-col { scroll-snap-align: start; background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board-col h4 { margin: 2px 4px 10px; font-size: 14px; display: flex; justify-content: space-between; }
.board-col .list { grid-template-columns: 1fr; }
@media (min-width: 900px) { .board { grid-auto-flow: initial; grid-template-columns: repeat(4, 1fr); overflow: visible; margin: 0; padding: 0; } }

/* ---------- Hoja (modal) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; max-height: 88vh; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-head h2 { font-size: 18px; margin: 0; flex: 1; }
.sec { margin-bottom: 16px; }
.sec-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.title-input { font-size: 18px !important; font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { min-height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; font-weight: 600; padding: 4px; }
.seg button.on.s-pendiente { background: var(--surface-2); border-color: var(--muted); }
.seg button.on.s-en_curso { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.seg button.on.s-esperando { background: var(--wait-soft); color: var(--wait); border-color: var(--wait); }
.seg button.on.s-hecha { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

.steps { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.step { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 12px; min-height: 48px; border-bottom: 1px solid var(--border); background: var(--surface); }
.step:last-child { border-bottom: 0; }
.step label { flex: 1; display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.step input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--ok); flex: 0 0 auto; }
.step.done .step-name { text-decoration: line-through; color: var(--muted); }
.step .by { font-size: 12px; color: var(--muted); display: block; text-decoration: none; }
.step-add { display: flex; gap: 8px; padding: 8px; background: var(--surface-2); }
.step-add .input { min-height: 40px; }
.x-btn { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; font-size: 20px; line-height: 1; }
.x-btn:active { background: var(--surface-2); }
.meta { font-size: 12px; color: var(--muted); margin: 10px 0 16px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }
.preview-steps { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.box h3 { margin: 0 0 10px; font-size: 16px; }
.user-row { display: grid; gap: 8px; grid-template-columns: 1fr; padding: 12px 0; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: 0; }
.user-row .email { font-size: 13px; color: var(--muted); word-break: break-all; }
.user-row .ctrls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-row .ctrls select { width: auto; min-height: 38px; padding: 6px 10px; }
@media (min-width: 700px) { .user-row { grid-template-columns: 1.3fr 1fr auto; align-items: center; } }
.tpl-step { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.tpl-step .input { min-height: 40px; }
.tpl-step .x-btn { flex: 0 0 auto; }
.tag-off { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 999px; }
.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 14px; }
.notice.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Toast ---------- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + 90px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #1f2329; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 480px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: up .2s; }
.toast.error { background: var(--danger); }
