/* =====================================================================
   Control Horario - estilos (móvil primero, modo oscuro automático)
   ===================================================================== */
:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #EEF2F6;
  --text: #14202E;
  --muted: #5B6B7D;
  --border: #DDE3EA;
  --primary: #12355B;
  --primary-ink: #FFFFFF;
  --ok: #1E8E5A;
  --ok-soft: #E3F4EC;
  --warn: #B87510;
  --warn-soft: #FBF0DC;
  --danger: #C0392B;
  --danger-soft: #FBE5E2;
  --focus: #3B82F6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 16px rgba(16, 32, 48, .06);
  --tabbar-h: 64px;
  --credit-h: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E141B;
    --surface: #17202A;
    --surface-2: #1F2A36;
    --text: #E8EEF4;
    --muted: #93A3B5;
    --border: #2A3644;
    --primary: #5B9BD5;
    --primary-ink: #0E141B;
    --ok: #3CC189;
    --ok-soft: #173326;
    --warn: #E8A33D;
    --warn-soft: #3A2D16;
    --danger: #F06A5B;
    --danger-soft: #3D1E1B;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; flex: none; } /* tamaño por defecto de los iconos */
.row .chev { width: 18px; height: 18px; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.mb { margin-bottom: 16px; }
.mt { margin-top: 16px; }
.grow { flex: 1; min-width: 0; }

/* ---- Carga ------------------------------------------------------------ */
.boot { min-height: 100dvh; display: grid; place-items: center; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Estructura --------------------------------------------------------- */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: var(--primary); color: var(--primary-ink);
}
.topbar .title { font-weight: 700; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .back { background: none; border: 0; color: inherit; padding: 4px; margin-left: -4px; display: flex; cursor: pointer; }
.content {
  flex: 1; width: 100%; max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--credit-h) + var(--safe-bottom) + 24px);
}
.content.no-tabs { padding-bottom: calc(var(--credit-h) + var(--safe-bottom) + 24px); }

/* Barra inferior + crédito, siempre abajo del todo */
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar { display: flex; max-width: 640px; margin: 0 auto; height: var(--tabbar-h); }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--primary); }
.credit {
  height: var(--credit-h); display: flex; align-items: center; justify-content: center;
  font-size: .7rem; color: var(--muted); letter-spacing: .02em;
}
.bottom.credit-only { border-top: 0; background: transparent; }

/* ---- Tarjetas y listas ------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 16px; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.list a.row, .list button.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  color: inherit; text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer;
}
.row .grow { flex: 1; min-width: 0; }
.row .chev { color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.stat .label { font-size: .78rem; color: var(--muted); }
.stat .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Etiquetas ---------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ---- Botones ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); font-weight: 700; cursor: pointer;
  text-decoration: none; touch-action: manipulation; transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--primary); border-color: transparent; min-height: 40px; padding: 6px 10px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

/* ---- Fichaje -------------------------------------------------------------- */
.clock-card { text-align: center; padding: 24px 16px; }
.now { font-size: 3rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.now .sec { font-size: 1.4rem; color: var(--muted); font-weight: 700; }
.today-label { color: var(--muted); margin-top: 6px; }
.today-label::first-letter, .day-date::first-letter, .month-picker .label::first-letter { text-transform: uppercase; }
.state {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; padding: 6px 14px;
  border-radius: 999px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.state::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.state.WORKING { background: var(--ok-soft); color: var(--ok); }
.state.WORKING::before { animation: pulse 1.6s ease-in-out infinite; }
.state.ON_BREAK { background: var(--warn-soft); color: var(--warn); }
@keyframes pulse { 50% { opacity: .35; } }
.clock-actions { display: grid; gap: 12px; margin-bottom: 16px; }
.clock-btn {
  min-height: 72px; border-radius: var(--radius); font-size: 1.2rem; font-weight: 800;
  border: 0; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: var(--shadow); touch-action: manipulation; transition: transform .08s;
}
.clock-btn:active { transform: scale(.98); }
.clock-btn:disabled { opacity: .55; }
.clock-btn svg { width: 26px; height: 26px; }
.clock-btn.IN, .clock-btn.BREAK_END { background: var(--ok); }
.clock-btn.BREAK_START { background: var(--warn); }
.clock-btn.OUT { background: var(--danger); }
@media (prefers-color-scheme: dark) { .clock-btn { color: #0E141B; } }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--border); }
.timeline li:first-child { border-top: 0; }
.timeline .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.timeline .dot.IN, .timeline .dot.BREAK_END { background: var(--ok); }
.timeline .dot.BREAK_START { background: var(--warn); }
.timeline .dot.OUT { background: var(--danger); }
.timeline .time { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Avisos ---------------------------------------------------------------- */
.alert { border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: .92rem; }
.alert.warn { background: var(--warn-soft); color: var(--text); border-left: 4px solid var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--text); border-left: 4px solid var(--danger); }
.alert.info { background: var(--surface-2); color: var(--text); border-left: 4px solid var(--primary); }
.alert.ok { background: var(--ok-soft); color: var(--text); border-left: 4px solid var(--ok); }

/* ---- Formularios ---------------------------------------------------------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); font-size: 16px; /* 16px evita el zoom en iOS */
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus, .btn:focus-visible, .tab:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; }
.form-error { color: var(--danger); font-weight: 600; margin-bottom: 12px; min-height: 1.2em; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Días de la semana (recordatorios) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); font-weight: 700; color: var(--muted);
}
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }

/* ---- Login ---------------------------------------------------------------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 16px calc(var(--credit-h) + var(--safe-bottom) + 24px); max-width: 420px; margin: 0 auto; }
.login .brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.login .brand img { width: 72px; height: 72px; border-radius: 18px; }

/* ---- Selector de mes ------------------------------------------------------- */
.month-picker { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.month-picker .label { font-weight: 800; font-size: 1.1rem; }

/* ---- Días (historial / admin) ----------------------------------------------- */
.day { padding: 12px 16px; border-top: 1px solid var(--border); }
.day:first-child { border-top: 0; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.day-date { display: inline-block; font-weight: 700; }
.day-total { font-weight: 800; font-variant-numeric: tabular-nums; }
.shift-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .9rem; color: var(--muted); margin-top: 4px; }
.entry-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed var(--border); }
.entry-row:first-of-type { border-top: 0; }
.entry-row.voided { opacity: .55; }
.entry-row.voided .time { text-decoration: line-through; }
.entry-row .time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.2em; }
.entry-row .actions { margin-left: auto; display: flex; gap: 6px; }

/* ---- Diálogo y avisos flotantes ----------------------------------------------- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px; max-height: 90dvh;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
dialog.sheet::backdrop { background: rgba(8, 16, 24, .5); }
dialog.sheet .sheet-body { padding: 20px 16px calc(16px + var(--safe-bottom)); overflow: auto; max-height: 90dvh; }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--credit-h) + var(--safe-bottom) + 16px);
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
.secret {
  font: 700 1.4rem/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .06em;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px; text-align: center; user-select: all;
  margin-bottom: 12px; word-break: break-all;
}

/* ---- Instalación -------------------------------------------------------------- */
.install-steps { margin: 8px 0 0; padding-left: 1.2rem; }
.install-steps li { margin-bottom: 6px; }
.inline-icon { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }

@media (min-width: 700px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
