/* Tokens, tipografía, controles y el plano. Compartido por el panel y la página pública. */

:root {
  --f-texto: Barlow, system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-cond: "Barlow Condensed", "Arial Narrow", Barlow, sans-serif;
}

:root, :root[data-tema="claro"] {
  --fondo: #f2f2f0;
  --superficie: #ffffff;
  --superficie-2: #f0efec;
  --linea: #dbd8d2;
  --texto: #1d1a17;
  --texto-2: #655e56;
  --acento: #c48a0e;
  --acento-suave: #f6ead0;
  --btn-pri: #1d1a17;
  --btn-pri-texto: #ffffff;
  --peligro: #b83a26;
  --ok: #2f7d57;

  --p-fondo: #ffffff;
  --p-zona: #f7f6f4;
  --p-zona-borde: #d9d5ce;
  --p-zona-texto: #8a837b;
  --p-pared: #3a3531;
  --p-tarima: #151210;
  --p-tarima-texto: #ffffff;
  --p-barra: #ffffff;
  --p-barra-borde: #3a3531;
  --p-bloque: #9c968f;
  --p-bloque-texto: #ffffff;
  --p-mesa: #57514b;
  --p-mesa-texto: #ffffff;
  --p-silla: #d2cec8;
  --reservada: #6a4fd6;
  --sentada: #c4412c;
  --elegida: #d69a12;
  --elegida-texto: #1d1a17;
  color-scheme: light;
}

:root[data-tema="oscuro"] {
  --fondo: #1a1511;
  --superficie: #231d18;
  --superficie-2: #2c251f;
  --linea: #3d342c;
  --texto: #f3eadb;
  --texto-2: #b2a291;
  --acento: #e6b54d;
  --acento-suave: #3a2f1c;
  --btn-pri: #e6b54d;
  --btn-pri-texto: #1a1511;
  --peligro: #ec7a64;
  --ok: #6fbf92;

  --p-fondo: #1e1814;
  --p-zona: #221c17;
  --p-zona-borde: #3b3129;
  --p-zona-texto: #8f7f6e;
  --p-pared: #75665a;
  --p-tarima: #0c0907;
  --p-tarima-texto: #e9dfcf;
  --p-barra: #2a231d;
  --p-barra-borde: #8a7968;
  --p-bloque: #3a3029;
  --p-bloque-texto: #b9a996;
  --p-mesa: #4b3f35;
  --p-mesa-texto: #f6eee2;
  --p-silla: #5c4e42;
  --reservada: #8b78e6;
  --sentada: #d8583f;
  --elegida: #e6b54d;
  --elegida-texto: #1a1511;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 400 15px/1.45 var(--f-texto);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .cond { font-family: var(--f-cond); font-weight: 600; letter-spacing: 0.005em; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }
a { color: inherit; }
.enlace { color: var(--acento); font-weight: 500; }
.sub { color: var(--texto-2); font-size: 14px; }
.h2 { font-size: 22px; }
.h3 { font-size: 17px; margin: 18px 0 8px; color: var(--texto-2); }

:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--linea); background: var(--superficie-2); color: var(--texto);
  font: 500 15px/1 var(--f-texto); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--texto-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primario { background: var(--btn-pri); color: var(--btn-pri-texto); border-color: var(--btn-pri); font-weight: 600; }
.btn-primario:hover { filter: brightness(1.08); border-color: var(--btn-pri); }
.btn-chico { min-height: 32px; padding: 0 11px; font-size: 14px; }
.btn-ancho { width: 100%; min-height: 48px; font-size: 17px; }
.btn-texto { background: none; border-color: transparent; color: var(--acento); padding: 0 6px; }
.btn-peligro { background: var(--peligro); border-color: var(--peligro); color: #fff; }
.btn-peligro-suave { color: var(--peligro); }
.btn-alerta { border-color: var(--acento); color: var(--acento); }
.btn-icono {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 8px;
  border: 1px solid transparent; background: none; color: var(--texto); cursor: pointer;
}
.btn-icono:hover { background: var(--superficie-2); }
.fila-btn { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.fila-btn.fin { justify-content: flex-end; }

/* ---------- campos ---------- */
.campo { display: flex; flex-direction: column; gap: 5px; min-width: 0; margin-bottom: 12px; flex: 1; }
.campo-etq { font-size: 13px; font-weight: 600; color: var(--texto-2); }
.campo-ayuda { font-size: 12.5px; color: var(--texto-2); }
input, select, textarea {
  font: inherit; color: var(--texto); background: var(--superficie); border: 1px solid var(--linea);
  border-radius: 8px; min-height: 42px; padding: 8px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--acento); }
.check { display: flex; align-items: center; gap: 9px; margin: 6px 0 12px; cursor: pointer; }
.fila-campos { display: flex; gap: 12px; flex-wrap: wrap; }
.fila-campos > .campo { flex: 1 1 140px; }
.fila-mini { display: flex; gap: 8px; }
.fila-mini input { max-width: 90px; }
.form-error { color: var(--peligro); font-weight: 500; min-height: 1em; margin: 4px 0; }
.form-error:empty { display: none; }
.aviso-linea { background: var(--acento-suave); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin-bottom: 10px; }

.contador { display: inline-flex; align-items: center; border: 1px solid var(--linea); border-radius: 8px; background: var(--superficie); height: 42px; }
.contador-btn { width: 42px; height: 100%; border: 0; background: none; color: var(--texto); font-size: 20px; cursor: pointer; border-radius: 8px; }
.contador-btn:disabled { opacity: 0.3; cursor: default; }
.contador-num { min-width: 34px; text-align: center; font: 600 20px/1 var(--f-cond); }

.chip-btn {
  display: inline-flex; align-items: baseline; gap: 2px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--linea); background: var(--superficie); color: var(--texto); cursor: pointer; font: 500 14px/1 var(--f-texto);
}
.chip-btn .chip-sub { color: var(--texto-2); font-size: 12.5px; }
.chip-btn[aria-pressed="true"], .chip-btn.activo { background: var(--elegida); border-color: var(--elegida); color: var(--elegida-texto); }
.chip-btn[aria-pressed="true"] .chip-sub, .chip-btn.activo .chip-sub { color: inherit; }

/* ---------- diálogos ---------- */
.dlg {
  border: 1px solid var(--linea); border-radius: 14px; padding: 0; background: var(--superficie); color: var(--texto);
  width: min(560px, calc(100vw - 24px)); max-height: min(88dvh, 900px);
}
.dlg-ancho { width: min(1020px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 8, 6, 0.55); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 6px 22px; }
.dlg-cab h2 { font-size: 26px; line-height: 1.1; }
.dlg-cuerpo { padding: 6px 22px 22px; overflow: auto; }
@media (prefers-reduced-motion: no-preference) {
  .dlg[open] { animation: aparece 160ms ease-out; }
}
@keyframes aparece { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- avisos flotantes ---------- */
.toasts { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(520px, calc(100vw - 24px)); }
.toast {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: var(--texto); color: var(--fondo); padding: 12px 16px; border-radius: 10px; font-weight: 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28); transition: opacity 0.3s;
}
.toast-error { background: var(--peligro); color: #fff; }
.toast-alerta { background: var(--acento); color: #1a1511; }
.toast-nuevo { background: var(--reservada); color: #fff; }
.toast.saliendo { opacity: 0; }
.toast-accion { background: none; border: 0; color: inherit; font: 600 15px var(--f-texto); text-decoration: underline; cursor: pointer; padding: 4px; }

/* ---------- logo por tema ---------- */
.logo { display: block; height: 34px; width: auto; }
:root[data-tema="oscuro"] .logo-sobre-claro { display: none; }
:root[data-tema="claro"] .logo-sobre-oscuro { display: none; }

/* ---------- plano ---------- */
.plano { display: block; width: 100%; height: 100%; background: var(--p-fondo); border-radius: 10px; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.zona rect { fill: var(--p-zona); stroke: var(--p-zona-borde); stroke-width: 1; stroke-dasharray: 4 4; }
.zona-etq { fill: var(--p-zona-texto); font: 600 13px var(--f-cond); letter-spacing: 0.04em; }
.elem-pared rect { fill: var(--p-pared); }
.elem-tarima rect { fill: var(--p-tarima); }
.elem-tarima .elem-etq { fill: var(--p-tarima-texto); }
.elem-barra rect { fill: var(--p-barra); stroke: var(--p-barra-borde); stroke-width: 1.5; }
.elem-barra .elem-etq { fill: var(--texto); }
.elem-bloque rect { fill: var(--p-bloque); }
.elem-bloque .elem-etq { fill: var(--p-bloque-texto); }
.elem-etq { font-family: var(--f-cond); font-weight: 700; letter-spacing: 0.08em; }

.mesa { --c: var(--p-mesa); }
.silla { fill: var(--p-silla); }
.silla.llena { fill: var(--c); }
.tablero { fill: var(--p-mesa); stroke: transparent; stroke-width: 3; }
.mesa-cod { fill: var(--p-mesa-texto); font-family: var(--f-cond); font-weight: 700; pointer-events: none; }
.mesa-l2 { fill: var(--p-mesa-texto); font-family: var(--f-texto); font-weight: 600; opacity: 0.92; pointer-events: none; }
.mesa .toque { fill: transparent; }
.mesa.tocable { cursor: pointer; }
.mesa.tocable:hover .tablero { stroke: var(--texto-2); }
.mesa:focus { outline: none; }
.mesa:focus-visible .tablero { stroke: var(--acento); stroke-width: 4; }

/* panel */
.mesa.est-proxima .tablero { stroke: var(--acento); stroke-width: 3; }
.mesa.est-proxima .mesa-l2 { fill: var(--acento); }
.mesa.est-reservada { --c: var(--reservada); }
.mesa.est-reservada .tablero { fill: var(--reservada); }
.mesa.est-sentada { --c: var(--sentada); }
.mesa.est-sentada .tablero { fill: var(--sentada); }
.mesa.atrasada .tablero { stroke: var(--sentada); stroke-dasharray: 5 3; stroke-width: 3; }
:root[data-tema="oscuro"] .mesa.atrasada .tablero { stroke: #ffb09f; }
.mesa.resaltada .tablero { stroke: var(--texto); stroke-width: 4; stroke-dasharray: none; }
.mesa.no-online .tablero { stroke: var(--p-zona-texto); stroke-dasharray: 3 3; stroke-width: 2; }

/* elegir mesa (formulario del panel y página pública) */
.mesa.est-ocupada { --c: var(--reservada); }
.mesa.est-ocupada .tablero { opacity: 0.4; }
.mesa.est-ocupada .mesa-cod { opacity: 0.7; }
.mesa.est-sugerida .tablero { stroke: var(--acento); stroke-width: 3; stroke-dasharray: 5 3; }
.mesa.est-elegida { --c: var(--elegida); }
.mesa.est-elegida .tablero { fill: var(--elegida); stroke: var(--elegida); }
.mesa.est-elegida .mesa-cod, .mesa.est-elegida .mesa-l2 { fill: var(--elegida-texto); }
.mesa.est-elegida.choque { --c: var(--sentada); }
.mesa.est-elegida.choque .tablero { fill: var(--sentada); stroke: var(--sentada); }
.mesa.est-apagada { opacity: 0.28; }
.mesa.est-disponible.tocable:hover .tablero { stroke: var(--elegida); }

/* selección del editor */
.sel-marco { fill: none; stroke: var(--acento); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
.sel-tirador { fill: var(--acento); stroke: var(--p-fondo); stroke-width: 2; cursor: nwse-resize; }
body.modo-editor [data-kind] { cursor: move; }

/* leyenda */
.leyenda { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 0; margin: 10px 2px 0; font-size: 13.5px; color: var(--texto-2); }
.leyenda li { display: inline-flex; align-items: center; gap: 7px; }
.ley { width: 16px; height: 16px; border-radius: 4px; display: inline-block; background: var(--p-mesa); }
.ley-proxima { box-shadow: inset 0 0 0 3px var(--acento); }
.ley-reservada { background: var(--reservada); }
.ley-sentada { background: var(--sentada); }
.ley-atrasada { background: var(--reservada); outline: 2px dashed var(--sentada); outline-offset: 1px; }
.ley-pub-libre { background: var(--p-mesa); }
.ley-pub-ocupada { background: var(--reservada); border-radius: 50%; width: 12px; height: 12px; }
.ley-pub-apagada { background: var(--p-mesa); opacity: 0.28; }
.ley-pub-elegida { background: var(--elegida); }

.trampa { position: absolute !important; left: -9999px; width: 1px; height: 1px; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
