/* Tu Fichaje Fácil — estilos
   Colores con significado: verde = trabajando, ámbar = pausa, pizarra = fuera, rojo = incidencia. */

:root {
  --ink: #1e2a32;
  --ink-2: #4a5a64;
  --ink-3: #74828b;
  --paper: #f1f4f2;
  --surface: #ffffff;
  --line: #d8dfdb;
  --line-2: #e8ece9;
  --brand: #1f4e5f;
  --brand-2: #2b6a80;
  --work: #0f7b5f;
  --work-tint: #e2f2ec;
  --pause: #a86a12;
  --pause-tint: #fbefd9;
  --out: #44546a;
  --out-tint: #e7ecf1;
  --alert: #b3372f;
  --alert-tint: #f9e4e1;
  --focus: #2b6a80;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(30, 42, 50, .06), 0 4px 14px rgba(30, 42, 50, .06);
  --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --nav-w: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--ink); }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 .75em; }
a { color: var(--brand-2); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- Botones y formularios ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius);
  font: inherit; font-weight: 600; font-size: .93rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--brand); color: #fff;
  transition: background-color .15s, opacity .15s;
}
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--line-2); }
.btn.ghost { background: transparent; color: var(--brand-2); padding: 0 8px; }
.btn.ghost:hover { background: var(--line-2); }
.btn.danger { background: var(--alert); }
.btn.danger:hover { background: #962c25; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: .85rem; }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label, .label { font-weight: 600; font-size: .88rem; color: var(--ink); }
.field .hint { font-size: .8rem; color: var(--ink-3); }
input, select, textarea {
  font: inherit; color: var(--ink);
  min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(43, 106, 128, .18); }
input[type="checkbox"] { width: auto; min-height: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.error-text { color: var(--alert); font-weight: 600; font-size: .9rem; }

/* ---------- Estructura de la app ---------- */

.shell { min-height: 100vh; }
.nav {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w);
  background: var(--brand); color: #e3eef2;
  display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -.02em;
}
.brand-name { font-weight: 700; font-size: 1.02rem; line-height: 1.15; }
.brand-company { font-size: .78rem; color: #a9c4ce; font-weight: 500; }
.nav-group { margin-top: 14px; }
.nav-group-title { font-size: .78rem; color: #a9c4ce; padding: 0 10px 6px; font-weight: 600; }
.nav a.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #e3eef2; text-decoration: none; font-weight: 500; font-size: .94rem;
}
.nav a.nav-item:hover { background: rgba(255, 255, 255, .08); }
.nav a.nav-item.active { background: #fff; color: var(--brand); font-weight: 700; }
.nav-item .badge { margin-left: auto; }
.nav-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .12); }
.nav-user { padding: 6px 10px 10px; font-size: .85rem; }
.nav-user strong { display: block; color: #fff; }
.nav-user span { color: #a9c4ce; }
.ico { width: 18px; height: 18px; flex: none; }

.main { margin-left: var(--nav-w); padding: 28px 32px 60px; max-width: calc(1180px + var(--nav-w)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

.topbar, .tabbar { display: none; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 20px; margin-bottom: 18px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.badge.work { background: var(--work-tint); color: var(--work); }
.badge.pause { background: var(--pause-tint); color: var(--pause); }
.badge.out { background: var(--out-tint); color: var(--out); }
.badge.alert { background: var(--alert-tint); color: var(--alert); }
.badge.count { background: #ffb547; color: #3b2600; min-width: 22px; justify-content: center; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--out); flex: none; }
.dot.work { background: var(--work); box-shadow: 0 0 0 3px var(--work-tint); }
.dot.pause { background: var(--pause); box-shadow: 0 0 0 3px var(--pause-tint); }

/* ---------- Panel de fichaje (protagonista) ---------- */

.clock {
  border-radius: 18px; padding: 26px 28px; margin-bottom: 18px;
  background: var(--out-tint); border: 1px solid #d3dbe4;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px 28px; align-items: center;
}
.clock.work { background: var(--work-tint); border-color: #bfe0d3; }
.clock.pause { background: var(--pause-tint); border-color: #efd8ae; }
.clock-state { font-size: .95rem; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.clock-word { font-size: clamp(2.2rem, 5vw, 3.2rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin: 2px 0 6px; }
.clock.work .clock-word { color: var(--work); }
.clock.pause .clock-word { color: var(--pause); }
.clock.out .clock-word { color: var(--out); }
.clock-sub { color: var(--ink-2); font-size: .95rem; }
.clock-total { text-align: right; }
.clock-total .big { font-size: clamp(2rem, 4.4vw, 2.8rem); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; }
.clock-total .lbl { color: var(--ink-2); font-size: .85rem; margin-top: 6px; }
.clock-actions { grid-column: 1 / -1; display: flex; gap: 12px; flex-wrap: wrap; }
.btn.punch { min-height: 60px; padding: 0 30px; font-size: 1.1rem; border-radius: 12px; flex: 1 1 220px; max-width: 360px; }
.btn.punch.in { background: var(--work); }
.btn.punch.in:hover { background: #0b654e; }
.btn.punch.out { background: var(--alert); }
.btn.punch.out:hover { background: #962c25; }
.btn.punch.pause { background: var(--surface); color: var(--pause); border: 2px solid #e2b766; }
.btn.punch.pause:hover { background: #fff8ea; }
.btn.punch.resume { background: var(--pause); }
.clock-note { grid-column: 1 / -1; background: rgba(255, 255, 255, .65); border-radius: 10px; padding: 10px 14px; font-size: .92rem; }
.clock-note.alert { background: var(--alert-tint); color: #7d231d; }

/* Línea de tiempo del día */
.timeline { margin-top: 4px; }
.tl-bar { position: relative; height: 30px; background: var(--line-2); border-radius: 8px; overflow: hidden; }
.tl-plan { position: absolute; top: 0; bottom: 0; border: 2px dashed #9fb0ba; border-radius: 6px; background: rgba(255,255,255,.5); }
.tl-work { position: absolute; top: 5px; bottom: 5px; background: var(--work); border-radius: 4px; }
.tl-pause { position: absolute; top: 5px; bottom: 5px; background: #e7a93d; border-radius: 4px; }
.tl-now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.tl-scale { display: flex; justify-content: space-between; font-size: .75rem; color: var(--ink-3); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tl-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); margin-top: 8px; }
.tl-legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---------- Listas y tablas ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.list .meta { font-size: .85rem; color: var(--ink-2); }
.entry-time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 52px; }
.entry-type { display: inline-flex; align-items: center; gap: 8px; }
.tag-edit { font-size: .8rem; color: var(--pause); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th { text-align: left; font-weight: 600; font-size: .8rem; color: var(--ink-2); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: #f7f9f8; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.pos { color: var(--work); }
.neg { color: var(--alert); }

.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: .82rem;
  background: #dbe7ec; color: var(--brand);
}

.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { margin-bottom: 0; }
.seg { display: inline-flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { white-space: nowrap; border: 0; background: transparent; font: inherit; font-size: .88rem; padding: 8px 14px; cursor: pointer; color: var(--ink-2); font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--ink-2); padding: 10px 14px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-2); }
.empty h3 { margin-bottom: 6px; }

.stats { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 4px; }
.stat .v { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .82rem; color: var(--ink-2); }

/* ---------- Calendario ---------- */

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-h { font-size: .78rem; color: var(--ink-3); font-weight: 600; text-align: center; padding-bottom: 2px; }
.cal-d {
  min-height: 78px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface);
  padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.cal-d:hover { border-color: var(--brand-2); }
.cal-d.off { background: transparent; border-style: dashed; cursor: default; }
.cal-d.weekend { background: #f7f8f7; }
.cal-d.today { border: 2px solid var(--brand); }
.cal-d.sel { box-shadow: 0 0 0 3px rgba(43, 106, 128, .25); }
.cal-d .n { font-weight: 700; font-size: .9rem; }
.cal-d .w { font-size: .82rem; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--work); }
.cal-d .x { font-size: .72rem; line-height: 1.2; }
.cal-d.holiday { background: #eef3f6; }
.cal-d.holiday .x { color: var(--brand-2); }
.cal-d.absence { background: #f3effa; }
.cal-d.absence .x { color: #5b3f8f; }
.cal-d.incid { border-color: #e9b5af; }
.cal-d.incid .x.i { color: var(--alert); }

/* ---------- Horario (editor) ---------- */

.sched { display: grid; grid-template-columns: 110px minmax(0, 1fr) 70px; gap: 8px 12px; align-items: center; }
.sched .d { font-weight: 600; }
.sched .h { font-size: .85rem; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Modal y avisos ---------- */

.modal-back {
  position: fixed; inset: 0; background: rgba(20, 30, 36, .45); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 540px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25); padding: 22px 22px 18px;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-close { border: 0; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 0 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: #fff; border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); font-size: .92rem; animation: toast-in .2s ease-out; }
.toast.ok { background: var(--work); }
.toast.err { background: var(--alert); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.callout { border-radius: 10px; padding: 12px 14px; background: var(--out-tint); margin-bottom: 14px; font-size: .92rem; }
.callout.warn { background: var(--pause-tint); color: #6b4410; }
.callout.alert { background: var(--alert-tint); color: #7d231d; }
.callout.ok { background: var(--work-tint); color: #0b4f3d; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.15rem; background: var(--paper); border: 1px dashed var(--line); padding: 10px 14px; border-radius: 8px; word-break: break-all; user-select: all; }

/* ---------- Acceso (login) ---------- */

.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side {
  background: var(--brand); color: #e3eef2; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-side .brand { padding: 0; }
.auth-claim { font-size: clamp(1.8rem, 3.2vw, 2.6rem); font-weight: 800; color: #fff; letter-spacing: -.02em; line-height: 1.12; max-width: 14ch; }
.auth-punch { display: flex; gap: 10px; flex-wrap: wrap; }
.auth-punch span { background: rgba(255,255,255,.1); border-radius: 999px; padding: 6px 12px; font-size: .85rem; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { margin-bottom: 6px; }
.auth-box > p { color: var(--ink-2); margin-bottom: 22px; }

.loading { padding: 60px 0; text-align: center; color: var(--ink-3); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Móvil ---------- */

@media (max-width: 900px) {
  .nav { display: none; }
  .nav.open { display: flex; width: min(86vw, 320px); box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .nav-scrim { position: fixed; inset: 0; background: rgba(20,30,36,.45); z-index: 19; }
  .main { margin-left: 0; padding: 74px 16px 96px; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: fixed; top: 0; left: 0; right: 0; height: 58px; z-index: 15;
    background: var(--brand); color: #fff; padding: 0 12px;
  }
  .topbar .brand { padding: 0; flex: 1; min-width: 0; }
  .topbar .brand-name { font-size: .98rem; }
  .icon-btn { border: 0; background: transparent; color: inherit; padding: 8px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
  .tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .72rem; color: var(--ink-2); text-decoration: none; padding: 4px 0; font-weight: 600; position: relative; }
  .tabbar a.active { color: var(--brand); }
  .tabbar a .badge { position: absolute; top: -2px; right: calc(50% - 22px); font-size: .65rem; padding: 0 5px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .clock { grid-template-columns: minmax(0, 1fr); padding: 20px; }
  .clock-total { text-align: left; }
  .btn.punch { max-width: none; }
  .panel { padding: 16px; border-radius: 12px; }
  .page-head { margin-bottom: 14px; }
  h1 { font-size: 1.35rem; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { padding: 22px 20px; gap: 16px; }
  .auth-claim { font-size: 1.5rem; max-width: none; }
  .auth-punch { display: none; }
  .cal { gap: 3px; }
  .cal-d { min-height: 54px; padding: 4px; border-radius: 7px; }
  .cal-d:hover { border-color: var(--line-2); }
  .toolbar form.actions input { flex: 1 1 140px; width: auto !important; }
  .cal-d .x { display: none; }
  .cal-d .w { font-size: .72rem; }
  .sched { grid-template-columns: 84px minmax(0, 1fr); }
  .sched .h { display: none; }
  .table-wrap { margin: 0; overflow-x: visible; }
  table.data.stack, table.data.stack tbody, table.data.stack tfoot { display: block; width: 100%; }
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; width: 100%; border-bottom: 1px solid var(--line-2); padding: 10px 0; }
  table.data.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 3px 0; text-align: right; width: 100%; }
  table.data.stack td::before { content: attr(data-l); font-weight: 600; font-size: .82rem; color: var(--ink-2); text-align: left; flex: none; }
  table.data.stack td:first-child { display: block; text-align: left; padding-bottom: 6px; }
  table.data.stack td:first-child::before { content: none; }
  table.data.stack td.n { white-space: normal; }
  table.data.stack .person > div { min-width: 0; overflow-wrap: anywhere; }
  table.data.stack tfoot tr { border-top: 2px solid var(--line); }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; }
  .toasts { left: 12px; right: 12px; bottom: 84px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Impresión (informes) ---------- */

.print-only { display: none; }
@media print {
  body { background: #fff; font-size: 11px; }
  .nav, .topbar, .tabbar, .toolbar, .no-print, .toasts, .btn { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; }
  .print-only { display: block; }
  table.data th, table.data td { padding: 4px 6px; }
  .page-break { page-break-before: always; }
}
