:root {
  --navy: #1f4a6e;
  --navy-d: #163754;
  --sky: #64adf2;
  --sky-l: #e8f3fd;
  --green: #2db742;
  --red: #cc0000;
  --bg: #f4f8fc;
  --card: #fff;
  --line: #e3ebf3;
  --muted: #6b7f92;
  --radius: 16px;
  --h: 'Montserrat', system-ui, sans-serif;
  --b: 'Open Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body { font-family: var(--b); background: var(--bg); color: var(--navy); -webkit-font-smoothing: antialiased; }
button { font: inherit; cursor: pointer; border: 0; }
h1, h2, h3 { font-family: var(--h); }
img.logo { height: 44px; display: block; mix-blend-mode: multiply; }

/* ---------- Botones / formularios ---------- */
.btn { background: var(--sky); color: #fff; font-weight: 700; padding: 12px 20px; border-radius: 12px; transition: transform .1s, filter .15s; }
.btn:hover { filter: brightness(1.06); } .btn:active { transform: scale(.97); }
.btn.navy { background: var(--navy); } .btn.green { background: var(--green); } .btn.red { background: var(--red); }
.btn.ghost { background: var(--sky-l); color: var(--navy); } .btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.big { font-size: 20px; padding: 18px 28px; width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
input, select { font: inherit; color: var(--navy); background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--sky); }
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 6px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 2px 10px rgba(31, 74, 110, .05); }
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 10px; border-radius: 10px; color: #fff; font: 800 15px var(--h); }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- Barra superior (personal) ---------- */
.topbar { display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .title { font: 800 18px var(--h); flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); display: inline-block; margin-right: 6px; }
.dot.on { background: var(--green); }
.conn { font-size: 12px; color: var(--muted); }

/* ---------- Selector de rol ---------- */
.picker { max-width: 760px; margin: 0 auto; padding: 40px 20px; text-align: center; }
.picker img.logo { height: 64px; margin: 0 auto 8px; }
.picker h1 { font-size: 26px; margin: 18px 0 6px; } .picker p { color: var(--muted); margin-bottom: 24px; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.role { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 18px 10px; font: 700 15px var(--h); color: var(--navy); transition: .15s; }
.role:hover { border-color: var(--sky); transform: translateY(-2px); }
.role.main { grid-column: 1 / -1; background: var(--navy); color: #fff; border-color: var(--navy); display: flex; justify-content: center; gap: 10px; }
.role small { display: block; font: 400 12px var(--b); opacity: .75; margin-top: 4px; }

/* ---------- PIN ---------- */
.pinbox { max-width: 280px; margin: 0 auto; display: grid; gap: 12px; }
.pin-input { text-align: center; font: 800 28px var(--h); letter-spacing: .4em; -webkit-text-security: disc; padding: 12px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key { background: #fff; border: 2px solid var(--line); border-radius: 14px; height: 58px; font: 800 22px var(--h); color: var(--navy); touch-action: manipulation; }
.key:active { background: var(--sky-l); }
.key.ok { background: var(--sky); border-color: var(--sky); color: #fff; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(22, 55, 84, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 20px; padding: 24px; width: min(560px, 100%); max-height: 92vh; overflow: auto; }
.modal h2 { margin-bottom: 14px; }
.row { display: grid; gap: 14px; margin-bottom: 16px; }
.row.two { grid-template-columns: 1fr 1fr; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 22px; height: 22px; accent-color: var(--sky); }
input[type=range] { padding: 0; accent-color: var(--sky); border: 0; }

/* ---------- Secretaria ---------- */
.sec { display: grid; grid-template-columns: 340px 1fr; gap: 20px; padding: 20px; align-items: start; }
@media (max-width: 900px) { .sec { grid-template-columns: 1fr; } }
.sec form { display: grid; gap: 14px; position: sticky; top: 80px; }
.cons-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.cons { border-top: 6px solid var(--c); }
.cons header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.cons header h3 { font-size: 15px; flex: 1; }
.person { padding: 10px 0; border-top: 1px dashed var(--line); font-size: 14px; }
.person .p-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.person .n { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.person .p-acts { display: grid; grid-template-columns: minmax(0, 1fr) 36px; gap: 6px; }
.person .mv { height: 36px; padding: 0 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--sky-l); color: var(--navy); }
.person .rm { height: 36px; border-radius: 9px; background: #fdecec; color: var(--red); font-weight: 800; }
.person .rm:hover { background: var(--red); color: #fff; }
.person.llamando { background: #f0fbf2; border: 1px solid #bfe8c7; border-radius: 12px; padding: 10px; margin: 6px 0; }
.person.llamando .n { color: #1c8a2f; }
.tag { font-size: 11px; font-weight: 700; background: #e3f7e7; color: #1c8a2f; padding: 3px 8px; border-radius: 99px; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.mini { background: var(--sky-l); color: var(--navy); border-radius: 8px; width: 30px; height: 30px; font-weight: 700; }
.mini:hover { background: var(--sky); color: #fff; }

/* ---------- Consultorio (profesional) ---------- */
.pro { max-width: 640px; margin: 0 auto; padding: 18px; display: grid; gap: 16px; }
.now { background: var(--navy); color: #fff; border: 0; text-align: center; padding: 26px 18px; }
.now .lbl { font: 700 12px var(--h); letter-spacing: .14em; opacity: .75; text-transform: uppercase; }
.now .nm { font: 800 clamp(26px, 6vw, 38px) var(--h); margin: 8px 0 16px; }
.now .acts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.queue-item { display: flex; align-items: center; gap: 10px; padding: 14px 0; border-top: 1px solid var(--line); }
.queue-item .pos { width: 30px; height: 30px; border-radius: 50%; background: var(--sky-l); display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.queue-item .n { flex: 1; font: 700 17px var(--h); }
.queue-item .t { font-size: 12px; color: var(--muted); }

/* ---------- TV pública ---------- */
.tv { height: 100vh; display: grid; grid-template-rows: auto 1fr; overflow: hidden; background: var(--bg); cursor: none; }
.tv header { display: flex; align-items: center; justify-content: space-between; padding: 14px 3vw; background: #fff; border-bottom: 4px solid var(--sky); }
.tv header img.logo { height: 6vh; }
.hdr-right { display: flex; align-items: center; gap: 2.6vw; }
.weather { display: flex; align-items: center; gap: .8vw; padding: .8vh 1.4vw; background: var(--sky-l); border-radius: 18px; color: var(--navy); }
.weather:empty { display: none; }
.weather .w-ic { font-size: 4.2vh; line-height: 1; }
.weather .w-t { font: 800 4vh var(--h); }
.weather .w-h { display: grid; font: 700 2.2vh var(--h); line-height: 1.15; margin-left: .4vw; }
.weather .w-h small { font: 400 1.6vh var(--b); color: var(--muted); }
.tv .clock { font: 700 3vh var(--h); color: var(--navy); text-align: right; line-height: 1.2; } .tv .clock small { display: block; font: 400 1.9vh var(--b); color: var(--muted); }
.tv main { display: grid; grid-template-columns: 1fr; gap: 2vw; padding: 2.4vh 3vw; min-height: 0; }
.tv.with-side main { grid-template-columns: 1.55fr 1fr; }
.stage { position: relative; background: linear-gradient(145deg, var(--navy), var(--navy-d)); border-radius: 28px; color: #fff; display: grid; place-content: center; text-align: center; padding: 3vh 3vw; overflow: hidden; min-height: 0; }
.stage::before, .stage::after { content: ''; position: absolute; border-radius: 50%; background: radial-gradient(circle, rgba(100, 173, 242, .28), transparent 70%); }
.stage::before { width: 60vh; height: 60vh; right: -15vh; top: -20vh; } .stage::after { width: 45vh; height: 45vh; left: -12vh; bottom: -18vh; }
.stage > .stc { position: relative; text-align: center; max-width: 100%; }
.stage .fx { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.stage .lbl { font: 700 2.6vh var(--h); letter-spacing: .22em; text-transform: uppercase; color: var(--sky); }
.stage .name { font: 800 clamp(4.5vh, 5.6vw, 11vh) / 1.05 var(--h); margin: 2vh 0 2.5vh; overflow-wrap: anywhere; }
.stage .goto { font: 600 2.8vh var(--h); opacity: .9; }
.stage .num { display: inline-grid; place-items: center; margin-top: 1.6vh; padding: 1vh 4vw; border-radius: 22px; font: 800 clamp(8vh, 9vw, 19vh) / 1 var(--h); background: var(--c, var(--sky)); box-shadow: 0 1.5vh 5vh rgba(0, 0, 0, .35); }
.stage .conname { display: block; font: 600 3vh var(--h); margin-top: 1.4vh; opacity: .9; }
.stage.idle .name { font-size: clamp(6vh, 8.5vw, 15vh); margin-bottom: 1.5vh; }
.stage.idle .goto { font-size: 3.4vh; opacity: .9; }
.tip { display: inline-flex; align-items: center; gap: 1.4vw; margin-top: 5vh; max-width: 90%; padding: 2vh 2.4vw; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); border-radius: 22px; text-align: left; backdrop-filter: blur(4px); }
.tip-ic { font-size: 5vh; }
.tip-t { font: 600 2.9vh/1.35 var(--h); transition: opacity .45s, transform .45s; }
.tip-t.out { opacity: 0; transform: translateY(1vh); }
.stage.pulse .num { animation: pop 1s ease-out 3; }
.stage.enter .name, .stage.enter .goto { animation: rise .7s cubic-bezier(.2, .9, .3, 1.2) both; }
.stage.enter .num { animation: pop 1s ease-out 3, rise .7s .15s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes rise { from { opacity: 0; transform: translateY(5vh) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.08); } 100% { transform: scale(1); } }
.side { display: grid; grid-template-rows: auto 1fr; gap: 2vh; min-height: 0; }
.side.no-video { grid-template-rows: 1fr; }
.video-wrap { background: #000; border-radius: 22px; overflow: hidden; aspect-ratio: 16 / 9; position: relative; }
.video-wrap iframe { width: 100%; height: 100%; border: 0; }
.video-err { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 2vh; text-align: center; padding: 3vh; background: var(--navy); }
.recent { background: #fff; border: 1px solid var(--line); border-radius: 22px; padding: 2vh 1.6vw; overflow: hidden; min-height: 0; }
.recent h2 { font: 800 2.2vh var(--h); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 1vh; }
.recent .item { display: flex; align-items: center; gap: 1.2vw; padding: 1.5vh 0; border-top: 1px solid var(--line); font: 700 2.8vh var(--h); }
.recent .item .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent .item .pill { min-width: 6vh; height: 6vh; font-size: 3vh; border-radius: 14px; }
.sound-gate { position: fixed; inset: 0; z-index: 60; background: rgba(22, 55, 84, .93); color: #fff; display: grid; place-content: center; gap: 2vh; text-align: center; cursor: pointer; }
.sound-gate h2 { font-size: 5vh; } .sound-gate .ic { font-size: 10vh; }

/* ---------- Fondo animado del cartel ---------- */
.aur { position: absolute; border-radius: 50%; filter: blur(46px); animation: breathe 38s ease-in-out infinite alternate; }
.aur.a1 { width: 70%; aspect-ratio: 1; left: -20%; top: -35%; background: radial-gradient(circle, rgba(100, 173, 242, .16), rgba(100, 173, 242, 0) 70%); }
.aur.a2 { width: 60%; aspect-ratio: 1; right: -22%; bottom: -40%; background: radial-gradient(circle, rgba(100, 173, 242, .12), rgba(100, 173, 242, 0) 70%); animation-delay: -19s; }
@keyframes breathe { 0% { transform: translate(0, 0) scale(1); opacity: .85; } 100% { transform: translate(3%, 2%) scale(1.08); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .aur { animation: none; } }

/* ---------- Logo animado al llamar ---------- */
.tv header img.logo.wiggle { animation: wiggle 1.1s ease-in-out 2; transform-origin: 30% 50%; }
@keyframes wiggle { 0%, 100% { transform: none; } 20% { transform: scale(1.18) rotate(-4deg); } 45% { transform: scale(1.12) rotate(3deg); } 70% { transform: scale(1.06) rotate(-1.5deg); } }

/* ---------- Bienvenida ---------- */
.welcome { position: fixed; left: 50%; bottom: 5vh; transform: translate(-50%, 14vh); z-index: 40; display: flex; align-items: center; gap: 1.2vw; padding: 2vh 2.6vw; background: #fff; color: var(--navy); border: 3px solid var(--sky); border-radius: 99px; box-shadow: 0 1.5vh 5vh rgba(22, 55, 84, .3); font: 800 3.4vh var(--h); opacity: 0; transition: transform .55s cubic-bezier(.2, .9, .3, 1.15), opacity .45s; pointer-events: none; max-width: 92vw; }
.welcome.show { transform: translate(-50%, 0); opacity: 1; }
.welcome .w-emoji { font-size: 4.6vh; }

/* ---------- Estadísticas ---------- */
.modal.wide { width: min(940px, 100%); }
.stats-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stats-head h2 { margin: 0; }
.seg { display: inline-flex; background: var(--sky-l); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.seg button { background: transparent; color: var(--navy); font-weight: 700; padding: 8px 14px; border-radius: 9px; }
.seg button.on { background: var(--navy); color: #fff; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi b { display: block; font: 800 26px var(--h); color: var(--navy); }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; }
.modal h3 { font-size: 15px; margin: 22px 0 10px; }
.peak { font: 700 12px var(--b); background: #fff3d6; color: #9a6400; padding: 3px 9px; border-radius: 99px; margin-left: 8px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 18px; }
.bar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.bar i { width: 100%; max-width: 38px; background: var(--sky); border-radius: 8px 8px 3px 3px; display: block; }
.bar i.peak { background: var(--navy); padding: 0; margin: 0; }
.bar em { position: absolute; top: 0; font: 700 11px var(--b); font-style: normal; color: var(--navy); }
.bar span { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bars.days { height: 120px; } .bars.days .bar span { font-size: 9px; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stats-foot { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }

.range { display: flex; gap: 12px; flex-wrap: wrap; margin: -4px 0 16px; }
.range label { display: flex; align-items: center; gap: 8px; margin: 0; }
.range input { width: auto; padding: 8px 10px; }

/* ---------- Consultorio: clima, fecha, indicadores, saludo ---------- */
.topbar { flex-wrap: wrap; }
.pw { display: flex; align-items: center; gap: 8px; background: var(--sky-l); border-radius: 12px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.pw:empty { display: none; }
.pw .pw-ic { font-size: 20px; line-height: 1; }
.pw b { font: 800 17px var(--h); }
.pw .pw-h { color: var(--muted); font-weight: 600; }
.pc { text-align: right; line-height: 1.15; white-space: nowrap; }
.pc b { font: 800 17px var(--h); display: block; }
.pc small { color: var(--muted); font-size: 12px; display: block; }
.pc small::first-letter { text-transform: uppercase; }
.ind { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.ind > div { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 10px; text-align: center; }
.ind b { display: block; font: 800 22px var(--h); color: var(--navy); }
.ind span { font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 1.2; display: block; margin-top: 2px; }
@media (max-width: 520px) { .ind { grid-template-columns: repeat(2, 1fr); } .pc small { display: none; } }
.greet-toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 12px); z-index: 30; background: #fff; color: var(--navy); border: 2px solid var(--sky); border-radius: 99px; padding: 12px 22px; font: 700 15px var(--h); box-shadow: 0 8px 24px rgba(31, 74, 110, .18); opacity: 0; transition: opacity .5s, transform .5s; pointer-events: none; max-width: 92vw; text-align: center; }
.greet-toast.show { opacity: 1; transform: translate(-50%, 0); }
.pro .card > .queue-item:first-child { border-top: 0; padding-top: 4px; }
.pro .card > .queue-item:last-child { padding-bottom: 4px; }

/* ---------- TV en vertical (celular, tablet o televisor girado) ---------- */
.tv { height: 100dvh; }
@media (orientation: portrait) {
  .tv header { padding: 1.2vh 3vw; }
  .tv header img.logo { height: 4.4vh; }
  .hdr-right { gap: 2vw; }
  .weather { padding: .6vh 2.4vw; gap: 1.4vw; }
  .weather .w-ic { font-size: 3vh; } .weather .w-t { font-size: 3vh; } .weather .w-h { font-size: 1.7vh; margin-left: 0; } .weather .w-h small { font-size: 1.3vh; }
  .tv .clock { font-size: 2.6vh; } .tv .clock small { font-size: 1.5vh; }
  .tv main, .tv.with-side main { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1.35fr) minmax(0, 1fr); gap: 2vh; padding: 2vh 3vw; }
  .stage { border-radius: 22px; padding: 2vh 4vw; }
  .stage .lbl { font-size: 2vh; }
  .stage .name { font-size: clamp(4vh, 11vw, 9vh); }
  .stage.idle .name { font-size: clamp(5vh, 15vw, 11vh); }
  .stage .goto { font-size: 2.4vh; }
  .stage .num { font-size: clamp(8vh, 24vw, 15vh); padding: 1vh 10vw; }
  .stage .conname { font-size: 2.4vh; }
  .tip { margin-top: 3vh; padding: 1.6vh 4vw; gap: 3vw; }
  .tip-ic { font-size: 4vh; } .tip-t { font-size: 2.3vh; }
  .side { grid-template-rows: auto minmax(0, 1fr); gap: 1.6vh; }
  .recent { padding: 1.6vh 4vw; border-radius: 18px; }
  .recent h2 { font-size: 1.9vh; } .recent .item { font-size: 2.5vh; padding: 1.2vh 0; }
  .recent .item .pill { min-width: 5vh; height: 5vh; font-size: 2.6vh; }
  .welcome { font-size: 2.6vh; padding: 1.6vh 5vw; }
}
@media (max-width: 480px) { .tv .clock small { display: none; } }
.tv .clock { white-space: nowrap; }
