:root {
  /* Colores corporativos */
  --azul: #1b75bb;
  --magenta: #e5006d;
  --naranja: #f9a03f;
  --verde: #3aa985;

  --bg: #fbfbfa;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #5f6675;
  --line: #e5e7eb;
  --brand: var(--azul);
  --brand-ink: #ffffff;
  --brand-soft: #eaf4fc;
  --btn: #cfe5f7;
  --btn-ink: #125a93;
  --btn-bad: #f9cfe2;
  --btn-bad-ink: #b0004f;
  --ok: #2a9473;
  --ok-soft: #e6f6f0;
  --bad: #d1005f;
  --bad-soft: #fdeaf3;
  --warn: #b36b00;
  --warn-soft: #fff2df;
  --blank: #adb5bd;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 8px 24px -14px rgba(20, 30, 60, .14);
  --tira: linear-gradient(90deg, var(--azul) 0 25%, var(--magenta) 25% 50%, var(--naranja) 50% 75%, var(--verde) 75% 100%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --card: #1b2130;
    --ink: #e8ecf5;
    --muted: #9aa3b5;
    --line: #2b3346;
    --brand: #5ea8e6;
    --brand-ink: #0d1220;
    --brand-soft: #1d2f45;
    --btn: #24486d;
    --btn-ink: #cfe5f7;
    --btn-bad: #5a2540;
    --btn-bad-ink: #ffc2db;
    --ok: #4cc79d;
    --ok-soft: #173329;
    --bad: #ff5aa0;
    --bad-soft: #3a1a2a;
    --warn: #f9a03f;
    --warn-soft: #3a2c17;
    --blank: #5c6578;
    --shadow: none;
    color-scheme: dark;
  }
}

* { 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 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--brand); }


/* Acceso */
body.noauth { padding-bottom: 24px; }
body.noauth .tabs { display: none; }
.login { max-width: 400px; margin: 7vh auto 0; }
body.entrada .top-in { display: none; }
.marca-app { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 20px; font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.marca-app img { height: 64px; width: 64px; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pass { position: relative; display: block; }
.pass input { padding-right: 46px; }
.pass button { position: absolute; top: 0; right: 0; width: 44px; height: 100%; display: flex; align-items: center; justify-content: center; border: 0; background: none; color: var(--muted); cursor: pointer; }
.pass button[aria-pressed="true"] { color: var(--brand); }
.pass button[aria-pressed="true"] .tacha { display: none; }
.sdn { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.sdnrow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.sdnrow:last-child { border-bottom: 0; }
.sdnrow .orig { font-size: .86rem; color: var(--muted); overflow-wrap: anywhere; }
.sdnrow input { padding: 6px 8px; min-width: 0; }
.sdnrow input.bad { border-color: var(--bad); }
.sdnrow .msg { grid-column: 1 / -1; color: var(--warn); }
.sdnrow .msg:empty { display: none; }
/* Cabecera y navegación */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.top::before { content: ""; display: block; height: 5px; background: var(--tira); }
.top h1 img.mini { height: 28px; width: auto; margin-right: 4px; }
.marca { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 28px; color: var(--muted); font-size: .8rem; }
.marca img { height: 34px; width: auto; opacity: .9; }
.marca span { text-align: center; line-height: 1.3; }
.marca small { display: block; font-size: .72rem; opacity: .85; }
.top-in {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; min-height: 52px;
}
.top h1 {
  flex: 1; margin: 0; font-size: 1.15rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
#top-actions { display: flex; gap: 6px; }
.top .back {
  text-decoration: none; font-size: 1.8rem; line-height: 1;
  padding: 0 8px 4px 0; color: var(--brand);
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 200px; text-align: center; text-decoration: none;
  color: var(--muted); font-size: .78rem; padding: 8px 0 10px;
}
.tabs a .ico { display: block; font-size: 1.3rem; line-height: 1.4; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--brand); font-weight: 600; }
.tabs a.on .ico { filter: none; opacity: 1; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* Piezas comunes */
h2.section { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: var(--brand); margin: 24px 4px 8px; }
.card {
  display: block; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 14px 16px; margin-bottom: 10px; color: inherit; text-decoration: none;
}
a.card:active { background: var(--brand-soft); }
.card-title { font-weight: 600; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .82rem; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: .92rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--brand-soft); color: var(--brand); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

.btn {
  appearance: none; border: 1px solid transparent; background: var(--btn); color: var(--btn-ink);
  border-radius: 10px; padding: 10px 14px; font: inherit; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { background: var(--btn-bad); color: var(--btn-bad-ink); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn {
  appearance: none; border: 0; background: none; color: var(--muted); font-size: 1.1rem;
  min-width: 36px; min-height: 36px; border-radius: 8px; cursor: pointer;
}
.iconbtn:active { background: var(--brand-soft); }

label.field { display: block; margin-bottom: 14px; }
label.field > span:not(.pass) { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=email], input[type=password], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 44px; }
textarea.code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); }
/* Ventanas */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 24, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal .sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal h3 { margin: 0 0 14px; font-size: 1.1rem; }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal .sheet { border-radius: 16px; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1b2233; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .92rem;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100% - 32px);
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#yo { flex: none; display: flex; align-items: center; justify-content: center; margin-left: 8px; width: 36px; height: 36px; border-radius: 50%; color: var(--ink); background: var(--brand-soft); font-size: .85rem; font-weight: 700; text-decoration: none; }
#yo.on { background: var(--brand); color: var(--brand-ink); }
body.noauth #yo { display: none; }
.top h1 span small { display: block; font-size: .78rem; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.top h1 img.mini { height: 30px; width: 30px; }

/* Ficha del equipo */
.estado { border-radius: var(--radius); padding: 18px 18px 16px; text-align: center; }
.estado b { display: block; font-size: 2rem; line-height: 1.15; letter-spacing: -.01em; }
.estado span { display: block; margin-top: 4px; font-size: .95rem; }
.estado.libre { background: var(--ok-soft); color: var(--ok); }
.estado.ocupado { background: var(--bad-soft); color: var(--bad); }
.datos { margin-top: 12px; padding: 4px 16px; }
.dato { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.dato:last-child { border-bottom: 0; }
.dato > span { color: var(--muted); }
.dato > b { text-align: right; font-weight: 600; }
.averia { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.averia:last-child { border-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chiptog input { position: absolute; opacity: 0; pointer-events: none; }
.chiptog span { display: inline-block; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: .92rem; cursor: pointer; }
.chiptog input:checked + span { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.chiptog input:disabled + span { opacity: .6; cursor: default; }
.chiptog input:focus-visible + span { outline: 2px solid var(--brand); }
img.etiqueta { display: block; width: 100%; max-width: 360px; margin: 0 auto 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.hist { padding: 10px 14px; }

/* Panel del taller */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats .card { margin: 0; text-align: center; padding: 10px; }
.stats b { display: block; font-size: 1.5rem; }
.filtros { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0 12px; padding-bottom: 2px; }
.filtros button { flex: none; appearance: none; font: inherit; font-size: .85rem; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.filtros button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.tile { position: relative; display: block; text-decoration: none; border-radius: 12px; padding: 10px 6px 8px; text-align: center; border: 1px solid transparent; }
.tile b { display: block; font-size: 1.5rem; line-height: 1.1; }
.tile span { display: block; font-size: .74rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.libre { background: var(--ok-soft); color: var(--ok); }
.tile.ocupado { background: var(--bad-soft); color: var(--bad); }
.tile .llave { position: absolute; top: 4px; right: 6px; font-style: normal; color: var(--warn); font-size: .85rem; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.legend i.libre { background: var(--ok); }
.legend i.ocupado { background: var(--bad); }

/* Grupos */
.apagado { opacity: .6; }
.students { list-style: none; padding: 0; margin: 0; }
.students li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.students li:last-child { border-bottom: 0; }
.students li span { flex: 1; }
.students .num { min-width: 28px; text-align: right; color: var(--brand); font-variant-numeric: tabular-nums; }
.checks { max-height: 50vh; overflow: auto; }
.checks .check { margin-bottom: 8px; }

/* El ❓ es rojo: al pasarlo a gris queda oscuro y en modo oscuro no se ve. Se aclara invirtiéndolo. */
@media (prefers-color-scheme: dark) {
  .tabs a .ico.ayuda { filter: grayscale(1) invert(1); opacity: .6; }
}
.legend .llave { color: var(--warn); }
