:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  color: #16211e;
  background: #f3f5f4;
  font-synthesis: none;
  --ink: #16211e;
  --muted: #68736f;
  --line: #d5dcda;
  --surface: #fff;
  --green: #087a55;
  --green-soft: #e3f4ed;
  --amber: #a46200;
  --amber-soft: #fff0d0;
  --red: #ac4139;
  --red-soft: #fbe8e6;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { min-width: 320px; background: #f3f5f4; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #f3f5f4;
  letter-spacing: 0;
}

button,
input,
textarea,
select { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

a { color: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(22, 33, 30, 0.14);
  background: rgba(243, 245, 244, 0.94);
  backdrop-filter: blur(12px);
}

.site-header__inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 15px;
  font-weight: 780;
  text-decoration: none;
}

.site-brand__mark {
  display: grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
}

nav {
  display: flex;
  align-items: center;
  gap: 5px;
}

nav a,
.nav-button {
  min-height: 34px;
  padding: 8px 11px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

nav a:hover,
.nav-button:hover,
nav .is-active {
  background: #e5eae8;
  color: var(--ink);
}

.store-main,
.admin-main,
.order-main,
.site-footer {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
}

.store-main { padding: 34px 0 60px; }

.store-summary {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  min-height: 165px;
  padding: 26px 0 30px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 11px;
  font-weight: 820;
}

h1,
h2,
h3,
p { overflow-wrap: anywhere; }

h1 {
  margin: 0;
  font-size: 36px;
  line-height: 1.14;
  letter-spacing: 0;
}

.store-summary p:last-child {
  max-width: 720px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.service-status {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa5a1;
}

.status-dot.is-live { background: #0b9769; box-shadow: 0 0 0 4px rgba(11,151,105,.12); }
.status-dot.is-offline { background: var(--red); }

.catalog { padding: 34px 0 0; }

.section-heading,
.admin-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.section-heading h2,
.admin-heading h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.category-filter {
  display: flex;
  max-width: 100%;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.category-filter button {
  min-height: 34px;
  flex: none;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.category-filter button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

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

.product-card {
  display: grid;
  min-width: 0;
  min-height: 430px;
  grid-template-rows: 150px auto 1fr auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(26, 45, 39, 0.045);
}

.product-cover {
  position: relative;
  display: grid;
  overflow: hidden;
  place-items: center;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(8,122,85,.14), rgba(255,255,255,.18) 48%, rgba(164,98,0,.12)),
    #e9efec;
}

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

.product-cover__initials {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 1px solid rgba(22,33,30,.15);
  border-radius: 8px;
  background: rgba(255,255,255,.8);
  color: var(--ink);
  font-size: 20px;
  font-weight: 820;
}

.product-category {
  position: absolute;
  top: 12px;
  left: 12px;
  max-width: calc(100% - 24px);
  padding: 5px 8px;
  overflow: hidden;
  border: 1px solid rgba(22,33,30,.13);
  border-radius: 4px;
  background: rgba(255,255,255,.9);
  color: #47534f;
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-card__heading { padding: 17px 18px 0; }

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

.product-card__subtitle {
  min-height: 20px;
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.product-card__description {
  display: -webkit-box;
  min-height: 66px;
  margin: 14px 18px 0;
  overflow: hidden;
  color: #44514d;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-line;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.product-card__bottom {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 14px;
  margin: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.product-stock {
  display: block;
  margin-bottom: 4px;
  color: var(--green);
  font-size: 11px;
  font-weight: 760;
}

.product-stock.is-empty { color: var(--red); }

.product-price {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.product-price small {
  margin-right: 2px;
  color: var(--amber);
  font-size: 12px;
  vertical-align: 5px;
}

.button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
}

.button:hover { border-color: #aab5b1; background: #f7f9f8; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button--dark { border-color: var(--ink); background: var(--ink); color: #fff; }
.button--dark:hover { border-color: #2c3935; background: #2c3935; }
.button--danger { border-color: #c94d4d; color: #a52c2c; }
.button--danger:hover { border-color: #a52c2c; background: #fff3f3; }
.button--block { width: 100%; }

.empty-state {
  grid-column: 1 / -1;
  min-height: 260px;
  padding: 40px;
  border: 1px dashed #bcc6c2;
  border-radius: 8px;
  background: #fafbfa;
  text-align: center;
}

.empty-state h3 { margin: 45px 0 8px; font-size: 18px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 13px; }

.product-skeleton {
  height: 430px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(100deg, #e8ecea 25%, #f8faf9 45%, #e8ecea 65%) 0 0 / 220% 100%;
  animation: shimmer 1.25s linear infinite;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 0 34px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.site-footer a { font-weight: 740; text-decoration: none; }
.site-footer a:hover { color: var(--ink); }

dialog {
  width: min(720px, calc(100% - 28px));
  max-height: min(88vh, 900px);
  padding: 0;
  overflow: auto;
  border: 1px solid #bdc6c2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(14, 28, 24, .24);
}

dialog::backdrop { background: rgba(22,33,30,.48); backdrop-filter: blur(3px); }

.dialog-close {
  position: sticky;
  top: 12px;
  z-index: 2;
  display: grid;
  width: 36px;
  height: 36px;
  float: right;
  margin: 12px 12px -48px 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255,255,255,.94);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
}

.dialog-product-cover {
  display: grid;
  width: 100%;
  height: 210px;
  overflow: hidden;
  place-items: center;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, var(--green-soft), #f5f7f6 50%, var(--amber-soft));
}

.dialog-product-cover img { width: 100%; height: 100%; object-fit: cover; }
.dialog-product-cover .product-cover__initials { width: 76px; height: 76px; font-size: 24px; }

.dialog-product-body { padding: 24px; }
.dialog-product-body h2 { margin: 0; padding-right: 42px; font-size: 25px; letter-spacing: 0; }
.dialog-subtitle { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.dialog-description { margin: 20px 0 0; color: #36433f; font-size: 14px; line-height: 1.75; white-space: pre-line; }

.detail-band {
  margin-top: 20px;
  padding: 15px 16px;
  border-left: 3px solid var(--green);
  background: #f1f6f4;
}

.detail-band--warning { border-left-color: var(--amber); background: #fff7e7; }
.detail-band h3 { margin: 0 0 7px; font-size: 13px; }
.detail-band p { margin: 0; color: #4d5955; font-size: 12px; line-height: 1.7; white-space: pre-line; }

.purchase-form {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 14px;
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 7px;
  color: #4f5a56;
  font-size: 12px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #cbd3d0;
  border-radius: 5px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

textarea { resize: vertical; line-height: 1.6; }
input:focus,
textarea:focus,
select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(8,122,85,.12); }

.purchase-form__contact { grid-column: 1 / -1; }

.payment-methods {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: wrap;
  gap: 8px;
}

.payment-option {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

.payment-option:has(input:checked) { border-color: var(--ink); background: #edf1ef; color: var(--ink); }
.payment-option input { width: 14px; min-height: 14px; margin: 0; box-shadow: none; }

.purchase-total {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.purchase-total span { color: var(--muted); font-size: 12px; }
.purchase-total strong { font-size: 25px; font-variant-numeric: tabular-nums; }

.form-message { grid-column: 1 / -1; margin: 0; color: var(--red); font-size: 12px; }

/* Order */
.order-main { padding: 48px 0 70px; }
.order-lookup,
.order-result {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.order-lookup h1 { font-size: 28px; }
.order-lookup > p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.order-lookup form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; margin-top: 22px; }
.order-result { margin-top: 18px; }

.order-status-line { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.order-status-line h2 { margin: 0; font-size: 22px; }
.status-badge { padding: 5px 8px; border-radius: 4px; background: var(--amber-soft); color: #734500; font-size: 11px; font-weight: 800; }
.status-badge.is-success { background: var(--green-soft); color: var(--green); }
.status-badge.is-error { background: var(--red-soft); color: var(--red); }
.order-meta { display: grid; grid-template-columns: repeat(3, 1fr); margin: 20px 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.order-meta div { padding: 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.order-meta dt { color: var(--muted); font-size: 10px; }
.order-meta dd { margin: 4px 0 0; font-size: 13px; font-weight: 760; overflow-wrap: anywhere; }
.code-list { display: grid; gap: 8px; margin-top: 16px; }
.code-row { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 8px; }
.code-row code { display: block; min-width: 0; padding: 12px; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: 5px; background: #f4f7f5; font-size: 13px; }
.icon-copy { width: 40px; border: 1px solid var(--line); border-radius: 5px; background: #fff; cursor: pointer; font-size: 17px; }
.order-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* Admin */
.admin-main { padding: 34px 0 70px; }
.admin-login { width: min(520px, 100%); margin: 48px auto; padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.admin-login h1 { font-size: 28px; }
.admin-login p:not(.eyebrow) { color: var(--muted); font-size: 13px; }
.admin-login form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; margin-top: 20px; }
.admin-heading { margin: 8px 0 20px; }
.admin-heading-actions { display: flex; gap: 8px; }
.admin-metrics { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 18px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.admin-metrics div { padding: 15px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.admin-metrics dt { color: var(--muted); font-size: 11px; }
.admin-metrics dd { margin: 5px 0 0; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.inline-notice { margin-bottom: 16px; padding: 11px 13px; border: 1px solid #e5c47b; border-radius: 5px; background: #fff6df; color: #724b04; font-size: 12px; }
.admin-product-list { display: grid; gap: 9px; }
.admin-product-row { display: grid; grid-template-columns: minmax(210px, 1.7fr) repeat(4, minmax(90px, .55fr)) auto; align-items: center; gap: 14px; min-height: 82px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.admin-product-row h3 { margin: 0; font-size: 15px; }
.admin-product-row p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.admin-cell span { display: block; color: var(--muted); font-size: 10px; }
.admin-cell strong { display: block; margin-top: 4px; font-size: 14px; font-variant-numeric: tabular-nums; }
.admin-row-actions { display: flex; gap: 6px; }
.state-pill { display: inline-flex !important; width: max-content; margin: 0 !important; padding: 4px 7px; border-radius: 4px; background: var(--green-soft); color: var(--green) !important; font-size: 10px !important; font-weight: 800; }
.state-pill.is-off { background: #edf0ef; color: #64706c !important; }
.admin-dialog { width: min(820px, calc(100% - 28px)); }
.admin-dialog--compact { width: min(620px, calc(100% - 28px)); }
.admin-dialog form { padding: 24px; }
.dialog-heading { margin-bottom: 18px; padding-right: 45px; }
.dialog-heading h2 { margin: 0; font-size: 23px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.span-2 { grid-column: 1 / -1; }
.toggle-row { display: inline-flex; width: max-content; align-items: center; grid-template-columns: 18px auto; }
.toggle-row input { width: 16px; min-height: 16px; margin: 0; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.order-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.order-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.order-table th { padding: 11px 12px; border-bottom: 1px solid var(--line); background: #f5f7f6; color: var(--muted); text-align: left; font-size: 10px; }
.order-table td { padding: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.order-table tr:last-child td { border-bottom: 0; }

.market-status {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.admin-market-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.admin-market-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-top: 4px solid var(--green);
  border-radius: 8px;
  background: #fff;
}

.admin-market-panel[data-color="amber"] { border-top-color: var(--amber); }
.admin-market-panel[data-color="red"] { border-top-color: var(--red); }

.admin-market-header {
  min-height: 104px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.admin-market-header h2 { margin: 0; font-size: 19px; }
.market-count { margin: 7px 0 0; color: var(--muted); font-size: 11px; }
.market-offers { margin: 0; padding: 0; list-style: none; }

.market-offer {
  min-width: 0;
  padding: 15px;
  border-bottom: 1px solid var(--line);
}

.market-offer:last-child { border-bottom: 0; }
.market-offer:first-child { background: linear-gradient(90deg, var(--green-soft), transparent 74%); }
.admin-market-panel[data-color="amber"] .market-offer:first-child { background: linear-gradient(90deg, var(--amber-soft), transparent 74%); }
.admin-market-panel[data-color="red"] .market-offer:first-child { background: linear-gradient(90deg, var(--red-soft), transparent 74%); }

.market-offer__top {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.market-rank {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
}

.market-shop { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.market-price { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.market-title { display: -webkit-box; min-height: 38px; margin: 11px 0 0 33px; overflow: hidden; color: #44514d; font-size: 12px; line-height: 1.55; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.market-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 10px 0 0 33px; color: var(--muted); font-size: 10px; }
.market-meta span:first-child { color: var(--green); font-weight: 760; }
.market-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 11px 0 0 33px; }
.market-actions .button { min-height: 32px; padding: 0 9px; font-size: 11px; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible { outline: 3px solid rgba(8,122,85,.2); outline-offset: 2px; }

@keyframes shimmer { to { background-position: -220% 0; } }

@media (max-width: 960px) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-market-grid { grid-template-columns: 1fr; }
  .admin-product-row { grid-template-columns: minmax(180px, 1.6fr) repeat(2, minmax(90px, .6fr)) auto; }
  .admin-product-row .admin-cell:nth-of-type(3),
  .admin-product-row .admin-cell:nth-of-type(4) { display: none; }
}

@media (max-width: 700px) {
  .site-header__inner,
  .store-main,
  .admin-main,
  .order-main,
  .site-footer { width: min(100% - 28px, 1280px); }
  .site-header__inner { gap: 12px; }
  nav { gap: 1px; }
  nav a,
  .nav-button { padding: 8px; font-size: 12px; }
  .store-main { padding-top: 20px; }
  .store-summary { min-height: 0; align-items: start; flex-direction: column; padding: 20px 0 24px; }
  h1 { font-size: 28px; }
  .section-heading { align-items: start; flex-direction: column; }
  .category-filter { width: 100%; }
  .product-grid { grid-template-columns: 1fr; }
  .product-card { min-height: 410px; }
  .site-footer { align-items: start; flex-direction: column; }
  .purchase-form { grid-template-columns: 1fr; }
  .purchase-form__contact,
  .payment-methods,
  .purchase-total { grid-column: 1; }
  .dialog-product-body { padding: 20px 17px; }
  .order-lookup,
  .order-result,
  .admin-login { padding: 20px 16px; }
  .order-lookup form,
  .admin-login form { grid-template-columns: 1fr; }
  .order-meta { grid-template-columns: 1fr; }
  .admin-heading { align-items: start; }
  .admin-heading-actions { flex-wrap: wrap; justify-content: end; }
  .admin-metrics { grid-template-columns: 1fr 1fr; }
  .admin-product-row { grid-template-columns: minmax(0, 1fr) auto; }
  .admin-product-row .admin-cell { display: none; }
  .admin-row-actions { flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1; }
}

@media (max-width: 420px) {
  .site-brand > span:last-child { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  nav a,
  .nav-button { padding: 7px 6px; }
  .product-card__bottom { grid-template-columns: 1fr; }
  .product-card__bottom .button { width: 100%; }
  .admin-heading { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
