:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --fg: #1d2330;
  --muted: #5d6676;
  --line: #d6dae2;
  --accent: #1f6f5c;
  --accent-fg: #ffffff;
  --accent-soft: #dff0eb;
  --danger: #a4281b;
  --warn-soft: #f8e9dc;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171d; --surface: #1d222b; --fg: #e9ecf2; --muted: #9aa3b2; --line: #2f3643;
    --accent: #5fc3a6; --accent-fg: #0d1512; --accent-soft: #1f3b35; --danger: #ff8a7a; --warn-soft: #3b2a1f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171d; --surface: #1d222b; --fg: #e9ecf2; --muted: #9aa3b2; --line: #2f3643;
  --accent: #5fc3a6; --accent-fg: #0d1512; --accent-soft: #1f3b35; --danger: #ff8a7a; --warn-soft: #3b2a1f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.aviso { background: var(--warn-soft); padding: 10px 12px; border-radius: 8px; }

.center-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 0;
}
.narrow { width: 100%; max-width: 380px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.card + .card, .card + form, form + .card { margin-top: 12px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; color: var(--muted); }
input, select, button { font: inherit; }
input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  font-weight: 600;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.ghost { background: transparent; }
button.big { min-height: 56px; font-size: 1.05rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { gap: 10px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  z-index: 2;
}
.content { display: flex; flex-direction: column; gap: 12px; padding-bottom: 96px; max-width: 900px; margin: 0 auto; }
.tab { display: flex; flex-direction: column; gap: 12px; }
.tab > h2 { margin: 8px 0 0; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  z-index: 5;
}
.tabbar button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  min-height: 52px;
}
.tabbar button.active { color: var(--accent); }

.fichajes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.fichajes li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}
.fichajes li.pendiente { color: var(--muted); font-style: italic; }
.resumen-dia dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-variant-numeric: tabular-nums; }
.resumen-dia dt { color: var(--muted); }
.resumen-dia dd { margin: 0; text-align: right; font-weight: 600; }

.cal-head { display: flex; justify-content: space-between; align-items: center; }
.cal-head button { min-width: 44px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { font-size: 0.75rem; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-day {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg);
  color: var(--fg);
  padding: 4px 0;
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 0;
}
.cal-day.otro { opacity: 0.35; }
.cal-day.hoy { border-color: var(--accent); }
.cal-day.sel { outline: 2px solid var(--accent); }
.cal-day.festivo, .cal-day.no_laboral { background: var(--warn-soft); }
.cal-day.vacaciones { background: var(--accent-soft); }
.cal-day.baja { background: var(--danger); color: #fff; }
.cal-day.asuntos, .cal-day.compensacion { background: var(--accent-soft); }
.leyenda { font-size: 0.85rem; color: var(--muted); }

.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table.informe { border-collapse: collapse; width: 100%; min-width: 560px; font-variant-numeric: tabular-nums; }
table.informe th, table.informe td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); }
table.informe th:first-child, table.informe td:first-child { text-align: left; }
table.informe th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
table.informe tfoot td { font-weight: 700; }

table.horario { border-collapse: collapse; width: 100%; min-width: 520px; }
table.horario th, table.horario td { padding: 6px; text-align: left; border-bottom: 1px solid var(--line); }
table.horario th { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
table.horario td:first-child { font-weight: 600; width: 44px; }
table.horario input { min-height: 40px; padding: 6px 8px; }

.lista-incidencias { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lista-incidencias li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn-soft);
}
.lista-incidencias li span { min-width: 0; }
.lista-incidencias button { min-height: 40px; padding: 6px 12px; flex-shrink: 0; }
#av-estado:empty { display: none; }

.qr { display: flex; justify-content: center; }
.qr img { width: 200px; max-width: 100%; height: auto; background: #fff; padding: 8px; border-radius: 8px; }
.secret { display: block; word-break: break-all; padding: 10px; background: var(--bg); border-radius: 8px; }

@media print {
  .topbar, .tabbar, .actions, #form-corregir, #form-dia, #form-ajustes, .cal-head { display: none !important; }
  body { background: #fff; color: #000; }
  .tab { display: none !important; }
  #tab-resumen { display: flex !important; }
  .card { border: none; }
}
@media (max-width: 420px) {
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
