:root {
  --bg: #f1f5f4;
  --card: #ffffff;
  --ink: #12302d;
  --muted: #5b7370;
  --line: #d8e3e1;
  --brand: #0f766e;
  --brand-dark: #0b5a54;
  --brand-soft: #d9f0ed;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --radius: 14px;
  --tabbar: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 1.1rem; }
h3:first-child { margin-top: 0; }
p { margin: .25rem 0; }
.muted { color: var(--muted); }
.grande { font-size: 1.6rem; }
.enorme { font-size: 2.6rem; line-height: 1; margin: .2rem 0; }

/* ---------- botones y campos ---------- */
.btn {
  min-height: 44px; min-width: 44px;
  padding: .55rem 1rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn:focus-visible, .tab:focus-visible, .seg-btn:focus-visible, .link:focus-visible { outline: 3px solid #5eead4; outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--err); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-block { width: 100%; margin-top: 1rem; }
.btn-icon { font-size: 1.3rem; padding: 0; width: 48px; }
.btn-grande { width: 100%; min-height: 76px; font-size: 1.4rem; border-radius: 16px; margin: .75rem 0; }
.btn-salida { background: #c2410c; border-color: #c2410c; }
.btn-salida:hover { background: #9a3412; }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; min-height: 44px; padding: 0 .5rem; text-decoration: underline; }

label { display: block; font-size: .9rem; font-weight: 600; margin: .8rem 0 .25rem; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=file] {
  width: 100%; min-height: 44px; padding: .5rem .7rem;
  border: 1px solid #b9cac7; border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit;
}
input:focus-visible { outline: 3px solid #5eead4; outline-offset: 0; border-color: var(--brand); }
label.inline { display: flex; align-items: center; justify-content: space-between; gap: .75rem; font-weight: 500; }
label.inline input { width: 90px; }
.radio { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-weight: 500; margin: 0; }
.radio input { width: 22px; height: 22px; }
fieldset.modos { border: 0; padding: 0; margin: .8rem 0; }
fieldset.modos legend { font-size: .9rem; font-weight: 600; padding: 0; }

.msg-error { color: var(--err); background: var(--err-bg); border-radius: 10px; padding: .6rem .9rem; margin: .8rem 0 0; }
ul.msg-error { list-style: none; }
ul.msg-error li + li { margin-top: .25rem; }

/* ---------- acceso ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0f766e 0%, #134e4a 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 1.75rem 1.5rem; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card h1 { font-size: 1.5rem; margin-top: .6rem; }
.login-card label { text-align: left; }

/* ---------- estructura de la app ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.top {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem; padding-top: max(.5rem, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.top h1 { flex: 1; margin: 0; min-width: 0; }
.top .btn-ghost { color: #d1f5f0; }
.pill { background: var(--warn-bg); color: var(--warn); padding: .2rem .6rem; border-radius: 99px; font-size: .8rem; font-weight: 700; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .75rem; font-weight: 600; cursor: pointer;
}
.tab-ico { font-size: 1.3rem; line-height: 1; }
.tab.is-active { color: var(--brand); background: var(--brand-soft); }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: .75rem; padding-bottom: calc(var(--tabbar) + 1.5rem + env(safe-area-inset-bottom)); }
.panel > * + * { margin-top: .75rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: 0 1px 2px rgba(16,48,45,.05); }
.cols { display: grid; gap: .75rem; grid-template-columns: minmax(0, 1fr); }
.cols > * + * { margin-top: 0; }
.barra { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.barra h2 { margin: 0; }
.botones { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.botones.fin { justify-content: flex-end; }
.aviso { background: var(--brand-soft); border-radius: 10px; padding: .6rem .9rem; }
.aviso.alerta { background: var(--warn-bg); color: var(--warn); font-weight: 600; }

/* Hoy */
.marcar { text-align: center; }
.crono { font-size: 3.2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .25rem 0; color: var(--brand); }
.marcar.abierto { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* Registros */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.item { display: flex; gap: .5rem; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.item-main { flex: 1; min-width: 0; }
.item-fechas { font-weight: 600; overflow-wrap: anywhere; }
.item-horas { font-size: 1.1rem; }
.item-meta { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.item-actions { display: flex; flex-direction: column; gap: .35rem; }
.badge { display: inline-block; background: var(--brand-soft); color: var(--brand-dark); border-radius: 99px; padding: 0 .55rem; font-size: .78rem; font-weight: 700; }
.vacio { text-align: center; padding: 2rem 1rem; }

/* Resumen */
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg-btn { min-height: 44px; min-width: 80px; border: 0; border-radius: 9px; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-btn.is-active { background: var(--brand); color: #fff; }
.nav-periodo { display: flex; align-items: center; gap: .5rem; }
.per-titulo { flex: 1; text-align: center; display: flex; flex-direction: column; align-items: center; }
.per-titulo strong { overflow-wrap: anywhere; }
.dias { list-style: none; margin: 0; padding: 0; }
.dias li { display: flex; justify-content: space-between; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.dias li:last-child { border-bottom: 0; }
.dias .extra { color: var(--warn); font-size: .85rem; }
.dias .cero { color: var(--muted); }

/* Diálogo y avisos */
.dialogo { width: min(520px, calc(100vw - 1.5rem)); max-height: calc(100vh - 1.5rem); overflow: auto; border: 0; border-radius: 18px; padding: 1.25rem; box-shadow: 0 25px 60px rgba(0,0,0,.35); color: var(--ink); }
.dialogo::backdrop { background: rgba(10, 30, 28, .55); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 .75rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + 1rem + env(safe-area-inset-bottom)); z-index: 30; max-width: calc(100vw - 1.5rem); background: #12302d; color: #fff; padding: .7rem 1.1rem; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.toast.error { background: var(--err); }

/* ---------- tablet ---------- */
@media (min-width: 600px) {
  main { padding: 1.25rem; padding-bottom: calc(var(--tabbar) + 2rem); }
  .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item { padding: .9rem 1rem; }
}

/* ---------- escritorio: pestañas arriba ---------- */
@media (min-width: 1024px) {
  .tabs {
    position: static; height: auto; padding-bottom: 0;
    display: flex; justify-content: center; gap: .25rem;
    border-top: 0; border-bottom: 1px solid var(--line);
  }
  .tab { flex-direction: row; gap: .5rem; padding: .5rem 1.5rem; font-size: .95rem; min-height: 52px; border-bottom: 3px solid transparent; }
  .tab.is-active { background: none; border-bottom-color: var(--brand); }
  .tab:hover { background: var(--brand-soft); }
  main { padding: 1.5rem; padding-bottom: 2rem; }
  .cols { gap: 1.25rem; }
  .toast { bottom: 1.5rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .tab, .seg-btn { transition: background-color .15s, border-color .15s, color .15s; }
}
