:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #17201e;
  --muted: #5d6b68;
  --border: #d9e0de;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d6efec;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --warn: #b45309;
  --warn-soft: #fbedd5;
  --danger: #b91c1c;
  --danger-soft: #fbe0e0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1514;
    --surface: #172120;
    --surface-2: #1f2b29;
    --text: #e8eeec;
    --muted: #9aaaa6;
    --border: #2c3a37;
    --primary: #2dd4bf;
    --primary-ink: #04201d;
    --primary-soft: #133d38;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --danger: #f87171;
    --danger-soft: #3d1717;
    --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, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 96px; }
.wrap.wide { max-width: 1180px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; margin: 0 0 .3rem; }
.field { margin-bottom: .9rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .65rem .75rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }
textarea { min-height: 90px; resize: vertical; }
/* iPhone: los campos de fecha ignoran el ancho y se descuadran si no se normalizan */
input[type=date], input[type=month], input[type=datetime-local] {
  -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%;
  min-height: 2.9rem; text-align: left;
}
input::-webkit-date-and-time-value { text-align: left; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.check input { width: auto; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  border-radius: 10px; padding: .65rem 1rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .6rem; font-size: .85rem; border-radius: 8px; }
.btn-link { border: 0; background: none; color: var(--primary); padding: .3rem; }

.msg { border-radius: 10px; padding: .65rem .8rem; margin: .5rem 0 .9rem; font-size: .92rem; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.info { background: var(--primary-soft); color: var(--text); }

/* ---------- Fichaje ---------- */
.clock { text-align: center; padding: 6px 0 2px; }
.clock .time { font-size: 3.2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.clock .date { color: var(--muted); }
.clock .date::first-letter { text-transform: uppercase; }
.estado { display: flex; justify-content: center; margin: 12px 0 18px; }
.pill {
  display: inline-flex; align-items: center; gap: .4rem; border-radius: 999px; padding: .3rem .8rem;
  font-weight: 600; font-size: .9rem; background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: currentColor; }
.pill.trabajando { background: var(--ok-soft); color: var(--ok); }
.pill.pausa { background: var(--warn-soft); color: var(--warn); }
.acciones { display: grid; gap: 10px; }
.btn-fichar { padding: 1.1rem; font-size: 1.15rem; border-radius: 14px; }
.btn-fichar.entrada { background: #15803d; border-color: #15803d; color: #fff; }
.btn-fichar.salida { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-fichar.entrada:hover, .btn-fichar.salida:hover { filter: brightness(1.1); }
.btn-fichar.inicio_pausa, .btn-fichar.fin_pausa { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.stat { text-align: center; margin-top: 14px; }
.stat b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; justify-content: space-between; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.lista li:last-child { border-bottom: 0; }
.lista .tag { align-self: flex-start; flex-shrink: 0; }
.lista li.solicitud { display: block; }
.lista li.solicitud .row { margin-bottom: .2rem; }
#f-solicitud button[type=submit] { width: 100%; }
.lista.dias li { align-items: center; }
.lista.dias li.vacio { color: var(--muted); font-size: .9rem; padding: .35rem 0; }
.lista.dias .tag { margin-top: .25rem; }
#h-resumen { margin: .2rem 0 .4rem; }
.descargas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Vacaciones ---------- */
.sel-anio { width: auto; padding: .4rem .6rem; }
.saldo { margin-top: .4rem; }
.saldo-num { display: flex; align-items: baseline; gap: .5rem; }
.saldo-num b { font-size: 2.6rem; line-height: 1; color: var(--primary); font-variant-numeric: tabular-nums; }
.saldo-num span { color: var(--muted); }
.barra { display: flex; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: .7rem 0 .5rem; }
.barra span:first-child { background: var(--ok); }
.barra span:last-child { background: var(--warn); }
.grid2.fechas { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }
.grid2 > * { min-width: 0; }
.grid2.fechas input { padding-left: .6rem; padding-right: .4rem; }
.lista li.solicitud .btn-sm { margin-top: .4rem; }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: .6rem; }
.tag.aus-vacaciones { background: var(--ok-soft); color: var(--ok); }
.tag.aus-baja { background: var(--danger-soft); color: var(--danger); }
.tag.aus-permiso, .tag.aus-asuntos_propios, .tag.aus-otro { background: var(--primary-soft); color: var(--text); }
.pill.ausencia { background: var(--primary-soft); color: var(--text); }

/* Calendario del panel */
.cal-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 12px; }
table.cal { border-collapse: separate; border-spacing: 0; font-size: .78rem; width: max-content; min-width: 100%; }
table.cal th, table.cal td { padding: 0; border-bottom: 1px solid var(--border); text-align: center; }
table.cal thead th { font-size: .68rem; padding: .3rem 0; width: 26px; min-width: 26px; text-transform: none; letter-spacing: 0; }
table.cal th.nom, table.cal td.nom {
  position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; padding: .35rem .6rem;
  min-width: 120px; max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--border);
}
table.cal td.d { height: 30px; }
table.cal .finde, table.cal .fest { background: var(--surface-2); }
table.cal .hoy { box-shadow: inset 0 0 0 2px var(--primary); }
table.cal td.d span { display: block; margin: 3px 1px; height: 22px; border-radius: 5px; line-height: 22px; font-weight: 700; font-size: .7rem; }
.c-vacaciones { background: var(--ok); color: #fff; }
.c-baja { background: var(--danger); color: #fff; }
.c-permiso, .c-asuntos_propios, .c-otro { background: var(--primary); color: var(--primary-ink); }
.c-pend { background: repeating-linear-gradient(45deg, var(--warn-soft), var(--warn-soft) 4px, transparent 4px, transparent 8px); color: var(--warn); border: 1px dashed var(--warn); }
.leyenda { display: flex; flex-wrap: wrap; gap: .5rem 1rem; font-size: .8rem; color: var(--muted); margin: .6rem 0; }
.leyenda i.fest { background: var(--surface-2); border: 1px solid var(--border); }
.leyenda i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: .3rem; }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: center; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 140px; border: 0; border-radius: 0; background: none; color: var(--muted);
  flex-direction: column; gap: 2px; font-size: .78rem; padding: .55rem .2rem;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.on { color: var(--primary); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.anulado td { color: var(--muted); text-decoration: line-through; }
tr.anulado td.nostrike { text-decoration: none; }
tr.finde td { background: var(--surface-2); }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; border-radius: 6px; padding: .1rem .4rem; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); white-space: nowrap; padding: .75rem .8rem; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.filtros { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; margin-bottom: 14px; }
.filtros .field { margin: 0; }
.cards-ahora { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cards-ahora .card { margin: 0; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog form { padding: 20px; max-height: 85vh; overflow-y: auto; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 10px; font-weight: 600;
  max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

.solo-movil { display: none; }

/* ---------- Móvil ---------- */
@media (max-width: 680px) {
  .solo-escritorio { display: none !important; }
  .solo-movil { display: inline; }
  .topbar { padding: .55rem 12px; }
  .topbar .row { gap: .4rem; flex-wrap: nowrap; }
  .wrap { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; }
  h1 { font-size: 1.2rem; }
  .row.between > h1 { margin-bottom: .4rem; }

  /* Pestañas del panel: en varias filas, todas visibles */
  .tabs { flex-wrap: wrap; gap: 6px; padding: 8px 12px; overflow: visible; }
  .tabs button {
    border: 1px solid var(--border); border-radius: 999px; padding: .4rem .75rem; font-size: .88rem;
  }
  .tabs button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }

  .filtros { grid-template-columns: 1fr 1fr; }
  .filtros button[type=submit] { grid-column: 1 / -1; }

  /* Tablas: cada fila se convierte en una tarjeta */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr { display: block; width: 100%; }
  table.responsive tr {
    border: 1px solid var(--border); border-radius: 12px; padding: .45rem .75rem;
    margin-bottom: .6rem; background: var(--surface);
  }
  table.responsive tr.finde { background: var(--surface-2); }
  table.responsive tr.finde td { background: none; }
  table.responsive td {
    display: block; position: relative; border: 0; padding: .28rem 0 .28rem 40%;
    min-height: 1.6rem; text-align: left; word-break: break-word;
  }
  table.responsive td::before {
    content: attr(data-label); position: absolute; left: 0; top: .32rem; width: 37%;
    font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
    text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  table.responsive td[data-label=""] { padding-left: 0; }
  table.responsive td[data-label=""]::before { content: none; }
  table.responsive td:empty { display: none; }
  .table-wrap:has(> table.responsive) { overflow-x: visible; }
  .card:has(> .table-wrap > table.responsive), .card:has(> table.responsive) {
    background: none; border: 0; box-shadow: none; padding: 0;
  }

  dialog form { padding: 16px; }
  dialog .row { flex-wrap: wrap; }
  .cards-ahora { grid-template-columns: 1fr; }
}

.centrado { text-align: center; }
.privacidad { font-size: .92rem; }
.privacidad h3 { margin-top: 1rem; }
.privacidad ul { padding-left: 1.2rem; margin: 0 0 .8rem; }

/* Modo soporte: el superadministrador está dentro de la cuenta de un cliente */
.aviso-soporte {
  position: sticky; top: 0; z-index: 11;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap;
  padding: .55rem 16px; background: #b45309; color: #fff; font-size: .9rem;
}
.aviso-soporte .btn-sm { background: #fff; color: #7c2d12; border-color: #fff; }
