:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d625b;
  --primary-soft: rgba(15, 118, 110, 0.1);
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --whatsapp: #16a34a;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --topbar-h: 64px;
  --bottomnav-h: 66px;
}

body.dark {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-alt: #1b2742;
  --border: #253352;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #14b8a6;
  --primary-hover: #0d9488;
  --primary-soft: rgba(20, 184, 166, 0.16);
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.15);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

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

.hidden {
  display: none !important;
}

/* Showcase Mode hides merchant-only financial metrics */
body.showcase-mode .merchant-only,
body.showcase-mode #sidebarNav button[data-tab="inventory"],
body.showcase-mode #sidebarNav button[data-tab="customers"],
body.showcase-mode #sidebarNav button[data-tab="reports"],
body.showcase-mode #sidebarNav button[data-tab="invoices"],
body.showcase-mode #bottomNav {
  display: none !important;
}

body:not(.showcase-mode) .showcase-only {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Buttons & Inputs */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-whatsapp {
  background: var(--whatsapp);
  color: #ffffff;
}

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

.btn-outline {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline.active-filter {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
}

body.showcase-mode .btn-chip {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.dot-live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 12px 16px;
  font-size: 0.98rem;
}

.full-width {
  width: 100%;
}

.btn-text {
  background: transparent;
  border: none;
  cursor: pointer;
  font-weight: 700;
  padding: 4px 8px;
}

.btn-text.danger {
  color: var(--danger);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="date"],
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
}

.input-compact,
.select-compact {
  padding: 6px 10px;
  font-size: 0.86rem;
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 225px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--text-muted);
  text-align: right;
}

.sidebar .nav-item:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.sidebar .nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.main-content {
  flex: 1;
  padding: 16px;
  min-width: 0;
  padding-bottom: 84px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Section Headers & Toolbars */
.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.muted {
  color: var(--text-muted);
  margin: 2px 0 0;
  font-size: 0.85rem;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.search-box {
  flex: 1 1 180px;
  min-width: 0;
  position: relative;
}

.search-box input {
  width: 100%;
  padding-right: 36px;
}

.search-icon {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 0.9rem;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* POS Layout */
.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.pos-catalog {
  min-width: 0;
}

.category-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
  scrollbar-width: none;
}

.category-pills::-webkit-scrollbar {
  display: none;
}

.cat-pill {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
}

.cat-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
  position: relative;
}

.product-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.product-card.out-of-stock {
  opacity: 0.55;
  cursor: not-allowed;
}

.product-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.product-emoji {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
}

.stock-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
}

.stock-badge.low {
  background: var(--accent-soft);
  color: var(--accent);
}

.stock-badge.empty {
  background: var(--danger-soft);
  color: var(--danger);
}

.product-name {
  font-weight: 800;
  font-size: 0.94rem;
  line-height: 1.3;
}

.product-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.product-price-row {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.price-tag {
  font-weight: 800;
  font-size: 1.02rem;
  color: var(--primary);
}

.add-mini-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  cursor: pointer;
}

/* Cart Panel */
.pos-cart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: calc(var(--topbar-h) + 14px);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--topbar-h) - 32px);
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.cart-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 120px;
}

.cart-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 10px;
  font-size: 0.9rem;
}

.cart-item {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cart-item-info {
  min-width: 0;
  flex: 1;
}

.cart-item-title {
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

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

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
}

.qty-val {
  min-width: 20px;
  text-align: center;
  font-weight: 800;
  font-size: 0.9rem;
}

.cart-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
}

.cart-row input[type="number"] {
  width: 90px;
  text-align: center;
}

.total-row {
  font-size: 1.08rem;
}

.total-row strong {
  color: var(--primary);
  font-size: 1.2rem;
}

.profit-badge {
  background: var(--success-soft);
  color: var(--success);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
}

.payment-methods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.pay-pill {
  position: relative;
  cursor: pointer;
}

.pay-pill input {
  position: absolute;
  opacity: 0;
}

.pay-pill span {
  display: block;
  text-align: center;
  padding: 7px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-alt);
}

.pay-pill input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.customer-select-wrap {
  display: flex;
  gap: 6px;
}

.customer-select-wrap select {
  flex: 1;
}

/* Stats & Cards */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-size: 1.32rem;
  font-weight: 800;
  margin-top: 2px;
}

.stat-value.primary { color: var(--primary); }
.stat-value.success { color: var(--success); }
.stat-value.accent { color: var(--accent); }
.stat-value.danger { color: var(--danger); }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.inventory-list,
.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inv-row,
.list-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.inv-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  flex: 1;
}

.inv-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.metric-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 700;
}

.inv-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.reports-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}

/* Mobile Cart FAB & Bottom Nav */
.mobile-cart-fab {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + 10px);
  left: 14px;
  right: 14px;
  z-index: 25;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.96rem;
  font-weight: 800;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottomnav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  justify-content: space-around;
  align-items: center;
}

.bottom-nav .nav-item {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 1.15rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 10px;
}

.bottom-nav .nav-item small {
  font-size: 0.72rem;
  font-weight: 700;
}

.bottom-nav .nav-item.active {
  color: var(--primary);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(3px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* Invoice Receipt Card */
.receipt-box {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.88rem;
}

.receipt-head {
  text-align: center;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.receipt-table th,
.receipt-table td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 0.84rem;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
}

.mobile-only-btn {
  display: none;
}

/* Responsive Breakpoints */
@media (max-width: 960px) {
  .mobile-only-btn {
    display: inline-flex;
  }

  .sidebar {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  .pos-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .pos-cart {
    position: fixed;
    inset: auto 0 var(--bottomnav-h) 0;
    max-height: 76vh;
    z-index: 28;
    border-radius: 18px 18px 0 0;
    transform: translateY(115%);
    transition: transform 0.22s ease;
  }

  .pos-cart.mobile-open {
    transform: translateY(0);
  }

  .main-content {
    padding: 12px;
    padding-bottom: 138px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0 10px;
    gap: 6px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .brand {
    gap: 6px;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
  }

  .brand h1 {
    font-size: 0.92rem;
  }

  .btn-chip {
    white-space: nowrap;
    font-size: 0.7rem;
    padding: 5px 8px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.88rem;
  }

  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .product-card,
  .inv-main {
    min-width: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .brand-sub {
    display: none;
  }
}

@media print {
  .topbar,
  .sidebar,
  .bottom-nav,
  .mobile-cart-fab,
  .no-print {
    display: none !important;
  }

  body,
  .modal-backdrop,
  .modal-box {
    background: #fff !important;
    color: #000 !important;
    position: static !important;
    box-shadow: none !important;
    border: none !important;
  }
}
