:root {
  --bg: #ffffff;
  --surface: #f6f8f6;
  --line: #e3e8e4;
  --text: #16201a;
  --muted: #5d6b62;
  --brand: #156a30;
  --brand-strong: #0f4f23;
  --on-brand: #ffffff;
  --pos: #157a3a;
  --neg: #b42318;
  --pos-soft: #dff0e4;
  --neg-soft: #fbe3e0;
  --focus: #2f8a4a;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #171e19;
    --line: #27312a;
    --text: #e8eee9;
    --muted: #9aa89f;
    --brand: #3fa25d;
    --brand-strong: #56b872;
    --on-brand: #06130a;
    --pos: #5cc47d;
    --neg: #f0857a;
    --pos-soft: #1b3323;
    --neg-soft: #3a1f1c;
    --focus: #6fcf8c;
    color-scheme: dark;
  }
  .top-logo, .auth-logo { filter: brightness(1.6) saturate(.9); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Montserrat, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding: env(safe-area-inset-top, 0) 16px env(safe-area-inset-bottom, 0);
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Controles ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-quiet { border-color: transparent; color: var(--muted); padding: 0 8px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .65; cursor: progress; }
.link { font: inherit; background: none; border: 0; padding: 4px 0; color: var(--text); cursor: pointer; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.link:hover { text-decoration-color: currentColor; }
.btn-danger { color: var(--neg); }

.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
.field.inline { display: flex; align-items: center; gap: 10px; margin: 0; }
input, select {
  font: inherit;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
select { width: auto; }
input:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.checks { display: flex; flex-wrap: wrap; gap: 18px; margin: 4px 0 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; min-height: 0; margin: 0; padding: 0; flex: none; accent-color: var(--brand); }
.form-error { color: var(--neg); margin: 0 0 12px; font-weight: 500; }
.form-ok { color: var(--pos); margin: 0 0 12px; font-weight: 500; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 4px; margin: 0 0 14px; }
legend { padding: 0 6px; font-weight: 600; font-size: .9rem; }

/* ---------- Acceso ---------- */
.auth { max-width: 360px; margin: 12vh auto 40px; }
.auth-logo { height: 40px; width: auto; display: block; margin-bottom: 28px; }
.auth h1 { margin-bottom: 8px; }
.auth form { margin-top: 24px; }

/* ---------- Cabecera y pestañas ---------- */
.top { max-width: 880px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 18px 0 10px; }
.top-logo { height: 28px; width: auto; }
.tabs { max-width: 880px; margin: 0 auto; display: flex; gap: 22px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0;
  padding: 12px 0 10px; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.tabs button:hover { color: var(--text); }

.panels { max-width: 880px; margin: 0 auto; padding: 24px 0 64px; position: relative; }
.panel { transition: filter .2s ease, opacity .2s ease; }
.panel.is-loading { filter: blur(3px); opacity: .55; pointer-events: none; user-select: none; }
.loading-note {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 2;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); font-weight: 500; font-size: .9rem;
}
.loader { width: 36px; height: 4px; border-radius: 2px; background: var(--line); position: relative; overflow: hidden; display: none; }
.loading-note.slow .loader { display: block; }
.loader::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--brand); border-radius: 2px; animation: slide 1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) {
  .loader::after { animation: none; width: 100%; opacity: .6; }
  .panel { transition: none; }
}

/* ---------- Fichar ---------- */
.clock { text-align: center; margin: 8px 0 22px; }
.clock-date { margin: 0; color: var(--muted); text-transform: capitalize; }
.clock-time { margin: 4px 0; font-size: clamp(3rem, 14vw, 4.6rem); font-weight: 600; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.05; }
.clock-status { margin: 0; font-weight: 500; }
.punch {
  display: block; width: 100%; max-width: 420px; margin: 0 auto;
  font: inherit; font-size: 1.35rem; font-weight: 700; letter-spacing: .01em;
  min-height: 88px; border-radius: 16px; border: 0; cursor: pointer;
  background: var(--brand); color: var(--on-brand);
  transition: background .15s ease, transform .1s ease;
}
.punch:hover { background: var(--brand-strong); }
.punch:active { transform: scale(.99); }
.punch.is-out { background: var(--text); color: var(--bg); }
.punch[disabled] { opacity: .7; cursor: progress; }
.punch-feedback { text-align: center; min-height: 1.5em; margin: 12px 0 18px; font-weight: 500; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 0 0 24px; }
.stats > div { background: var(--bg); padding: 12px 14px; }
.stats dt { font-size: .78rem; color: var(--muted); font-weight: 500; }
.stats dd { margin: 2px 0 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (max-width: 620px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.today-list h2 { margin-bottom: 8px; }
.sessions { list-style: none; margin: 0; padding: 0; }
.sessions li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.sessions li:last-child { border-bottom: 0; }
.sessions .empty { color: var(--muted); }

/* ---------- Historial ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav h2 { min-width: 9.5em; text-align: center; text-transform: capitalize; }

.days { border-top: 1px solid var(--line); }
.day {
  display: grid; grid-template-columns: 7.2em minmax(0, 1fr) 6.5em 9em; gap: 4px 14px; align-items: center;
  padding: 11px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.day.is-clickable { cursor: pointer; }
.day.is-clickable:hover { background: var(--surface); }
.day.is-weekend:not(.has-work) { color: var(--muted); }
.day.is-today { background: var(--surface); }
.day-date b { display: block; font-weight: 600; }
.day-date small { color: var(--muted); }
.day-main { min-width: 0; }
.day-punches { font-weight: 500; overflow-wrap: anywhere; }
.day-plan { font-size: .82rem; color: var(--muted); }
.day-hours { text-align: right; font-size: .9rem; }
.day-hours small { display: block; color: var(--muted); }
.day-diff { text-align: right; }
.day-diff b { font-weight: 600; }
.day-diff small { display: block; font-size: .76rem; color: var(--muted); }
.bar { height: 6px; background: var(--surface); border-radius: 3px; position: relative; margin-top: 5px; }
.bar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line); }
.bar i { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.bar i.pos { left: 50%; background: var(--pos); }
.bar i.neg { right: 50%; background: var(--neg); }
@media (max-width: 620px) {
  .day { grid-template-columns: 5.6em minmax(0, 1fr) 6.2em; }
  .day-hours { display: none; }
}

.export { margin-top: 32px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); }
.export h3 { margin-bottom: 4px; }
.export p { margin: 0 0 14px; }
.export-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.export-row .field { margin: 0; flex: 1 1 140px; }

/* ---------- Horario ---------- */
.sched { display: grid; gap: 0; border-top: 1px solid var(--line); margin-bottom: 16px; }
.sched-row { display: grid; grid-template-columns: 7.5em 5.5em 1fr 1fr 6.5em 4.5em; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sched-row .day-name { font-weight: 600; }
.sched-row input[type="time"], .sched-row input[type="number"] { min-height: 38px; padding: 6px 8px; }
.sched-row .total { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sched-row.off input:not([type="checkbox"]) { opacity: .4; }
.sched-head { font-size: .78rem; color: var(--muted); font-weight: 500; border-bottom: 0; padding-bottom: 0; }
.sched-foot { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.sched-foot .field { margin: 0; }
.versions { margin-top: 24px; font-size: .9rem; color: var(--muted); }
.versions ul { padding-left: 18px; }
@media (max-width: 620px) {
  .sched-row { grid-template-columns: 1fr 1fr 1fr; }
  .sched-row .day-name { grid-column: 1 / 3; }
  .sched-row .check { justify-self: end; }
  .sched-head { display: none; }
}

/* ---------- Equipo ---------- */
.people { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--line); }
.people li { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.people .who b { display: block; }
.people .who small { color: var(--muted); }
.people .inactive { opacity: .55; }
.people .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Diálogos ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--bg); color: var(--text); }
dialog::backdrop { background: rgb(10 20 14 / .45); }
.dlg { padding: 22px; }
.dlg h2 { margin-bottom: 14px; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sessions.editable li { padding: 8px 0; }
.sessions.editable .actions { display: flex; gap: 4px; }
