*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f0f2f5; --card: #fff; --primary: #2563eb; --danger: #dc2626;
  --success: #16a34a; --border: #e2e8f0; --muted: #64748b; --radius: 8px;
  --sidebar-w: 200px;
}
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: #1e293b; font-size: 14px; }

/* APP LAYOUT */
.app-layout { display: flex; min-height: 100vh; }

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 0 0 0 0;
}
.sidebar-logo {
  font-size: 1rem; font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.sidebar-nav { display: flex; flex-direction: column; padding: 8px 0; flex: 1; overflow-y: auto; }
.tab-btn {
  background: transparent; border: none; color: #94a3b8;
  padding: 13px 20px; cursor: pointer; font-size: 0.9rem;
  text-align: left; border-left: 3px solid transparent;
  transition: all 0.15s; white-space: nowrap;
}
.tab-btn:hover { color: #fff; background: rgba(255,255,255,0.05); }
.tab-btn.active { color: #fff; background: rgba(255,255,255,0.08); border-left-color: var(--primary); }
.sidebar-clock { padding: 12px 16px; font-size: 0.75rem; color: #64748b; border-top: 1px solid rgba(255,255,255,0.08); }

/* MAIN CONTENT */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; }

.tab { display: none; padding: 24px; }
.tab.active { display: block; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }

/* POS */
.pos-layout { display: grid; grid-template-columns: 360px 1fr; gap: 16px; align-items: start; }
.scan-box, .payment-box {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.scan-box label, .payment-box label {
  display: block; font-weight: 600; margin-bottom: 8px;
  color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: .05em;
}
.scan-row { display: flex; gap: 8px; }
.scan-row input {
  flex: 1; padding: 10px 12px; border: 2px solid var(--primary);
  border-radius: var(--radius); font-size: 1rem; outline: none;
}
.scan-row button {
  background: var(--primary); color: #fff; border: none;
  padding: 10px 16px; border-radius: var(--radius); cursor: pointer; font-size: 1.1rem;
}
#scan-result { margin-top: 8px; font-size: 0.85rem; min-height: 20px; }
#scan-result.error { color: var(--danger); }
#scan-result.ok { color: var(--success); }

.product-card {
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.product-info { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; margin-bottom: 6px; }
.product-meta { display: flex; gap: 16px; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
.qty-row { display: flex; gap: 8px; }
.qty-row input { width: 72px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; text-align: center; }
.qty-row button { flex: 1; background: var(--success); color: #fff; border: none; padding: 8px 12px; border-radius: var(--radius); cursor: pointer; font-weight: 600; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 700; background: #dbeafe; color: #1d4ed8; }
.badge-ok  { background: #dcfce7; color: #15803d; }
.badge-low { background: #fef9c3; color: #a16207; }
.badge-out { background: #fee2e2; color: #b91c1c; }

.pay-btns { display: flex; gap: 8px; }
.pay-btn { flex: 1; padding: 10px; border: 2px solid var(--border); border-radius: var(--radius); background: #fff; cursor: pointer; font-size: 0.9rem; transition: all .15s; }
.pay-btn.active { border-color: var(--primary); background: #eff6ff; color: var(--primary); font-weight: 600; }

/* CART */
.pos-right { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07); display: flex; flex-direction: column; }
.cart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cart-header h2 { font-size: 1rem; }
.cart-scroll { max-height: 340px; overflow-y: auto; }
.cart-total { display: flex; justify-content: space-between; align-items: center; padding: 12px 0 10px; font-size: 1.2rem; font-weight: 700; border-top: 2px solid var(--border); margin-top: 8px; }
#btn-checkout { width: 100%; padding: 14px; background: var(--success); color: #fff; border: none; border-radius: var(--radius); font-size: 1.1rem; font-weight: 700; cursor: pointer; margin-top: 10px; transition: background .15s; }
#btn-checkout:disabled { background: #94a3b8; cursor: not-allowed; }
#btn-checkout:not(:disabled):hover { background: #15803d; }

/* TABLES */
table { width: 100%; border-collapse: collapse; }
th { background: #f8fafc; padding: 9px 12px; text-align: left; border-bottom: 2px solid var(--border); font-size: 0.78rem; color: var(--muted); text-transform: uppercase; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8fafc; }

/* TOOLBAR */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 180px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
.toolbar button, .btn-export { background: var(--primary); color: #fff; border: none; padding: 9px 16px; border-radius: var(--radius); cursor: pointer; font-size: 0.9rem; white-space: nowrap; }
.btn-export { background: #0891b2; }

/* BUTTONS */
button.primary { background: var(--primary); color: #fff; border: none; padding: 9px 20px; border-radius: var(--radius); cursor: pointer; }
.btn-sm.danger, button.danger { background: var(--danger); color: #fff; border: none; padding: 6px 12px; border-radius: var(--radius); cursor: pointer; font-size: 0.8rem; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 4px; }
.btn-icon:hover { background: var(--border); }

/* DASHBOARD */
.stats-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 160px; background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.07); text-align: center; }
.stat-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.stat-val { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-grid .card h3, .card h3 { margin-bottom: 12px; font-size: 0.95rem; }

/* MODAL */
#modal-overlay, #receipt-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; }
#modal, #receipt-modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: #fff; border-radius: 10px; padding: 24px; z-index: 201; width: 580px; max-width: 95vw; max-height: 90vh; overflow-y: auto; }
#modal h2 { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.form-group input, .form-group select { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions button { padding: 9px 20px; border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer; background: #fff; }
.modal-actions button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.modal-actions button.primary:hover { background: #1d4ed8; }

.hidden { display: none !important; }

/* RECEIPT */
#receipt-content, #ret-receipt-content {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  max-width: 300px;
  margin: 0 auto;
  color: #000;
  text-align: center;
}
#receipt-content h2, #ret-receipt-content h2 {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 900;
  color: #000;
  margin: 0 0 4px 0;
}
#receipt-content p, #ret-receipt-content p {
  color: #000;
  margin: 2px 0;
}
.sep { border-top: 1px dashed #000; margin: 8px 0; }
#receipt-content table, #ret-receipt-content table {
  width: 100%;
  table-layout: auto;
  word-wrap: break-word;
  text-align: left;
}
#receipt-content table td, #ret-receipt-content table td,
#receipt-content table th, #ret-receipt-content table th {
  padding: 3px 4px;
  border: none;
  font-size: 12px;
  color: #000;
  white-space: normal;
  word-wrap: break-word;
}

@media print {
  @page {
    margin: 0;
    size: 80mm 150mm;
  }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    width: 80mm !important;
    background: #fff !important;
  }
  body * { visibility: hidden !important; }
  #receipt-modal:not(.hidden), #receipt-modal:not(.hidden) *,
  #ret-receipt-modal:not(.hidden), #ret-receipt-modal:not(.hidden) * {
    visibility: visible !important;
  }
  #receipt-modal:not(.hidden), #ret-receipt-modal:not(.hidden) {
    position: absolute !important;
    top: 0 !important; left: 0 !important; right: 0 !important;
    transform: none !important;
    width: 80mm !important;
    max-width: 80mm !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    background: #fff !important;
    z-index: 99999 !important;
    padding: 2mm !important;
    margin: 0 auto !important;
  }
  #receipt-content, #ret-receipt-content {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
    max-width: 74mm !important;
    margin: 0 auto !important;
    color: #000 !important;
    font-size: 13px !important;
    line-height: 1.6 !important;
    text-align: center !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  #receipt-content *, #ret-receipt-content * {
    color: #000 !important;
  }
  #receipt-content h2, #ret-receipt-content h2 {
    font-size: 15px !important;
    font-weight: 900 !important;
    color: #000 !important;
    margin-bottom: 2px !important;
  }
  #receipt-content p, #ret-receipt-content p {
    font-size: 11px !important;
    color: #000 !important;
    margin: 2px 0 !important;
  }
  #receipt-content table, #ret-receipt-content table {
    width: 100% !important;
    table-layout: auto !important;
    word-wrap: break-word !important;
    overflow: visible !important;
    text-align: left !important;
  }
  #receipt-content table td, #ret-receipt-content table td,
  #receipt-content table th, #ret-receipt-content table th {
    overflow: visible !important;
    white-space: normal !important;
    word-wrap: break-word !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    color: #000 !important;
    padding: 2px 3px !important;
  }
  #receipt-content strong, #ret-receipt-content strong {
    font-weight: 900 !important;
    color: #000 !important;
  }
  .sep {
    border-top: 1px dashed #000 !important;
    margin: 6px 0 !important;
  }
  .hidden { display: none !important; visibility: hidden !important; }
  .no-print { display: none !important; }
  #receipt-overlay, #ret-receipt-overlay { display: none !important; }
  .sidebar, #demo-banner, .app-layout > aside { display: none !important; }
}

/* RETURN TAB */
#btn-confirm-return {
  width: 100%; padding: 14px;
  background: #d97706; color: #fff; border: none;
  border-radius: var(--radius); font-size: 1.1rem; font-weight: 700;
  cursor: pointer; margin-top: 10px; transition: background .15s;
}
#btn-confirm-return:disabled { background: #94a3b8; cursor: not-allowed; }
#btn-confirm-return:not(:disabled):hover { background: #b45309; }

.ret-sale-item {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 6px; cursor: pointer; font-size: 0.82rem; background: #fff;
  transition: all .15s;
}
.ret-sale-item:hover { border-color: var(--primary); background: #eff6ff; }
.ret-sale-item.selected { border-color: var(--success); background: #f0fdf4; }

.refund-badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 0.75rem; font-weight: 700; background: #fee2e2; color: #b91c1c;
}

/* CATEGORY FILTERS */
.cat-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.cat-btn {
  padding: 6px 14px; border-radius: 20px; border: 2px solid var(--border);
  background: #fff; cursor: pointer; font-size: 0.82rem; font-weight: 600;
  color: var(--muted); transition: all .15s;
}
.cat-btn:hover { border-color: var(--primary); color: var(--primary); }
.cat-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.cat-btn .cat-count { font-size: 0.72rem; opacity: 0.8; margin-left: 4px; }

/* CRM */
.star-btn {
  background: none; border: none; font-size: 1.6rem; cursor: pointer;
  color: #d1d5db; transition: color .1s; padding: 0 2px;
}
.star-btn.active { color: #f59e0b; }

.feedback-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; background: #fafafa;
}
.feedback-card .stars { color: #f59e0b; font-size: 1rem; }
.feedback-card .meta { font-size: 0.78rem; color: var(--muted); margin-top:4px; }

.customer-row { cursor: pointer; }
.customer-row:hover td { background: #eff6ff; }

.tag-vip    { background:#fef9c3;color:#854d0e;padding:2px 8px;border-radius:12px;font-size:0.72rem;font-weight:700; }
.tag-gros   { background:#ede9fe;color:#5b21b6;padding:2px 8px;border-radius:12px;font-size:0.72rem;font-weight:700; }
.tag-fidele { background:#dcfce7;color:#14532d;padding:2px 8px;border-radius:12px;font-size:0.72rem;font-weight:700; }

.pos-customer-item {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 4px; cursor: pointer; font-size: 0.83rem; background:#fff;
}
.pos-customer-item:hover { border-color: var(--primary); background: #eff6ff; }

.points-badge { background:#7c3aed;color:#fff;padding:2px 8px;border-radius:12px;font-size:0.75rem;font-weight:700; }

#customer-detail-modal { width: 680px; }
.detail-section { margin-bottom: 16px; }
.detail-section h3 { font-size:0.9rem;color:var(--muted);margin-bottom:8px;text-transform:uppercase;letter-spacing:.04em; }

/* COMM MODAL */
#comm-modal { width: 520px; }
#comm-modal textarea { outline: none; }
#comm-modal textarea:focus { border-color: var(--primary); }

/* ANALYTICS DASHBOARD */
.dash-filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 16px;
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.dash-filter-btn {
  padding: 7px 16px; border-radius: 20px; border: 2px solid var(--border);
  background: #fff; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  color: var(--muted); transition: all .15s;
}
.dash-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.dash-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.dash-filter-bar input[type="date"] {
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.85rem;
}
.stat-delta {
  font-size: 0.75rem; font-weight: 600; margin-top: 4px; min-height: 16px;
}
.stat-delta.up   { color: #16a34a; }
.stat-delta.down { color: #dc2626; }
.stat-delta.flat { color: #94a3b8; }

/* CAMPAIGNS */
#tab-campaigns .card { margin-bottom: 0; }
#tab-campaigns .cat-btn { text-align: left; width: 100%; }

/* ALL MODALS - ensure centered popup */
#customer-modal, #customer-detail-modal, #sup-modal, #sup-detail-modal, #purchase-modal, #user-modal, #comm-modal {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  z-index: 201;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

#customer-overlay, #customer-detail-overlay, #sup-overlay, #sup-detail-overlay, #purchase-overlay, #user-overlay, #comm-overlay {
  position: fixed !important;
  inset: 0 !important;
  background: rgba(0,0,0,.45) !important;
  z-index: 200 !important;
}

/* Sidebar bottom section */
.sidebar > div:last-of-type { flex-shrink: 0; }
.sidebar-clock { flex-shrink: 0; padding: 8px 16px; font-size: 0.75rem; color: #64748b; border-top: 1px solid rgba(255,255,255,0.08); }

/* Marketing sub-tabs */
.mkt-sub { animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile & Tablet
   ═══════════════════════════════════════════════════════════════ */

/* Mobile top bar — hidden on desktop */
.mobile-topbar {
  display: none;
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 99;
}
.hamburger-btn {
  background: none; border: none; color: #fff;
  font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
}
.mobile-logo { font-weight: 700; font-size: 1rem; }
.mobile-user { margin-left: auto; font-size: 0.78rem; color: #94a3b8; }
.hamburger-close {
  display: none;
  background: none; border: none; color: #94a3b8;
  font-size: 1.2rem; cursor: pointer; padding: 4px;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header .sidebar-logo { padding: 0; border: none; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ── TABLET (< 1024px) ─────────────────────────────────────── */
@media (max-width: 1024px) {
  .pos-layout { grid-template-columns: 1fr !important; }
  .dash-grid { grid-template-columns: 1fr !important; }
  .stats-row { flex-wrap: wrap; }
  .stat-card { min-width: 120px !important; }
  #tab-marketing > div > div:first-child { display: block; }
  #tab-marketing .mkt-sub > div { grid-template-columns: 1fr !important; }
}

/* ── MOBILE (< 768px) ──────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show mobile topbar, hide desktop sidebar */
  .mobile-topbar { display: flex; }
  .hamburger-close { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 101;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; z-index: 100; }

  .main-content { margin-left: 0 !important; }

  /* Tabs */
  .tab { padding: 12px !important; }

  /* POS layout — stack vertically */
  .pos-layout { grid-template-columns: 1fr !important; gap: 10px !important; }
  .pos-left, .pos-right { width: 100% !important; }

  /* Cart scroll */
  .cart-scroll { max-height: 200px !important; }

  /* Tables — horizontal scroll */
  table { display: block; overflow-x: auto; white-space: nowrap; }
  thead, tbody, tr { display: table; width: 100%; table-layout: auto; }

  /* Stats row */
  .stats-row { gap: 8px !important; }
  .stat-card { min-width: 90px !important; padding: 12px !important; }
  .stat-val { font-size: 1.2rem !important; }
  .stat-label { font-size: 0.68rem !important; }

  /* Dashboard grids */
  .dash-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .dash-filter-bar { flex-wrap: wrap; gap: 6px !important; padding: 8px 10px !important; }
  .dash-filter-btn { padding: 5px 10px !important; font-size: 0.78rem !important; }

  /* Modals — full screen on mobile */
  #modal, #receipt-modal, #ret-receipt-modal, #customer-modal,
  #customer-detail-modal, #sup-modal, #sup-detail-modal,
  #purchase-modal, #user-modal, #comm-modal,
  #quick-add-product {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    border-radius: 0 !important;
  }

  /* Form grids */
  .form-grid { grid-template-columns: 1fr !important; }

  /* Toolbar */
  .toolbar { flex-direction: column; align-items: stretch !important; }
  .toolbar input { min-width: unset !important; }

  /* Category filters */
  .cat-filters { flex-wrap: wrap; gap: 6px !important; }
  .cat-btn { padding: 4px 10px !important; font-size: 0.78rem !important; }

  /* Scan box */
  .scan-row { flex-direction: column; gap: 6px !important; }
  .scan-row input { width: 100% !important; }
  .scan-row button { width: 100% !important; }

  /* Payment buttons */
  .pay-btns { flex-direction: column; }

  /* Cart total */
  .cart-total { font-size: 1rem !important; }
  #btn-checkout { font-size: 0.95rem !important; padding: 12px !important; }

  /* Discount section */
  #discount-section { padding: 6px 0 !important; }

  /* Marketing sub-tabs */
  #tab-marketing > div:first-child { flex-wrap: wrap; }

  /* Charges layout */
  #tab-charges > div { grid-template-columns: 1fr !important; }

  /* Feedback layout */
  #tab-feedback > div { grid-template-columns: 1fr !important; }

  /* Campaigns layout */
  .mkt-sub > div { grid-template-columns: 1fr !important; }

  /* Suppliers layout */
  #tab-suppliers .stats-row { gap: 6px; }

  /* Hide less important columns on mobile */
  .hide-mobile { display: none !important; }

  /* Bigger touch targets */
  .btn-icon { padding: 8px 10px !important; font-size: 1.1rem !important; }
  button, select, input { min-height: 40px; }
}

/* ── SMALL MOBILE (< 480px) ────────────────────────────────── */
@media (max-width: 480px) {
  .stats-row { gap: 4px !important; }
  .stat-card { min-width: 70px !important; padding: 8px !important; }
  .stat-val { font-size: 1rem !important; }
  .card { padding: 10px !important; }
  .card h2, .card h3 { font-size: 0.9rem !important; }
}
