:root{
  --bg:#eef3f7;
  --bg2:#f8fafc;
  --card:#ffffff;
  --ink:#10201c;
  --muted:#66756f;
  --brand:#0d6b57;
  --brand-dark:#064e3b;
  --brand-soft:#e6f5f0;
  --accent:#c69335;
  --line:#dfe8e3;
  --line-strong:#cbd8d2;
  --danger:#b91c1c;
  --ok:#15803d;
  --shadow:0 16px 38px rgba(15,23,42,.08);
  --radius:18px;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  min-height:100vh;
  background:
    radial-gradient(circle at top left,rgba(13,107,87,.12),transparent 34rem),
    linear-gradient(180deg,var(--bg),var(--bg2));
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Arial,sans-serif;
  color:var(--ink);
  font-size:16px;
}
a{color:var(--brand-dark);font-weight:700;text-decoration:none}
a:hover{text-decoration:underline}
.app-header{
  margin:18px auto 10px;
  width:min(1440px,calc(100% - 32px));
  background:linear-gradient(135deg,var(--brand-dark),var(--brand));
  color:white;
  border-radius:24px;
  padding:22px 24px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
  box-shadow:var(--shadow);
}
.brand-block{display:flex;align-items:center;gap:16px;min-width:0}
.brand-mark{
  width:58px;height:58px;border-radius:18px;
  display:grid;place-items:center;
  font-weight:900;letter-spacing:-.04em;
  background:rgba(255,255,255,.16);
  border:1px solid rgba(255,255,255,.25);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.2);
}
.brand-title{font-size:1.45rem;font-weight:900;line-height:1.1;letter-spacing:-.03em}
.brand-title span{font-size:.85rem;font-weight:800;color:#d7f7ec;background:rgba(255,255,255,.13);padding:3px 8px;border-radius:999px;margin-left:6px}
.brand-subtitle{opacity:.86;margin-top:5px;font-size:.95rem}
.session-card{
  min-width:230px;text-align:right;
  padding:12px 14px;border-radius:18px;
  background:rgba(255,255,255,.12);
  border:1px solid rgba(255,255,255,.2);
}
.session-label{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;opacity:.75}
.session-user{font-size:1.05rem;font-weight:900;margin-top:2px}
.session-role{font-size:.86rem;opacity:.92}.session-role a{color:white;text-decoration:underline}
.app-nav{
  width:min(1440px,calc(100% - 32px));
  margin:0 auto 20px;
  padding:10px;
  display:flex;gap:8px;flex-wrap:wrap;
  background:rgba(255,255,255,.82);
  border:1px solid var(--line);
  border-radius:20px;
  box-shadow:0 10px 24px rgba(15,23,42,.06);
  backdrop-filter:blur(10px);
  position:sticky;top:8px;z-index:20;
}
.nav-item{
  display:inline-flex;align-items:center;gap:7px;
  padding:9px 12px;border-radius:14px;
  color:#1d3d36;font-weight:800;font-size:.93rem;
  border:1px solid transparent;
}
.nav-item:hover{background:var(--brand-soft);text-decoration:none;border-color:#cde7de}
.nav-item.active{background:var(--brand);color:white;box-shadow:0 8px 18px rgba(13,107,87,.18)}
.wrap{width:min(1440px,calc(100% - 32px));margin:0 auto 28px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:18px}.grid.four{grid-template-columns:repeat(4,minmax(180px,1fr))}
.card{
  background:rgba(255,255,255,.96);
  border:1px solid var(--line);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  padding:22px;
  margin-bottom:18px;
}
.card h1,.card h2,.card h3{margin-top:0;letter-spacing:-.035em}.card h2{font-size:1.45rem}.card h3{font-size:1.08rem}
.hero{
  background:linear-gradient(135deg,#ffffff,#f4fbf8);
  border:1px solid var(--line);
  border-radius:24px;
  padding:24px;
  margin-bottom:18px;
  box-shadow:var(--shadow);
}
.hero h1{margin:0 0 8px;font-size:2rem;letter-spacing:-.05em}.hero p{margin:0;color:var(--muted);font-size:1.05rem}.quick-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:18px}
.kpi-card{position:relative;overflow:hidden}.kpi-card:after{content:"";position:absolute;right:-34px;top:-34px;width:108px;height:108px;border-radius:50%;background:rgba(13,107,87,.08)}
.kpi-label{color:var(--muted);font-weight:800;text-transform:uppercase;letter-spacing:.06em;font-size:.77rem}.kpi{font-size:2.2rem;font-weight:950;letter-spacing:-.05em;margin-top:6px}.muted{color:var(--muted)}
label{display:block;font-weight:850;margin:12px 0 6px;color:#22352f}input,select,textarea{width:100%;padding:11px 12px;border:1px solid var(--line-strong);border-radius:13px;background:#fff;font:inherit;color:var(--ink)}input:focus,select:focus,textarea:focus{outline:3px solid rgba(13,107,87,.14);border-color:var(--brand)}input[type=color]{height:45px;padding:3px}.row{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:14px}
.btn,button{display:inline-flex;align-items:center;justify-content:center;gap:8px;background:var(--brand);color:white;border:none;border-radius:13px;padding:11px 15px;text-decoration:none;cursor:pointer;font-weight:900;box-shadow:0 8px 16px rgba(13,107,87,.16)}.btn:hover,button:hover{text-decoration:none;filter:brightness(.96)}.btn.secondary{background:#334155}.btn.warn{background:#b45309}.btn.danger,button.danger{background:var(--danger);color:#fff}.btn.primary{background:var(--brand-dark);color:#fff}
.msg,.alert.ok{padding:12px 14px;background:#ecfdf5;border:1px solid #bbf7d0;border-radius:14px;margin-bottom:12px;color:#14532d}.err,.alert.bad{padding:12px 14px;background:#fef2f2;border:1px solid #fecaca;border-radius:14px;margin-bottom:12px;color:#7f1d1d}.alert{padding:12px 14px;border-radius:14px;margin:12px 0}
.table-wrap{overflow-x:auto;border-radius:16px;border:1px solid var(--line);background:white}table{width:100%;border-collapse:separate;border-spacing:0;background:#fff;border-radius:16px;overflow:hidden}th,td{padding:12px 13px;border-bottom:1px solid var(--line);text-align:left;vertical-align:top}th{background:#f3f8f6;color:#29423b;font-size:.82rem;text-transform:uppercase;letter-spacing:.05em}tr:hover td{background:#fbfdfc}tr:last-child td{border-bottom:0}.swatch{display:inline-block;width:18px;height:18px;border-radius:6px;border:1px solid rgba(0,0,0,.18);vertical-align:middle;margin-right:6px}.badge,.pill{display:inline-block;border-radius:999px;padding:5px 10px;background:var(--brand-soft);color:var(--brand-dark);font-size:12px;font-weight:900;margin:2px}.ok{color:var(--ok);font-weight:900}.bad{color:var(--danger);font-weight:900}.chartbox{height:380px}.foot{text-align:center;color:var(--muted);padding:30px}.small{font-size:.9rem}.actions{display:flex;gap:8px;flex-wrap:wrap}td input,td select{min-width:120px}code{background:#f1f5f9;padding:2px 6px;border-radius:6px}
.flow-step{border-left:4px solid var(--brand);padding-left:14px}.flow-step .badge{margin-bottom:8px}.login-body{min-height:100vh;display:grid;place-items:center;background:linear-gradient(135deg,#064e3b,#0d6b57)}.login-box{width:min(440px,92vw);background:#fff;border-radius:24px;padding:30px;box-shadow:0 22px 60px rgba(0,0,0,.22)}.login-box h1{margin-top:0;letter-spacing:-.04em}
@media(max-width:900px){.app-header{align-items:flex-start;flex-direction:column}.session-card{text-align:left;width:100%}.grid.four{grid-template-columns:1fr}.brand-title{font-size:1.2rem}.hero h1{font-size:1.55rem}.app-nav{position:static}.nav-item{flex:1 1 auto}.chartbox{height:320px}}
@media(max-width:560px){.wrap,.app-header,.app-nav{width:calc(100% - 20px)}.card,.hero{padding:16px}.brand-mark{width:48px;height:48px}.nav-item{font-size:.88rem;padding:9px 10px}}
.swatch{display:inline-block;width:18px;height:18px;border-radius:6px;border:1px solid rgba(0,0,0,.16);vertical-align:middle;margin-right:8px;box-shadow:0 1px 2px rgba(0,0,0,.12)}
.swatch.big{width:30px;height:30px;border-radius:10px;margin-right:12px}
.hero.compact{padding:24px;margin-bottom:18px}
.toolbar{display:flex;gap:14px;align-items:flex-end;flex-wrap:wrap}
.toolbar label{min-width:220px;flex:1}

/* Evoluciones: gráficos en vertical para mejor lectura */
.graph-stack{display:flex;flex-direction:column;gap:18px;margin-bottom:18px}
.graph-card{width:100%}
.graph-card .chartbox{height:460px}
@media(max-width:900px){.graph-card .chartbox{height:360px}}
.compact-list{margin:0;padding-left:18px}.compact-list li{margin:3px 0}.err-inline{display:inline-block;color:#8a1f1f;background:#fdecec;border:1px solid #f5c2c2;border-radius:999px;padding:4px 8px;font-size:12px;font-weight:700}
.help-box{margin-top:14px;padding:14px 16px;border:1px solid rgba(14,42,71,.14);background:#f8fafc;border-radius:16px;color:#334155;line-height:1.7}
.help-box code{background:#e2e8f0;border-radius:8px;padding:2px 6px;color:#0f172a}
.small-cell{max-width:320px;font-size:.88rem;line-height:1.35;color:var(--muted)}

/* Mesas: listado principal y formularios en ventana flotante */
.section-head{display:flex;align-items:flex-start;justify-content:space-between;gap:18px;flex-wrap:wrap;margin-bottom:16px}
.section-head h2{margin-bottom:6px}.section-head p{margin:0}.section-head .btn{white-space:nowrap}
.modal-overlay{position:fixed;inset:0;background:rgba(15,23,42,.58);display:none;align-items:flex-start;justify-content:center;padding:48px 16px;z-index:999;overflow:auto;backdrop-filter:blur(4px)}
.modal-overlay.open{display:flex}
.modal-window{width:min(980px,100%);background:#fff;border-radius:24px;border:1px solid var(--line);box-shadow:0 30px 80px rgba(15,23,42,.28);padding:24px;position:relative;animation:modalIn .16s ease-out}
.modal-window h2{margin-right:42px}.modal-close{position:absolute;right:16px;top:14px;width:38px;height:38px;border-radius:999px;padding:0;background:#e2e8f0;color:#0f172a;box-shadow:none;font-size:26px;line-height:1}
@keyframes modalIn{from{opacity:0;transform:translateY(10px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}
@media(max-width:680px){.section-head .btn{width:100%}.modal-overlay{padding:18px 10px}.modal-window{padding:18px;border-radius:18px}}


.crud-modal-overlay{
  position:fixed !important; inset:0 !important; z-index:99998 !important;
  display:none !important; align-items:center !important; justify-content:center !important;
  padding:24px !important; background:rgba(15,23,42,.62) !important; backdrop-filter:blur(4px); overflow:auto !important;
}
.crud-modal-overlay.is-visible{display:flex !important}
.crud-modal-window{
  width:min(1040px,calc(100vw - 32px)) !important; max-height:calc(100vh - 48px) !important; overflow:auto !important;
  background:#fff !important; border:1px solid var(--line,#dbe4df) !important; border-radius:24px !important;
  box-shadow:0 34px 90px rgba(15,23,42,.35) !important; padding:24px !important; position:relative !important;
}
.crud-modal-window.narrow{width:min(720px,calc(100vw - 32px)) !important}
.crud-modal-close{position:absolute !important;top:14px !important;right:16px !important;width:40px !important;height:40px !important;border-radius:999px !important;padding:0 !important;background:#e2e8f0 !important;color:#0f172a !important;box-shadow:none !important;font-size:28px !important;line-height:1 !important}
body.crud-modal-open{overflow:hidden !important}
.inline-actions{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
@media(max-width:680px){.crud-modal-overlay{padding:12px !important;align-items:flex-start !important}.crud-modal-window{width:100% !important;max-height:calc(100vh - 24px) !important;padding:18px !important;border-radius:18px !important}}


/* Carga por mesa: filas clicables y estados */
.clickable-table .mesa-click-row{cursor:pointer}
.clickable-table .mesa-click-row:hover td{background:#eef9f4 !important}
.clickable-table .mesa-click-row:focus td{background:#eef9f4 !important;outline:3px solid rgba(13,107,87,.18);outline-offset:-3px}
.badge.ok-badge{background:#dcfce7;color:#166534}
.badge.bad-badge{background:#fee2e2;color:#991b1b}
.badge.pending-badge{background:#f1f5f9;color:#475569}

/* Ajuste definitivo: carga por mesa en modal real y estados por color */
.crud-modal-overlay[hidden]{display:none !important;}
.crud-modal-overlay.is-visible{display:flex !important;}
.clickable-table .mesa-click-row{cursor:pointer;}
.clickable-table .mesa-click-row:hover td{background:#eef9f4 !important;}
.badge.status-green{background:#dcfce7 !important;color:#166534 !important;border:1px solid #86efac !important;}
.badge.status-red{background:#fee2e2 !important;color:#991b1b !important;border:1px solid #fecaca !important;}
.badge.status-orange{background:#ffedd5 !important;color:#9a3412 !important;border:1px solid #fdba74 !important;}

/* Carga por mesa: ventana flotante real obligatoria */
.carga-modal-overlay{
  position:fixed !important;
  inset:0 !important;
  z-index:2147483000 !important;
  display:none !important;
  align-items:center !important;
  justify-content:center !important;
  padding:24px !important;
  background:rgba(15,23,42,.68) !important;
  backdrop-filter:blur(4px) !important;
  overflow:auto !important;
}
.carga-modal-overlay[hidden]{display:none !important;}
.carga-modal-overlay.is-visible{display:flex !important;}
.carga-modal-window{
  width:min(1080px,calc(100vw - 32px)) !important;
  max-height:calc(100vh - 48px) !important;
  overflow:auto !important;
  background:#fff !important;
  border:1px solid var(--line,#dbe4df) !important;
  border-radius:24px !important;
  box-shadow:0 34px 90px rgba(15,23,42,.38) !important;
  padding:26px !important;
  position:relative !important;
}
.carga-modal-close{
  position:absolute !important;
  top:14px !important;
  right:16px !important;
  width:40px !important;
  height:40px !important;
  border-radius:999px !important;
  padding:0 !important;
  background:#e2e8f0 !important;
  color:#0f172a !important;
  box-shadow:none !important;
  font-size:28px !important;
  line-height:1 !important;
}
body.carga-modal-open{overflow:hidden !important;}
template{display:none !important;}
@media(max-width:680px){
  .carga-modal-overlay{padding:12px !important;align-items:flex-start !important;}
  .carga-modal-window{width:100% !important;max-height:calc(100vh - 24px) !important;padding:18px !important;border-radius:18px !important;}
}


/* Refuerzo global: ningún formulario modal debe caer debajo de listados */
.crud-modal-overlay,
.mesa-modal-overlay,
.carga-modal-overlay{
  position:fixed !important;
  inset:0 !important;
  z-index:2147483000 !important;
}
.crud-modal-overlay:not(.is-visible),
.crud-modal-overlay[hidden]{display:none !important;visibility:hidden !important;}
.crud-modal-overlay.is-visible{display:flex !important;visibility:visible !important;}
.crud-modal-window{margin:auto !important;}
body.crud-modal-open, body.mesa-modal-open, body.carga-modal-open{overflow:hidden !important;}

/* Comicios: ventana flotante real con dialog nativo */
.native-crud-dialog{
  width:min(1080px,calc(100vw - 32px)) !important;
  max-height:calc(100vh - 48px) !important;
  padding:0 !important;
  border:0 !important;
  border-radius:24px !important;
  background:transparent !important;
  overflow:visible !important;
  position:fixed !important;
  inset:0 !important;
  margin:auto !important;
  z-index:2147483600 !important;
}
.native-crud-dialog::backdrop{
  background:rgba(15,23,42,.68) !important;
  backdrop-filter:blur(4px) !important;
}
.native-crud-window{
  width:100% !important;
  max-height:calc(100vh - 48px) !important;
  overflow:auto !important;
  background:#fff !important;
  border:1px solid var(--line,#dbe4df) !important;
  border-radius:24px !important;
  box-shadow:0 34px 90px rgba(15,23,42,.38) !important;
  padding:26px !important;
  position:relative !important;
}
.native-crud-dialog:not([open]){display:none !important;}
body.crud-modal-open{overflow:hidden !important;}
@media(max-width:680px){
  .native-crud-dialog{width:calc(100vw - 24px) !important;max-height:calc(100vh - 24px) !important;}
  .native-crud-window{max-height:calc(100vh - 24px) !important;padding:18px !important;border-radius:18px !important;}
}
.color-dot{display:inline-block;width:12px;height:12px;border-radius:999px;margin-right:7px;vertical-align:-1px;border:1px solid rgba(0,0,0,.18)}
a.flow-step{display:block;text-decoration:none;color:inherit}

/* Menú privado agrupado por bloques extensibles */

.app-nav-accordion{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:10px;
  position:sticky;
  overflow:visible;
  z-index:50;
}
.nav-group{
  position:relative;
  flex:0 0 auto;
}
.nav-group-button{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  min-width:215px;
  padding:12px 14px;
  cursor:pointer;
  font:inherit;
  font-weight:950;
  color:var(--brand-dark);
  background:linear-gradient(135deg,var(--brand-soft),#fff);
  border:1px solid var(--line);
  border-radius:18px;
  box-shadow:0 8px 18px rgba(15,23,42,.045);
  user-select:none;
}
.nav-group.active-group .nav-group-button{
  outline:2px solid rgba(218,33,40,.18);
  background:linear-gradient(135deg,#fff0f0,#fff);
}
.nav-group-button small{
  display:inline-grid;
  place-items:center;
  width:24px;
  height:24px;
  border-radius:999px;
  background:#fff;
  border:1px solid var(--line);
  transition:transform .18s ease;
}
.nav-group.open .nav-group-button small,
.nav-group:hover .nav-group-button small{transform:rotate(180deg)}
.nav-group-links{
  position:absolute;
  top:calc(100% + 6px);
  left:0;
  min-width:280px;
  display:none;
  flex-direction:column;
  gap:6px;
  padding:10px;
  background:#fff;
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:0 22px 45px rgba(15,23,42,.18);
  z-index:1000;
}
.nav-group.open .nav-group-links,
.nav-group:hover .nav-group-links{
  display:flex;
}
.nav-group .nav-item{
  width:100%;
  justify-content:flex-start;
  padding:10px 11px;
  font-size:.92rem;
}
.nav-group .nav-item span{
  width:22px;
  text-align:center;
}
.nav-group .nav-item.active{
  background:var(--brand);
  color:#fff;
}
@media(max-width:900px){
  .app-nav-accordion{position:sticky;align-items:stretch}
  .nav-group{width:100%}
  .nav-group-button{width:100%;min-width:0}
  .nav-group-links{
    min-width:100%;
    max-height:65vh;
    overflow:auto;
  }
}

  width:48px;
  height:48px;
  display:grid;
  place-items:center;
  border-radius:16px;
  background:var(--brand-soft);
  font-size:1.35rem;
  border:1px solid #cde7de;
}
