:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --border: #334155;
  --success: #10b981;
  --danger: #ef4444;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Header */
.header {
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}
.header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.nav { display: flex; gap: 24px; align-items: center; }
.nav-link {
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color .2s;
}
.nav-link:hover, .nav-link.active { color: var(--text); }
.cart-link {
  position: relative;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.cart-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
}

/* Hero */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}
.hero h1 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { color: var(--text2); font-size: 16px; }

/* Filters */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.filter-btn:hover { background: var(--bg-hover); color: var(--text); }
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Search */
.search-bar { margin-bottom: 24px; }
.search-bar input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar input::placeholder { color: var(--text3); }

/* Products Grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 48px;
}

.product-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--bg-hover);
}

.product-info { padding: 16px; }
.product-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 6px;
}
.product-desc {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 12px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.product-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--success);
}
.product-price small {
  font-size: 12px;
  font-weight: 400;
  color: var(--text3);
}
.btn {
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.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: #059669; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.loading {
  grid-column: 1/-1;
  text-align: center;
  color: var(--text3);
  padding: 48px;
}

/* Cart page */
.cart-page { padding: 32px 0; }
.cart-page h1 { font-size: 24px; margin-bottom: 24px; }
.cart-item {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  align-items: center;
}
.cart-item img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
}
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; margin-bottom: 4px; }
.cart-item-price { color: var(--success); font-weight: 600; }
.cart-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cart-summary {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-top: 24px;
}
.cart-total {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 16px;
}
.cart-total span { color: var(--success); }

/* Checkout form */
.checkout-form { margin-top: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
}
.form-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); }

/* Success page */
.success-page {
  text-align: center;
  padding: 80px 0;
}
.success-icon { font-size: 64px; margin-bottom: 16px; }
.success-page h1 { font-size: 28px; margin-bottom: 12px; }
.success-page p { color: var(--text2); margin-bottom: 24px; }

.empty-cart {
  text-align: center;
  padding: 60px 0;
  color: var(--text3);
}
.empty-cart p { margin-bottom: 16px; }

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text3);
  font-size: 13px;
  margin-top: 48px;
}
.footer-note { margin-top: 4px; font-size: 11px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--success);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: all .3s;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Pagination */
.pagination { display: flex; justify-content: center; gap: 6px; margin: 32px 0; flex-wrap: wrap; }
.page-btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text2); font-size: 13px;
  cursor: pointer; transition: all .2s; min-width: 36px; text-align: center;
}
.page-btn:hover { background: var(--bg-hover); color: var(--text); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .3; cursor: not-allowed; }

/* Login overlay */
.login-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 10000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: var(--bg-card); border-radius: 16px; padding: 40px 32px;
  border: 1px solid var(--border); text-align: center; width: 90%; max-width: 380px;
}
.login-box h2 { font-size: 20px; margin-bottom: 8px; }
.login-box p { color: var(--text3); font-size: 13px; margin-bottom: 24px; }
.login-box input {
  width: 100%; padding: 12px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; outline: none;
}
.login-box input:focus { border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; display: none; }

/* Category management */
.cat-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.cat-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 16px; font-size: 12px; font-weight: 500;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
}
.cat-tag .del {
  cursor: pointer; color: var(--text3); font-size: 14px; line-height: 1;
  transition: color .2s;
}
.cat-tag .del:hover { color: var(--danger); }

/* ── Mobile: ≤768px ── */
@media (max-width: 768px) {
  .container { padding: 0 14px; }

  /* Header */
  .header { padding: 12px 0; }
  .logo { font-size: 16px; }
  .nav { gap: 12px; }
  .nav-link { font-size: 12px; padding: 6px 10px; }
  .cart-link { padding: 6px 10px; }

  /* Hero */
  .hero { padding: 28px 0 20px; }
  .hero h1 { font-size: 22px; }
  .hero p { font-size: 13px; }

  /* Filters */
  .filters { gap: 6px; }
  .filter-btn { padding: 6px 14px; font-size: 12px; }

  /* Products grid */
  .products-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .product-image { height: 140px; }
  .product-info { padding: 10px; }
  .product-name { font-size: 13px; margin-bottom: 4px; }
  .product-desc { font-size: 11px; -webkit-line-clamp: 2; margin-bottom: 8px; }
  .product-footer { flex-direction: column; align-items: flex-start; gap: 8px; }
  .product-price { font-size: 16px; }
  .btn { padding: 7px 14px; font-size: 12px; }

  /* Cart */
  .cart-page { padding: 16px 0; }
  .cart-page h1 { font-size: 18px; margin-bottom: 16px; }
  .cart-item { flex-direction: column; text-align: center; gap: 10px; padding: 12px; }
  .cart-item img { width: 100%; height: 160px; border-radius: 8px; }
  .cart-item-actions { justify-content: center; }
  .cart-summary { padding: 16px; }
  .cart-total { font-size: 20px; }

  /* Checkout */
  .checkout-layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 0; }
  .checkout-form-card { padding: 16px; }
  .form-row { grid-template-columns: 1fr !important; }
  .summary-items { max-height: 200px; }
  .summary-item { gap: 8px; padding: 8px 0; }
  .summary-item img { width: 40px; height: 40px; }
  .pay-btn { padding: 14px; font-size: 15px; }

  /* Success page */
  .success-page { padding: 40px 0; }
  .success-icon { font-size: 48px; }
  .success-page h1 { font-size: 22px; }

  /* Pagination */
  .pagination { margin: 20px 0; gap: 4px; }
  .page-btn { padding: 6px 10px; font-size: 12px; min-width: 32px; }

  /* Footer */
  .footer { padding: 16px 0; margin-top: 32px; }
}

/* ── Mobile: ≤480px ── */
@media (max-width: 480px) {
  .container { padding: 0 12px; }

  /* Header */
  .nav { gap: 8px; }
  .nav-link { font-size: 11px; padding: 5px 8px; }
  .cart-link { padding: 5px 8px; font-size: 11px; }

  /* Hero */
  .hero { padding: 20px 0 16px; }
  .hero h1 { font-size: 18px; }
  .hero p { font-size: 12px; }

  /* Products: single column on very small screens */
  .products-grid { grid-template-columns: 1fr; gap: 12px; }
  .product-image { height: 180px; }

  /* Cart */
  .cart-item img { height: 140px; }

  /* Checkout */
  .checkout-layout { padding: 12px 0; }
  .checkout-form-card { padding: 14px; border-radius: 10px; }
  .summary-item img { width: 36px; height: 36px; }
  .summary-item-name { font-size: 12px; }
  .summary-item-price { font-size: 13px; }

  /* Toast: full width on small screens */
  .toast { left: 12px; right: 12px; bottom: 12px; text-align: center; }

  /* Login */
  .login-box { padding: 28px 20px; border-radius: 12px; }
  .login-box h2 { font-size: 18px; }
}

/* ── Admin pages mobile ── */
@media (max-width: 768px) {
  .admin-header { flex-direction: column; align-items: flex-start; }
  .admin-header h1 { font-size: 18px; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
  .stat-card .num { font-size: 22px; }

  .toolbar { flex-direction: column; }
  .toolbar input { min-width: 100%; }
  .toolbar select { width: 100%; }

  .cat-add { flex-direction: column; }
  .cat-add input { max-width: 100% !important; }

  .product-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .product-table th, .product-table td { padding: 8px 10px; font-size: 12px; white-space: nowrap; }

  .order-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .order-table th, .order-table td { padding: 8px 10px; font-size: 12px; white-space: nowrap; }

  .detail-grid { grid-template-columns: 1fr; }
  .detail-card { padding: 16px; }
  .detail-product { gap: 8px; }
  .detail-product img { width: 40px; height: 40px; }

  .modal-box { width: 95%; padding: 20px; border-radius: 12px; max-height: 85vh; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; }

  .admin-header .btn { font-size: 12px; padding: 8px 14px; }
}

/* ── Checkout page mobile ── */
@media (max-width: 768px) {
  .checkout-layout { grid-template-columns: 1fr; }
  .order-summary { order: -1; }
}

/* ── Cart badge fix on small screens ── */
@media (max-width: 380px) {
  .cart-badge { display: none; }
}
