:root {
  --bg: #0f1720;
  --bg-2: #16212e;
  --surface: #1c2836;
  --surface-2: #23303f;
  --border: #2c3a4a;
  --text: #e7edf3;
  --text-dim: #9fb0c0;
  --primary: #22c55e;
  --primary-d: #16a34a;
  --accent: #38bdf8;
  --danger: #ef4444;
  --warn: #f59e0b;
  --purple: #a78bfa;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 244px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 100% -10%, #1b3a2b 0%, transparent 55%),
              radial-gradient(1000px 500px at -10% 110%, #12283b 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { font-size: 13px; color: var(--text-dim); display: block; margin-bottom: 6px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: #2b3a4c; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary-d); color: #06240f; }
.btn.primary:hover { background: var(--primary-d); color: #fff; }
.btn.danger { background: transparent; border-color: #5b2222; color: #fca5a5; }
.btn.danger:hover { background: #3a1414; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 34px;
  box-shadow: var(--shadow);
}
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { text-align: center; margin: 6px 0 2px; font-size: 24px; }
.login-card p.sub { text-align: center; color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.login-card .field { margin-bottom: 16px; }
.login-error { background: #3a1414; border: 1px solid #5b2222; color: #fca5a5;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--text-dim); text-align: center; line-height: 1.7; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #13202d, #101b26);
  border-right: 1px solid var(--border); padding: 18px 14px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo { font-size: 26px; }
.brand .name { font-weight: 800; font-size: 17px; letter-spacing: .3px; }
.brand .name small { display: block; font-weight: 500; font-size: 11px; color: var(--text-dim); }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 12px; border-radius: 10px;
  color: var(--text-dim); font-weight: 600; font-size: 14px; cursor: pointer;
}
.nav-item .ic { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--primary); color: #06240f; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #5f7185;
  padding: 14px 12px 6px; font-weight: 700; }
.sidebar .spacer { flex: 1; }
.user-box { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
.user-box .u-name { font-weight: 700; font-size: 14px; }
.user-box .u-role { font-size: 12px; color: var(--text-dim); }

.main { padding: 22px 26px 60px; overflow: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; }
.topbar h2 { margin: 0; font-size: 22px; }
.topbar .subtitle { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

/* Menú móvil */
.mobile-top { display: none; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .k { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 30px; font-weight: 800; }
.stat .foot { font-size: 12px; color: var(--text-dim); }
.stat .badge-ic { font-size: 22px; }
.stat-row { display: flex; align-items: flex-start; justify-content: space-between; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; }
.pill.green { background: #123a24; color: #67e29a; }
.pill.blue { background: #10314a; color: #7dd3fc; }
.pill.amber { background: #3d2f12; color: #fcd34d; }
.pill.red { background: #3a1414; color: #fca5a5; }
.pill.gray { background: #2a3644; color: #a9b8c7; }
.pill.purple { background: #2b2450; color: #c4b5fd; }

/* ---------- Tabla ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; color: var(--text-dim); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .5px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
table.tbl tr:hover td { background: var(--surface-2); }
.tbl-wrap { overflow-x: auto; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar input, .toolbar select { width: auto; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: transparent; color: var(--text-dim); padding: 7px 14px;
  border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button.active { background: var(--primary); color: #06240f; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(5, 10, 15, .65);
  display: grid; place-items: center; z-index: 50; padding: 20px; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  width: 100%; max-width: 560px; box-shadow: var(--shadow); max-height: 92vh; display: flex; flex-direction: column; }
.modal.lg { max-width: 860px; }
.modal.xl { max-width: 1040px; }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 20px; overflow: auto; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; }
.x-close { background: transparent; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Mesas ---------- */
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.table-card { border-radius: 14px; padding: 16px; border: 2px solid; cursor: pointer;
  position: relative; transition: transform .08s ease; min-height: 118px; display: flex; flex-direction: column; }
.table-card:hover { transform: translateY(-2px); }
.table-card .tnum { font-size: 26px; font-weight: 800; }
.table-card .tzone { font-size: 12px; color: var(--text-dim); }
.table-card .tstate { margin-top: auto; font-size: 12px; font-weight: 700; }
.table-card .ttotal { font-size: 15px; font-weight: 700; margin-top: 4px; }
.t-libre { background: #10241a; border-color: #1c4a30; }
.t-libre .tstate { color: #67e29a; }
.t-ocupada { background: #2a1414; border-color: #5b2222; }
.t-ocupada .tstate { color: #fca5a5; }
.t-reservada { background: #2b2450; border-color: #4a3f8a; }
.t-reservada .tstate { color: #c4b5fd; }

.zone-title { margin: 22px 0 10px; font-size: 14px; color: var(--text-dim); font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px; }

/* ---------- POS (bar/resto) ---------- */
.pos { display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
.pos .catalog { display: flex; flex-direction: column; gap: 12px; }
.sector-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--bg-2); color: var(--text-dim);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; }
.chip.active { color: #fff; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.product-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 82px; }
.product-btn:hover { border-color: var(--primary); }
.product-btn .pname { font-weight: 600; font-size: 13px; line-height: 1.25; }
.product-btn .pprice { font-weight: 800; color: var(--primary); font-size: 15px; margin-top: auto; }
.product-btn .psec { font-size: 11px; }

.ticket { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  display: flex; flex-direction: column; max-height: calc(100vh - 150px); position: sticky; top: 10px; }
.ticket-head { padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.ticket-items { flex: 1; overflow: auto; padding: 6px 10px; }
.ticket-line { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px dashed var(--border); }
.ticket-line .tl-name { flex: 1; font-size: 13px; }
.ticket-line .tl-qty { display: flex; align-items: center; gap: 6px; }
.qtybtn { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); cursor: pointer; font-weight: 700; }
.ticket-foot { padding: 14px 16px; border-top: 1px solid var(--border); }
.ticket-total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 800; margin-bottom: 12px; }
.empty { color: var(--text-dim); text-align: center; padding: 30px 10px; font-size: 14px; }

/* ---------- QR scanner ---------- */
.scan-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
#qr-reader { width: 100%; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.scan-result { min-height: 160px; }
.big-num { font-size: 44px; font-weight: 800; line-height: 1; }

/* ---------- misc ---------- */
.muted { color: var(--text-dim); }
.right { text-align: right; }
.center { text-align: center; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.gap { gap: 12px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-dim); }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; min-width: 240px; animation: slideIn .2s ease; }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.qr-print { text-align: center; }
.qr-print img { width: 260px; height: 260px; background: #fff; padding: 12px; border-radius: 12px; }
.qr-print .code { font-size: 22px; font-weight: 800; letter-spacing: 2px; margin-top: 12px; }

.loading { display: grid; place-items: center; padding: 60px; color: var(--text-dim); }

@media (max-width: 980px) {
  .cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cols-3 { grid-template-columns: 1fr; }
  .pos { grid-template-columns: 1fr; }
  .scan-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 260px; left: -280px; transition: left .2s ease; }
  .sidebar.open { left: 0; }
  .mobile-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); z-index: 30; }
  .mobile-top .hamb { font-size: 22px; background: none; border: none; color: var(--text); cursor: pointer; }
  .cols-4, .cols-2, .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
