:root {
  color-scheme: light;
  --bg: #f3f7f6;
  --surface: #ffffff;
  --surface-soft: #e9f4f2;
  --text: #173332;
  --muted: #617675;
  --line: #d5e3e1;
  --primary: #116765;
  --primary-dark: #0a5150;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warning: #8a5a00;
  --warning-bg: #fff7e6;
  --success: #176b45;
  --shadow: 0 12px 34px rgb(19 67 65 / 10%);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: linear-gradient(145deg, #edf6f4 0, var(--bg) 45%, #f8faf9 100%);
  line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
button, input, select { font: inherit; }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid #bfcfcd;
  border-radius: 9px;
}

input:focus, select:focus {
  border-color: var(--primary);
  outline: 3px solid rgb(17 103 101 / 14%);
}

label { font-weight: 650; }

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.page-shell.narrow { width: min(820px, calc(100% - 32px)); }

.public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 34px max(24px, calc((100% - 1120px) / 2));
  color: #fff;
  background: linear-gradient(120deg, #0d5654, #147b77);
}

.public-header h1 { margin: 3px 0 5px; font-size: clamp(25px, 4vw, 38px); }
.public-header p { margin: 0; color: #d9efed; }
.eyebrow { color: #aee0db; font-size: 13px; font-weight: 700; letter-spacing: .14em; }
.admin-link { flex: none; padding: 9px 14px; color: #fff; border: 1px solid #89c5c0; border-radius: 9px; }

.card, .panel {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.panel { margin-bottom: 20px; }
.panel h2 { margin-top: 0; }
.edit-panel, .account-panel { max-width: 680px; }

.form-section {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 16px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.form-section:first-child { padding-top: 0; }
.form-section:last-of-type { border-bottom: 0; }
.section-number {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: #fff;
  background: var(--primary);
  border-radius: 50%;
  font-weight: 800;
}
.section-content h2 { margin: 2px 0 16px; font-size: 20px; }
.section-content label { display: block; margin: 12px 0 6px; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
.button:hover { text-decoration: none; }
.button.primary { color: #fff; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: var(--primary); background: #fff; border-color: #a8c4c1; }
.button.full { width: 100%; margin-top: 18px; }
.button.small { min-height: 36px; padding: 6px 11px; font-size: 14px; }
.button:disabled { cursor: wait; opacity: .65; }

.hint { margin: 6px 0 12px; color: var(--muted); font-size: 14px; }
.notice { margin-bottom: 18px; padding: 13px 16px; border-radius: 9px; }
.notice.error { color: var(--danger); background: var(--danger-bg); border: 1px solid #f4c7c3; }
.notice.warning { color: var(--warning); background: var(--warning-bg); border: 1px solid #f1d49b; }

.autocomplete-wrap { position: relative; }
.autocomplete-results {
  position: absolute;
  z-index: 20;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  max-height: 320px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.store-option { display: block; width: 100%; padding: 11px 14px; text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.store-option:hover { background: var(--surface-soft); }
.store-option strong, .store-option span { display: block; }
.store-option span { color: var(--muted); font-size: 13px; }
.no-result, .product-list-empty { padding: 18px; color: var(--muted); text-align: center; }
.selected-store { margin: 10px 0; padding: 11px 13px; background: var(--surface-soft); border-radius: 9px; }
.selected-store strong, .selected-store span { display: block; }
.selected-store span { color: var(--muted); font-size: 13px; }
.other-store-fields { margin-top: 12px; }

.product-quantity-list { margin-top: 14px; }
.product-quantity-header, .product-quantity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 130px;
  gap: 16px;
  align-items: center;
}
.product-quantity-header { padding: 10px 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.product-quantity-row { padding: 11px 12px; border-top: 1px solid var(--line); }
.product-quantity-row label strong, .product-quantity-row label span { display: block; }
.product-unit { color: var(--muted); font-size: 13px; font-weight: 400; }
.other-product-row { margin-top: 14px; padding: 14px; background: #f7faf9; border: 1px solid var(--line); border-radius: 10px; }
.other-product-row label strong, .other-product-row label span { display: block; }
.other-product-row label span { color: var(--muted); font-size: 13px; }
.other-product-inputs { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 12px; margin-top: 10px; }
.server-time-note { margin-top: 18px; padding: 12px 14px; background: #f1f7f6; border-radius: 9px; }

.modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  padding: 22px;
  place-items: center;
  overflow: auto;
  background: rgb(7 36 35 / 62%);
}
.modal[hidden] { display: none; }
.modal-panel { width: min(620px, 100%); padding: 25px; background: #fff; border-radius: 15px; box-shadow: 0 24px 70px rgb(0 0 0 / 30%); }
.modal-actions, .form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.success-panel { text-align: center; }
.success-icon { display: grid; width: 56px; height: 56px; margin: 0 auto; place-items: center; color: #fff; background: var(--success); border-radius: 50%; font-size: 30px; }

.admin-layout { display: grid; min-height: 100vh; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; padding: 24px 18px; color: #dff3f1; background: #123f3e; }
.brand { margin-bottom: 24px; color: #fff; font-size: 20px; font-weight: 800; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar nav a, .sidebar-footer a { padding: 9px 11px; color: #dff3f1; border-radius: 8px; }
.sidebar nav a:hover, .sidebar-footer a:hover { background: rgb(255 255 255 / 10%); text-decoration: none; }
.sidebar-footer { margin-top: auto; padding-top: 20px; }
.admin-main { min-width: 0; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 14px 28px; background: #fff; border-bottom: 1px solid var(--line); }
.admin-topbar h1 { margin: 0; font-size: 24px; }
.admin-content { padding: 28px; }
.menu-button { display: none; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { padding: 18px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.stat-card strong { display: block; margin-top: 4px; font-size: 26px; }
.panel-heading, .search-row, .filters, .visibility-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.stack-form { display: grid; gap: 8px; }
.stack-form label:not(:first-child) { margin-top: 7px; }
.inline-form { display: inline; }
.link-button { padding: 0; color: var(--primary); background: none; border: 0; cursor: pointer; }
.template-link { display: inline-block; margin-top: 12px; }
.back-link.inline { display: inline-block; margin-bottom: 15px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: #496462; background: #f3f7f6; font-size: 13px; white-space: nowrap; }
.empty-cell { padding: 30px; color: var(--muted); text-align: center; }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.status.active { color: var(--success); background: #e8f7ef; }
.status.inactive { color: #7a4d00; background: #fff1d6; }
.detail-grid, .confirm-list { display: grid; gap: 10px; }
.detail-grid div, .confirm-list div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; }
.detail-grid dt, .confirm-list dt { color: var(--muted); }
.detail-grid dd, .confirm-list dd { margin: 0; }
.visibility-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.visibility-item { padding: 10px; background: #f7faf9; border: 1px solid var(--line); border-radius: 8px; }

.login-page { display: grid; min-height: 100vh; padding: 24px; place-items: center; }
.login-card { width: min(430px, 100%); }
.error-text { color: var(--danger); }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column { grid-template-columns: 1fr; }
  .visibility-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .public-header { align-items: flex-start; flex-direction: column; }
  .admin-layout { display: block; }
  .sidebar { min-height: auto; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-footer { margin-top: 10px; }
  .admin-content, .admin-topbar { padding: 18px; }
  .product-quantity-header, .product-quantity-row, .other-product-inputs { grid-template-columns: minmax(0, 1fr) 105px; }
  .panel-heading, .search-row, .filters, .visibility-actions { align-items: stretch; flex-direction: column; }
}

@media (max-width: 480px) {
  .page-shell, .page-shell.narrow { width: min(100% - 20px, 820px); margin-top: 14px; }
  .card, .panel { padding: 17px; border-radius: 11px; }
  .form-section { grid-template-columns: 1fr; }
  .stats-grid, .visibility-grid { grid-template-columns: 1fr; }
  .sidebar nav { grid-template-columns: 1fr; }
  .modal-actions, .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .modal-actions .button, .form-actions .button { width: 100%; }
}
