:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #f0f3f7;
  --ink: #16191f;
  --muted: #697180;
  --line: #dfe4ec;
  --line-strong: #c8d0dc;
  --accent: #0f8f83;
  --accent-strong: #0b6f66;
  --accent-soft: #dff4f1;
  --coral: #d75f4f;
  --coral-soft: #ffe8e3;
  --violet: #7756d9;
  --shadow: 0 18px 40px rgba(25, 30, 40, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 143, 131, 0.12), transparent 30rem),
    linear-gradient(315deg, rgba(215, 95, 79, 0.09), transparent 28rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid rgba(223, 228, 236, 0.9);
  background: rgba(247, 248, 251, 0.86);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 45%, rgba(255, 255, 255, 0.78) 45% 58%, transparent 58%),
    linear-gradient(135deg, #0f8f83, #44b78b 48%, #d75f4f);
  box-shadow: 0 10px 25px rgba(15, 143, 131, 0.24);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.1;
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  width: min(46rem, 100%);
}

.search-box {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
  min-width: min(24rem, 40vw);
  height: 2.65rem;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.button,
.icon-button {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 0.9rem;
  white-space: nowrap;
}

.icon-button {
  width: 2.5rem;
  display: inline-grid;
  place-items: center;
}

.button:hover,
.icon-button:hover,
.filter-button:hover,
.album-item:hover,
.segmented button:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button.danger {
  border-color: rgba(215, 95, 79, 0.45);
  background: var(--coral-soft);
  color: #a4382c;
}

.layout {
  display: grid;
  grid-template-columns: minmax(16rem, 18.5rem) minmax(0, 1fr);
  gap: 1rem;
  width: min(96rem, 100%);
  margin: 0 auto;
  padding: 1rem clamp(1rem, 3vw, 2rem) 2rem;
}

.sidebar,
.workspace,
.toolbar,
.selection-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 5.35rem;
  padding: 1rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.metrics div {
  min-width: 0;
  padding: 0.75rem 0.5rem;
  border-radius: 8px;
  background: var(--panel-soft);
  text-align: center;
}

.metrics strong {
  display: block;
  font-size: 1.05rem;
}

.metrics span {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.filter-list,
.album-list {
  display: grid;
  gap: 0.45rem;
}

.filter-button,
.album-item {
  width: 100%;
  min-height: 2.6rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.filter-button small,
.album-item small {
  color: var(--muted);
}

.filter-button.is-active,
.album-item.is-active {
  border-color: rgba(15, 143, 131, 0.22);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 1.1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.album-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.2rem;
  align-items: center;
  gap: 0.35rem;
}

.album-row .icon-button {
  width: 2.2rem;
  min-height: 2.2rem;
  color: var(--muted);
}

.album-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.5rem;
  gap: 0.45rem;
  margin-top: 1rem;
}

.album-form input,
.select-label select,
.selection-bar select,
.field select,
.field textarea {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.album-form input {
  height: 2.5rem;
  padding: 0 0.75rem;
}

.workspace {
  min-width: 0;
  padding: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(4.5rem, 1fr));
  gap: 0.25rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.segmented button {
  min-height: 2rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.segmented button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 5px 15px rgba(25, 30, 40, 0.08);
}

.select-label,
.range-label,
.field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.select-label {
  grid-template-columns: auto minmax(8rem, 12rem);
  align-items: center;
}

.select-label select,
.selection-bar select,
.field select {
  height: 2.35rem;
  padding: 0 0.65rem;
}

.range-label {
  grid-template-columns: auto minmax(8rem, 12rem);
  align-items: center;
}

.range-label input {
  accent-color: var(--accent);
}

.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.selection-bar strong {
  margin-right: auto;
}

.drop-zone {
  position: relative;
  min-height: calc(100vh - 12rem);
  border: 1px dashed transparent;
  border-radius: 8px;
  outline: 0;
}

.drop-zone.is-dragging {
  border-color: var(--accent);
  background: rgba(15, 143, 131, 0.07);
}

.gallery {
  --thumb-size: 220px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--thumb-size)), 1fr));
  gap: 0.8rem;
}

.gallery[data-size="160"] {
  --thumb-size: 160px;
}

.gallery[data-size="180"] {
  --thumb-size: 180px;
}

.gallery[data-size="200"] {
  --thumb-size: 200px;
}

.gallery[data-size="220"] {
  --thumb-size: 220px;
}

.gallery[data-size="240"] {
  --thumb-size: 240px;
}

.gallery[data-size="260"] {
  --thumb-size: 260px;
}

.gallery[data-size="280"] {
  --thumb-size: 280px;
}

.gallery[data-size="300"] {
  --thumb-size: 300px;
}

.gallery[data-size="320"] {
  --thumb-size: 320px;
}

.gallery.is-list {
  grid-template-columns: 1fr;
}

.photo-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(25, 30, 40, 0.06);
}

.photo-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 143, 131, 0.18);
}

.photo-button {
  width: 100%;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #d9dee8;
  object-fit: cover;
}

.photo-meta {
  display: grid;
  gap: 0.2rem;
  padding: 0.7rem;
}

.photo-title {
  overflow: hidden;
  color: var(--ink);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-subtitle {
  color: var(--muted);
  font-size: 0.82rem;
}

.photo-controls {
  position: absolute;
  inset: 0.45rem 0.45rem auto 0.45rem;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.photo-controls button {
  width: 2rem;
  min-height: 2rem;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  background: rgba(22, 25, 31, 0.6);
  color: #ffffff;
  pointer-events: auto;
}

.photo-controls button.is-on {
  background: var(--coral);
}

.gallery.is-list .photo-card {
  display: grid;
  grid-template-columns: minmax(8rem, 13rem) minmax(0, 1fr);
}

.gallery.is-list .photo-button {
  display: contents;
}

.gallery.is-list .photo-thumb {
  height: 100%;
  min-height: 8rem;
  aspect-ratio: auto;
}

.gallery.is-list .photo-meta {
  align-content: center;
  padding-right: 3.5rem;
}

.empty-state {
  min-height: calc(100vh - 16rem);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.85rem;
  padding: 3rem 1rem;
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.empty-state p {
  max-width: 28rem;
  margin: 0;
  color: var(--muted);
}

.empty-visual {
  position: relative;
  width: min(14rem, 60vw);
  height: 9rem;
  margin-bottom: 0.5rem;
}

.empty-visual span {
  position: absolute;
  inset: 1rem 2.2rem;
  border: 5px solid #ffffff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.empty-visual span:nth-child(1) {
  transform: rotate(-8deg) translateX(-1.2rem);
  background: linear-gradient(135deg, #0f8f83, #f3c65b);
}

.empty-visual span:nth-child(2) {
  transform: rotate(6deg) translateX(1.2rem);
  background: linear-gradient(135deg, #7756d9, #69b7e8);
}

.empty-visual span:nth-child(3) {
  inset: 0.7rem 2.7rem;
  background: linear-gradient(135deg, #d75f4f, #f3c65b 55%, #44b78b);
}

.viewer {
  width: min(92rem, calc(100vw - 2rem));
  height: min(50rem, calc(100vh - 2rem));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
}

.viewer::backdrop {
  background: rgba(12, 15, 21, 0.68);
  backdrop-filter: blur(8px);
}

.viewer-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 22rem);
  background: #0c0f15;
  border-radius: 8px;
  overflow: hidden;
}

.viewer-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 2rem 3.25rem;
}

.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  object-fit: contain;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.viewer-panel {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 1rem;
  padding: 1.2rem;
  background: var(--panel);
}

.viewer-panel h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
}

.viewer-panel p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.field textarea {
  width: 100%;
  resize: vertical;
  padding: 0.7rem;
  line-height: 1.5;
}

.viewer-close,
.viewer-nav {
  position: absolute;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  backdrop-filter: blur(10px);
}

.viewer-close {
  top: 1rem;
  right: calc(22rem + 1rem);
  width: 2.35rem;
  min-height: 2.35rem;
}

.viewer-nav {
  top: 50%;
  width: 2.5rem;
  min-height: 2.5rem;
  transform: translateY(-50%);
  font-size: 1.35rem;
}

.viewer-prev {
  left: 0.85rem;
}

.viewer-next {
  right: calc(22rem + 0.85rem);
}

.toast-region {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  display: grid;
  gap: 0.6rem;
  width: min(22rem, calc(100vw - 2rem));
}

.toast {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .search-box {
    min-width: 0;
    flex: 1 1 14rem;
  }

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

  .sidebar {
    position: static;
  }

  .viewer-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .viewer-panel {
    max-height: 42vh;
    overflow: auto;
  }

  .viewer-close {
    right: 1rem;
  }

  .viewer-next {
    right: 0.85rem;
  }
}

@media (max-width: 680px) {
  .top-actions,
  .toolbar,
  .selection-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions .button,
  .search-box {
    width: 100%;
  }

  .select-label,
  .range-label {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .gallery.is-list .photo-card {
    grid-template-columns: 1fr;
  }

  .gallery.is-list .photo-thumb {
    height: auto;
    aspect-ratio: 4 / 3;
  }

  .viewer {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
  }

  .viewer-shell,
  .viewer {
    border-radius: 0;
  }

  .viewer-stage {
    padding: 3.4rem 1rem 1rem;
  }

  .viewer-nav {
    top: 2.1rem;
    transform: none;
  }

  .viewer-prev {
    left: 1rem;
  }

  .viewer-next {
    right: 4rem;
  }
}
