:root {
  --color-primary: #d84315;
  --color-primary-dark: #a0330e;
  --color-primary-light: #ff8a50;
  --color-accent: #ffb300;
  --color-bg: #f6f3ee;
  --color-surface: #ffffff;
  --color-border: #e6ded3;
  --color-text: #2b2118;
  --color-text-muted: #7a6f63;

  --color-libre: #43a047;
  --color-ocupada: #6c7fd8;
  --color-preparacion: #f9a825;
  --color-listo: #29b6a4;
  --color-pendiente-pago: #e53935;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(43, 33, 24, 0.08);
  --shadow-md: 0 4px 16px rgba(43, 33, 24, 0.12);
  --shadow-lg: 0 16px 40px rgba(43, 33, 24, 0.22);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0 0 8px; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 8px; }
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

:focus-visible { outline: 2px solid var(--color-primary-light); outline-offset: 2px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d8ccbb; border-radius: 8px; }

/* ---------- LAYOUT ---------- */
.app-shell { display: flex; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-sm);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; color: var(--color-primary); }
.topbar .brand .logo { font-size: 26px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--color-bg); padding: 6px 14px; border-radius: 100px;
  font-size: 14px; font-weight: 600;
}
.role-tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--color-primary); color: #fff; padding: 2px 8px; border-radius: 100px;
}
.main-content { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }

.sidebar {
  width: 220px; background: var(--color-surface); border-right: 1px solid var(--color-border);
  min-height: 100vh; padding: 20px 0; position: sticky; top: 0;
}
.sidebar .brand { padding: 0 20px 20px; font-size: 18px; font-weight: 800; color: var(--color-primary); }
.sidebar nav a, .sidebar nav button.navlink {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 12px 20px; text-decoration: none; color: var(--color-text-muted);
  font-weight: 600; font-size: 14.5px; border: none; background: none;
}
.sidebar nav a.active, .sidebar nav button.navlink.active { color: var(--color-primary); background: #fff2ea; border-right: 3px solid var(--color-primary); }
.sidebar nav a:hover, .sidebar nav button.navlink:hover { background: #f4efe8; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: none;
  font-weight: 700; font-size: 14.5px; transition: transform 0.05s ease, filter 0.15s, box-shadow 0.15s;
  background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border);
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); box-shadow: 0 2px 8px rgba(216, 67, 21, 0.28); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-success { background: var(--color-libre); color: #fff; border-color: var(--color-libre); }
.btn-warning { background: var(--color-accent); color: #3a2a00; border-color: var(--color-accent); }
.btn-danger { background: var(--color-pendiente-pago); color: #fff; border-color: var(--color-pendiente-pago); }
.btn-outline { background: transparent; border: 1.5px solid var(--color-primary); color: var(--color-primary); }
.btn-lg { padding: 16px 22px; font-size: 17px; border-radius: var(--radius-md); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { padding: 8px 10px; font-size: 16px; }

/* ---------- CARDS ---------- */
.card {
  background: var(--color-surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm); border: 1px solid var(--color-border);
  padding: 18px;
}
.card-hover:hover { box-shadow: var(--shadow-md); }

.stat-card { padding: 18px 20px; transition: box-shadow 0.15s, transform 0.15s; }
.stat-card .label { font-size: 13px; color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 30px; font-weight: 800; margin-top: 4px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }

/* ---------- BADGES / STATUS ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 100px; font-size: 12.5px; font-weight: 700;
  color: #fff;
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge-libre { background: var(--color-libre); }
.badge-ocupada { background: var(--color-ocupada); }
.badge-en_preparacion { background: var(--color-preparacion); color: #3a2a00; }
.badge-listo { background: var(--color-listo); }
.badge-pendiente_pago { background: var(--color-pendiente-pago); }
.badge-nuevo { background: #78909c; }
.badge-entregado { background: #8e63d1; }
.badge-en_camino { background: #3f88f2; }
.badge-cerrado { background: #9e9e9e; }
.badge-cancelado { background: #4a4a4a; }
.badge-confirmado { background: #5c6bc0; }

/* ---------- GRID: MESAS ---------- */
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.table-card {
  position: relative;
  border-radius: var(--radius-md); padding: 20px 16px; text-align: center;
  border: none; box-shadow: var(--shadow-sm); font-weight: 700; color: #fff;
  min-height: 130px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  transition: box-shadow 0.15s, transform 0.15s;
}
.table-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.table-card .name { font-size: 20px; }
.table-card .status-label { font-size: 13px; font-weight: 600; opacity: 0.95; text-transform: uppercase; }
.table-card .amount { font-size: 15px; opacity: 0.95; }
.table-card.status-libre { background: linear-gradient(145deg, var(--color-libre), #2e7d32); }
.table-card.status-ocupada { background: linear-gradient(145deg, var(--color-ocupada), #4a5bc4); }
.table-card.status-en_preparacion { background: linear-gradient(145deg, var(--color-preparacion), #ef6c00); }
.table-card.status-listo { background: linear-gradient(145deg, var(--color-listo), #00897b); }
.table-card.status-pendiente_pago { background: linear-gradient(145deg, var(--color-pendiente-pago), #b71c1c); }
.table-edit-btn {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; padding: 0;
  border: none; border-radius: 50%; background: rgba(255,255,255,0.28); color: #fff; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.table-edit-btn:hover { background: rgba(255,255,255,0.45); }

/* ---------- GRID: PEDIDOS ACTIVOS (admin) ---------- */
.pedidos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.pedido-card { cursor: pointer; transition: box-shadow 0.15s, transform 0.15s; }
.pedido-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* ---------- MENU / CATEGORIAS ---------- */
.category-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.category-tab {
  padding: 10px 18px; border-radius: 100px; border: 1.5px solid var(--color-border);
  background: var(--color-surface); font-weight: 700; font-size: 14px; color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.category-tab.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.product-card {
  appearance: none; -webkit-appearance: none; margin: 0; cursor: pointer;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 100px;
  transition: box-shadow 0.15s, transform 0.1s;
}
.product-card:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.product-card .pname { font-weight: 700; font-size: 15px; }
.product-card .pprice { color: var(--color-primary); font-weight: 800; font-size: 16px; }
.product-card:disabled, .product-card.unavailable { opacity: 0.45; cursor: not-allowed; }
.product-card.unavailable::after { content: "AGOTADO"; font-size: 11px; font-weight: 800; color: var(--color-pendiente-pago); }

/* ---------- CART / ORDER PANEL ---------- */
.split-layout { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .split-layout { grid-template-columns: 1fr; } }
.cart-item { display: flex; justify-content: space-between; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--color-border); gap: 8px; }
.cart-item:last-child { border-bottom: none; }
.cart-item .qty-controls { display: flex; align-items: center; gap: 6px; }
.qty-btn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--color-border); background: #fff; font-weight: 800; }
.cart-note { font-size: 12.5px; color: var(--color-text-muted); font-style: italic; }
.cart-total-row { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; padding-top: 12px; border-top: 2px solid var(--color-border); margin-top: 8px; }
.tag-nuevo { background: #fff3e0; color: #ef6c00; font-size: 10.5px; font-weight: 800; padding: 2px 6px; border-radius: 4px; margin-left: 6px; }

/* ---------- KDS (COCINA) ---------- */
.kds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.kds-card {
  background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  border-top: 8px solid var(--color-preparacion); overflow: hidden;
}
.kds-card.status-nuevo, .kds-card.status-en_preparacion { border-top-color: var(--color-preparacion); }
.kds-card.status-listo { border-top-color: var(--color-listo); }
.kds-card-header { padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; background: #fffaf3; }
.kds-card-header .title { font-size: 19px; font-weight: 800; }
.kds-card-header .time { font-size: 12.5px; color: var(--color-text-muted); font-weight: 600; }
.kds-items { padding: 14px 16px; }
.kds-item { padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.kds-item:last-child { border-bottom: none; }
.kds-item .line { font-weight: 700; font-size: 15.5px; }
.kds-item .note { color: var(--color-primary); font-size: 13.5px; font-weight: 600; margin-top: 2px; }
.kds-footer { padding: 12px 16px; display: flex; gap: 8px; background: #fbf8f4; }
.kds-badge-delivery { background: #5c6bc0; color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 800; margin-left: 8px; }

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 14, 8, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
  animation: modalFadeIn 0.15s ease;
}
.modal-box {
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 24px;
  animation: modalScaleIn 0.15s ease;
}
.modal-box.wide { max-width: 900px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header .close-btn { border: none; background: none; font-size: 22px; color: var(--color-text-muted); }
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalScaleIn { from { opacity: 0; transform: scale(0.97) translateY(4px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 6px; color: var(--color-text-muted); }
.form-control {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm); border: 1.5px solid var(--color-border);
  font-size: 15px; background: #fff; color: var(--color-text);
}
.form-control:focus { outline: none; border-color: var(--color-primary); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ---------- TABLES (data) ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { text-align: left; padding: 10px 12px; background: #fbf7f1; color: var(--color-text-muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table td { padding: 10px 12px; border-top: 1px solid var(--color-border); }
.data-table tr:hover td { background: #fdfaf6; }
.table-wrap { overflow-x: auto; }

/* ---------- MISC ---------- */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.section-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--color-text-muted); }
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--color-text); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); font-weight: 600; font-size: 14px; animation: fadein 0.2s ease; }
.toast.error { background: var(--color-pendiente-pago); }
.toast.success { background: var(--color-libre); }
@keyframes fadein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 110px; font-size: 13px; font-weight: 700; color: var(--color-text-muted); flex-shrink: 0; }
.bar-track { flex: 1; background: #f0e9de; border-radius: 100px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--color-primary), var(--color-accent)); border-radius: 100px; }
.bar-value { width: 90px; text-align: right; font-weight: 800; font-size: 13.5px; flex-shrink: 0; }

.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top, #fff3e6, var(--color-bg));
}
.login-card { width: 380px; padding: 40px 34px; text-align: center; }
.login-card .logo { font-size: 48px; margin-bottom: 6px; }
.login-card h1 { font-size: 22px; color: var(--color-primary); }
.login-card .subtitle { color: var(--color-text-muted); font-size: 14px; margin-bottom: 24px; }
.login-error { background: #fdecea; color: #c62828; padding: 10px; border-radius: 8px; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; display: none; }
.demo-users { margin-top: 20px; font-size: 12px; color: var(--color-text-muted); text-align: left; background: var(--color-bg); padding: 12px 14px; border-radius: 10px; }
.demo-users b { color: var(--color-text); }

/* ---------- NAV INFERIOR (MÓVIL) ---------- */
.mobile-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  justify-content: space-around; align-items: stretch;
  background: var(--color-surface); border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 16px rgba(43, 33, 24, 0.10);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: none; background: none; color: var(--color-text-muted); font-weight: 700; font-size: 10.5px;
  padding: 6px 2px;
}
.mobile-nav-item span { font-size: 19px; line-height: 1; }
.mobile-nav-item.active { color: var(--color-primary); }

.more-menu { display: flex; flex-direction: column; gap: 8px; }
.more-menu-item {
  text-align: left; padding: 14px 16px; border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-bg); font-weight: 700; font-size: 15px; color: var(--color-text);
}
.more-menu-item:hover { background: #efe8dc; }

@media (max-width: 700px) {
  .sidebar { display: none; }
  .main-content { padding: 14px; padding-bottom: 84px; }
  .topbar { padding: 10px 14px; }
  .mobile-nav { display: flex; }
}
