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

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-w: 220px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--text);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.logo-icon { font-size: 28px; }
.logo-title { font-size: 16px; font-weight: 700; }
.logo-sub { font-size: 11px; color: rgba(255,255,255,.5); }

nav { flex: 1; padding: 12px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.1);
}
.store-name { font-weight: 600; font-size: 13px; }
.store-status { font-size: 11px; color: var(--success); margin-top: 2px; }

/* ── Main ───────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page { display: none; height: 100vh; overflow: auto; }
.page.active { display: flex; flex-direction: column; }

/* ── Page Header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 16px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: 8px; font-weight: 600;
  font-size: 13px; cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px; border-radius: 6px; font-size: 14px; }
.btn-icon:hover { background: var(--bg); }

/* ── Card ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin: 0 28px 24px;
}

/* ── POS Layout ─────────────────────────────────────────────── */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: 100vh;
  overflow: hidden;
}

/* Product Panel */
.product-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

.panel-header {
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.search-bar input {
  border: none; background: none; outline: none;
  flex: 1; font-size: 14px; color: var(--text);
}

.category-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.cat-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
}
.cat-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cat-btn:hover:not(.active) { background: var(--bg); }

.product-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  align-content: start;
}

.product-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  position: relative;
}
.product-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.product-card:active { transform: scale(.97); }
.product-card.out-of-stock { opacity: .5; cursor: not-allowed; }
.product-cat-badge {
  font-size: 10px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 6px;
  font-weight: 600;
}
.product-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; line-height: 1.3; }
.product-price { color: var(--primary); font-weight: 700; font-size: 16px; }
.product-stock { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.product-stock.low { color: var(--warn); }
.product-stock.out { color: var(--danger); }

/* Cart Panel */
.cart-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.cart-header h2 { font-size: 16px; font-weight: 700; }

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.cart-empty {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; color: var(--text-muted);
  gap: 8px; padding: 40px;
}
.cart-empty-icon { font-size: 48px; opacity: .3; }
.cart-empty p { font-weight: 500; }

.cart-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 8px;
  transition: background .1s;
}
.cart-item:hover { background: var(--bg); }
.ci-info { flex: 1; min-width: 0; }
.ci-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-price { font-size: 12px; color: var(--text-muted); }
.ci-qty {
  display: flex; align-items: center; gap: 6px;
}
.qty-btn {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); cursor: pointer; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center; transition: all .1s;
}
.qty-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.qty-num { font-weight: 700; min-width: 20px; text-align: center; }
.ci-subtotal { font-weight: 700; font-size: 14px; color: var(--primary); min-width: 60px; text-align: right; }
.ci-remove { color: var(--danger); font-size: 16px; cursor: pointer; opacity: .6; }
.ci-remove:hover { opacity: 1; }

/* Cart Footer */
.cart-footer {
  border-top: 1px solid var(--border);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-totals { display: flex; flex-direction: column; gap: 6px; }
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}
.total-row--grand {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding-top: 8px;
  border-top: 2px solid var(--border);
  margin-top: 4px;
}
.total-row--grand span:last-child { color: var(--primary); }

.discount-input {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; font-size: 12px;
}
.discount-input input {
  border: none; background: none; outline: none;
  width: 60px; text-align: right; font-weight: 600;
}

.payment-methods { display: flex; flex-direction: column; gap: 6px; }
.pm-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.pm-options { display: flex; gap: 6px; flex-wrap: wrap; }
.pm-btn {
  flex: 1; min-width: 70px;
  padding: 7px 6px; font-size: 11px; font-weight: 600;
  border: 2px solid var(--border); border-radius: 8px; background: var(--bg);
  cursor: pointer; transition: all .15s;
}
.pm-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }

.notes-input {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none; background: var(--bg);
}
.notes-input:focus { border-color: var(--primary); }

/* ── Table ──────────────────────────────────────────────────── */
.table-toolbar { padding: 16px; }
.search-input {
  width: 100%; max-width: 360px;
  padding: 8px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.search-input:focus { border-color: var(--primary); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 16px;
  background: var(--bg); font-size: 12px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

.loading { text-align: center; color: var(--text-muted); padding: 32px; }

/* ── Dashboard ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 0 28px 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card--warn { border-color: var(--warn); background: #fffbeb; }
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-val { font-size: 24px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

.chart-card { padding: 20px; }
.chart-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.chart-wrap { height: 220px; position: relative; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 1000;
  align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--text-muted); }
.modal-close:hover { color: var(--danger); }

form { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.form-group input, .form-group select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; width: 100%;
}
.form-group input:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--border); background: var(--bg);
}

/* Receipt */
.modal-receipt { max-width: 360px; }
.receipt { padding: 24px; font-family: 'Courier New', monospace; }
.receipt-header { text-align: center; margin-bottom: 16px; }
.receipt-header h2 { font-size: 20px; font-weight: 700; }
.receipt-header p { font-size: 12px; color: var(--text-muted); }
.receipt-divider { border: none; border-top: 1px dashed var(--border); margin: 12px 0; }
.receipt-item { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 13px; }
.receipt-item-name { flex: 1; }
.receipt-item-qty { width: 40px; text-align: center; color: var(--text-muted); }
.receipt-item-price { width: 80px; text-align: right; }
.receipt-totals { margin-top: 8px; }
.rt-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.rt-total { font-weight: 700; font-size: 16px; margin-top: 8px; }
.receipt-footer { text-align: center; margin-top: 16px; font-size: 12px; color: var(--text-muted); }
.receipt-actions { border-top: 1px solid var(--border); }

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: fixed; top: 0; left: 0; width: 100%; }
  .receipt-actions, .modal-actions { display: none !important; }
}
