:root {
  --background: #f8fafc;
  --foreground: #0f172a;
  --card: #ffffff;
  --muted: #f1f5f9;
  --muted-foreground: #64748b;
  --border: #e2e8f0;
  --input: #cbd5e1;
  --primary: #2563eb;
  --primary-foreground: #ffffff;
  --accent: #06b6d4;
  --danger: #dc2626;
  --sidebar: #f8fafc;
  --sidebar-accent: #eff6ff;
  --sidebar-foreground: #0f172a;
  --radius: 10px;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--foreground);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, #eef5ff 0, transparent 28rem),
    linear-gradient(180deg, #f8fafc 0%, var(--background) 18rem);
}

button,
input,
select {
  font: inherit;
}

button {
  border-radius: 8px;
}

.app-shell {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid rgba(226, 232, 240, 0.92);
  background: rgba(248, 250, 252, 0.96);
  box-shadow: 1px 0 0 rgba(226, 232, 240, 0.7);
  padding: 16px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 4px 6px 18px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.brand-title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
}

.nav-list {
  display: grid;
  gap: 6px;
  padding: 8px 0 14px;
  border-top: 1px solid rgba(226, 232, 240, 0.78);
}

.nav-item {
  position: relative;
  width: 100%;
  height: 40px;
  border: 0;
  background: transparent;
  color: rgba(15, 23, 42, 0.72);
  text-align: left;
  padding: 0 12px 0 18px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.nav-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 20px;
  transform: translateY(-50%);
  border-radius: 0 8px 8px 0;
  background: var(--primary);
  opacity: 0;
}

.nav-item.active {
  background: #dbeafe;
  color: #1d4ed8;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.16), 0 8px 18px rgba(37, 99, 235, 0.1);
}

.nav-item.active::before {
  opacity: 1;
}

.nav-item:hover {
  background: rgba(241, 245, 249, 0.9);
  color: #0f172a;
}

.main {
  min-width: 0;
  padding: 22px 24px 32px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
}

h2 {
  font-size: 17px;
  font-weight: 900;
}

.topbar p,
.panel p,
.dialog-head p {
  margin-top: 7px;
  color: var(--muted-foreground);
  font-size: 13px;
}

.top-actions,
.button-row,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  flex-wrap: wrap;
}

.button {
  min-height: 38px;
  border: 1px solid var(--border);
  padding: 8px 13px;
  background: #ffffff;
  color: #0f172a;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.button.primary:hover {
  background: #1d4ed8;
}

.button.secondary:hover {
  border-color: rgba(37, 99, 235, 0.36);
  background: #eff6ff;
  color: #1d4ed8;
}

.button.danger {
  border-color: rgba(220, 38, 38, 0.28);
  color: var(--danger);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 900;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 160px 190px;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--input);
  border-radius: 8px;
  background: #ffffff;
  color: var(--foreground);
  padding: 8px 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.summary-strip > div,
.panel,
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.summary-strip > div {
  padding: 14px 16px;
}

.summary-strip span:last-child {
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 800;
}

.metric {
  display: block;
  color: #0f172a;
  font-size: 24px;
  font-weight: 900;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1260px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

th[data-field="image"],
td[data-field="image"] {
  width: 24%;
  min-width: 220px;
}

td {
  color: #1e293b;
  font-size: 13px;
}

tbody tr:hover td {
  background: #f8fbff;
}

tbody tr {
  cursor: default;
}

tbody tr[data-product-id] {
  cursor: pointer;
}

.product-image,
.image-preview img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--muted);
}

.image-placeholder {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--muted-foreground);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

.image-placeholder-button {
  cursor: pointer;
}

.image-placeholder-button:hover {
  border-color: rgba(37, 99, 235, 0.56);
  color: #1d4ed8;
  background: #eff6ff;
}

.image-cell-list {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 184px;
  max-width: min(620px, 30vw);
  overflow: hidden;
}

.image-cell-button {
  display: inline-grid;
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  place-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: zoom-in;
}

.image-cell-button:hover .product-image,
.preview-image-button:hover img,
.gallery-thumb:hover img {
  border-color: rgba(37, 99, 235, 0.56);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.14);
}

.image-count {
  display: inline-grid;
  min-width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #1d4ed8;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  padding: 4px;
  font-size: 13px;
  font-weight: 900;
}

.text-button.danger {
  color: var(--danger);
}

.empty-state {
  display: none;
  padding: 42px 20px;
  text-align: center;
  color: var(--muted-foreground);
}

.empty-state strong {
  display: block;
  margin-bottom: 8px;
  color: var(--foreground);
  font-size: 17px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.pagination-info {
  color: #334155;
  font-size: 13px;
  font-weight: 900;
}

.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-button-light {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
}

.page-jump,
.page-size-select {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  color: #334155;
}

.page-jump input,
.page-size-select select {
  width: 70px;
  min-height: 32px;
  text-align: center;
}

.page-size-select select {
  width: 88px;
}

.export-scope-field {
  margin: 16px 0 14px;
}

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

.panel {
  padding: 18px;
}

.stack {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.field-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.field-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
}

.field-item strong {
  display: block;
  margin-bottom: 4px;
  color: #0f172a;
  font-size: 13px;
}

.field-item span {
  color: var(--muted-foreground);
  font-size: 12px;
}

.hidden-field-picker {
  display: grid;
  gap: 8px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 800;
}

.multi-select {
  position: relative;
}

.multi-select-trigger {
  position: relative;
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--input);
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  padding: 8px 34px 8px 10px;
  text-align: left;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.multi-select-trigger::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: translateY(-70%) rotate(45deg);
}

.multi-select.open .multi-select-trigger {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.multi-select-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.14);
}

.multi-select.open .multi-select-menu {
  display: grid;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  color: #0f172a;
  font-size: 13px;
  font-weight: 800;
}

.checkbox-item input {
  width: 16px;
  min-height: 16px;
  height: 16px;
  accent-color: var(--primary);
}

dialog {
  width: min(900px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.gallery-dialog::backdrop {
  background: rgba(15, 23, 42, 0.86);
}

#productForm,
#accountForm,
#passwordForm {
  padding: 20px;
}

.login-dialog {
  width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(226, 232, 240, 0.94);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
}

.login-dialog::backdrop {
  background:
    linear-gradient(rgba(15, 23, 42, 0.62), rgba(15, 23, 42, 0.62)),
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.24), transparent 34rem);
}

.login-card {
  padding: 34px 34px 30px;
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin-bottom: 26px;
  text-align: center;
}

.login-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  font-size: 24px;
}

.login-brand h2 {
  font-size: 24px;
  letter-spacing: 0;
}

.login-brand p {
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 800;
}

.login-grid {
  display: grid;
  gap: 14px;
}

.login-grid input {
  min-height: 46px;
}

.login-actions {
  margin-top: 22px;
}

.login-submit {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

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

.image-upload-field {
  grid-column: 1 / -1;
}

.image-upload-field input {
  display: none;
}

.image-preview {
  display: flex;
  grid-column: 1 / -1;
  flex-wrap: nowrap;
  gap: 10px;
  min-height: 74px;
  align-items: center;
  justify-content: flex-start;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 800;
  padding: 9px;
  overflow-x: auto;
}

.preview-thumb {
  position: relative;
  width: 62px;
  height: 62px;
}

.preview-image-button {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: zoom-in;
}

.preview-add {
  display: grid;
  width: 62px;
  height: 62px;
  flex: 0 0 62px;
  place-items: center;
  border: 1px dashed #93c5fd;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.preview-add:hover {
  border-color: #2563eb;
  background: #dbeafe;
}

.preview-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 8px 14px rgba(220, 38, 38, 0.22);
}

.dialog-actions {
  margin-top: 18px;
}

.readonly-dialog input:disabled {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #0f172a;
  opacity: 1;
}

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

.compact-table {
  box-shadow: none;
}

.compact-table table {
  min-width: 920px;
}

.account-log-panel {
  margin-top: 16px;
}

#settingsView > .panel + .panel {
  margin-top: 16px;
}

.admin-settings-panel {
  margin-bottom: 16px;
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) max-content max-content;
  gap: 12px;
  align-items: end;
}

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

.storage-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 13px 14px;
}

.storage-card span {
  display: block;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 800;
}

.storage-card strong {
  display: block;
  margin-top: 6px;
  color: #0f172a;
  font-size: 20px;
  font-weight: 900;
}

.storage-note {
  margin-top: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.success {
  background: #dcfce7;
  color: #166534;
}

.status-pill.danger {
  background: #fee2e2;
  color: #991b1b;
}

.gallery-dialog {
  width: fit-content;
  max-width: calc(100vw - 48px);
  height: fit-content;
  max-height: calc(100vh - 48px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.gallery-dialog::backdrop {
  background: transparent;
}

.gallery-shell {
  display: grid;
  grid-template-rows: auto auto auto;
  width: fit-content;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  padding: 0;
  background: transparent;
}

.gallery-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: #ffffff;
}

.gallery-title-block h2 {
  color: #ffffff;
}

.gallery-title-block p {
  color: rgba(255, 255, 255, 0.72);
}

.gallery-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-button {
  min-height: 34px;
  padding: 6px 10px;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.62);
  color: #ffffff;
  font-size: 12px;
}

.gallery-tools .icon-button {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.62);
  color: #ffffff;
}

.gallery-stage {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  overflow: hidden;
}

.gallery-stage img {
  width: auto;
  height: auto;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 180px);
  object-fit: contain;
  justify-self: center;
  align-self: center;
  border-radius: 0;
  cursor: zoom-in;
  transition: transform 0.12s ease;
  transform-origin: center center;
  user-select: none;
  touch-action: none;
}

.gallery-stage img.is-zoomed {
  cursor: grab;
}

.gallery-stage img.is-dragging {
  cursor: grabbing;
  transition: none;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  width: 42px;
  height: 64px;
  transform: translateY(-50%);
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
}

#prevImageBtn {
  left: 8px;
}

#nextImageBtn {
  right: 8px;
}

.gallery-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.gallery-thumb-strip {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 8px;
  padding: 12px 2px 0;
}

.gallery-thumb-nav {
  display: grid;
  width: 34px;
  height: 54px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.62);
  color: #ffffff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.gallery-thumb-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.gallery-thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  justify-content: center;
  padding: 0;
}

.gallery-thumb {
  display: grid;
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid transparent;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.gallery-thumb.active {
  border-color: #ffffff;
}

.gallery-thumb img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--muted);
}

.spacer {
  flex: 1;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  border-radius: 10px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden-field,
.readonly-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    height: auto;
    z-index: 5;
    padding: 12px 14px;
  }

  .brand {
    min-height: 52px;
    padding-bottom: 10px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    min-width: max-content;
  }

  .topbar,
  .toolbar,
  .summary-strip,
  .panel-grid,
  .field-list,
  .settings-form,
  .storage-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .pagination-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .pagination-controls,
  .dialog-actions {
    justify-content: flex-start;
  }

  .main {
    padding: 16px;
  }
}
