:root {
  --bg: #fdfaf1;
  --panel: #ffffff;
  --ink: #2b2618;
  --muted: #7a7260;
  --line: #e9e2cc;
  --accent: #e0a100;
  --accent-ink: #2b2000;
  --accent-soft: #fff1bf;
  --ok: #2f8a4c;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(60, 45, 0, .08), 0 4px 14px rgba(60, 45, 0, .07);
  --radius: 12px;
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1813;
    --panel: #24211a;
    --ink: #f1ecdd;
    --muted: #a59d88;
    --line: #3a3528;
    --accent: #f5b301;
    --accent-ink: #1f1700;
    --accent-soft: #3d3313;
    --ok: #5cc27d;
    --danger: #ef6b5b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
}
body.publico { padding-bottom: 24px; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.ok { color: var(--ok); }
.loading { color: var(--muted); text-align: center; padding: 3rem 0; }
[hidden] { display: none !important; }

/* Barra superior y búsqueda */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; white-space: nowrap; }
.search { flex: 1; max-width: 520px; margin-left: auto; }
.search input { width: 100%; }
@media (max-width: 560px) { .brand span { display: none; } }

/* Barra inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  align-items: center; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--panel); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--muted); text-decoration: none; }
.tabbar a .ico { font-size: 1.2rem; line-height: 1; }
.tabbar a.on { color: var(--ink); font-weight: 600; }
.fab {
  justify-self: center; width: 58px; height: 58px; margin-top: -26px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 2rem; line-height: 1; box-shadow: var(--shadow);
  cursor: pointer; transform: rotate(-3deg);
}
.fab:active { transform: rotate(-3deg) scale(.95); }

/* Formularios */
input, textarea, select {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 1rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; flex: 0 0 auto;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.wa { background: #25d366; border-color: #25d366; color: #06301a; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; font: inherit; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Filtros */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 14px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; text-decoration: none;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Tarjetas de tarea (post-its) */
.dia { margin: 18px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  position: relative; display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 10px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  border-top: 5px solid var(--papel, var(--accent));
}
.card .thumb {
  width: 84px; height: 84px; border-radius: 8px; object-fit: cover; background: var(--papel, var(--accent-soft));
  display: grid; place-items: center; font-size: 1.6rem; color: var(--accent-ink);
}
.card .t { font-weight: 650; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .x { color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; font-size: .78rem; color: var(--muted); align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); font-size: .78rem; }
.tag.share { background: color-mix(in srgb, #3a7bd5 18%, var(--panel)); }
.tag.done { background: color-mix(in srgb, var(--ok) 20%, var(--panel)); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.vacio { text-align: center; padding: 48px 16px; color: var(--muted); }
.vacio .grande { font-size: 3rem; }

/* Detalle de tarea */
.cabecera { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cabecera .grow { flex: 1; min-width: 0; }
.volver { text-decoration: none; font-size: 1.4rem; padding: 4px 8px; }
.fotos { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.foto {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  border-top: 5px solid var(--papel, var(--accent));
}
.foto img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; cursor: zoom-in; background: var(--accent-soft); }
.foto .cuerpo { padding: 8px 10px; }
.foto .ocr { white-space: pre-wrap; font-size: .9rem; }
.foto .herr { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.leyendo { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: .9rem; }
.leyendo::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--accent); border-top-color: transparent;
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
.aviso {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 12px;
  background: var(--accent-soft); border-radius: 10px; font-size: .92rem;
}
.aviso .grow { flex: 1 1 200px; }
.aviso.error { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); }
.historial { list-style: none; padding: 0; margin: 0; font-size: .85rem; color: var(--muted); }
.historial li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.estado { font-size: .8rem; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); white-space: nowrap; }
.estado.archivada { background: color-mix(in srgb, var(--ok) 20%, var(--panel)); }

/* Personas */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { border-bottom: 1px solid var(--line); }
.lista a, .lista .item { display: flex; gap: 12px; align-items: center; padding: 12px 4px; text-decoration: none; }
.lista .grow { flex: 1; min-width: 0; }
.lista button.item { width: 100%; text-align: left; text-decoration: none; color: inherit; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: var(--papel, var(--accent-soft)); color: #2b2000; flex: 0 0 auto;
}

/* Galería */
.galeria { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.galeria a { position: relative; display: block; border-radius: 8px; overflow: hidden; border-bottom: 4px solid var(--papel, var(--accent)); }
.galeria img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--accent-soft); }
.galeria span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 6px 4px; font-size: .72rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Diálogos */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 48px);
  background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(20, 16, 4, .5); }
dialog .d-body { padding: 18px; overflow: auto; max-height: calc(100vh - 48px); }
dialog .d-body > h2 { margin-bottom: 12px; }
dialog.visor { width: auto; max-width: calc(100vw - 16px); background: #000; }
dialog.visor img { display: block; max-width: calc(100vw - 16px); max-height: calc(100vh - 32px); }
.opciones { display: grid; gap: 8px; }
.opciones .btn { justify-content: flex-start; width: 100%; }

/* Avisos emergentes */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom)); z-index: 100; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: .92rem; }
.toast.error { background: var(--danger); color: #fff; }

/* Acceso */
.acceso { max-width: 400px; margin: 8vh auto 0; }
.acceso .logo { display: block; margin: 0 auto 12px; }
.acceso h1 { text-align: center; }

/* Página pública */
.tarea-publica { max-width: 720px; margin: 0 auto; }
.tarea-publica .texto { white-space: pre-wrap; font-size: 1.05rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.fotos-publicas { display: grid; gap: 12px; margin: 16px 0; }
.fotos-publicas img { width: 100%; border-radius: var(--radius); display: block; }

table.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabla-scroll { overflow-x: auto; }
pre.codigo { background: var(--accent-soft); padding: 10px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; }
