/* ==========================================================================
   MSA Mall - Clean, Minimal & Modern Style System (Light / Dark Theme)
   ========================================================================== */

/* 1. CSS Variables & Theme Definition */
:root {
  /* Common */
  --font-sans: 'Plus Jakarta Sans', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Light Theme (Default) */
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-text: #1d4ed8;

  --success: #10b981;
  --success-subtle: #ecfdf5;
  --success-text: #047857;

  --warning: #f59e0b;
  --error: #ef4444;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --modal-backdrop: rgba(15, 23, 42, 0.4);
}

/* System Dark Theme (when no manual override is set) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-body: #0b0f19;
    --bg-card: #151d2f;
    --bg-card-subtle: #1e293b;
    --bg-hover: #2d3748;
    --border-color: #243048;
    --border-focus: #60a5fa;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-inverse: #0f172a;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-subtle: #1e3a8a33;
    --primary-text: #93c5fd;

    --success: #10b981;
    --success-subtle: #064e3b33;
    --success-text: #6ee7b7;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.7);
    --modal-backdrop: rgba(0, 0, 0, 0.7);
  }
}

/* Explicit Dark Theme override */
:root[data-theme="dark"] {
  --bg-body: #0b0f19;
  --bg-card: #151d2f;
  --bg-card-subtle: #1e293b;
  --bg-hover: #2d3748;
  --border-color: #243048;
  --border-focus: #60a5fa;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-inverse: #0f172a;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: #1e3a8a33;
  --primary-text: #93c5fd;

  --success: #10b981;
  --success-subtle: #064e3b33;
  --success-text: #6ee7b7;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.7);
  --modal-backdrop: rgba(0, 0, 0, 0.7);
}

/* Explicit Light Theme override */
:root[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-text: #1d4ed8;

  --success: #10b981;
  --success-subtle: #ecfdf5;
  --success-text: #047857;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --modal-backdrop: rgba(15, 23, 42, 0.4);
}

/* 2. Base Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

/* 3. Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  transition: var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
}

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

.brand-icon {
  font-size: 24px;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

/* User Badge */
.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  color: var(--text-main);
}

.user-name {
  font-weight: 600;
}

.user-id {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Theme Switcher */
.theme-switcher {
  display: flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 3px;
}

.theme-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  line-height: 1;
  transition: var(--transition);
}

.theme-btn.active {
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

/* Cart Button */
.cart-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

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

.cart-badge {
  background: #ffffff;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
}

/* 4. Main Section & Products */
.main-content {
  margin-top: 32px;
  margin-bottom: 36px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 20px;
}

.section-title-wrap h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.section-desc code {
  background: var(--bg-card-subtle);
  padding: 1px 4px;
  border-radius: 4px;
}

/* Product Grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 24px;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
}

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

.product-img-wrap {
  position: relative;
  width: 100%;
  height: 210px;
  background: var(--bg-card-subtle);
  overflow: hidden;
}

.product-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.product-card:hover .product-img {
  transform: scale(1.05);
}

.product-card-badge-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.product-id-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.product-stock-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  background: rgba(100, 116, 139, 0.8);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.product-stock-tag.in-stock {
  color: #ffffff;
  background: rgba(22, 163, 74, 0.85);
}

.product-card-body {
  padding: 18px 18px 12px 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-name {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-main);
  line-height: 1.35;
}

.product-price {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-text);
  margin-top: 4px;
}

.product-card-actions {
  padding: 0 18px 18px 18px;
}

.btn-card-add {
  width: 100%;
  padding: 10px 16px;
  font-size: 0.92rem;
}

/* 6. Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-card-subtle);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 6px 12px;
}

/* 7. Modals */
.modal {
  margin: auto;
  border: none;
  background: transparent;
  padding: 0;
  max-width: 500px;
  width: 90%;
  border-radius: var(--radius-lg);
  overflow: visible;
}

.modal::backdrop {
  background: var(--modal-backdrop);
  backdrop-filter: blur(4px);
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-title-with-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.endpoint-tag {
  font-size: 0.72rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: monospace;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--bg-card-subtle);
  border-top: 1px solid var(--border-color);
}

/* Detail Modal Specifics */
.modal-product-img-wrap {
  width: 100%;
  height: 220px;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
}

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

.detail-badge-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-badge-wrap .badge {
  background: var(--primary-subtle);
  color: var(--primary-text);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.detail-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
}

.detail-info-row:last-of-type {
  border-bottom: none;
}

.detail-info-row .label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.detail-info-row .value {
  font-weight: 600;
  font-size: 0.95rem;
}

.detail-info-row .value.price {
  font-size: 1.15rem;
  color: var(--primary-text);
}

/* Quantity Control */
.quantity-control {
  display: flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card-subtle);
}

.qty-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-btn:hover {
  background: var(--bg-hover);
}

.quantity-control input {
  width: 44px;
  text-align: center;
  border: none;
  background: var(--bg-card);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
}

/* 8. Cart Items & Summary */
.cart-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.cart-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cart-item-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.cart-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cart-item-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cart-qty-control {
  display: flex;
  align-items: center;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.btn-icon-sm {
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.95rem;
  transition: var(--transition);
}

.btn-icon-sm:hover {
  background: var(--bg-hover);
}

.cart-item-qty-badge {
  background: transparent;
  padding: 0 8px;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}

.btn-delete-cart {
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition);
}

.btn-delete-cart:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #dc2626;
  transform: scale(1.05);
}

.cart-summary {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px dashed var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.summary-row.total-row {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.summary-total-price {
  color: var(--primary-text);
}

/* 9. Checkout & Flow Steps */
.checkout-amount-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary-subtle);
  border: 1px solid var(--primary-text);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.checkout-amount-banner strong {
  font-size: 1.25rem;
  color: var(--primary-text);
}

.flow-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.flow-step {
  display: flex;
  gap: 14px;
  padding: 12px 14px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.flow-step.active {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.flow-step.completed {
  border-color: var(--success);
  background: var(--success-subtle);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.flow-step.active .step-num {
  background: var(--primary);
  color: #fff;
}

.flow-step.completed .step-num {
  background: var(--success);
  color: #fff;
}

.step-content {
  flex-grow: 1;
}

.step-title {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-main);
}

.step-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.step-desc code {
  font-family: monospace;
}

.step-result {
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.flow-step.completed .step-result {
  color: var(--success-text);
  font-weight: 600;
}

/* 10. Logs & Inspector Section */
.logs-section {
  margin-bottom: 40px;
}

.logs-details {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.logs-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  background: var(--bg-card-subtle);
  cursor: pointer;
  user-select: none;
}

.btn-clear-logs {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-clear-logs:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.logs-content {
  padding: 14px 18px;
  max-height: 200px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-item {
  display: flex;
  gap: 10px;
  line-height: 1.4;
}

.log-item.info { color: var(--text-muted); }
.log-item.request { color: var(--primary-text); }
.log-item.success { color: var(--success-text); }
.log-item.error { color: var(--error); }

.log-time {
  font-weight: 700;
  flex-shrink: 0;
}

/* 11. Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.25s ease-out;
  transition: var(--transition);
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.info {
  border-left: 4px solid var(--primary);
}

.toast.error {
  border-left: 4px solid var(--error);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 12. Empty & Loading States */
.empty-state,
.loading-state {
  text-align: center;
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}
