:root {
  color-scheme: light;
  --bg: #f7f5f2;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #767676;
  --accent: #c7623f;
  --accent-dark: #a34f32;
  --border: #e5e1db;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.profile-reminder-banner {
  background: #fbeee7;
  color: var(--accent-dark);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  text-align: center;
  font-size: 0.9em;
}
.profile-reminder-banner a { color: var(--accent-dark); font-weight: bold; }

header.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-size: 1.15em;
}

.site-header-inner {
  padding: 18px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.site-header-inner-narrow {
  max-width: 1280px;
  margin: 0 auto;
}

header.site-header a { color: var(--text); text-decoration: none; font-weight: 600; }

.site-header-brand > a { font-size: 1.2em; font-weight: 700; }

.site-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.site-header-brand .admin-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.85em;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  text-decoration: none;
}

.site-header-brand .admin-badge:hover { background: var(--accent-dark); }

header.site-header nav ul.nav-menu {
  list-style: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
}

header.site-header nav ul.nav-menu > li {
  position: relative;
  display: flex;
  align-items: center;
}

header.site-header nav ul.nav-menu > li > a {
  margin-left: 14px;
  color: var(--muted);
  font-weight: 500;
  font-size: 1em;
}

.submenu-toggle {
  background: none;
  border: none;
  box-shadow: none;
  border-radius: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2em;
  font-weight: 400;
  line-height: normal;
  padding: 4px;
  display: inline-block;
  transform: none;
}

.submenu-toggle:hover {
  background: none;
  box-shadow: none;
  transform: none;
}

.submenu {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  position: absolute;
  top: 100%;
  left: 12px;
  min-width: 130px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  display: none;
  z-index: 100;
}

.has-submenu:hover .submenu,
.has-submenu.open .submenu {
  display: block;
}

.submenu li a,
.submenu li button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 16px;
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-weight: 400;
  text-align: left;
  box-shadow: none;
  cursor: pointer;
}

/* 前台頁首（shop.css）對 header 內所有 <a> 都設了較大的字級，
   這裡要加上 nav 提高選擇器優先度才能蓋掉，讓子選單字體跟父選單一致 */
nav .submenu li a,
nav .submenu li button {
  font-size: 1em;
}

.submenu li a:hover,
.submenu li button:hover {
  background: var(--bg);
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

h1, h2, h3 { line-height: 1.3; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.dashboard-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.dashboard-stat .stat-label {
  color: var(--muted);
  font-size: 1.1em;
  font-weight: 700;
  margin-bottom: 6px;
}

.dashboard-stat .stat-value {
  font-size: 1.6em;
  font-weight: 800;
  color: var(--accent-dark);
}

.dashboard-stat .stat-value a {
  color: inherit;
}

.dashboard-date-input {
  padding: 12px 14px;
  font-size: 1.1em;
  max-width: none;
  width: auto;
}

.product-code {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.85em;
  margin-right: 6px;
}

.price { font-weight: 700; margin: 8px 0; }
.deposit-note { color: #b45309; font-size: 0.9em; margin: -4px 0 8px; }
.variant-tag { display: inline-block; color: var(--muted); font-size: 0.85em; }

.special-item-tag {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  vertical-align: middle;
}

.special-item-tag.special-item-tag-gacha {
  background: #ecd9c4;
  color: #8a5a28;
}

.special-item-tag.special-item-tag-live {
  background: #ece2bd;
  color: #8a7524;
}

.color-swatch-group { display: flex; flex-wrap: wrap; gap: 6px; max-width: 252px; }
.color-swatch {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: block;
}
.color-swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.color-swatch:has(input:checked) { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent-dark, #333); }

button, input[type="submit"], .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95em;
  text-decoration: none;
  display: inline-block;
}

button:hover, input[type="submit"]:hover, .btn:hover { background: var(--accent-dark); }

.btn-secondary { background: #999; }
.btn-danger { background: #b13a3a; }
.btn-line { background: #06c755; }
.btn-line:hover { background: #05a648; }

/* 按鈕元件做成純文字連結外觀（例如低庫存提醒的「移除提醒」）：拿掉按鈕底色/邊框，只留藍字加底線 */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  display: inline;
  border-radius: 0;
  color: #2563eb;
  text-decoration: underline;
  font-size: inherit;
  cursor: pointer;
}
.btn-link:hover { background: none; color: #1d4ed8; }

.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); margin: 16px 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

button:disabled, input[type="submit"]:disabled, .btn:disabled {
  background: #ccc;
  color: #888;
  cursor: not-allowed;
}
button:disabled:hover, input[type="submit"]:disabled:hover, .btn:disabled:hover {
  background: #ccc;
}

form.inline { display: inline; }

.next-step-cell form.inline,
.next-step-cell > a {
  display: inline-block;
  margin: 3px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.92em;
}

th { background: #f0ece6; }

.status-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
  white-space: nowrap;
  display: inline-block;
}

/* 訂單管理表格的「訂單狀態」欄：狀態徽章下面接付款方式時，蓋掉 .deposit-note 原本給價格用的
   負的 margin-top（會讓文字疊到徽章上），改成往下留一點間距 */
.status-cell .deposit-note {
  display: block;
  margin: 4px 0 0;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px 24px;
}

.info-grid .info-label {
  color: var(--muted);
  font-size: 0.8em;
  margin-bottom: 2px;
}

.info-grid .info-value {
  font-weight: 600;
}

.info-grid .info-full {
  grid-column: 1 / -1;
}

.error { color: #b13a3a; margin: 10px 0; }
.success { color: #2f8a4b; margin: 10px 0; }

input[type="text"], input[type="tel"], input[type="email"], input[type="number"], input[type="password"], input[type="date"], select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  max-width: 320px;
  font-size: 0.95em;
}

label { display: block; margin: 10px 0 4px; font-weight: 600; }

.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.form-section h2 { margin-top: 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 24px;
  align-items: start;
}

.form-grid > div { display: flex; flex-direction: column; min-width: 0; }
.form-grid label { margin: 10px 0 4px; }
.form-grid input, .form-grid select { width: 100%; max-width: none; }
.form-full { grid-column: 1 / -1; }

.form-checkbox-row { flex-direction: row; flex-wrap: wrap; gap: 24px; margin-top: 6px; }
.form-checkbox-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 500;
}
.form-checkbox-row input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

.order-checkbox { width: 22px; height: 22px; cursor: pointer; }

@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }

  /* 表格在窄螢幕上改用橫向捲動，避免中文字被擠到一字一行 */
  table { display: block; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; }
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* 搜尋框的 placeholder 說明文字比較長，寬度夠時完整顯示；外層 div 也要跟著設上限，
   不然 div 撐開後面會留一大塊空白，把其他搜尋條件擠到最右邊，而不是緊接在搜尋框後面 */
.filters .search-field { flex: 1 1 260px; max-width: 420px; }
.filters .search-field input { width: 100%; max-width: 100%; }

th select.header-filter {
  width: auto;
  max-width: none;
  padding: 2px 18px 2px 6px;
  margin: 0;
  border: none;
  background-color: transparent;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    right 4px top 55%,
    right 0px top 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

th select.header-filter:focus {
  outline: none;
}

th select.header-filter.active {
  color: var(--accent);
}

.admin-shell {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 72px);
}

.admin-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 14px 0 12px;
  display: flex;
  flex-direction: column;
  /* 固定在畫面左側，訂單清單再長也不會跟著捲走；選單太多放不下時側邊欄自己內部捲動 */
  position: sticky;
  top: var(--admin-header-h, 72px);
  align-self: flex-start;
  height: calc(100vh - var(--admin-header-h, 72px));
  overflow-y: auto;
  box-sizing: border-box;
}

/* 後台頁面的頂部導覽列也固定在最上方，側邊欄才能緊貼在它下面 */
body:has(.admin-shell) header.site-header {
  position: sticky;
  top: 0;
  z-index: 200;
}

.admin-sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.admin-sidebar nav a {
  padding: 8px 20px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.admin-sidebar nav a:hover {
  background: var(--bg);
}

.admin-sidebar nav a.active {
  background: var(--accent);
  color: #fff;
}

.admin-sidebar-logout {
  padding: 8px 20px 0;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.admin-sidebar-group {
  display: flex;
  flex-direction: column;
}

/* 子選單父項目：長得跟一般選單連結一樣，但本身是按鈕，點擊只負責展開/收合，不會跳轉頁面 */
.admin-sidebar-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 8px 20px;
  color: var(--text);
  font-weight: 600;
}

.admin-sidebar-group-toggle:hover {
  background: var(--bg);
}

.admin-sidebar-group-toggle.active {
  background: var(--accent);
  color: #fff;
}

.admin-sidebar-group-arrow {
  display: inline-block;
  transition: transform 0.15s;
  font-size: 0.85em;
}

.admin-sidebar-group.is-open .admin-sidebar-group-arrow {
  transform: rotate(180deg);
}

/* 子選單預設收合，展開時才顯示（手機版橫向選單列不受這個影響，見下方 media query） */
.admin-sidebar-submenu {
  display: none;
  flex-direction: column;
}

.admin-sidebar-group.is-open .admin-sidebar-submenu {
  display: flex;
}

.admin-sidebar nav .admin-sidebar-submenu a {
  padding: 6px 20px 6px 36px;
  font-size: 0.9em;
  font-weight: 500;
}

.admin-sidebar nav .admin-sidebar-submenu a.active {
  background: #ffe0b2;
  color: #8a4b1e;
}

.admin-shell main {
  max-width: none;
  margin: 0;
  flex: 1;
  min-width: 0;
}

@media (max-width: 700px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    min-height: auto;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
  }
  .admin-sidebar nav { flex-direction: row; }
  .admin-sidebar-group { flex-direction: row; align-items: center; }
  /* 手機版側邊欄是橫向捲動列，子選單一律展開顯示，收合/展開只在桌面版直向選單才有意義 */
  .admin-sidebar-submenu { display: flex; flex-direction: row; }
  .admin-sidebar nav a, .admin-sidebar-group-toggle { white-space: nowrap; flex-shrink: 0; width: auto; }
  .admin-sidebar-group-arrow { display: none; }
  .admin-sidebar nav .admin-sidebar-submenu a { padding: 8px 12px; }
  .admin-sidebar-logout { margin: 0; padding: 0; border: none; white-space: nowrap; }
}

.bank-info {
  background: #fff8ee;
  border: 1px solid #eadfc8;
  border-radius: 10px;
  padding: 16px;
  margin: 16px 0;
}

.confirm-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.confirm-modal-overlay.open {
  display: flex;
}

/* 表單送出後蓋住畫面，避免整頁重新整理時的閃爍 */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-overlay.open {
  display: flex;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

.confirm-modal-box {
  background: var(--card);
  border-radius: 10px;
  padding: 20px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.confirm-modal-message {
  margin: 0 0 16px;
  font-size: 0.95em;
  white-space: pre-wrap;
}

.confirm-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* 內容是表格的彈窗（例如購物金紀錄），需要比一般確認視窗寬很多，且可以左右／上下捲動 */
.credit-logs-modal {
  position: relative;
  max-width: 720px;
  max-height: 80vh;
  overflow: auto;
  text-align: left;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
  border-radius: 8px;
  cursor: pointer;
}

.nav-toggle:hover { background: var(--bg); box-shadow: none; transform: none; }

.nav-toggle-bar {
  display: block;
  width: 22px;
  height: 2px;
  margin: 0 auto;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.15s, opacity 0.15s;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 700px) {
  .site-header-inner {
    flex-wrap: wrap;
    position: relative;
  }

  .nav-toggle { display: flex; }

  header.site-header nav#siteNav {
    display: none;
    width: 100%;
    order: 3;
    margin-top: 14px;
  }

  header.site-header nav#siteNav.nav-open { display: block; }

  header.site-header nav ul.nav-menu {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  header.site-header nav ul.nav-menu > li {
    display: block;
    border-top: 1px solid var(--border);
  }

  header.site-header nav ul.nav-menu > li > a {
    display: block;
    margin-left: 0;
    padding: 12px 4px;
  }

  header.site-header nav ul.nav-menu > li.has-submenu {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }

  header.site-header nav ul.nav-menu > li.has-submenu > a { flex: 1; }

  .submenu {
    position: static;
    box-shadow: none;
    border: none;
    width: 100%;
    padding: 0 0 8px 16px;
  }
}

@media (max-width: 600px) {
  .site-header-inner { flex-direction: row; align-items: center; }
}

.order-item-row {
  margin-bottom: 4px;
}

.order-item-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
  text-align: left;
}

.order-item-link:hover {
  background: none;
}


.product-info-box {
  max-width: 320px;
}

.product-info-image {
  width: 100%;
  height: 160px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.product-info-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-info-noimage {
  color: var(--muted);
  font-size: 0.9em;
}

.product-info-name {
  margin: 0 0 6px;
}

.product-info-meta {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9em;
}

.product-info-description {
  margin: 0 0 16px;
  font-size: 0.9em;
  white-space: pre-wrap;
}

.file-upload-btn {
  font-size: 0.85em;
  padding: 6px 12px;
  white-space: nowrap;
}

.file-upload-btn input[type="file"] {
  display: none;
}

.file-upload-widget {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

.file-upload-filename {
  font-size: 0.85em;
  color: var(--muted);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-upload-clear {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1em;
  line-height: 1;
  padding: 0 2px;
}

.file-upload-clear[hidden] {
  display: none;
}

.file-upload-clear:hover {
  color: #b13a3a;
}

.lightbox-image {
  cursor: zoom-in;
}

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 24px;
}

.lightbox-overlay.open {
  display: flex;
}

.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2em;
  cursor: pointer;
  line-height: 1;
}

.product-photo-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  max-width: 160px;
}

.product-photo-thumb-wrap {
  position: relative;
}

.product-photo-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.product-photo-delete-form {
  position: absolute;
  top: -6px;
  right: -6px;
}

.product-photo-delete {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: #b13a3a;
  color: #fff;
  font-size: 0.75em;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
