*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #f8fafc; --surface: #ffffff; --surface2: #f1f5f9;
  --border: #e2e8f0; --border-dark: #cbd5e1;
  --accent: #ea580c; --accent-hover: #c2410c;
  --text: #0f172a; --muted: #64748b;
  --head-bg: #0f172a; --head-text: #ffffff;
  --ok: #16a34a; --warn: #b45309; --err: #dc2626; --info: #0369a1;
  --ok-bg: #dcfce7; --warn-bg: #fef3c7; --err-bg: #fee2e2; --info-bg: #e0f2fe;
  --radius: 10px; --input-h: 46px;
  --nav-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #131c2e; --surface2: #1b2740;
    --border: #243049; --border-dark: #34425f;
    --accent: #f97316; --accent-hover: #ea580c;
    --text: #e5ebf5; --muted: #93a1ba;
    --head-bg: #1b2740; --head-text: #e5ebf5;
    --ok: #4ade80; --warn: #fbbf24; --err: #f87171; --info: #7dd3fc;
    --ok-bg: #12301f; --warn-bg: #3a2c0b; --err-bg: #3b1616; --info-bg: #0f2a3d;
  }
}

html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.4; overflow-x: hidden;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Barra superior ───────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface); border-bottom: 2px solid var(--border);
  padding: 8px 12px 8px; padding-top: max(8px, env(safe-area-inset-top));
}
.row1 { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.row2 { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-size: 12px; }
.nav-btn {
  width: 38px; height: 38px; flex: none; border-radius: var(--radius);
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  font-weight: 700; font-size: 14px; touch-action: manipulation;
}
#selJornada {
  flex: 1; min-width: 0; height: 38px; border: 1.5px solid var(--accent); border-radius: var(--radius);
  padding: 0 8px; font-size: 14px; font-weight: 700; color: var(--text); background: var(--surface);
  -webkit-appearance: none; appearance: none; text-overflow: ellipsis;
}
.badge {
  display: inline-block; padding: 4px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 700; border: 0;
  max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.info { background: var(--info-bg); color: var(--info); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
#badgeGuardado { font-size: 11.5px; font-weight: 600; flex: 1; text-align: center; white-space: nowrap; }

#avisos .aviso {
  margin: 8px 12px 0; padding: 10px 12px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 600;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
}
#avisos .aviso.err { background: var(--err-bg); color: var(--err); }
#avisos .aviso button { flex: none; border: 0; background: transparent; color: inherit; font-weight: 800; font-size: 13px; text-decoration: underline; padding: 4px; }

/* ── Páginas ───────────────── */
main { flex: 1; padding: 12px; padding-bottom: calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }
.page { display: none; }
.page.active { display: block; }
body.sin-jornada .page, body.sin-jornada .bottom-nav { display: none !important; }
body.sin-jornada #tab-ajustes.active { display: none; }
#sinJornada { display: none; margin-top: 30px; }
body.sin-jornada #sinJornada { display: block; }
body.sin-jornada .row2, body.sin-jornada #btnPrev, body.sin-jornada #btnNext { visibility: hidden; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card.center { text-align: center; }
.card.center h2 { margin-bottom: 8px; }
.card.center .btn { margin-top: 12px; }
.section-title {
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  margin-bottom: 12px; padding-bottom: 5px; border-bottom: 1px solid var(--border);
}
.aviso-final { background: var(--info-bg); color: var(--info); border-color: transparent; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.mt { margin-top: 10px; }
label { font-size: 12.5px; font-weight: 600; }

input[type="text"], input[type="date"], input[type="url"], input[type="password"], input[type="search"], select, textarea {
  height: var(--input-h); padding: 8px 12px; font-size: 16px; font-family: inherit;
  color: var(--text); background: var(--surface); border: 1.5px solid var(--border-dark);
  border-radius: var(--radius); width: 100%; outline: none; -webkit-appearance: none; appearance: none; min-width: 0;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px;
}
#selJornada { background-image: none; padding-right: 8px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(234, 88, 12, .18); }
input:disabled, select:disabled, textarea:disabled { opacity: .65; }
input[readonly] { background: var(--surface2); }
textarea { height: 96px; resize: vertical; line-height: 1.4; padding-top: 10px; }
textarea.lista { height: 130px; }

/* ── Botones ───────────────── */
.btn {
  height: 46px; padding: 0 16px; font-size: 15px; font-weight: 700; font-family: inherit;
  border-radius: var(--radius); border: 0; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1.5px solid var(--border-dark); }
.btn-outline-danger { background: transparent; color: var(--err); border: 1.5px solid var(--err); }
.btn-danger { background: var(--err); color: #fff; }
.btn-sm { height: 38px; padding: 0 12px; font-size: 13px; flex: none; }
.btn-block { width: 100%; margin-bottom: 8px; }
.btn[hidden] { display: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 130px; }
.btn-nav {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-weight: 700; font-family: inherit; touch-action: manipulation;
}
.file-btn { cursor: pointer; }

/* ── Tomas ───────────────── */
.quick-box {
  background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.quick-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); gap: 6px; }
.quick-nav { display: flex; gap: 4px; }
.pill { background: var(--head-bg); color: var(--head-text); font-weight: 800; font-size: 13px; padding: 5px 10px; border-radius: 6px; white-space: nowrap; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-grid .full { grid-column: 1 / -1; }
.quick-actions { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; margin-top: 14px; }
.quick-actions .btn { padding: 0 8px; }

.u-row {
  display: flex; gap: 8px; align-items: baseline; padding: 9px 4px; border-bottom: 1px solid var(--border);
  font-size: 14px; cursor: pointer;
}
.u-row:last-child { border-bottom: 0; }
.u-row b { min-width: 34px; color: var(--accent); }
.u-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Revisar ───────────────── */
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; }
.subtab {
  flex: 1; height: 40px; border-radius: var(--radius); font-weight: 700; font-size: 14px; font-family: inherit;
  background: var(--surface2); color: var(--muted); border: 1.5px solid var(--border);
}
.subtab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.vista { display: none; }
.vista.active { display: block; }
.zoombar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.filtros { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.filtros-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.filtros-row select { font-size: 14px; padding-left: 8px; padding-right: 22px; height: 42px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.check input { width: 20px; height: 20px; }

.table-container { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: 62vh; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; white-space: nowrap; }
th { background: var(--head-bg); color: var(--head-text); padding: 9px 10px; font-weight: 700; text-align: left; position: sticky; top: 0; z-index: 2; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
tbody tr:nth-child(even) { background: var(--surface2); }
tbody tr { cursor: pointer; }
td.num { color: var(--muted); font-weight: 700; text-align: center; }
td.notas { white-space: normal; min-width: 150px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 6px; text-align: center; }
.stat b { display: block; font-size: 24px; color: var(--accent); line-height: 1.1; }
.stat span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 600; }
.chip i { font-style: normal; color: var(--accent); font-weight: 800; margin-left: 4px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: 0; }

/* Informe (siempre claro, como el papel) */
.inf-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #cbd5e1; padding: 6px; -webkit-overflow-scrolling: touch; }
#infSizer { position: relative; overflow: hidden; }
#infPages { transform-origin: top left; width: 794px; }
.sheet { width: 794px; background: #fff; color: #000; padding: 22px 26px; margin-bottom: 14px; font-size: 12px; border: 1px solid #94a3b8; }
.sh-title { display: flex; justify-content: space-between; gap: 12px; border: 1.5px solid #000; padding: 6px 8px; font-size: 13px; }
.sh-grid { display: grid; margin-top: -1.5px; }
.sh-grid.g1 { grid-template-columns: 1fr; }
.sh-grid.g2 { grid-template-columns: 1fr 1fr; }
.sh-grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.sh-grid > div { border: 1.5px solid #000; margin-left: -1.5px; padding: 5px 8px; min-height: 26px; }
.sh-grid > div:first-child { margin-left: 0; }
.sh-grid i { font-style: normal; font-weight: 800; font-size: 10.5px; margin-right: 4px; }
.sh-table { width: 100%; border-collapse: collapse; margin-top: 8px; table-layout: fixed; white-space: normal; font-size: 11.5px; }
.sh-table th { background: #e5e7eb; color: #000; border: 1.5px solid #000; padding: 4px; font-size: 10.5px; position: static; text-align: center; }
.sh-table td { border: 1.5px solid #000; padding: 0 4px; height: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fff !important; }
.sh-table tbody tr { cursor: default; }
.sh-foot { margin-top: 8px; }
.sh-box { white-space: pre-wrap; min-height: 56px; }

/* ── Ajustes ───────────────── */
.jrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.jrow:last-child { border-bottom: 0; }
.jrow small { display: block; color: var(--muted); font-size: 12px; }

/* ── Navegación inferior ───────────────── */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex;
  background: var(--surface); border-top: 2px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-tab {
  flex: 1; height: var(--nav-h); background: none; border: 0; color: var(--muted); font-family: inherit;
  font-size: 11px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  touch-action: manipulation; border-top: 3px solid transparent; margin-top: -2px;
}
.nav-tab .ic { font-size: 19px; line-height: 1; }
.nav-tab.active { color: var(--accent); border-top-color: var(--accent); }

/* ── Modal y toast ───────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 24, .65); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal-box { background: var(--surface); color: var(--text); border-radius: 14px; width: 100%; max-width: 380px; padding: 18px; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.modal-box h3 { margin-bottom: 8px; font-size: 17px; }
.modal-box p { margin-bottom: 14px; font-size: 14px; }
.modal-box .btn { width: 100%; margin-bottom: 8px; }

#toast {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 300;
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 30px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 8px 20px rgba(0,0,0,.3); display: none; text-align: center; max-width: 92%;
}
#toast.show { display: block; }
#toast.ok { background: #16a34a; }
#toast.err { background: #dc2626; }
