* {
  box-sizing: border-box;
}

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 14px 35px rgba(15, 23, 42, .10);
  --radius: 18px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

.shop-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.shop-header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  font-weight: 900;
}

.brand strong {
  display: block;
  font-size: 18px;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.shop-nav, .admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.shop-nav a {
  padding: 9px 12px;
  border-radius: 999px;
  color: #374151;
}

.shop-nav a:hover {
  background: var(--surface-2);
}

.cart-pill {
  display: inline-flex;
  min-width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: 12px;
  margin-left: 4px;
}

.hero {
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, .22), transparent 34%),
    linear-gradient(135deg, #0f172a, #1e293b);
  color: white;
}

.hero-content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 72px 20px;
}

.eyebrow {
  color: #60a5fa;
  font-size: 12px;
  letter-spacing: .14em;
  font-weight: 800;
}

.hero h1 {
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.05;
  max-width: 760px;
  margin: 14px 0;
}

.hero p {
  color: #cbd5e1;
  max-width: 680px;
  font-size: 18px;
  line-height: 1.7;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 0;
  cursor: pointer;
  font-weight: 800;
  background: #e5e7eb;
  color: #111827;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  color: white;
  background: var(--primary);
  box-shadow: 0 10px 22px rgba(37, 99, 235, .25);
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  color: white;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.24);
}

.btn.ghost.dark {
  color: var(--text);
  background: white;
  border: 1px solid var(--line);
}

.btn.danger {
  background: var(--danger);
  color: white;
}

.btn.small {
  min-height: 34px;
  padding: 7px 12px;
}

.btn.full {
  width: 100%;
}

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

.shop-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 20px 60px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.section-title h1, .section-title h2 {
  margin: 6px 0 0;
  font-size: 30px;
}

.section-title p {
  margin: 0;
  color: var(--muted);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
  transition: transform .18s ease, box-shadow .18s ease;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.product-image {
  position: relative;
  aspect-ratio: 1 / .76;
  background: #e5e7eb;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #dbeafe, #ede9fe);
}

.image-placeholder span {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: white;
  color: var(--primary);
  font-size: 32px;
  font-weight: 900;
}

.badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(22, 163, 74, .92);
  color: white;
  font-size: 12px;
  font-weight: 800;
}

.badge.soldout {
  background: rgba(220, 38, 38, .92);
}

.product-body {
  padding: 15px;
}

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 9px;
}

.product-meta span {
  font-size: 11px;
  color: #475569;
  background: #f1f5f9;
  padding: 4px 7px;
  border-radius: 999px;
}

.product-body h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.desc {
  min-height: 48px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 9px 0 14px;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.price {
  font-size: 21px;
  font-weight: 900;
}

.product-footer small {
  color: var(--muted);
}

.add-cart {
  background: #111827;
  color: white;
  min-width: 70px;
}

.shop-footer {
  border-top: 1px solid var(--line);
  padding: 26px 20px;
  text-align: center;
  color: var(--muted);
  background: white;
}

.cart-layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
}

.cart-panel, .checkout-panel, .empty-card, .form-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
  padding: 20px;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr 110px 100px 120px 80px;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.cart-item strong {
  display: block;
}

.cart-item small {
  color: var(--muted);
}

.cart-item input {
  margin: 0;
}

.cart-price, .cart-subtotal {
  font-weight: 800;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  padding-top: 18px;
  font-size: 20px;
}

.cart-total strong {
  font-size: 26px;
}

input, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  margin: 7px 0 14px;
  font: inherit;
  background: white;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

label {
  font-weight: 700;
}

.alert {
  border-radius: 12px;
  padding: 12px;
  margin: 12px 0;
}

.alert.error {
  background: #fee2e2;
  color: #991b1b;
}

.success-card {
  background: #ecfdf5;
  color: #065f46;
  border-radius: 14px;
  padding: 16px;
  margin-top: 14px;
}

.success-card h2 {
  margin: 8px 0;
  font-size: 24px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: white;
  padding: 12px 16px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Admin */
.admin-body {
  background: #f8fafc;
}

.admin-header {
  padding: 20px;
  background: #111827;
  color: white;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.admin-header h1 {
  margin: 0 0 6px;
}

.admin-header p {
  margin: 0;
  color: #cbd5e1;
}

.admin-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px;
}

.admin-main.narrow {
  max-width: 820px;
}

.search-form {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.search-form input {
  margin: 0;
}

.admin-table-wrap {
  overflow: auto;
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.table th, .table td {
  padding: 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: #f8fafc;
  font-size: 13px;
  color: #475569;
}

.admin-thumb {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  object-fit: cover;
}

.thumb-empty {
  display: inline-flex;
  width: 58px;
  height: 58px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 13px;
}

.status {
  display: inline-flex;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.active {
  background: #dcfce7;
  color: #166534;
}

.status.inactive {
  background: #fee2e2;
  color: #991b1b;
}

.link-btn {
  color: var(--primary);
  font-weight: 800;
}

.form-card {
  padding: 24px;
}

.product-form .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: auto;
  margin: 0;
}

.current-image {
  margin: 0 0 16px;
}

.current-image span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.current-image img {
  width: 180px;
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
}

code {
  background: #eef2ff;
  color: #3730a3;
  padding: 4px 7px;
  border-radius: 8px;
  font-weight: 800;
}

/* legacy login/admin compatibility */
.site-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
  background: #111827;
  color: white;
}

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

.container.wide {
  max-width: 1280px;
}

.card, .checkout-box {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .08);
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: white;
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

/* RWD */
@media (max-width: 1100px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cart-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shop-header-inner, .admin-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .shop-nav, .admin-actions {
    width: 100%;
  }

  .shop-nav a, .admin-actions a {
    flex: 1;
    text-align: center;
  }

  .hero-content {
    padding: 46px 20px;
  }

  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .product-body {
    padding: 12px;
  }

  .product-body h3 {
    font-size: 16px;
  }

  .price {
    font-size: 18px;
  }

  .cart-item {
    grid-template-columns: 1fr;
    background: #f8fafc;
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 10px;
    border-bottom: 0;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .product-form .form-grid {
    grid-template-columns: 1fr;
  }

  .table {
    min-width: 850px;
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: 1fr;
  }

  .hero h1 {
    font-size: 30px;
  }

  .hero p {
    font-size: 16px;
  }

  .shop-main, .cart-layout, .admin-main {
    padding-left: 12px;
    padding-right: 12px;
  }
}
