:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1c1d1f;
  --muted: #64676d;
  --line: #e2e0d9;
  --accent: #1f5f8b;
  --accent-soft: #e3eef6;
  --ok: #2f7d4f;
  --ok-soft: #e2f2e8;
  --warn: #9a6200;
  --warn-soft: #fbefd9;
  --err: #b3362c;
  --err-soft: #f9e3e0;
  --info: #5a4fa8;
  --info-soft: #ebe8f8;
  --neutral-soft: #ecebe6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --tabbar-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1f2226;
    --surface-2: #272a2f;
    --text: #ecebe8;
    --muted: #a0a3a8;
    --line: #33363c;
    --accent: #7db6dc;
    --accent-soft: #1f3241;
    --ok: #7ccb9a;
    --ok-soft: #1d3326;
    --warn: #e8b55b;
    --warn-soft: #3a2f1a;
    --err: #f08a80;
    --err-soft: #3e2220;
    --info: #b3a9f0;
    --info-soft: #2a2740;
    --neutral-soft: #2a2d31;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
p { margin: 0.4em 0; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.86em; }

.wrap { max-width: 760px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 14px) 16px 16px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.topbar .sub { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.back { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; font-weight: 500; padding: 6px 0; margin-bottom: 6px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card > h2 { margin-bottom: 10px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 20px 2px 8px; }
.section-title h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 8px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 9px 14px; min-height: 40px; font-weight: 500; cursor: pointer; text-decoration: none; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0e1a23; } }
.btn.danger { color: var(--err); }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 0.85rem; border-radius: 8px; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.iconbtn { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.spin svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-esperando_enunciado { background: var(--neutral-soft); color: var(--muted); }
.st-enunciado_disponible { background: var(--accent-soft); color: var(--accent); }
.st-preparando { background: var(--info-soft); color: var(--info); }
.st-pausado { background: var(--warn-soft); color: var(--warn); }
.st-borrador_listo { background: var(--ok-soft); color: var(--ok); }
.st-requiere_revision { background: var(--warn-soft); color: var(--warn); }
.st-error { background: var(--err-soft); color: var(--err); }

.alert { border-radius: 12px; padding: 10px 12px; font-size: 0.9rem; margin-bottom: 10px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert b { font-weight: 650; }

.tasklist { list-style: none; margin: 0; padding: 0; }
.taskitem { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.taskitem:active { background: var(--surface-2); }
.taskitem .t { font-weight: 600; line-height: 1.3; }
.taskitem .c { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.taskitem .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.due { font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.due.soon { color: var(--warn); font-weight: 600; }
.due.late { color: var(--err); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: left; }
.stat b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 0.78rem; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 500; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
select, input[type=text], input[type=number], input[type=password], input[type=datetime-local], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 10px; min-height: 42px; font-size: 16px;
}
textarea { min-height: 120px; resize: vertical; }
label.field { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
label.field > span { display: block; margin-bottom: 4px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.check input { width: 20px; height: 20px; }

.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.month-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.month-head b { font-size: 1.02rem; }
.grid7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dow { text-align: center; font-size: 0.72rem; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.day { height: 48px; border: 0; background: transparent; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; gap: 3px; cursor: pointer; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.day.out { color: var(--muted); opacity: 0.45; }
.day.today .n { background: var(--accent); color: #fff; border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; }
@media (prefers-color-scheme: dark) { .day.today .n { color: #0e1a23; } }
.day.sel { background: var(--surface-2); }
.dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 34px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.dot.borrador_listo { background: var(--ok); }
.dot.preparando { background: var(--info); }
.dot.error { background: var(--err); }
.dot.requiere_revision, .dot.pausado { background: var(--warn); }
.dot.enunciado_disponible { background: var(--accent); }
.dot.entregado { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ok); }
.delivered { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.delivered-tag { display: inline-flex; align-items: center; gap: 4px; background: var(--ok); color: #fff; border-radius: 999px; padding: 2px 10px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.01em; }
@media (prefers-color-scheme: dark) { .delivered-tag { color: #10241a; } }
.daygroup h3 { font-size: 0.82rem; color: var(--muted); font-weight: 600; margin: 14px 2px 6px; }

.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.dates div span { display: block; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.dates div b { font-weight: 600; font-variant-numeric: tabular-nums; font-size: 0.93rem; }
.dates .unknown { color: var(--muted); font-weight: 500; font-style: italic; }

.files { list-style: none; margin: 0; padding: 0; }
.files li { border-top: 1px solid var(--line); padding: 10px 0; }
.files li:first-child { border-top: 0; padding-top: 0; }
.fname { font-weight: 550; word-break: break-word; }
.chip { display: inline-block; font-size: 0.74rem; border-radius: 6px; padding: 1px 7px; background: var(--neutral-soft); color: var(--muted); font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.err { background: var(--err-soft); color: var(--err); }
.replaced { opacity: 0.6; }

.versions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.versions button { flex: none; }
.analysis h3 { margin: 14px 0 4px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.analysis ul { margin: 0; padding-left: 20px; }
.analysis li { margin: 3px 0; }
.out { border: 1px solid var(--line); border-radius: 12px; margin-top: 10px; overflow: hidden; }
.out-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface-2); }
.out-head .fname { flex: 1; }
.out-body { padding: 12px; max-height: 70vh; overflow: auto; }
.out-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
.md h1 { font-size: 1.25rem; margin: 0.6em 0 0.3em; }
.md h2 { font-size: 1.08rem; margin: 1em 0 0.3em; }
.md h3 { font-size: 0.98rem; margin: 0.9em 0 0.3em; }
.md pre { background: var(--surface-2); border-radius: 8px; padding: 10px; overflow-x: auto; }
.md blockquote { margin: 0.5em 0; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md ul, .md ol { padding-left: 22px; }
.pending { background: var(--warn-soft); color: var(--warn); border-radius: 4px; padding: 0 3px; }

.statement { width: 100%; border: 0; min-height: 160px; background: transparent; }
.statement-text { white-space: pre-wrap; word-break: break-word; max-height: 60vh; overflow: auto; }
details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: " ▾"; color: var(--muted); }
details[open] > summary::after { content: " ▴"; }

.log { list-style: none; padding: 0; margin: 0; font-size: 0.85rem; }
.log li { padding: 6px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: 0; }
.log .lv-warn { color: var(--warn); }
.log .lv-error { color: var(--err); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tabbar[hidden], .toast[hidden] { display: none; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 0.7rem; font-weight: 500; }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; z-index: 20; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgb(0 0 0 / 0.2); }

.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 360px; padding: 22px; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.src { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.9rem; }
.src:first-of-type { border-top: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (hover: hover) {
  .btn:hover { background: var(--surface-2); }
  .btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
  .taskitem:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
}
@media (min-width: 700px) {
  .dates { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .spin svg { animation: none; }
}
