:root {
  --bg: #f6f5ef;
  --surface: #ffffff;
  --surface-soft: #eeefe7;
  --ink: #252723;
  --muted: #6d7069;
  --line: #d8d8cd;
  --sage: #5f725d;
  --blue: #42586f;
  --brick: #a5533e;
  --gold: #bd8b3f;
  --shadow: 0 18px 60px rgba(37, 39, 35, 0.13);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  background: #20231f;
  color: #f7f5ec;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--gold);
  color: #191a17;
  font-weight: 800;
}

.brand h1,
.title-block h2,
.drawer-header h3 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 {
  font-size: 18px;
}

.brand p {
  margin: 5px 0 0;
  color: #cfd1c7;
  font-size: 13px;
}

.category-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.category-button {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.category-button:hover,
.category-button.active {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.25);
}

.category-button strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.category-button span {
  color: #c4c7bd;
  font-size: 12px;
}

.category-count {
  min-width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
}

.source-panel {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 13px;
}

.panel-title,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.source-panel .panel-title {
  color: #aeb3a8;
}

.source-panel a {
  color: #f7f5ec;
}

.content {
  min-width: 0;
  padding: 26px 30px 42px;
}

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

.title-block h2 {
  margin-top: 4px;
  font-size: clamp(26px, 3vw, 42px);
  font-weight: 750;
}

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

.search-field,
.upload-form label {
  display: grid;
  gap: 7px;
}

.search-field span,
.upload-form label span {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
}

.search-field input {
  width: min(36vw, 320px);
}

.primary-button,
.icon-button {
  height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  padding: 0 16px;
  background: var(--sage);
  color: white;
  font-weight: 700;
}

.primary-button:hover {
  background: #4f624e;
}

.primary-button.wide {
  width: 100%;
}

.icon-button {
  width: 42px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  font-size: 24px;
  line-height: 1;
}

.icon-grid {
  width: 16px;
  height: 16px;
  display: block;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 6px 6px,
    linear-gradient(var(--ink), var(--ink)) 10px 0 / 6px 6px,
    linear-gradient(var(--ink), var(--ink)) 0 10px / 6px 6px,
    linear-gradient(var(--ink), var(--ink)) 10px 10px / 6px 6px;
  background-repeat: no-repeat;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
  align-items: start;
}

.gallery.compact {
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.material-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(37, 39, 35, 0.06);
}

.material-card button {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.material-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-soft);
}

.card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(-3px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.material-card:hover .card-actions,
.material-card:focus-within .card-actions {
  opacity: 1;
  transform: translateY(0);
}

.mini-action {
  min-width: 34px;
  height: 32px;
  padding: 0 9px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(20, 21, 18, 0.64);
  color: white;
  cursor: pointer;
  font-size: 12px;
  backdrop-filter: blur(8px);
}

.mini-action.danger {
  background: rgba(118, 44, 35, 0.72);
}

.card-meta {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
}

.card-title-row strong {
  font-size: 14px;
  line-height: 1.25;
}

.badge {
  flex: 0 0 auto;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 999px;
  color: white;
  background: var(--blue);
  font-size: 12px;
}

.card-detail {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.load-more {
  display: block;
  min-width: 220px;
  height: 44px;
  margin: 22px auto 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.load-more:hover {
  border-color: var(--sage);
  color: var(--sage);
}

.load-more:disabled {
  cursor: default;
  color: var(--muted);
  background: var(--surface-soft);
  border-color: var(--line);
}

.load-more:disabled:hover {
  color: var(--muted);
  border-color: var(--line);
}

.upload-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(430px, 100vw);
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  transform: translateX(100%);
  transition: transform 180ms ease;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.upload-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.drawer-header h3 {
  margin-top: 4px;
  font-size: 26px;
}

.upload-form {
  display: grid;
  gap: 14px;
  overflow: auto;
}

.dropzone {
  min-height: 190px;
  place-items: center;
  justify-items: center;
  border: 1px dashed #aeb4a8;
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
  text-align: center;
}

.dropzone.dragging {
  border-color: var(--sage);
  background: #e4eadf;
}

.dropzone input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.drop-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sage);
  color: white;
  font-size: 28px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.upload-preview {
  display: grid;
  gap: 10px;
}

.upload-preview img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(25, 26, 23, 0.42);
}

.lightbox {
  width: min(1100px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: #151714;
  color: #f7f5ec;
}

.lightbox::backdrop {
  background: rgba(20, 21, 18, 0.72);
}

.lightbox img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 110px);
  object-fit: contain;
  background: #10110f;
}

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.45);
  color: white;
}

.lightbox-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
}

.lightbox-meta span {
  display: block;
  margin-top: 4px;
  color: #bfc3b8;
  font-size: 13px;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.secondary-button,
.lightbox-meta a {
  color: #f7f5ec;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 8px 12px;
  background: transparent;
  cursor: pointer;
}

.secondary-button:hover,
.lightbox-meta a:hover {
  border-color: rgba(255, 255, 255, 0.42);
}

.empty-state {
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .category-list {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  }

  .source-panel {
    margin-top: 0;
  }

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

  .tools {
    width: 100%;
    justify-content: flex-start;
  }

  .search-field,
  .search-field input {
    width: 100%;
  }

  .metric-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .content,
  .sidebar {
    padding: 18px;
  }

  .metric-row,
  .field-grid {
    grid-template-columns: 1fr;
  }

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

.primary-button:disabled { opacity: 0.62; cursor: wait; }
