:root {
  --primary: #f9d043;
  --primary-dark: #e0b82e;
  --brand-gray: #4a4d52;
  --brand-dark: #1a1a1a;
  --bg: #fffbf0;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #666;
  --border: #ece5d0;
  --success: #2d6a4f;
  --danger: #d00000;
  --warning: #c9920a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--brand-gray); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.navbar {
  background: var(--brand-dark);
  color: white;
  padding: 0.6rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.navbar__bar {
  display: contents;
}

.navbar a { color: var(--primary); font-weight: 600; text-decoration: none; }
.navbar a:hover { color: #fff; text-decoration: none; }
.navbar__nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.navbar .user-email { color: #ccc; font-size: 0.9rem; }

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #444;
  border-radius: 8px;
  background: #333;
  cursor: pointer;
}

.nav-toggle__bar {
  display: block;
  width: 20px;
  height: 2px;
  margin: 0 auto;
  background: var(--primary);
  border-radius: 1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.brand-logo { display: inline-flex; align-items: center; line-height: 0; }
.brand-logo__img { height: 44px; width: auto; display: block; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.flash.notice { background: #fff8dc; color: #7a6200; border: 1px solid var(--primary); }
.flash.alert { background: #ffe5e5; color: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

h1, h2, h3 { margin-top: 0; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: var(--brand-gray); }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: var(--brand-dark); }
.btn-secondary { background: #eee; color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn:disabled, .btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

th, td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th { background: #fff8e1; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-pending { background: #fff3bf; color: #7a6200; }
.badge-confirmed { background: #dbe4ff; color: #364fc7; }
.badge-shipped { background: #d0ebff; color: #1864ab; }
.badge-delivered { background: #d8f3dc; color: var(--success); }
.badge-cancelled { background: #ffe5e5; color: var(--danger); }
.badge-out-of-stock { background: #eee; color: #888; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
.form-group input, .form-group select {
  width: 100%;
  max-width: 400px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.form-group input:focus, .form-group select:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

.filter-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-row .form-group { margin-bottom: 0; }

.form-hint {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.muted-cell { color: var(--muted); }

.login-page {
  min-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.login-logo { margin-bottom: 1.5rem; }
.login-logo__img { height: 120px; width: auto; display: block; }

.login-card {
  width: 100%;
  max-width: 420px;
}

.login-card h1 {
  font-size: 1.25rem;
  color: var(--brand-gray);
  text-align: center;
}

.login-links {
  margin: 1rem 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.product-card.out-of-stock {
  opacity: 0.65;
}

.product-list {
  margin-bottom: 2rem;
}

.product-list .product-name {
  font-weight: 600;
}

.product-item-number code {
  font-size: 0.85rem;
  color: var(--brand-gray);
  background: #f5f5f5;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.product-row.out-of-stock {
  opacity: 0.65;
  background: #fafafa;
}

.product-add-form {
  justify-content: flex-start;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.badge-in-cart {
  background: var(--primary);
  color: var(--brand-gray);
  margin-left: 0.5rem;
  font-size: 0.75rem;
}

.product-row.in-cart {
  background: #fffde7;
}

.order-summary {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 3px solid var(--primary);
}

.order-summary h2 {
  margin-bottom: 1rem;
}

.order-count {
  color: var(--brand-gray);
  font-size: 1rem;
}

.order-summary-footer {
  margin-top: 1rem;
}

.order-total {
  font-size: 1.15rem;
  margin-bottom: 1rem;
}

.btn-remove {
  padding: 0.2rem 0.55rem;
  font-size: 1rem;
  line-height: 1;
}

.product-card .price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand-gray);
}

.product-card .stock-low { color: var(--warning); font-size: 0.9rem; }
.product-card .stock-out { color: var(--danger); font-size: 0.9rem; }

.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input[type="number"] {
  width: 70px;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}

.stat-card .number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--brand-gray);
}

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.locale-switcher {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
  padding: 0.5rem 1.5rem;
  background: var(--brand-dark);
  border-bottom: 1px solid #333;
}

.btn-locale {
  padding: 0.25rem 0.65rem;
  font-size: 0.85rem;
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
}

.btn-locale:hover { color: var(--primary); border-color: var(--primary); }

.btn-locale.active {
  background: var(--primary);
  color: var(--brand-gray);
  border-color: var(--primary);
}

.navbar .btn-secondary {
  background: #333;
  color: var(--primary);
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
}

.navbar .btn-secondary:hover {
  background: var(--primary);
  color: var(--brand-gray);
}

.actions--stack-mobile form {
  display: inline;
}

/* ---- Mobile (phones & small tablets) ---- */
@media (max-width: 768px) {
  .container {
    padding: 0.75rem 1rem 2rem;
  }

  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.15rem; }

  .locale-switcher {
    padding: 0.4rem 1rem;
  }

  .navbar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
    gap: 0;
  }

  .navbar__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 0;
  }

  .nav-toggle {
    display: flex;
  }

  .navbar__nav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
    padding-top: 0.75rem;
    margin-top: 0.75rem;
    border-top: 1px solid #333;
  }

  .navbar__nav.is-open {
    display: flex;
  }

  .navbar__nav a,
  .navbar__nav .btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.65rem 0.5rem;
    min-height: 44px;
  }

  .navbar__nav form {
    display: block;
    width: 100%;
  }

  .navbar__nav .btn-secondary {
    width: 100%;
    text-align: center;
    min-height: 44px;
  }

  .navbar .user-email {
    font-size: 0.8rem;
    padding: 0.5rem;
    word-break: break-all;
  }

  .brand-logo__img {
    height: 36px;
  }

  .btn {
    min-height: 44px;
    padding: 0.65rem 1rem;
  }

  .btn-sm {
    min-height: 40px;
    padding: 0.5rem 0.85rem;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    max-width: none;
    font-size: 16px;
  }

  .inline-form input[type="number"] {
    width: 4.5rem;
    min-height: 44px;
    font-size: 16px;
  }

  .actions--stack-mobile {
    flex-direction: column;
  }

  .actions--stack-mobile .btn,
  .actions--stack-mobile form {
    display: block;
    width: 100%;
  }

  .actions--stack-mobile form button {
    width: 100%;
  }

  .order-summary {
    margin-top: 2rem;
    padding-top: 1.5rem;
  }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-row .form-group input,
  .filter-row .form-group select {
    max-width: none;
  }

  .actions:not(.actions--stack-mobile) {
    flex-direction: column;
    align-items: stretch;
  }

  .actions:not(.actions--stack-mobile) .btn,
  .actions:not(.actions--stack-mobile) form {
    width: 100%;
  }

  .actions:not(.actions--stack-mobile) form button {
    width: 100%;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  /* Card-style tables for owner flows */
  .stack-table {
    border: none;
    background: transparent;
  }

  .stack-table thead {
    display: none;
  }

  .stack-table tbody tr {
    display: block;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .stack-table td {
    display: grid;
    grid-template-columns: 6.25rem 1fr;
    gap: 0.25rem 0.75rem;
    align-items: center;
    padding: 0.45rem 0;
    border: none;
  }

  .stack-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--muted);
  }

  .stack-table td[data-label=""] {
    display: block;
    padding-top: 0.75rem;
    margin-top: 0.35rem;
    border-top: 1px solid var(--border);
  }

  .stack-table td[data-label=""]::before {
    display: none;
  }

  .stack-table .stack-table__actions .inline-form,
  .stack-table .stack-table__actions .product-add-form,
  .stack-table .stack-table__qty-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    width: 100%;
  }

  .stack-table .stack-table__qty-form {
    flex-direction: row;
  }

  .stack-table .stack-table__actions input[type="number"] {
    flex: 1 1 5rem;
    width: auto;
    max-width: none;
  }

  .stack-table .stack-table__actions .btn {
    flex: 1 1 auto;
  }

  /* Admin / wide tables: horizontal scroll */
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
  }

  .table-scroll table {
    min-width: 32rem;
  }

  .container > table:not(.stack-table),
  .container h2 + table:not(.stack-table),
  .container .card + table:not(.stack-table),
  .container table:not(.stack-table):not(.order-summary-table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .container > table:not(.stack-table) thead,
  .container h2 + table:not(.stack-table) thead,
  .container .card + table:not(.stack-table) thead,
  .container table:not(.stack-table):not(.order-summary-table) thead,
  .container > table:not(.stack-table) tbody,
  .container h2 + table:not(.stack-table) tbody,
  .container .card + table:not(.stack-table) tbody,
  .container table:not(.stack-table):not(.order-summary-table) tbody {
    display: table;
    width: 100%;
    min-width: 32rem;
  }

  th, td {
    padding: 0.55rem;
    font-size: 0.9rem;
  }

  .login-page {
    padding: 1.5rem 1rem;
  }

  .login-logo__img {
    height: 88px;
  }

  .stat-card .number {
    font-size: 1.5rem;
  }
}
