:root {
  --bg: #f4f6f7;
  --paper: #ffffff;
  --ink: #161d23;
  --muted: #66727d;
  --line: #9aa5ac;
  --line-soft: #d9e1e5;
  --red: #e51f24;
  --orange: #ff7438;
  --teal: #176a64;
  --shadow: 0 16px 40px rgba(22, 29, 35, 0.08);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(360px, 1.2fr) minmax(360px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 12px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand span {
  display: grid;
  place-items: center;
  width: 57px;
  height: 57px;
  border-radius: 8px;
  background: var(--orange);
  color: white;
  font-weight: 900;
  overflow: hidden;
}

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

.brand span.has-logo-image {
  background: white;
  border: 1px solid var(--line-soft);
  color: transparent;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.tools {
  display: grid;
  grid-template-columns: minmax(220px, 340px) 140px;
  gap: 10px;
  justify-content: end;
}

.official-site {
  color: var(--teal);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}

.top-center {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: clamp(28px, 5vw, 72px);
  justify-self: stretch;
}

.top-center h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(22px, 2.3vw, 30px);
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
}

.tools input,
.tools select,
.admin-toggle,
.console-card input,
.console-card select,
.login-card input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 0 11px;
  background: white;
}

.admin-toggle,
.console-card button,
.login-card button {
  border: 0;
  color: white;
  background: var(--teal);
  font-weight: 900;
}

.admin-toggle.active { background: var(--orange); }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px clamp(10px, 2vw, 22px) 40px;
}

.admin-console h2 {
  margin: 0;
  font-size: clamp(24px, 2.6vw, 32px);
  letter-spacing: 0;
}

.manage-tip {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1180px;
  margin: 0 auto 12px;
  padding: 8px 12px;
  border: 1px solid #f3c9a9;
  border-radius: 8px;
  background: #fff7f1;
  color: #6c3b16;
}

.mindmap {
  display: grid;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
}

.category-block {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  min-height: 120px;
  position: relative;
  padding: 14px 0;
  border: 1px solid #e4ebee;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: var(--shadow);
  overflow: visible;
}

.category-label-wrap {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 0 20px;
}

.category-label-wrap::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  width: 20px;
  border-top: 2px solid var(--line);
}

.category-label {
  display: grid;
  place-items: center;
  width: 118px;
  min-height: 60px;
  padding: 9px;
  border: 2px solid #2a353c;
  border-radius: 9px;
  background: white;
  text-align: center;
}

.category-label strong {
  display: block;
  font-size: 19px;
}

.category-label small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.branch-list {
  position: relative;
  display: grid;
  gap: 14px;
  padding-left: 32px;
}

.branch-list::before {
  content: "";
  position: absolute;
  left: 0;
  top: 30px;
  bottom: 30px;
  border-left: 2px solid var(--line);
}

.branch-row {
  position: relative;
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.branch-row::before {
  content: "";
  position: absolute;
  left: -32px;
  top: 28px;
  width: 32px;
  border-top: 2px solid var(--line);
}

.branch-label {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 46px;
  padding: 6px 9px;
  border: 2px solid #2a353c;
  border-radius: 8px;
  background: white;
  font-size: 16px;
  font-weight: 900;
  text-align: center;
}

.product-list {
  position: relative;
  display: grid;
  border-left: 2px solid var(--line);
}

.product-row {
  position: relative;
  display: grid;
  grid-template-columns: 64px 118px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 60px;
  padding: 7px 0 7px 20px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.product-row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 18px;
  border-top: 2px solid var(--line);
}

.product-image {
  position: relative;
  width: 58px;
  height: 40px;
  overflow: visible;
  border: 1px solid #cfd9df;
  border-radius: 7px;
  background: #f7f8f9;
  z-index: 1;
}

.empty-thumb {
  display: block;
  width: 100%;
  height: 100%;
}

.product-image .thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

.product-image:hover {
  z-index: 45;
}

.thumb-zoom {
  display: none;
  position: absolute;
  right: 0;
  top: 50%;
  width: 475px;
  height: 330px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: white;
  box-shadow: 0 18px 48px rgba(22, 29, 35, 0.22);
  transform: translateY(-50%);
  pointer-events: none;
}

.thumb-zoom img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.product-image:hover .thumb-zoom {
  display: block;
}

.product-name {
  display: grid;
  gap: 3px;
}

.product-name strong {
  font-size: 15px;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 18px;
  padding: 0 6px;
  border-radius: 5px;
  background: var(--red);
  color: white;
  font-size: 10px;
  font-weight: 900;
}

.summary {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.product-row.hot .summary {
  color: var(--red);
  font-weight: 900;
}

.product-link:hover,
.name-link:hover {
  color: var(--teal);
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 6px;
  padding-right: 8px;
}

.file-toggle {
  min-height: 28px;
  border: 1px solid #cfd9df;
  border-radius: 8px;
  background: #f7faf9;
  color: var(--teal);
  font-weight: 900;
  font-size: 12px;
  white-space: nowrap;
}

.file-toggle:disabled {
  color: var(--muted);
  background: #f2f4f5;
  cursor: default;
}

.files {
  grid-column: 3 / 5;
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 7px;
  padding: 0 8px 7px 0;
}

.product-row.open .files { display: grid; }

.file-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
  padding: 7px 9px;
  border: 1px solid #cfd9df;
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 12px;
  font-weight: 800;
}

.file-item:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.no-files {
  color: var(--muted);
  font-size: 13px;
}

.admin-controls,
.branch-admin-controls,
.product-admin-controls {
  display: none;
  gap: 5px;
}

.admin-mode .admin-controls,
.admin-mode .branch-admin-controls,
.admin-mode .product-admin-controls {
  display: flex;
}

.admin-controls { margin-top: 8px; justify-content: center; }
.product-admin-controls { justify-content: end; }

.move-btn,
.mini-edit-btn {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.move-btn:hover,
.mini-edit-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.move-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.empty {
  padding: 34px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  text-align: center;
}

.admin-console {
  max-width: 1180px;
  margin: 24px auto 0;
  padding: 20px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: white;
  box-shadow: var(--shadow);
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--orange);
  font-weight: 900;
}

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

.console-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #f8fafb;
}

.console-card h3 {
  margin: 0 0 4px;
}

.console-card label,
.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.login-card .button-row {
  grid-template-columns: 1fr 1fr;
}

.console-card button,
.login-card button,
.ghost-btn,
.danger-btn {
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
}

.danger-btn {
  border: 1px solid #f0b9b9 !important;
  color: #b42318 !important;
  background: #fff3f3 !important;
}

.ghost-btn {
  border: 1px solid var(--line-soft) !important;
  color: var(--ink) !important;
  background: white !important;
  font-weight: 900;
}

.attachment-list {
  display: grid;
  gap: 6px;
  max-height: 150px;
  overflow: auto;
}

.thumb-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 8px;
  border: 1px dashed var(--line-soft);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  font-size: 12px;
}

.logo-preview {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  padding: 8px;
  border: 1px dashed var(--line-soft);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  font-size: 12px;
}

.logo-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}

.two-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.thumb-preview img {
  width: 64px;
  height: 42px;
  object-fit: cover;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

.attachment-admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: white;
  font-size: 12px;
}

.site-footer {
  max-width: 1180px;
  margin: 22px auto 0;
  padding: 14px 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
}

.footer-admin {
  width: auto;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-soft);
  color: var(--muted);
  background: white;
  font-size: 13px;
}

.footer-admin.active {
  color: white;
  background: var(--orange);
}

.login-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 29, 0.42);
}

.wechat-float {
  position: fixed;
  right: 16px;
  top: 50%;
  z-index: 30;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 10px;
  transform: translateY(-50%);
}

.wechat-toggle {
  display: none;
  place-items: center;
  width: 58px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: white;
  color: var(--teal);
  box-shadow: 0 12px 34px rgba(22, 29, 35, 0.16);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.2;
  cursor: pointer;
}

.wechat-toggle:hover {
  border-color: var(--teal);
}

.wechat-popover {
  display: block;
  width: 168px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: white;
  box-shadow: 0 14px 38px rgba(22, 29, 35, 0.16);
  text-align: center;
}

.wechat-float.open .wechat-popover {
  display: block;
}

.wechat-popover img {
  width: 138px;
  height: 138px;
  object-fit: cover;
  border-radius: 8px;
}

.wechat-popover span {
  display: grid;
  place-items: center;
  width: 138px;
  height: 138px;
  margin: 0 auto;
  border: 1px dashed var(--line-soft);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.wechat-popover strong {
  display: block;
  margin-top: 8px;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  min-width: 180px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  color: white;
  background: var(--teal);
  box-shadow: 0 16px 44px rgba(22, 29, 35, 0.2);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  transform: translateX(-50%);
}

.toast.error {
  background: var(--red);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.login-card h2,
.login-card p {
  margin: 0;
}

.login-card p,
.login-error,
.form-message {
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  min-height: 18px;
  color: var(--red);
  font-weight: 800;
}

.form-message {
  min-height: 18px;
  font-weight: 800;
  color: var(--teal);
}

@media (max-width: 1100px) {
  .category-block,
  .branch-row {
    grid-template-columns: 1fr;
  }

  .category-label-wrap,
  .branch-list {
    padding: 0;
  }

  .category-label-wrap::after,
  .branch-list::before,
  .branch-row::before {
    display: none;
  }

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

@media (max-width: 720px) {
  .topbar,
  .console-head {
    align-items: stretch;
    display: flex;
    flex-direction: column;
  }

  .top-center {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .tools,
  .console-grid {
    grid-template-columns: 1fr;
  }

  .product-list {
    border-left: 0;
    gap: 10px;
  }

  .product-row {
    grid-template-columns: 70px minmax(0, 1fr);
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
  }

  .product-row::before { display: none; }
  .summary, .row-actions, .files { grid-column: 1 / -1; }
  .summary { font-size: 13px; }

  .wechat-float {
    right: 8px;
    transform: translateY(-50%) scale(0.86);
    transform-origin: right center;
  }

  .wechat-toggle {
    display: grid;
  }

  .wechat-popover {
    display: none;
  }

  .wechat-float.open .wechat-popover {
    display: block;
  }
}
