/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #1e293b;
  background: #f8fafc;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.header {
  background: #1a3a1a;
  color: #fff;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.header-left { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.header-brand { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 1.15rem; font-weight: 600; line-height: 1.2; }
.header-center { flex: 1; max-width: 420px; }
.header-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.header-logo { height: 44px; width: auto; }

.sidebar-toggle {
  display: none;
  background: none; border: none; color: #fff; cursor: pointer; padding: 4px;
}

/* Search */
.search-box {
  position: relative; display: flex; align-items: center;
  background: #244d24; border-radius: 8px; padding: 0 12px;
}
.search-icon { color: #7cb87c; flex-shrink: 0; }
.search-box input {
  background: none; border: none; color: #fff; padding: 8px 8px;
  width: 100%; font-size: 0.9rem; outline: none;
}
.search-box input::placeholder { color: #7cb87c; }
.search-clear {
  background: none; border: none; color: #64748b; cursor: pointer;
  font-size: 1.2rem; padding: 0 4px; display: none;
}
.search-clear.visible { display: block; }

/* Sort */
.sort-control { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; }
.sort-control label { color: #a3c9a3; white-space: nowrap; }
.sort-control select {
  background: #244d24; color: #fff; border: 1px solid #3d6b3d;
  border-radius: 6px; padding: 5px 8px; font-size: 0.8rem; cursor: pointer;
}

/* Cart button */
.cart-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  position: relative; padding: 6px;
}
.cart-badge {
  position: absolute; top: -2px; right: -4px;
  background: #8cb63c; color: #fff; font-size: 0.65rem; font-weight: 700;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.cart-badge:empty, .cart-badge[data-count="0"] { display: none; }

/* === Layout === */
.layout { display: flex; flex: 1; }

/* === Sidebar === */
.sidebar {
  width: 260px; flex-shrink: 0;
  background: #fff; border-right: 1px solid #e2e8f0;
  height: calc(100vh - 60px); position: sticky; top: 60px;
  overflow-y: auto; padding: 12px 0;
}
.sidebar-backdrop { display: none; }
.sidebar-header { padding: 0 16px 8px; }
.sidebar-all {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; cursor: pointer;
  font-size: 0.95rem; font-weight: 600; color: #0f172a; padding: 8px 12px;
  border-radius: 6px; transition: background .15s;
}
.sidebar-all:hover { background: #f1f5f9; }
.sidebar-all.active { background: #f0f7e6; color: #4a7c2e; }
.product-count {
  font-size: 0.75rem; font-weight: 500; color: #64748b;
  background: #f1f5f9; padding: 2px 8px; border-radius: 10px;
}

/* Category Groups */
.cat-group { margin-bottom: 4px; }
.cat-group-header {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; cursor: pointer; font-weight: 600; font-size: 0.8rem;
  color: #64748b; text-transform: uppercase; letter-spacing: 0.5px;
  user-select: none;
}
.cat-group-header:hover { color: #334155; }
.cat-group-arrow {
  transition: transform .2s; font-size: 0.7rem;
}
.cat-group.collapsed .cat-group-arrow { transform: rotate(-90deg); }
.cat-group.collapsed .cat-group-items { display: none; }
.cat-group-items { padding: 0 8px; }
.cat-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; margin: 1px 0; cursor: pointer;
  border-radius: 6px; font-size: 0.85rem; color: #475569;
  transition: background .15s;
}
.cat-item:hover { background: #f1f5f9; }
.cat-item.active { background: #f0f7e6; color: #4a7c2e; font-weight: 500; }
.cat-item-count { font-size: 0.75rem; color: #94a3b8; }

/* === Main Content === */
.main { flex: 1; padding: 16px 20px; min-width: 0; }
.breadcrumb {
  font-size: 0.85rem; color: #64748b; margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}
.breadcrumb-link { color: #4a7c2e; cursor: pointer; }
.breadcrumb-link:hover { text-decoration: underline; }
.breadcrumb-sep { color: #cbd5e1; }

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.no-results {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 60px 20px; color: #94a3b8;
}

/* Product Card */
.product-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  overflow: hidden; cursor: pointer;
  transition: box-shadow .2s, transform .15s;
}
.product-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  transform: translateY(-2px);
}
.card-image {
  width: 100%; aspect-ratio: 1; background: #f8fafc;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; border-bottom: 1px solid #f1f5f9;
}
.card-image img {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
.card-body { padding: 12px; }
.card-sku { font-size: 0.7rem; color: #94a3b8; margin-bottom: 4px; font-family: monospace; }
.card-desc {
  font-size: 0.85rem; font-weight: 500; color: #1e293b;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 2.4em; margin-bottom: 8px;
}
.card-price { font-size: 1rem; font-weight: 700; color: #0f172a; margin-bottom: 4px; }
.card-price.tba { color: #94a3b8; font-weight: 500; }
.card-stock { font-size: 0.75rem; display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.stock-dot {
  width: 7px; height: 7px; border-radius: 50; display: inline-block;
  border-radius: 50%;
}
.stock-dot.in-stock { background: #22c55e; }
.stock-dot.out-of-stock { background: #ef4444; }
.card-footer {
  display: flex; align-items: center; gap: 6px;
  border-top: 1px solid #f1f5f9; padding: 10px 12px;
}

/* Quantity Control */
.qty-control { display: flex; align-items: center; border: 1px solid #e2e8f0; border-radius: 6px; overflow: hidden; }
.qty-btn {
  width: 30px; height: 30px; border: none; background: #f8fafc;
  cursor: pointer; font-size: 1rem; color: #475569; display: flex;
  align-items: center; justify-content: center;
}
.qty-btn:hover { background: #e2e8f0; }
.qty-input {
  width: 36px; height: 30px; border: none; text-align: center;
  font-size: 0.85rem; -moz-appearance: textfield;
  border-left: 1px solid #e2e8f0; border-right: 1px solid #e2e8f0;
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Buttons */
.btn {
  padding: 7px 14px; border-radius: 6px; font-size: 0.8rem;
  font-weight: 500; cursor: pointer; transition: background .15s;
  border: none; white-space: nowrap;
}
.btn-primary { background: #4a7c2e; color: #fff; }
.btn-primary:hover { background: #3d6824; }
.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-outline { background: #fff; border: 1px solid #e2e8f0; color: #475569; }
.btn-outline:hover { background: #f1f5f9; }
.btn-add { flex: 1; }

/* === Shopping List Panel === */
.cart-overlay { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.cart-overlay.open { pointer-events: auto; }
.cart-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; transition: opacity .25s;
}
.cart-overlay.open .cart-backdrop { opacity: 1; }
.cart-panel {
  position: absolute; right: 0; top: 0; bottom: 0; width: 420px;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.1);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
.cart-overlay.open .cart-panel { transform: translateX(0); }
.cart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #e2e8f0;
}
.cart-header h2 { font-size: 1.1rem; font-weight: 600; }
.cart-close {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: #64748b; padding: 0 4px;
}
.cart-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.cart-empty { text-align: center; padding: 40px 0; color: #94a3b8; }
.cart-empty p { margin-top: 12px; }
.cart-empty-hint { font-size: 0.8rem; }
.cart-items { display: flex; flex-direction: column; gap: 4px; }
.cart-group-header {
  font-size: 0.75rem; font-weight: 600; color: #64748b;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 12px 0 4px; border-bottom: 1px solid #f1f5f9;
}
.cart-group-header:first-child { padding-top: 0; }
.cart-line {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid #f8fafc;
}
.cart-line-desc { flex: 1; font-size: 0.8rem; min-width: 0; }
.cart-line-desc span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-line-sku { font-size: 0.65rem; color: #94a3b8; font-family: monospace; }
.cart-line-qty { width: 50px; }
.cart-line-qty input {
  width: 100%; text-align: center; border: 1px solid #e2e8f0;
  border-radius: 4px; padding: 3px; font-size: 0.8rem;
}
.cart-line-total { font-weight: 600; font-size: 0.85rem; white-space: nowrap; min-width: 70px; text-align: right; }
.cart-line-remove {
  background: none; border: none; color: #ef4444; cursor: pointer;
  font-size: 1.1rem; padding: 0 2px; opacity: .5;
}
.cart-line-remove:hover { opacity: 1; }
.cart-subtotal {
  display: flex; justify-content: space-between; padding: 6px 0 2px;
  font-size: 0.8rem; font-weight: 600; color: #475569;
}
.cart-install-line { font-weight: 500; color: #4a7c2e; font-style: italic; }
.cart-footer {
  padding: 16px 20px; border-top: 1px solid #e2e8f0;
}
.cart-total {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 4px;
}
.cart-total span:first-child { font-weight: 500; color: #475569; }
.cart-total-amount { font-size: 1rem; font-weight: 600; color: #0f172a; }
.cart-total-line { padding: 2px 0; }
.cart-total-grand {
  margin-top: 6px; padding-top: 8px;
  border-top: 2px solid #1a3a1a; margin-bottom: 12px;
}
.cart-total-grand .cart-total-amount { font-size: 1.3rem; font-weight: 700; }
.cart-total-grand span:first-child { font-weight: 600; color: #1e293b; }
.cart-actions { display: flex; gap: 8px; }
.cart-actions .btn { flex: 1; text-align: center; }

/* === Detail Modal === */
.modal-overlay { position: fixed; inset: 0; z-index: 300; pointer-events: none; display: flex; align-items: center; justify-content: center; }
.modal-overlay.open { pointer-events: auto; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s;
}
.modal-overlay.open .modal-backdrop { opacity: 1; }
.modal-panel {
  position: relative; background: #fff; border-radius: 12px;
  max-width: 700px; width: 90%; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  transform: scale(.95); opacity: 0; transition: transform .2s, opacity .2s;
}
.modal-overlay.open .modal-panel { transform: scale(1); opacity: 1; }
.modal-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: #64748b; z-index: 1;
}
.modal-body { display: flex; gap: 24px; padding: 32px; }
.modal-image {
  flex-shrink: 0; width: 240px; height: 240px;
  background: #f8fafc; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.modal-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.modal-info { flex: 1; min-width: 0; }
.modal-sku { font-size: 0.75rem; color: #94a3b8; font-family: monospace; margin-bottom: 6px; }
.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; line-height: 1.3; }
.modal-category { font-size: 0.8rem; color: #64748b; margin-bottom: 12px; }
.modal-price { font-size: 1.4rem; font-weight: 700; color: #0f172a; margin-bottom: 8px; }
.modal-price.tba { color: #94a3b8; }
.modal-stock { font-size: 0.85rem; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.modal-link {
  display: inline-block; color: #4a7c2e; font-size: 0.85rem;
  text-decoration: none; margin-bottom: 16px;
}
.modal-link:hover { text-decoration: underline; }
.modal-cart { display: flex; align-items: center; gap: 10px; }

/* === Toast === */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #1a3a1a; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 0.85rem; opacity: 0; transition: transform .3s, opacity .3s;
  z-index: 400; white-space: nowrap; pointer-events: none;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* === Footer === */
.footer {
  background: #fff; border-top: 1px solid #e2e8f0;
  padding: 10px 20px; font-size: 0.75rem; color: #94a3b8;
  display: flex; justify-content: space-between;
}

/* === Print Styles === */
.print-only { display: none; }
@media print {
  body > *:not(.print-only) { display: none !important; }
  .print-only {
    display: block !important; padding: 20px; font-size: 11px;
    color: #000; background: #fff;
  }
  .print-only h2 { font-size: 16px; margin-bottom: 4px; }
  .print-only .print-subtitle { font-size: 11px; color: #666; margin-bottom: 16px; }
  .print-only table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
  .print-only th, .print-only td { border: 1px solid #ddd; padding: 4px 8px; text-align: left; }
  .print-only th { background: #f5f5f5; font-weight: 600; }
  .print-only .text-right { text-align: right; }
  .print-only .subtotal-row td { font-weight: 600; background: #fafafa; }
  .print-only .total-row td { font-weight: 700; font-size: 13px; background: #f0f0f0; }
  .print-only .print-footer { margin-top: 20px; font-size: 10px; color: #888; }
}

/* === Responsive === */
@media (max-width: 1024px) {
  .sidebar { position: fixed; left: -280px; top: 60px; z-index: 150; height: calc(100vh - 60px); transition: left .25s; box-shadow: none; }
  .sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,.1); }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; top: 60px; background: rgba(0,0,0,.3); z-index: 149; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .sidebar-toggle { display: flex; }
  .sort-control label { display: none; }
}
@media (max-width: 640px) {
  .header { padding: 0 12px; gap: 8px; }
  .header-subtitle { display: none; }
  .header-center { max-width: none; }
  .sort-control { display: none; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .card-body { padding: 8px; }
  .cart-panel { width: 100%; }
  .modal-body { flex-direction: column; padding: 20px; }
  .modal-image { width: 100%; height: 200px; }
}
