:root {
  color-scheme: light;
  --ink: #263238;
  --muted: #66736e;
  --line: #d8ded8;
  --paper: #faf8f2;
  --panel: #ffffff;
  --olive: #546a4d;
  --olive-dark: #344738;
  --terracotta: #b86f52;
  --gold: #d7a84e;
  --sky: #8bb7c8;
  --shadow: 0 18px 45px rgba(45, 55, 50, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(84, 106, 77, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(184, 111, 82, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  color: var(--ink);
  font-family:
    "Noto Sans TC",
    "Microsoft JhengHei",
    system-ui,
    sans-serif;
}

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

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100vh;
  padding: 28px 20px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: var(--olive-dark);
  color: #fffaf0;
  font-weight: 800;
}

.brand-block h1,
.brand-block p,
.title-area h2,
.title-area p,
.stat p,
.drop-zone h3,
.drop-zone p,
.card-body h3,
.card-body p {
  margin: 0;
}

.brand-block h1 {
  font-size: 20px;
  line-height: 1.25;
}

.brand-block p,
.title-area p,
.stat p,
.card-meta,
.card-note {
  color: var(--muted);
}

.primary-action,
.secondary-action,
.ghost-action,
.category-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
}

.primary-action {
  width: 100%;
  padding: 0 16px;
  background: var(--olive-dark);
  color: #fff;
  font-weight: 700;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: #26352a;
}

.primary-action.compact {
  width: auto;
  min-width: 120px;
}

.secondary-action {
  padding: 0 16px;
  background: #fff;
  border-color: var(--line);
  color: var(--olive-dark);
  font-weight: 700;
}

.secondary-action:hover,
.secondary-action:focus-visible,
.category-button:hover,
.category-button:focus-visible {
  border-color: var(--olive);
  box-shadow: 0 0 0 4px rgba(84, 106, 77, 0.1);
}

.ghost-action {
  padding: 0 14px;
  background: transparent;
  border-color: #e4c9bd;
  color: #9a4d37;
  font-weight: 700;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

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

.category-button {
  width: 100%;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  justify-content: space-between;
}

.category-button span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-button.active {
  background: #eef2ea;
  border-color: rgba(84, 106, 77, 0.35);
  color: var(--olive-dark);
  font-weight: 800;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(84, 106, 77, 0.12);
  color: var(--olive-dark);
  font-size: 13px;
}

.new-category {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.new-category label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.new-category div {
  display: flex;
  gap: 8px;
}

.new-category input {
  min-width: 0;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.new-category button {
  flex: 0 0 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--olive-dark);
}

.album-info {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.album-info p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.album-info strong {
  color: var(--olive-dark);
  font-size: 16px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 28px clamp(18px, 3vw, 40px) 42px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 18px;
  align-items: end;
}

.title-area h2 {
  max-width: 780px;
  font-size: clamp(26px, 3vw, 42px);
  line-height: 1.15;
  letter-spacing: 0;
}

.title-area p {
  margin-bottom: 8px;
  color: var(--terracotta);
  font-weight: 800;
}

.search-wrap {
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  color: var(--muted);
  transform: translateY(-50%);
}

.search-wrap input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px rgba(67, 73, 62, 0.06);
}

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

.stat {
  min-height: 92px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat span {
  display: block;
  margin-bottom: 8px;
  color: var(--olive-dark);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.drop-zone,
.album-note {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
  min-height: 190px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(139, 183, 200, 0.22), rgba(215, 168, 78, 0.18)),
    rgba(255, 255, 255, 0.88);
  border: 1px dashed rgba(84, 106, 77, 0.48);
  border-radius: 8px;
}

.album-note {
  grid-template-columns: 150px minmax(0, 1fr);
}

.drop-zone.dragging {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 6px rgba(184, 111, 82, 0.12);
}

.drop-zone h3,
.album-note h3 {
  font-size: 22px;
}

.drop-zone p,
.album-note p {
  margin-top: 6px;
}

.drop-visual {
  position: relative;
  width: 138px;
  height: 132px;
}

.photo-stack {
  position: absolute;
  width: 92px;
  height: 112px;
  background: #fff;
  border: 1px solid rgba(38, 50, 56, 0.16);
  box-shadow: 0 12px 24px rgba(38, 50, 56, 0.14);
}

.photo-stack::before {
  content: "";
  position: absolute;
  inset: 10px 10px 28px;
  background:
    radial-gradient(circle at 65% 36%, rgba(255, 255, 255, 0.95) 0 8px, transparent 9px),
    linear-gradient(145deg, rgba(84, 106, 77, 0.84), rgba(139, 183, 200, 0.8) 55%, rgba(215, 168, 78, 0.78));
}

.photo-stack::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 13px;
  height: 6px;
  background: rgba(84, 106, 77, 0.18);
}

.stack-one {
  left: 7px;
  top: 12px;
  transform: rotate(-10deg);
}

.stack-two {
  left: 35px;
  top: 6px;
  transform: rotate(7deg);
}

.stack-three {
  left: 22px;
  top: 18px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.photo-card {
  overflow: hidden;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(44, 51, 47, 0.08);
}

.image-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: #f4f0e7;
}

.image-button img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.missing-image .image-button {
  background:
    linear-gradient(135deg, rgba(84, 106, 77, 0.22), rgba(215, 168, 78, 0.22)),
    #f4f0e7;
}

.missing-image .image-button img {
  opacity: 0;
}

.card-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.card-category {
  color: var(--terracotta);
  font-size: 12px;
  font-weight: 900;
}

.card-body h3 {
  overflow: hidden;
  margin-top: 2px;
  font-size: 18px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta,
.card-note {
  overflow: hidden;
  font-size: 14px;
  line-height: 1.45;
}

.card-note {
  display: -webkit-box;
  min-height: 40px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 26px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.photo-dialog {
  width: min(900px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.photo-dialog::backdrop {
  background: rgba(32, 38, 34, 0.46);
}

.dialog-card {
  background: var(--panel);
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-body {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.preview-pane {
  overflow: hidden;
  align-self: start;
  background: #f4f0e7;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview-pane img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
}

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

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

.field-grid .wide {
  grid-column: 1 / -1;
}

.field-grid input,
.field-grid select,
.field-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.field-grid input,
.field-grid select {
  height: 42px;
  padding: 0 10px;
}

.field-grid textarea {
  resize: vertical;
  min-height: 92px;
  padding: 10px;
}

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

.detail-list div {
  min-width: 0;
  padding: 12px;
  background: #faf8f2;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.detail-list .wide {
  grid-column: 1 / -1;
}

.detail-list dt {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
  color: var(--ink);
  line-height: 1.55;
}

.dialog-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

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

  .sidebar {
    position: relative;
    height: auto;
    padding: 18px;
  }

  .category-list {
    flex-direction: row;
    overflow-x: auto;
  }

  .category-button {
    flex: 0 0 auto;
    width: auto;
    min-width: 132px;
  }

  .new-category {
    margin-top: 0;
  }

  .topbar,
  .drop-zone,
  .album-note,
  .dialog-body {
    grid-template-columns: 1fr;
  }

  .drop-visual {
    display: none;
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 18px 14px 30px;
  }

  .stats-row,
  .field-grid,
  .detail-list {
    grid-template-columns: 1fr;
  }

  .drop-zone,
  .album-note {
    gap: 14px;
    min-height: 0;
  }

  .secondary-action,
  .primary-action.compact,
  .ghost-action {
    width: 100%;
  }

  .dialog-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }
}
