@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css');

/* ── DESIGN TOKENS ─────────────────────────────────────────────────── */
:root {
  --bg-deep: #0a0c14;
  --bg-card: #111827;
  --bg-surface: #1a2235;
  --bg-hover: #1f2d45;
  --border: rgba(255, 255, 255, .07);

  --accent: #f97316;
  --accent-glow: rgba(249, 115, 22, .35);
  --accent-soft: #fff7ed;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --info: #38bdf8;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --sidebar-w: 240px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, .6);
  --transition: .2s ease;
}

body.light-mode {
  --bg-deep: #f1f5f9;
  --bg-card: #ffffff;
  --bg-surface: #f8fafc;
  --bg-hover: #e2e8f0;
  --border: rgba(0, 0, 0, .08);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow: 0 4px 12px rgba(0, 0, 0, .05);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .08);
}

/* ── RESET & BASE ────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

img {
  max-width: 100%;
}

/* ── SCROLLBAR ───────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-card);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ── LAYOUT ─────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 1100;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo .logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #dc2626);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: #fff;
  box-shadow: 0 0 20px var(--accent-glow);
}

.sidebar-logo h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .1em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  cursor: pointer;
  transition: all var(--transition);
}

.nav-item:hover,
.nav-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(249, 115, 22, .18), transparent);
  color: var(--accent);
  border-left: 3px solid var(--accent);
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #dc2626);
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin var(--transition);
  background: var(--bg-deep);
}

.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
}

.page-body {
  padding: 24px;
  flex: 1;
}

/* ── POS LAYOUT (CRITICAL FIX) ───────────────────────────────────────── */
.pos-layout {
  display: flex;
  gap: 20px;
  height: calc(100vh - 100px);
  overflow: hidden;
  padding-bottom: 20px;
}

.pos-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  padding-right: 8px;
}

.pos-ticket {
  width: 400px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

/* ── MOBILE OVERRIDES ────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .pos-layout {
    height: auto;
    min-height: calc(100vh - 80px);
    flex-direction: column;
    overflow: visible;
  }

  .pos-menu {
    overflow: visible;
    padding-bottom: 120px;
  }

  .pos-ticket {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
  }

  .pos-ticket.open {
    transform: translateX(0);
    visibility: visible;
  }

  .fab-ticket {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 8px 32px var(--accent-glow);
    z-index: 1500;
    border: none;
    cursor: pointer;
  }

  .fab-ticket .badge-count {
    position: absolute;
    top: -5px;
    left: -5px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    width: 26px;
    height: 26px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    border: 2px solid var(--bg-deep);
  }

  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }
}

@media (min-width: 1025px) {
  .fab-ticket {
    display: none;
  }
}

/* ── UI COMPONENTS ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.orange {
  background: rgba(249, 115, 22, .15);
  color: var(--accent);
}

.stat-icon.green {
  background: rgba(34, 197, 94, .15);
  color: var(--success);
}

.stat-icon.blue {
  background: rgba(56, 189, 248, .15);
  color: var(--info);
}

.stat-icon.red {
  background: rgba(239, 68, 68, .15);
  color: var(--danger);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}

.badge-pending {
  background: rgba(234, 179, 8, .15);
  color: var(--warning);
}

.badge-preparing {
  background: rgba(56, 189, 248, .15);
  color: var(--info);
}

.badge-ready {
  background: rgba(34, 197, 94, .15);
  color: var(--success);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #ea6c0a;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: block;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--bg-surface);
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

tbody td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

/* ── PRODUCTS & TABLES ───────────────────────────────────────────────── */
.category-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.cat-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  background: rgba(56, 189, 248, .05);
  border: 1px solid rgba(56, 189, 248, .2);
  color: var(--info);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.cat-tab i {
  font-size: 16px;
  opacity: 0.7;
}

.cat-tab:hover {
  background: rgba(56, 189, 248, .12);
  border-color: var(--info);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.cat-tab.active {
  background: var(--info);
  color: #fff;
  border-color: var(--info);
  box-shadow: 0 8px 20px rgba(56, 189, 248, .35);
  transform: scale(1.05);
}

.cat-tab.active i {
  opacity: 1;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.product-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.product-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.product-card .pc-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.product-card .pc-name {
  font-size: 13px;
  font-weight: 600;
}

.product-card .pc-price {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
  margin-top: 4px;
}

.table-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 14px;
}

.table-tile {
  aspect-ratio: 1;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.table-tile.occupied {
  border-color: var(--danger);
  background: rgba(239, 68, 68, .07);
}

.table-tile.available {
  border-color: var(--success);
  background: rgba(34, 197, 94, .05);
}

.table-tile .ti-num {
  font-size: 24px;
  font-weight: 800;
}

/* ── TICKET ELEMENTS ─────────────────────────────────────────────────── */
.ticket-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.ticket-items {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.ticket-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.ticket-item:hover {
  background: var(--bg-hover);
}

.ti-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.ti-qty-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ti-qty-ctrl button {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: var(--bg-hover);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.ti-qty-ctrl button:hover {
  background: var(--accent);
}

.ti-subtotal {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 60px;
  text-align: right;
}

.ticket-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.ticket-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.ticket-total .amount {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

.ticket-actions {
  display: flex;
  gap: 8px;
}

/* ── MODAL & ALERTS ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: min(520px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-danger {
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #fca5a5;
}

.alert-success {
  background: rgba(34, 197, 94, .1);
  border: 1px solid rgba(34, 197, 94, .3);
  color: #86efac;
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 14px;
  min-width: 280px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideUp .3s ease;
}

.toast.success {
  border-left: 4px solid var(--success);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.search-bar {
  position: relative;
}

.search-bar i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-bar input {
  padding-left: 36px;
}

.order-settings {
  background: var(--bg-surface);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.ord-type-btn {
  flex: 1;
}

.ord-type-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ── THEME TOGGLE ────────────────────────────────────────────────────── */
.theme-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 20px;
  background: var(--bg-surface);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.theme-switch:hover {
  background: var(--bg-hover);
}

.theme-switch i {
  font-size: 16px;
  color: var(--warning);
  transition: transform 0.4s ease;
}

.theme-switch:hover i {
  transform: rotate(15deg);
}

.ts-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

body.light-mode .theme-switch i.fa-moon {
  display: block;
  color: var(--info);
}

body.light-mode .theme-switch i.fa-sun {
  display: none;
}

body:not(.light-mode) .theme-switch i.fa-moon {
  display: none;
}

body:not(.light-mode) .theme-switch i.fa-sun {
  display: block;
}