/* Light theme (default variables) */
:root,
[data-theme="light"] {
  --bg: #f5f0e8;
  --surface: #ffffff;
  --surface-2: #ebe4d9;
  --accent: #b83227;
  --accent-hover: #d4463a;
  --gold: #9a7228;
  --text: #2c2419;
  --muted: #6b5d4f;
  --border: #d4c9b8;
  --success: #1e8449;
  --shadow: rgba(44, 36, 25, 0.12);
  --radius: 12px;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0a0806;
  --surface: #161210;
  --surface-2: #241e19;
  --accent: #c0392b;
  --accent-hover: #e74c3c;
  --gold: #d4a853;
  --text: #ece4d8;
  --muted: #9a8878;
  --border: #3a322a;
  --success: #27ae60;
  --shadow: rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.page-section { padding: 1.5rem 1rem 3rem; }
.page-title { color: var(--gold); margin-bottom: 1rem; font-size: clamp(1.35rem, 4vw, 1.75rem); }
.empty-state { color: var(--muted); grid-column: 1 / -1; text-align: center; padding: 2rem; }
.form-footer { text-align: center; margin-top: 1rem; color: var(--muted); font-size: 0.9rem; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.logo {
  font-size: clamp(1.1rem, 3.5vw, 1.4rem);
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.logo span { color: var(--accent); }

.nav-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  font-size: 1.2rem;
  cursor: pointer;
}

.main-nav {
  display: flex;
  gap: 0.75rem 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--text);
  font-size: 0.9rem;
}

.main-nav a:hover { color: var(--gold); text-decoration: none; }

.cart-badge {
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

.hero {
  text-align: center;
  padding: clamp(2rem, 6vw, 3rem) 1rem 1.5rem;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
}

.hero h1 {
  font-size: clamp(1.5rem, 5vw, 2rem);
  margin-bottom: 0.5rem;
  color: var(--gold);
}

.hero p {
  color: var(--muted);
  max-width: 520px;
  margin: 0 auto;
  font-size: clamp(0.9rem, 2.5vw, 1rem);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 1.25rem;
  padding: 1.5rem 0 3rem;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
}

.product-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 3rem;
}

.product-image img { width: 100%; height: 100%; object-fit: cover; }

.product-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; }
.product-body h3 { font-size: 1.05rem; margin-bottom: 0.25rem; }

.product-body p.desc {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  margin-top: auto;
}

.price { font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.stock { font-size: 0.8rem; color: var(--muted); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.badge-normal { background: #34495e; color: #ecf0f1; }
.badge-sold { background: #7f8c8d; color: #fff; }
.badge-last-few { background: #e67e22; color: #fff; }
.badge-discount { background: #8e44ad; color: #fff; }
.badge-promotion { background: var(--accent); color: #fff; }

.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
  text-align: center;
}

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #666; cursor: not-allowed; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-gold { background: var(--gold); color: #fff; font-weight: 600; }
[data-theme="light"] .btn-gold { color: #fff; }
.btn-gold:hover { filter: brightness(1.08); }
.btn-block { width: 100%; }

.form-card,
.settings-card,
.order-success-card {
  max-width: 420px;
  margin: 2rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 4vw, 2rem);
}

.form-card h2,
.settings-card h2,
.order-success-card h2 {
  margin-bottom: 1.25rem;
  color: var(--gold);
  text-align: center;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
}

.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--gold);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-error { background: rgba(192, 57, 43, 0.15); border: 1px solid var(--accent); color: var(--accent); }
.alert-success { background: rgba(39, 174, 96, 0.15); border: 1px solid var(--success); color: var(--success); }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1rem 0; }

.cart-table, .admin-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
}

.cart-table th, .cart-table td,
.admin-table th, .admin-table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.cart-table th, .admin-table th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.qty-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.qty-input { width: 4rem; padding: 0.35rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); color: var(--text); }

.summary-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  max-width: 360px;
  margin-left: auto;
}

.checkout-page .summary-box { max-width: none; }

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.summary-row.total {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold);
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
}

.discount-line { color: var(--success); }
.checkout-btn { margin-top: 1rem; }

.checkout-grid {
  display: grid;
  grid-template-columns: 1fr min(360px, 100%);
  gap: 1.5rem;
  align-items: start;
}

.checkout-fields {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.discount-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.discount-row input { flex: 1; min-width: 140px; }

.discount-preview { color: var(--success); font-size: 0.9rem; margin-top: 0.5rem; }

footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* Admin */
.admin-layout { display: flex; min-height: calc(100vh - 56px); }

.admin-sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  flex-shrink: 0;
}

.admin-sidebar h3 {
  color: var(--gold);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  padding: 0 0.5rem;
}

.admin-sidebar a {
  display: block;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  border-radius: 8px;
  margin-bottom: 0.2rem;
  font-size: 0.88rem;
}

.admin-sidebar a:hover,
.admin-sidebar a.active {
  background: var(--surface-2);
  color: var(--gold);
  text-decoration: none;
}

.admin-content { flex: 1; padding: clamp(1rem, 3vw, 2rem); min-width: 0; }

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.admin-header h1 { font-size: clamp(1.25rem, 4vw, 1.5rem); color: var(--gold); }
.admin-email, .admin-hint { color: var(--muted); font-size: 0.9rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}

.stat-card .value { font-size: clamp(1.5rem, 5vw, 2rem); font-weight: 700; color: var(--gold); }
.stat-card .label { color: var(--muted); font-size: 0.85rem; }

.admin-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.admin-form h3 { margin-bottom: 1rem; color: var(--gold); font-size: 1rem; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
  gap: 1rem;
}

.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }

/* Responsive */
@media (max-width: 768px) {
  .nav-toggle { display: block; }

  .main-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem 1rem;
    box-shadow: 0 8px 20px var(--shadow);
  }

  .main-nav.open { display: flex; }

  .main-nav a { padding: 0.5rem 0; }

  header .container { position: relative; }

  .admin-layout { flex-direction: column; }

  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
  }

  .admin-sidebar h3 { width: 100%; margin-bottom: 0.25rem; }
  .admin-sidebar a { display: inline-block; margin: 0; }

  .checkout-grid { grid-template-columns: 1fr; }

  .summary-box { margin-left: 0; max-width: none; }

  .cart-table { min-width: 0; }

  .cart-table thead { display: none; }

  .cart-table tr {
    display: block;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    background: var(--surface);
  }

  .cart-table td {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    border: none;
    padding: 0.35rem 0;
  }

  .cart-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.8rem;
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .product-grid { grid-template-columns: 1fr; }
  .discount-row { flex-direction: column; }
  .discount-row .btn { width: 100%; }
}
