/* =====================================================================
   AppMenu.org — Sistema visual uniforme (Bootstrap 5 + tokens propios)
   El color de marca (--brand) se inyecta por página: global o del restaurante.
   ===================================================================== */
:root {
  --radius: .9rem;
  --radius-sm: .6rem;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --surface: #ffffff;
  --surface-2: #f5f6f8;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e5e7eb;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --topbar-h: 56px;
  --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--surface-2);
  --bs-border-radius: var(--radius-sm);
  --bs-border-radius-lg: var(--radius);
  --bs-link-color: var(--brand-dark);
  --bs-link-color-rgb: 0,0,0;
  --bs-link-hover-color: var(--brand);
  --bs-primary: var(--brand);
}

/* El fondo del documento usa el color de marca: así, cuando la página se
   dibuja bajo la barra de estado (viewport-fit=cover / PWA), el color
   "sube" hasta la hora y la batería. */
html { background: var(--brand); }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--surface-2);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  font-size: .95rem;
}
a { color: var(--brand-dark); }
a:hover { color: var(--brand); }

/* ---------- Barra superior que se extiende bajo la barra de estado ---------- */
.app-topbar {
  background: var(--brand);
  color: var(--brand-contrast);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.app-topbar a, .app-topbar .btn-icon { color: var(--brand-contrast); }
.topbar-row { min-height: var(--topbar-h); }
.topbar-title { max-width: 55vw; }
.site-topbar .navbar { --bs-navbar-color: rgba(255,255,255,.9); --bs-navbar-hover-color: #fff; padding-top: .55rem; padding-bottom: .55rem; }
.site-topbar .navbar-brand { color: var(--brand-contrast) !important; }
.brand-logo { height: 34px; width: auto; border-radius: 8px; background: #fff; padding: 2px; }
.btn-icon { width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: transparent; }
.btn-icon:hover { background: rgba(255, 255, 255, .15); }

/* ---------- Botones y componentes con color de marca ---------- */
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark); --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-color: var(--brand-contrast); --bs-btn-hover-color: var(--brand-contrast); --bs-btn-active-color: var(--brand-contrast);
}
.btn-outline-primary {
  --bs-btn-color: var(--brand-dark); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand); --bs-btn-hover-color: var(--brand-contrast);
  --bs-btn-active-bg: var(--brand-dark); --bs-btn-active-border-color: var(--brand-dark); --bs-btn-active-color: var(--brand-contrast);
}
.btn { border-radius: var(--radius-sm); font-weight: 500; }
.btn-lg { border-radius: var(--radius); }
.text-brand { color: var(--brand) !important; }
.bg-brand { background: var(--brand) !important; color: var(--brand-contrast) !important; }
.bg-brand-soft { background: var(--brand-soft) !important; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--brand) 25%, transparent); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.nav-pills .nav-link.active { background: var(--brand); color: var(--brand-contrast); }
.nav-pills .nav-link { color: var(--ink); }
.page-link { color: var(--brand-dark); }
.active > .page-link { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.form-label { font-weight: 500; font-size: .875rem; color: #374151; }
.form-text { font-size: .8rem; }

/* ---------- Tarjetas uniformes ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-header { background: transparent; border-bottom: 1px solid var(--line); font-weight: 600; padding: .85rem 1rem; }
.card-header:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.stat-card { padding: 1rem 1.1rem; height: 100%; }
.stat-card .stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.stat-card .stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); font-size: 1.2rem; }
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .65rem .75rem; vertical-align: middle; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; border-bottom-width: 1px; white-space: nowrap; }
.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-state i { font-size: 2.4rem; display: block; margin-bottom: .5rem; opacity: .6; }

/* ---------- Panel: sidebar + contenido ---------- */
.panel-wrap { display: flex; min-height: calc(100dvh - var(--topbar-h) - var(--safe-top)); }
.sidebar { width: 250px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line); }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: calc(var(--topbar-h) + var(--safe-top)); height: calc(100dvh - var(--topbar-h) - var(--safe-top)); overflow-y: auto; }
}
.sidebar .offcanvas-header { padding-top: calc(1rem + var(--safe-top)); }
.sidebar-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: .9rem .8rem .3rem; }
.sidebar-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .8rem; border-radius: .6rem; color: #374151; text-decoration: none; font-weight: 500; font-size: .9rem; }
.sidebar-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; color: var(--muted); }
.sidebar-link:hover { background: var(--surface-2); color: var(--ink); }
.sidebar-link.active { background: var(--brand-soft); color: var(--brand-dark); }
.sidebar-link.active i { color: var(--brand); }
.panel-main { flex: 1; min-width: 0; padding-bottom: calc(1rem + var(--safe-bottom)); }
.toast-safe { padding-bottom: calc(1rem + var(--safe-bottom)) !important; z-index: 1090; }

/* Indicador de conexión en vivo */
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(255,255,255,.35); display: inline-block; margin-right: .3rem; }
.conn-dot.off { background: #ef4444; animation: pulse 1s infinite; }
.conn-dot.sync { background: #facc15; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Sitio público ---------- */
.site-main { min-height: 60vh; }
.site-footer { background: #111827; color: #9ca3af; padding-bottom: var(--safe-bottom); }
.site-footer a { color: #e5e7eb; text-decoration: none; }
.hero {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: var(--brand-contrast);
  padding: 3.2rem 0 4.5rem;
}
.hero h1 { font-weight: 800; letter-spacing: -.02em; }
.hero-search { margin-top: -2.6rem; }
.rest-card { overflow: hidden; height: 100%; transition: transform .15s, box-shadow .15s; }
.rest-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.rest-card .cover { height: 140px; background: var(--brand-soft) center/cover no-repeat; position: relative; }
.rest-card .logo { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; background: #fff; border: 3px solid #fff; position: absolute; left: 1rem; bottom: -28px; box-shadow: var(--shadow-sm); }
.badge-soft { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .65rem; border-radius: 999px; background: var(--surface-2); font-size: .78rem; font-weight: 500; }
.stars { color: #f59e0b; letter-spacing: .05em; }

.auth-wrap { max-width: 460px; margin: 2rem auto; }
.auth-card { padding: 1.75rem; }

/* ---------- Mesas (mapa de estados) ---------- */
.mesa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .7rem; }
.mesa {
  border-radius: var(--radius); padding: .8rem .6rem; text-align: center; cursor: pointer;
  border: 2px solid transparent; background: var(--surface); box-shadow: var(--shadow-sm);
  min-height: 98px; display: flex; flex-direction: column; justify-content: center; gap: .15rem;
  transition: transform .1s; user-select: none;
}
.mesa:active { transform: scale(.97); }
.mesa .mesa-nombre { font-weight: 700; font-size: 1.05rem; }
.mesa .mesa-estado { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.mesa .mesa-info { font-size: .75rem; color: var(--muted); }
.est-libre { border-color: #d1fae5; } .est-libre .mesa-estado { color: #059669; }
.est-ocupada { border-color: #93c5fd; background: #eff6ff; } .est-ocupada .mesa-estado { color: #1d4ed8; }
.est-pedido_enviado { border-color: #fcd34d; background: #fffbeb; } .est-pedido_enviado .mesa-estado { color: #b45309; }
.est-en_preparacion { border-color: #fdba74; background: #fff7ed; } .est-en_preparacion .mesa-estado { color: #c2410c; }
.est-pedido_listo { border-color: #22c55e; background: #f0fdf4; animation: glow 1.4s infinite; } .est-pedido_listo .mesa-estado { color: #15803d; }
.est-pendiente_cobro { border-color: #c084fc; background: #faf5ff; } .est-pendiente_cobro .mesa-estado { color: #7e22ce; }
.est-reservada { border-color: #94a3b8; background: #f8fafc; } .est-reservada .mesa-estado { color: #475569; }
.est-inactiva { opacity: .5; } .est-inactiva .mesa-estado { color: #6b7280; }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(34,197,94,.25); } }
.leyenda .chip i { font-size: .6rem; }

/* ---------- Cocina ---------- */
.kds { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: .9rem; align-items: start; }
.comanda { border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); border-top: 6px solid #fcd34d; overflow: hidden; }
.comanda.st-nuevo { border-top-color: #ef4444; animation: nuevo 1.2s 3; }
.comanda.st-aceptado { border-top-color: #f59e0b; }
.comanda.st-en_preparacion { border-top-color: #f97316; }
.comanda.st-parcial { border-top-color: #84cc16; }
.comanda.st-listo { border-top-color: #22c55e; opacity: .85; }
.comanda.tarde .comanda-head .tiempo { background: #ef4444; color: #fff; }
@keyframes nuevo { 50% { box-shadow: 0 0 0 6px rgba(239,68,68,.35); } }
.comanda-head { padding: .7rem .9rem; display: flex; align-items: center; gap: .5rem; border-bottom: 1px dashed var(--line); }
.comanda-head .num { font-size: 1.25rem; font-weight: 800; }
.comanda-head .tiempo { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface-2); border-radius: 999px; padding: .15rem .6rem; font-size: .85rem; }
.comanda-item { padding: .55rem .9rem; display: flex; gap: .6rem; align-items: flex-start; border-bottom: 1px solid var(--surface-2); }
.comanda-item .qty { font-weight: 800; font-size: 1.1rem; min-width: 2rem; }
.comanda-item.it-listo, .comanda-item.it-entregado { opacity: .5; text-decoration: line-through; }
.comanda-item .obs { color: #b91c1c; font-weight: 600; font-size: .82rem; }
.comanda-item .adic { color: var(--muted); font-size: .82rem; }

/* ---------- Menú de pedido (mozo / cliente) ---------- */
.sticky-cart {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035;
  padding: .7rem 1rem calc(.7rem + var(--safe-bottom));
  background: var(--surface); box-shadow: 0 -4px 16px rgba(0,0,0,.1);
}
.qty-ctrl { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.qty-ctrl button { border: 0; background: var(--surface-2); width: 36px; height: 36px; font-size: 1.1rem; }
.qty-ctrl span { min-width: 2.2rem; text-align: center; font-weight: 700; }
.plato-row { display: flex; gap: .8rem; padding: .8rem; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.plato-row:hover { border-color: var(--brand); }
.plato-row img { width: 64px; height: 64px; object-fit: cover; border-radius: .6rem; }
.modal-content { border-radius: var(--radius); border: 0; }
.modal-fullscreen-sm-down .modal-header { padding-top: calc(1rem + var(--safe-top)); }
.modal-fullscreen-sm-down .modal-footer { padding-bottom: calc(.75rem + var(--safe-bottom)); }
.offcanvas-bottom { height: auto; max-height: 88vh; border-radius: var(--radius) var(--radius) 0 0; }
.offcanvas-bottom .offcanvas-body { padding-bottom: calc(1rem + var(--safe-bottom)); }
.offcanvas-end .offcanvas-header { padding-top: calc(1rem + var(--safe-top)); }

/* ---------- QR ---------- */
.qr-card { text-align: center; padding: 1rem; }
.qr-card svg, .qr-card img { width: 100%; max-width: 180px; height: auto; }
@media print {
  .app-topbar, .sidebar, .no-print, .site-footer { display: none !important; }
  body, html { background: #fff !important; }
  .print-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8mm; }
  .print-sheet .qr-print { border: 1px dashed #999; padding: 6mm; text-align: center; break-inside: avoid; }
}

/* ---------- Utilidades ---------- */
.mono { font-variant-numeric: tabular-nums; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.fw-800 { font-weight: 800; }
.cursor-pointer { cursor: pointer; }
.swatch { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); display: inline-block; vertical-align: middle; }
.color-input { width: 3.2rem; height: 2.4rem; padding: .2rem; }
.img-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: .5rem; background: var(--surface-2); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs-scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs-scroll .nav-link { white-space: nowrap; }
.list-actions { white-space: nowrap; }
@media (max-width: 575.98px) {
  .page-head h1 { font-size: 1.15rem; }
  .table-mobile thead { display: none; }
  .table-mobile tr { display: block; border-bottom: 1px solid var(--line); padding: .4rem 0; }
  .table-mobile td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem .75rem; }
  .table-mobile td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .8rem; }
}
.panel-full .panel-main { padding-bottom: calc(5rem + var(--safe-bottom)); }

/* Avisos: no deben tapar botones (carrito, enviar). En celular aparecen arriba. */
#toasts { pointer-events: none; }
#toasts .toast { pointer-events: auto; }
@media (max-width: 767.98px) {
  #toasts { top: calc(var(--safe-top) + .5rem); bottom: auto !important; left: 50% !important; right: auto !important; transform: translateX(-50%); width: min(94vw, 420px); padding: 0 !important; }
  #toasts .toast { width: 100%; }
  .mesa-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: .55rem; }
}
