:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #15202b;
  --muted: #5b6b7b;
  --line: #dde3e9;
  --accent: #0b6e8a;
  --accent-ink: #ffffff;
  --ok: #157f3b;
  --ok-bg: #e5f5ea;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --danger: #b42318;
  --pref: #6b3fa0;
  --radius: 14px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.4; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5rem; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.btn {
  appearance: none; border: 0; border-radius: 10px; padding: .75rem 1.1rem;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.ok { background: var(--ok); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.big { font-size: 1.25rem; padding: 1rem 1.5rem; width: 100%; }
.btn.sm { padding: .4rem .7rem; font-size: .9rem; }

input[type=text], input[type=password], select {
  width: 100%; padding: .8rem .9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
input:focus-visible, .btn:focus-visible, .choice:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; min-height: 1.4em; margin: .5rem 0 0; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: #efe7f8; color: var(--pref); }
.badge.src { background: #eef2f5; color: var(--muted); }

/* ---------- Paciente (mobile first) ---------- */
.patient { max-width: 480px; margin: 0 auto; padding: 1.25rem 1rem 3rem; font-size: 1.1rem; }
.patient header { text-align: center; margin: .5rem 0 1.25rem; }
.patient header .center { font-weight: 700; font-size: 1.3rem; }
.patient label.field { display: block; font-weight: 600; margin: 1rem 0 .4rem; }
.patient input#rut { font-size: 1.5rem; letter-spacing: .03em; text-align: center; }
.choices { display: grid; gap: .6rem; }
.choice { display: flex; align-items: center; gap: .75rem; padding: 1rem; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; font-weight: 600; }
.choice input { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.check { display: flex; gap: .75rem; align-items: flex-start; margin: 1.25rem 0; font-size: 1rem; }
.check input { width: 1.3rem; height: 1.3rem; margin-top: .15rem; flex: none; accent-color: var(--pref); }
.privacy { font-size: .85rem; text-align: center; margin-top: 1rem; }

.ticket { text-align: center; }
.ticket .code { font-size: clamp(4rem, 22vw, 6.5rem); font-weight: 800; letter-spacing: .02em; line-height: 1; margin: .5rem 0; font-variant-numeric: tabular-nums; }
.ticket .status { border-radius: var(--radius); padding: 1.1rem; margin: 1.25rem 0; font-size: 1.2rem; }
.ticket .status.waiting { background: #e8f2f6; }
.ticket .status.called { background: var(--ok-bg); color: var(--ok); font-size: 1.5rem; font-weight: 700; animation: pulse 1.2s ease-in-out infinite; }
.ticket .status.closed { background: #eef2f5; }
.ticket .status.warn { background: var(--warn-bg); color: var(--warn); }
.ticket .ahead { font-size: 3rem; font-weight: 800; display: block; }
@keyframes pulse { 50% { transform: scale(1.02); } }

/* ---------- Mesón ---------- */
.staff { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.staff .topbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.staff .topbar .who { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { display: inline-flex; gap: .35rem; align-items: center; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; font-size: .9rem; }
.chip:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); } }
.list { display: grid; gap: .5rem; margin: .75rem 0 0; padding: 0; list-style: none; }
.row { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; }
.row.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.row .code { font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; min-width: 4.5ch; }
.row .meta { flex: 1; min-width: 10rem; }
.row .actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .9rem; }
.manual { display: grid; gap: .6rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .manual { grid-template-columns: 1.2fr 1fr auto auto; align-items: center; } }
.login { max-width: 380px; margin: 10vh auto; }
.login label { display: block; font-weight: 600; margin: 1rem 0 .4rem; }

/* ---------- Pantalla ---------- */
.screen { --s-bg: #0d1b24; --s-panel: #132834; --s-text: #f2f7fa; --s-muted: #8fa8b8; --s-hi: #ffd166;
  background: var(--s-bg); color: var(--s-text); min-height: 100vh; margin: 0; overflow: hidden;
  display: grid; grid-template-rows: auto 1fr auto auto; padding: 2vh 2.5vw 1vh; gap: 2vh; font-size: 2vh; }
.screen header { display: flex; justify-content: space-between; align-items: baseline; font-size: 3vh; }
.screen header .clock { font-variant-numeric: tabular-nums; font-weight: 700; }
.screen main { display: grid; grid-template-columns: 1.6fr 1fr; gap: 2vw; min-height: 0; }
.screen .panel { background: var(--s-panel); border-radius: 2vh; padding: 3vh 2vw; min-height: 0; overflow: hidden; }
.screen h2 { color: var(--s-muted); font-size: 2.6vh; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 2vh; }
.screen .current { text-align: center; padding: 2vh 0 3vh; border-bottom: 1px solid #ffffff1a; margin-bottom: 2vh; }
.screen .current .code { min-height: 1em; font-size: 20vh; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.screen .current .where { font-size: 6vh; font-weight: 700; color: var(--s-hi); }
.screen .current.flash { animation: flash 1s ease-in-out 4; }
@keyframes flash { 50% { background: #ffd16633; border-radius: 2vh; } }
.screen .prev { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5vh 2vw; font-size: 4.5vh; }
.screen .prev div { white-space: nowrap; display: flex; justify-content: space-between; gap: 1vw; }
.screen .prev .where { color: var(--s-muted); }
.screen .queue { display: grid; gap: 2.5vh; }
.screen .queue .q h3 { font-size: 3vh; display: flex; justify-content: space-between; }
.screen .queue .q h3 span { color: var(--s-muted); font-weight: 500; }
.screen .queue .q .next { display: flex; flex-wrap: wrap; gap: .5vh 1.5vw; font-size: 5vh; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.screen .queue .q .next .first { color: var(--s-hi); }
.screen footer { display: flex; align-items: center; gap: 2vw; font-size: 2.8vh; }
.screen footer .qr { background: #fff; padding: .8vh; border-radius: 1vh; width: 13vh; height: 13vh; }
.screen footer .qr svg { width: 100%; height: 100%; display: block; }
.overlay { position: fixed; inset: 0; background: #000c; color: #fff; display: grid; place-items: center; font-size: 4vh; cursor: pointer; text-align: center; padding: 2rem; }

/* ---------- Navegación demo ---------- */
.demo-nav { display: flex; flex-wrap: wrap; gap: .4rem .6rem; justify-content: center; align-items: center; margin-top: 2rem; padding: .9rem 1rem; border-top: 1px dashed var(--line); font-size: .9rem; color: var(--muted); }
.demo-nav a { font-weight: 600; text-decoration: none; padding: .25rem .6rem; border-radius: 6px; }
.demo-nav a:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.demo-nav a[aria-current=page] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); }
.screen .demo-nav { margin: 0; padding: .8vh 0 0; font-size: 1.8vh; border-top-color: #ffffff22; color: var(--s-muted); }
.screen .demo-nav a { color: var(--s-text); }
.screen .demo-nav a[aria-current=page], .screen .demo-nav a:hover { background: #ffffff1a; }

/* ---------- QR imprimible ---------- */
.poster { max-width: 720px; margin: 2rem auto; text-align: center; padding: 1rem; }
.poster h1 { font-size: 2.6rem; }
.poster .qr svg { width: min(80vw, 420px); height: auto; }
.poster .steps { font-size: 1.4rem; margin: 1.5rem auto; max-width: 30ch; }
@media print { .no-print { display: none; } body { background: #fff; } }
