:root {
  /* Oscuro por defecto (mismos tonos que ismaelse95-webs) */
  --brand: #4da3ff;
  --brand-contrast: #ffffff;
  --text: #e7e9ee;
  --muted: #8b93a1;
  --bg: #14161a;
  --card: #1c1f26;
  --card-2: #23262d;
  --input-bg: #23262d;
  --border: #333740;
  --ok: #2ecc82;
  --ok-bg: #163828;
  --warn: #e0a832;
  --warn-bg: #3a2f14;
  --danger: #f0564a;
  --danger-bg: #3a1f1c;
  --other: #b48cff;
  --other-bg: #2c2340;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --brand: #0a6fdc;
  --text: #1f2328;
  --muted: #6b7280;
  --bg: #f3f4f7;
  --card: #ffffff;
  --card-2: #eef0f4;
  --input-bg: #ffffff;
  --border: #e1e4ea;
  --ok: #138a52;
  --ok-bg: #e3f6ec;
  --warn: #a86b00;
  --warn-bg: #fdf1dc;
  --danger: #c0392b;
  --danger-bg: #fbe9e7;
  --other: #6d3fd1;
  --other-bg: #efe8fc;
  --shadow: 0 8px 24px rgba(15, 23, 42, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; }
h2 { font-size: 16px; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Estructura ---------- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  min-height: 52px;
  padding: calc(var(--safe-top) + 8px) 12px 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { flex: 1; font-size: 19px; }

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h);
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}
.tabbar a.active { color: var(--brand); font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; }

.boot { display: flex; align-items: center; justify-content: center; min-height: 60vh; color: var(--muted); }

/* ---------- Componentes base ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: var(--brand-contrast);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
button.secondary, .btn.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: none; color: var(--brand); padding: 8px 10px; }
button.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
button.block { width: 100%; }
button:disabled { opacity: .45; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 42px; min-height: 42px; padding: 8px;
  background: none; border: none; border-radius: 10px;
  color: var(--text); font-size: 20px; font-weight: 400;
}
.icon-btn:active { background: var(--card-2); }
.icon-btn svg { width: 20px; height: 20px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px evita el zoom automatico de iOS al enfocar */
}
textarea { min-height: 80px; resize: vertical; }
input[type="color"] { padding: 4px; min-height: 44px; width: 56px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; color: var(--text); font-size: 15px; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--brand); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.segmented { display: flex; gap: 3px; padding: 3px; background: var(--card-2); border-radius: 11px; }
.segmented button {
  flex: 1; min-height: 36px; padding: 6px 8px;
  background: transparent; color: var(--muted);
  border-radius: 8px; font-size: 14px;
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.neutral { background: var(--card-2); color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

.kv { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv .v { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 12px; color: var(--muted); }

.section-title { margin: 22px 4px 8px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }

/* Muestra de color de un tipo de turno */
.swatch {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 12px; font-weight: 800;
}
.swatch.sm { width: 22px; height: 22px; border-radius: 6px; font-size: 10px; }
.swatch.empty-step { background: var(--card-2); color: var(--muted); border: 1px dashed var(--border); }

/* Chips seleccionables (turnos) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: 0 -2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 6px 12px;
  border: 2px solid transparent; border-radius: 999px;
  background: var(--card-2); color: var(--text);
  font-size: 14px; font-weight: 600;
}
.chip.selected { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--bg); }
.chip .swatch { width: 20px; height: 20px; border-radius: 5px; font-size: 10px; }

/* ---------- Hojas inferiores (modales) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .5);
  animation: fade-in .15s ease-out;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 6px 16px calc(18px + var(--safe-bottom));
  background: var(--card);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  animation: slide-up .2s ease-out;
}
.sheet-handle { width: 40px; height: 4px; margin: 6px auto 10px; border-radius: 2px; background: var(--border); }
.sheet-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sheet-header h2 { flex: 1; font-size: 18px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions > * { flex: 1; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: .5; } }

/* ---------- Avisos ---------- */
.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  width: 100%; max-width: 480px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #2b2f37; color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
  pointer-events: auto;
  animation: slide-up .2s ease-out;
}
.toast .msg { flex: 1; }
.toast.error { background: #b3261e; }
.toast button { min-height: 32px; padding: 4px 8px; background: none; color: #8cc4ff; }

/* ---------- Calendario ---------- */
.month-nav { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.month-nav .title {
  flex: 1; min-height: 40px;
  background: none; color: var(--text);
  font-size: 18px; font-weight: 700; text-transform: capitalize;
}
.paint-hint { font-size: 12px; color: var(--muted); margin: 6px 2px 8px; min-height: 17px; }
.paint-hint strong { color: var(--text); }

.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-weekdays span { padding: 2px 0 4px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-day {
  position: relative;
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start;
  aspect-ratio: 1 / 1.12;
  min-height: 0; padding: 0;
  overflow: hidden;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--card); color: var(--text);
  font-weight: 400; text-align: left;
}
.cal-day .num { padding: 3px 5px 0; font-size: 12px; font-weight: 700; line-height: 1.2; text-align: center; }
.cal-day .shifts { flex: 1; display: flex; flex-direction: column; align-items: stretch; justify-content: center; min-height: 0; }
.cal-day .abbr { display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 800; letter-spacing: .02em; }
.cal-day.split .shifts { justify-content: stretch; gap: 1px; }
.cal-day .half { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; }
.cal-day.other-month { opacity: .38; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--brand); }
.cal-day.today .num { color: var(--brand); }
.cal-day.painted.today .num { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.cal-day.holiday:not(.painted) .num { color: var(--danger); }
.cal-day.holiday::before {
  content: ""; position: absolute; top: 0; right: 0;
  border-top: 12px solid var(--danger); border-left: 12px solid transparent;
}
.cal-day .marks { position: absolute; left: 4px; bottom: 3px; display: flex; gap: 3px; }
.cal-day .mark { width: 6px; height: 6px; border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.mark.note { background: var(--warn); }
.mark.punch { background: var(--ok); }
.cal-day.selected { box-shadow: inset 0 0 0 3px var(--brand); }
.cal-day.selected .num { color: var(--brand); }

.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend .mark { width: 8px; height: 8px; border-radius: 50%; }
.cal-legend .tri { width: 0; height: 0; border-top: 9px solid var(--danger); border-left: 9px solid transparent; }

.year-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .year-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.mini-month {
  display: block; width: 100%; min-height: 0; padding: 8px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text); text-align: left;
}
.mini-month h3 { margin-bottom: 6px; font-size: 13px; text-transform: capitalize; }
.mini-month.current h3 { color: var(--brand); }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-grid span { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 3px; font-size: 8px; font-weight: 700; }
.mini-grid .blank { background: transparent; }
.mini-grid .d { background: var(--card-2); color: var(--muted); }
.mini-grid .hol { box-shadow: inset 0 0 0 1px var(--danger); }
.mini-grid .today { box-shadow: inset 0 0 0 1.5px var(--brand); }

/* ---------- Fichar ---------- */
.clock { padding: 6px 0 14px; text-align: center; }
.clock .time { font-size: 50px; font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.clock .date { color: var(--muted); }

.status-line { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.status-pill { padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.status-fuera { background: var(--card-2); color: var(--muted); }
.status-trabajando { background: var(--ok-bg); color: var(--ok); }
.status-comida { background: var(--warn-bg); color: var(--warn); }
.status-otros { background: var(--other-bg); color: var(--other); }
.planned-today { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); }

.counters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; text-align: center; }
.counter { padding: 10px 4px; border-radius: 10px; background: var(--card-2); }
.counter .value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.counter .label { font-size: 12px; color: var(--muted); }

.punch-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.punch-btn {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
  min-height: 78px; padding: 12px 14px;
  border: 1px solid var(--border); border-left-width: 5px; border-radius: 14px;
  background: var(--card); color: var(--text);
  font-size: 16px; font-weight: 800; text-align: left;
}
.punch-btn small { font-size: 12px; font-weight: 500; color: var(--muted); }
.punch-btn.k-in { border-left-color: var(--ok); }
.punch-btn.k-out { border-left-color: var(--danger); }
.punch-btn.k-lunch { border-left-color: var(--warn); }
.punch-btn.k-other { border-left-color: var(--other); }
.punch-btn.suggested { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.punch-btn.suggested small { color: rgba(255, 255, 255, .85); }
.punch-btn:disabled { opacity: .3; }
.punch-btn:not(:disabled):active { transform: scale(.98); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .t-time { width: 58px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timeline .t-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.timeline .t-main { flex: 1; min-width: 0; }
.timeline .t-reason { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.dot-in { background: var(--ok); }
.dot-out { background: var(--danger); }
.dot-lunch { background: var(--warn); }
.dot-other { background: var(--other); }

/* ---------- Registros ---------- */
.period-nav { display: flex; align-items: center; gap: 4px; margin-top: 10px; }
.period-nav .title { flex: 1; text-align: center; font-weight: 700; text-transform: capitalize; }
.day-row { border-bottom: 1px solid var(--border); }
.day-row:last-child { border-bottom: 0; }
.day-row-head {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 0; padding: 12px 0;
  background: none; color: var(--text); border-radius: 0;
  font-weight: 400; text-align: left;
}
.day-row-head .grow { flex: 1; min-width: 0; }
.day-row-head .date { font-weight: 700; }
.day-row-head .meta { font-size: 12px; color: var(--muted); }
.day-row-head .worked { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.day-row .timeline { padding: 0 0 10px 12px; border-left: 2px solid var(--border); margin: 0 0 12px 4px; }

.export-ready { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--card-2); }
.export-ready .name { flex: 1 1 100%; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.export-ready button { flex: 1; }

/* ---------- Login ---------- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
}
.login-card { width: 100%; max-width: 360px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand img { width: 48px; height: 48px; border-radius: 12px; }
.login-brand h1 { font-size: 22px; }
.auth-title { font-size: 18px; margin-bottom: 6px; }
.auth-links { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 12px; }
.auth-links .ghost { font-weight: 500; }
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--muted); font-size: 13px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.code-input { font-size: 26px; letter-spacing: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.info-text { color: var(--ok); font-size: 13px; margin-top: 10px; }

/* ---------- Editores ---------- */
button.swatch { min-height: 0; padding: 0; border: 0; }
.selected-color { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--text); }
.pattern-steps {
  display: flex; flex-wrap: wrap; gap: 6px;
  min-height: 52px; padding: 8px;
  border: 1px dashed var(--border); border-radius: 10px;
}
.pattern-steps .step {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 0; padding: 2px;
  background: none; color: var(--muted);
  font-size: 10px; font-weight: 600;
}
.pattern-preview { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 8px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.cal-day.pick { aspect-ratio: 1; }
.cal-day:disabled { opacity: .3; }
.day-row-head .badge { flex: none; }

/* ---------- Administracion ---------- */
.big-number { font-size: 28px; font-weight: 800; }
.avatar {
  position: relative; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: 16px;
}
.online-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 2px var(--card);
}
.user-row .title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; overflow-wrap: anywhere; }
.user-row .sub { overflow-wrap: anywhere; }
button.danger-text { color: var(--danger); }

/* Con 6 pestanas (admin) las etiquetas se recortan en moviles estrechos */
.tabbar a { min-width: 0; }
.tabbar a span { max-width: 100%; padding: 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 380px) { .tabbar a { font-size: 10px; } }

/* ---------- Atajos de iPhone ---------- */
.token-box { padding: 12px; border: 1px solid var(--warn); border-radius: 12px; background: var(--warn-bg); margin-bottom: 8px; }
.token-box p { margin: 0 0 8px; }
.code-box {
  display: block; margin: 6px 0;
  padding: 8px 10px; border-radius: 8px;
  background: var(--card-2); color: var(--text);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px;
  overflow-wrap: anywhere; user-select: all;
}
.guide-title { margin: 20px 0 8px; font-size: 15px; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; }
.steps li { margin: 8px 0; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; }
