/* Panel Auto Véndemelo — estilos. Pensado para 34" y 49" (1440 px de alto). */
:root {
  --bg: #0e1318;
  --panel: #161c23;
  --panel-2: #1c242d;
  --border: #27323d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --blue: #3B6FB5;
  --blue-2: #5b8fd6;
  --green: #43A856;
  --red: #e5484d;
  --amber: #f0b429;
  --header-h: 52px;
  --radius: 10px;
  --gap: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
body.scroll { overflow: auto; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }
a { color: var(--blue-2); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem .95rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-weight: 600; line-height: 1.1;
  transition: filter .12s, transform .05s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); }
.btn.good { background: var(--green); border-color: var(--green); color: #06130a; }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.warn { background: var(--amber); border-color: var(--amber); color: #1a1200; }
.btn.big { padding: .9rem 1.3rem; font-size: 1.1rem; border-radius: 10px; }
.btn.ghost { background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .85rem; font-weight: 500; }
.btn.icon { padding: .35rem .5rem; }

.input {
  width: 100%; padding: .6rem .75rem; border-radius: 8px; border: 1px solid var(--border);
  background: #0b0f13; color: var(--text); outline: none;
}
.input:focus { border-color: var(--blue-2); }
textarea.input { min-height: 320px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

/* ---------- autenticación ---------- */
#auth {
  position: fixed; inset: 0; display: grid; place-items: center; background:
    radial-gradient(1200px 600px at 20% -10%, #17365d 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 100%, #0f3b22 0%, transparent 60%), var(--bg);
}
.card {
  width: min(440px, 92vw); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.card .sub { margin: 0 0 18px; color: var(--muted); }
.card label { display: block; margin: 12px 0 6px; font-size: .85rem; color: var(--muted); }
.card .err { color: #ff8589; margin-top: 10px; min-height: 1.2em; font-size: .9rem; }
.card .actions { margin-top: 18px; display: flex; gap: 10px; justify-content: flex-end; }
#qr { background: #fff; padding: 12px; border-radius: 10px; width: fit-content; margin: 10px auto; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand .logo { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, var(--blue), var(--green)); display: grid; place-items: center; font-weight: 800; }

/* ---------- cabecera ---------- */
header#top {
  height: var(--header-h); display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: #11171d; border-bottom: 1px solid var(--border);
}
header#top .brand { margin: 0; }
header#top .brand b { font-size: 1.02rem; }
header#top .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .7rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: .9rem; font-weight: 600;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(67,168,86,.2); }
.dot.off { background: var(--red); box-shadow: 0 0 0 3px rgba(229,72,77,.2); }
.dot.warn { background: var(--amber); }
.dot.blink { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
#clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.05rem; }
header select { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .35rem .5rem; }

/* ---------- aviso de llamada ---------- */
#incoming {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--red); color: #fff;
  font-weight: 700; font-size: 1.1rem; animation: pulse-bg 1.2s infinite;
}
@keyframes pulse-bg { 50% { background: #b3262b; } }
#incoming .spacer { flex: 1; }

/* ---------- rejilla ---------- */
main#grid {
  height: calc(100vh - var(--header-h)); padding: var(--gap); display: grid; gap: var(--gap);
}
body.has-incoming main#grid { height: calc(100vh - var(--header-h) - 52px); }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
}
.panel > .ph {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border);
  background: #141a21; flex: none;
}
.panel > .ph h2 { margin: 0; font-size: .95rem; font-weight: 700; letter-spacing: .01em; }
.panel > .ph .spacer { flex: 1; }
.panel > .pb { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
.panel > .pb.nopad { padding: 0; }
.panel.max { position: fixed; inset: var(--header-h) 0 0 0; z-index: 40; border-radius: 0; }
body.has-incoming .panel.max { top: calc(var(--header-h) + 52px); }

/* áreas */
#p-cams { grid-area: cams; }
#left2 { grid-area: left2; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: var(--gap); min-height: 0; }
#p-center { grid-area: center; }
#p-call { grid-area: call; }
#p-events { grid-area: events; }

main#grid.L49 {
  grid-template-columns: 1280px minmax(0, 1fr) 1320px;
  grid-template-rows: 730px minmax(0, 1fr);
  grid-template-areas: "cams center call" "left2 center events";
}
main#grid.L34 {
  grid-template-columns: 1000px minmax(0, 1fr) 860px;
  grid-template-rows: 575px minmax(0, 1fr);
  grid-template-areas: "cams center call" "left2 center events";
}
main#grid.Lauto {
  grid-template-columns: minmax(0, 1fr) 460px;
  grid-template-rows: 500px 520px 760px;
  grid-template-areas: "cams call" "left2 events" "center center";
  height: auto;
}
main#grid.Lauto #left2 { grid-template-rows: 1fr 1fr; }
main#grid.Lleft {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 52%) minmax(0, 48%);
  grid-template-areas: "cams" "left2";
}
main#grid.Lright {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 460px minmax(0, 1fr) 360px;
  grid-template-areas: "call" "center" "events";
}

/* ---------- cámaras ---------- */
#cams-grid { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px; height: 100%; }
.cam { position: relative; background: #000; border-radius: 6px; overflow: hidden; display: grid; place-items: center; }
.cam video-stream { position: absolute; inset: 0; display: block; }
.cam video-stream video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.cam .label { position: absolute; left: 8px; bottom: 6px; font-size: .8rem; font-weight: 600; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; }
.cam .nosig { color: var(--muted); font-size: .9rem; text-align: center; }
.cam .tools { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.cam:hover .tools { opacity: 1; }
.cam.full { position: fixed; inset: var(--header-h) 0 0 0; z-index: 45; border-radius: 0; }

/* ---------- tótem ---------- */
.state-badge {
  display: inline-flex; align-items: center; gap: .6rem; padding: .5rem .9rem; border-radius: 10px;
  font-weight: 800; font-size: 1.15rem; background: var(--panel-2); border: 1px solid var(--border);
}
.state-badge.idle { border-color: var(--green); color: #9ee3a9; }
.state-badge.waiting { border-color: var(--red); color: #ff9a9d; background: rgba(229,72,77,.15); animation: pulse-border 1s infinite; }
.state-badge.call { border-color: var(--blue-2); color: #a9c9f5; }
.state-badge.end { border-color: var(--muted); }
.state-badge.offline { border-color: var(--red); color: #ff9a9d; }
@keyframes pulse-border { 50% { border-color: transparent; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9rem; margin: 10px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.talk { width: 100%; justify-content: center; }
.talk.on { background: var(--red); border-color: var(--red); animation: pulse-bg 1.2s infinite; }
.say { display: flex; gap: 8px; margin-top: 10px; }
.say .input { flex: 1; }

/* ---------- controles ---------- */
.dev { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.dev:last-child { border-bottom: 0; }
.dev .ic { font-size: 1.3rem; width: 1.8rem; text-align: center; }
.dev .nm { flex: 1; font-weight: 600; }
.dev .nm small { display: block; color: var(--muted); font-weight: 400; font-size: .8rem; }
.switch { position: relative; width: 52px; height: 28px; border-radius: 999px; background: #2b3540; border: 1px solid var(--border); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--green); } .switch.on::after { left: 27px; }
.switch:disabled { opacity: .35; cursor: not-allowed; }
.macros { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.macros .btn { padding: .8rem; font-size: 1rem; }

/* ---------- huecos ---------- */
.placeholder { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); }
.placeholder .big { font-size: 2.2rem; margin-bottom: 6px; }

/* ---------- centro (pestañas) ---------- */
.tabs { display: flex; gap: 4px; }
.tab { padding: .35rem .8rem; border-radius: 8px; border: 1px solid transparent; background: transparent; font-weight: 600; color: var(--muted); }
.tab.on { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.tabpane { height: 100%; }
.tabpane iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.rustdesk { height: 100%; display: grid; place-items: center; text-align: center; background:
  repeating-linear-gradient(45deg, #121820 0 14px, #141b23 14px 28px); }
.rustdesk .id { font-size: 2rem; font-weight: 800; letter-spacing: .08em; }

/* ---------- llamada ---------- */
#jitsi-call { height: 100%; }
#jitsi-call iframe { width: 100%; height: 100%; border: 0; }
.call-idle { height: 100%; display: grid; place-items: center; text-align: center; }
.call-idle .big { font-size: 1.4rem; font-weight: 800; }
.call-idle.ring .big { color: #ff9a9d; animation: blink 1s infinite; }

/* ---------- eventos ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: .2rem .6rem; border-radius: 999px; border: 1px solid var(--border); background: transparent; font-size: .8rem; color: var(--muted); }
.chip.on { background: var(--panel-2); color: var(--text); }
.ev { display: grid; grid-template-columns: 52px 26px 1fr auto; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #1f2830; align-items: start; font-size: .9rem; }
.ev .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.ev .ic { text-align: center; }
.ev .tt { font-weight: 600; }
.ev .dd { color: var(--muted); font-size: .82rem; }
.ev .ac { color: var(--muted); font-size: .78rem; }
.ev.alert .tt { color: #ff9a9d; }
.ev.warn .tt { color: #ffd37a; }

/* ---------- avisos ---------- */
#toasts { position: fixed; right: 14px; top: calc(var(--header-h) + 10px); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: 360px; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--blue-2); border-radius: 10px; padding: 10px 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); cursor: pointer; }
.toast.warn { border-left-color: var(--amber); }
.toast.alert { border-left-color: var(--red); }
.toast b { display: block; }
.toast span { color: var(--muted); font-size: .85rem; }

/* ---------- diálogos ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: min(720px, 94vw); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: .85rem; }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
