:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #1d1d1b;
  --muted: #6f6b63;
  --line: #d9d4ca;
  --panel: #ffffff;
  --accent: #8f1d2c;
  --accent-2: #204f4a;
  --soft: #ebe6dc;
  --shadow: 0 22px 60px rgba(31, 28, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 36px;
  background: rgba(246, 244, 239, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand,
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 650;
}

.view-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  background: var(--soft);
}

body:not(.authenticated) .view-toggle {
  display: none;
}

.seg {
  min-width: 92px;
  border: 0;
  padding: 9px 14px;
  background: transparent;
  color: var(--muted);
}

.seg:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.seg.active {
  background: var(--ink);
  color: white;
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 34px 36px 52px;
}

.app-shell {
  display: none;
}

body.authenticated .app-shell {
  display: block;
}

.access-gate {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 24px;
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 54px 36px;
}

body.authenticated .access-gate {
  display: none;
}

.access-card {
  min-height: 340px;
  padding: 34px;
  border: 1px solid var(--line);
  background: white;
}

.access-card h2 {
  margin: 8px 0 12px;
  font-size: 36px;
}

.access-card p {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.65;
}

.access-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.access-form label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.access-form input {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 14px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}

.access-form input:focus {
  border-color: var(--accent);
}

.access-form button {
  width: max-content;
  border: 0;
  padding: 12px 18px;
  background: var(--ink);
  color: white;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 28px;
  align-items: stretch;
  min-height: 320px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 34px;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 320px;
  padding-right: 8vw;
}

.hero-copy h2 {
  max-width: 760px;
  margin: 10px 0 18px;
  font-size: 48px;
  line-height: 1.05;
  font-weight: 680;
}

.hero-copy p:last-child {
  max-width: 650px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: end;
  gap: 10px;
}

.hero-metrics div {
  min-height: 150px;
  padding: 18px;
  background: var(--ink);
  color: white;
}

.hero-metrics strong {
  display: block;
  font-size: 42px;
  line-height: 1;
}

.hero-metrics span {
  display: block;
  margin-top: 14px;
  color: #d9d4ca;
}

.controls {
  display: flex;
  align-items: end;
  justify-content: flex-start;
  gap: 22px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.admin-panel {
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-top: 24px;
  padding: 22px 0 26px;
  border-bottom: 1px solid var(--line);
}

.upload-panel {
  gap: 24px;
  justify-content: space-between;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
}

body.internal .upload-panel.internal-only {
  display: flex;
}

.upload-panel h3 {
  margin-bottom: 8px;
  font-size: 22px;
}

.upload-panel p {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 420px;
}

.upload-form input {
  max-width: 230px;
}

.upload-form button,
.upload-form a {
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: white;
  color: var(--ink);
  text-decoration: none;
}

.upload-form button {
  background: var(--accent-2);
  color: white;
}

.upload-status {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.image-upload-panel {
  flex-wrap: wrap;
}

.image-preview {
  flex-basis: 100%;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  background: white;
}

.image-preview[hidden] {
  display: none;
}

.image-preview-head h4 {
  margin: 0 0 6px;
  font-size: 17px;
}

.image-preview-groups {
  display: grid;
  gap: 14px;
  margin-top: 14px;
  max-height: 480px;
  overflow: auto;
}

.image-preview-group {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.image-preview-group h5 {
  margin: 0 0 8px;
  font-size: 14px;
}

.image-preview-files {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.image-preview-file {
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.image-preview-file img {
  display: block;
  width: 100%;
  height: 100px;
  margin-bottom: 5px;
  object-fit: contain;
  background: #f5f5f5;
}

.image-preview-file .image-skipped {
  color: #a13d2d;
}

.image-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.image-category:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  font-size: 14px;
}

.image-category select {
  max-width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  background: white;
}

.image-preview-actions button {
  border: 1px solid var(--line);
  padding: 10px 14px;
  background: white;
  color: var(--ink);
}

.image-preview-actions button:first-child {
  background: var(--accent-2);
  color: white;
}

.image-preview-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

body.internal .admin-panel.internal-only {
  display: flex;
}

body.internal .customer-code-panel.internal-only {
  display: flex;
}

.customer-code-panel {
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 24px;
  padding: 22px 0 26px;
  border-bottom: 1px solid var(--line);
}

.customer-code-panel h3 {
  margin: 4px 0 8px;
  font-size: 22px;
}

.customer-code-panel p:last-child {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.code-box {
  min-width: 210px;
  padding: 18px;
  background: var(--ink);
  color: white;
  text-align: center;
}

.code-box strong {
  display: block;
  font-size: 40px;
  line-height: 1;
  letter-spacing: 2px;
}

.code-box span {
  display: block;
  margin-top: 10px;
  color: #d9d4ca;
  font-size: 13px;
}

.code-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.code-actions button {
  border: 1px solid var(--line);
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}

.admin-panel h2 {
  margin: 4px 0 8px;
  font-size: 28px;
}

.admin-panel p:last-child {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
  min-width: 430px;
}

.admin-stats div {
  min-height: 94px;
  padding: 14px;
  background: var(--ink);
  color: white;
}

.admin-stats strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.admin-stats span {
  display: block;
  margin-top: 12px;
  color: #d9d4ca;
  font-size: 13px;
}

.search {
  flex: 1;
  max-width: 520px;
}

.search span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 0 14px;
  background: white;
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: var(--accent);
}

.content-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 34px;
  padding-top: 34px;
}

.logic-panel {
  position: sticky;
  top: 96px;
  align-self: start;
  padding-right: 24px;
  border-right: 1px solid var(--line);
}

.logic-panel h3 {
  font-size: 22px;
}

.category-nav {
  display: grid;
  gap: 8px;
}

.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 1px solid var(--line);
  padding: 14px 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.category-item span {
  font-weight: 650;
}

.category-item strong {
  min-width: 28px;
  color: inherit;
  font-weight: 650;
  text-align: right;
}

.category-item.active {
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: white;
}

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

.section-head h2 {
  margin: 4px 0 0;
  font-size: 28px;
}

#resultCount {
  color: var(--muted);
}

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

.product-card {
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
}

.product-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  background: var(--soft);
}

.product-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 280ms ease;
}

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

.badge {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 6px 9px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-size: 12px;
}

.product-info {
  display: grid;
  gap: 8px;
  padding: 12px 0 6px;
}

.product-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.product-title strong {
  font-size: 19px;
}

.product-title span,
.meta {
  color: var(--muted);
  font-size: 13px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 25px;
}

.tag {
  border: 1px solid var(--line);
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 12px;
}

.admin-card {
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.54);
  color: var(--muted);
  font-size: 12px;
}

body.internal .admin-card {
  display: grid;
}

.admin-card strong {
  color: var(--ink);
  font-weight: 650;
  text-align: right;
}

.internal-only {
  display: none;
}

body.internal .internal-only {
  display: block;
}

.product-dialog {
  width: min(1180px, calc(100% - 36px));
  max-height: calc(100vh - 36px);
  border: 0;
  padding: 0;
  background: white;
  box-shadow: var(--shadow);
}

.product-dialog::backdrop {
  background: rgba(20, 18, 15, 0.52);
}

.auth-dialog {
  width: min(420px, calc(100% - 36px));
  border: 0;
  padding: 0;
  background: white;
  box-shadow: var(--shadow);
}

.auth-dialog::backdrop {
  background: rgba(20, 18, 15, 0.52);
}

.auth-box {
  padding: 28px;
}

.auth-box h2 {
  margin: 8px 0 22px;
  font-size: 28px;
}

.auth-box label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.auth-box input {
  width: 100%;
  border: 1px solid var(--line);
  padding: 13px 12px;
  background: var(--bg);
  color: var(--ink);
}

.auth-error {
  min-height: 22px;
  margin-top: 10px;
  color: var(--accent);
  font-size: 13px;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.auth-actions button {
  border: 1px solid var(--line);
  padding: 10px 14px;
  background: white;
  color: var(--ink);
}

.auth-actions button[type="submit"] {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.close {
  position: sticky;
  top: 0;
  z-index: 3;
  float: right;
  width: 48px;
  height: 48px;
  border: 0;
  background: var(--ink);
  color: white;
  font-size: 28px;
  line-height: 1;
}

.detail {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 28px;
  padding: 28px;
}

.detail-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-gallery-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.detail-gallery-meta strong {
  color: var(--ink);
  font-weight: 650;
}

.detail-gallery img {
  width: 100%;
  display: block;
  background: var(--soft);
}

.detail-side {
  position: sticky;
  top: 28px;
  align-self: start;
}

.detail-side h2 {
  margin: 8px 0 10px;
  font-size: 40px;
}

.color-picker {
  margin: 18px 0 20px;
  padding: 14px 0 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.color-picker p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.color-picker div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-option {
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: white;
  color: var(--muted);
}

.color-option.active {
  border-color: var(--accent-2);
  background: var(--accent-2);
  color: white;
}

.color-empty {
  margin: 16px 0 18px;
  padding: 12px;
  background: var(--bg);
  color: var(--muted);
  line-height: 1.5;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.detail-row strong {
  color: var(--ink);
  font-weight: 650;
  text-align: right;
}

.note {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg);
  color: var(--muted);
  line-height: 1.6;
}

.empty {
  padding: 50px;
  background: white;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 820px) {
  .topbar,
  .controls,
  .admin-panel,
  .customer-code-panel,
  .upload-panel,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  main,
  .topbar,
  .access-gate {
    padding-left: 18px;
    padding-right: 18px;
  }

  .access-gate {
    grid-template-columns: 1fr;
  }

  .hero-copy h2 {
    font-size: 40px;
  }

  .hero-metrics {
    grid-template-columns: 1fr;
  }

  .admin-stats {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .upload-form {
    justify-content: flex-start;
    min-width: 0;
  }

  .upload-status {
    text-align: left;
  }

  .code-actions {
    justify-content: flex-start;
  }

  .content-grid,
  .detail {
    grid-template-columns: 1fr;
  }

  .logic-panel {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 20px;
  }

  .product-grid,
  .detail-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .product-grid,
  .detail-gallery {
    grid-template-columns: 1fr;
  }

  .view-toggle {
    width: 100%;
  }
}
