/* ===== CSS Variables & Reset ===== */
:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --primary-light: #e8f0fe;
  --accent: #ff6d00;
  --success: #0d904f;
  --danger: #d93025;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #202124;
  --text-light: #5f6368;
  --border: #dadce0;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.15);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .2s ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ===== App Shell ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Top Bar ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,.1);
}
.top-bar h1 {
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
  letter-spacing: -.3px;
}
.top-bar .badge {
  background: var(--accent);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 2px 8px;
  min-width: 22px;
  text-align: center;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  font-size: .68rem;
  color: var(--text-light);
  cursor: pointer;
  transition: color var(--transition);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; fill: currentColor; }

/* ===== Pages ===== */
.page {
  flex: 1;
  padding: 16px;
  padding-bottom: 80px;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Scanner Page ===== */
.scanner-container {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  max-height: 360px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}
#reader { width: 100%; height: 100%; }
.scanner-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scanner-frame {
  width: 85%;
  aspect-ratio: 2.4;
  border: 2px solid rgba(26, 115, 232, .7);
  border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35);
  position: relative;
}
.scanner-frame::before, .scanner-frame::after {
  content: '';
  position: absolute;
  width: 24px; height: 24px;
  border-color: var(--primary);
  border-style: solid;
  border-width: 0;
}
.scanner-frame::before {
  top: -2px; left: -2px;
  border-top-width: 3px; border-left-width: 3px;
  border-top-left-radius: 12px;
}
.scanner-frame::after {
  bottom: -2px; right: -2px;
  border-bottom-width: 3px; border-right-width: 3px;
  border-bottom-right-radius: 12px;
}
.scan-line {
  position: absolute;
  top: 0; left: 10%; width: 80%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: scanLine 2s ease-in-out infinite;
}
@keyframes scanLine { 0%, 100% { top: 5%; } 50% { top: 95%; } }

.scanner-status {
  text-align: center;
  font-size: .8rem;
  padding: 8px 12px;
  border-radius: 0 0 var(--radius) var(--radius);
  margin-top: -4px;
  font-weight: 500;
}
.scanner-status.active {
  background: #e8f5e9;
  color: var(--success);
}
.scanner-status.error {
  background: #fce8e6;
  color: var(--danger);
}

.scan-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.scan-actions button {
  flex: 1;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0a7a42; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b3261e; }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: 8px 14px; font-size: .8rem; border-radius: 6px; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-header h3 { font-size: .9rem; font-weight: 600; }

/* ===== Product List ===== */
.product-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.product-item:last-child { border-bottom: none; }
.product-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.product-info { flex: 1; min-width: 0; }
.product-name { font-weight: 600; font-size: .9rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-sku { font-size: .75rem; color: var(--text-light); }
.product-price { font-weight: 700; font-size: .95rem; color: var(--primary); white-space: nowrap; }

/* ===== Cart Items ===== */
.cart-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item .product-icon { margin-top: 2px; }
.cart-details { flex: 1; min-width: 0; }
.cart-details .product-name { margin-bottom: 6px; }
.qty-control {
  display: flex;
  align-items: center;
  gap: 10px;
}
.qty-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--text);
}
.qty-btn:active { transform: scale(.9); }
.qty-btn.minus:hover { border-color: var(--danger); color: var(--danger); }
.qty-btn.plus:hover { border-color: var(--primary); color: var(--primary); }
.qty-value {
  width: 40px;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
}
.cart-line-total {
  font-weight: 700;
  font-size: .95rem;
  color: var(--primary);
  margin-top: 8px;
}
.cart-remove {
  background: none; border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 4px;
  margin-top: 4px;
}
.cart-remove svg { width: 20px; height: 20px; fill: currentColor; }

/* ===== Cart Summary ===== */
.cart-summary {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  position: sticky;
  bottom: 72px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: .9rem;
}
.summary-row.total {
  border-top: 2px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

/* ===== Invoice Form ===== */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  background: var(--card);
  transition: border-color var(--transition);
  color: var(--text);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .15);
}
.form-group textarea { resize: vertical; min-height: 64px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ===== Manual Add Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn .15s ease;
}
.modal {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp .3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all .3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .95rem; margin-bottom: 16px; }

/* ===== Discount Input ===== */
.discount-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.discount-row select { width: 80px; }
.discount-row input { flex: 1; }

/* ===== Products Page Search ===== */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}
.search-bar input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  font-size: .9rem;
  background: var(--card);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}
.search-bar svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px; height: 20px;
  fill: var(--text-light);
}

/* ===== Responsive ===== */
@media (min-width: 481px) {
  body { background: #e8eaed; }
  #app { box-shadow: 0 0 20px rgba(0,0,0,.1); }
}
