:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --text: #1f1a17;
  --muted: #8a8178;
  --accent: #c45c4a;
  --line: #ece6df;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.top {
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: rgba(250, 248, 245, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.top h1 { margin: 0; font-size: 22px; font-weight: 600; }
.top .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

#app {
  padding: 0 12px calc(72px + var(--safe-bottom));
  min-height: 60vh;
}

.loading, .empty, .error {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 15px;
}

.month-title {
  margin: 20px 4px 10px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(31, 26, 23, 0.04);
}
.card img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  display: block;
  background: #f0ebe5;
}
.card .info {
  padding: 8px 10px 10px;
}
.card .date { font-size: 13px; font-weight: 600; }
.card .outfit {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.badge {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff0ec;
  color: var(--accent);
}
.badge.done { background: #edf7ef; color: #3d7a4d; }

.pick-hero {
  background: linear-gradient(135deg, #fff7f2, #f7f2ea);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
}
.pick-hero h2 { margin: 0 0 6px; font-size: 18px; }
.pick-hero p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.toolbar {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.toolbar button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
}
.toolbar button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.organize-list .row {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 8px;
}
.organize-list img {
  width: 56px;
  height: 74px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #f0ebe5;
}
.organize-list .meta { flex: 1; min-width: 0; }
.organize-list .meta .date { font-size: 13px; font-weight: 600; }
.organize-list .meta .outfit {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(255,255,255,0.96);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  backdrop-filter: blur(10px);
}
.tab {
  border: 0;
  background: transparent;
  padding: 10px 4px 12px;
  font-size: 12px;
  color: var(--muted);
}
.tab.active { color: var(--accent); font-weight: 600; }

.detail-inner {
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(24px + var(--safe-bottom));
}
.close {
  position: sticky;
  top: 8px;
  float: right;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,0.9);
  font-size: 24px;
  line-height: 1;
}
.detail-hero {
  width: 100%;
  max-height: 68vh;
  min-height: 42vh;
  object-fit: contain;
  object-position: center top;
  border-radius: 12px;
  display: block;
  background: #f0ebe5;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.94);
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom));
}

.image-viewer.is-open {
  display: flex;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-viewer-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 26px;
  line-height: 1;
}

.item-stats {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}

.outfit-mini-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
}
.outfit-mini-list img {
  width: 52px;
  height: 68px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #f0ebe5;
  border: 1px solid var(--line);
}

.link-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.link-picker.compact {
  padding-bottom: 12px;
}

.linked-selected {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  min-height: 58px;
  padding: 4px 0;
  margin-bottom: 6px;
}

.linked-selected:empty::before {
  content: '尚未关联单品';
  font-size: 13px;
  color: var(--muted);
  line-height: 58px;
}

.linked-chip {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.linked-chip img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  border: 2px solid var(--accent);
  background: #f0ebe5;
}

.linked-chip span {
  display: block;
  font-size: 9px;
  margin-top: 2px;
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  text-align: center;
}

.linked-chip .unlink {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  padding: 0;
}

.link-add-btn {
  width: 100%;
  border: 1px dashed var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  color: var(--muted);
}

.link-tile {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 0;
  background: #fff;
  overflow: hidden;
  text-align: center;
  cursor: pointer;
}

.link-tile.active {
  border-color: var(--accent);
}

.link-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #f0ebe5;
  pointer-events: none;
}

.link-tile span {
  display: block;
  font-size: 9px;
  padding: 3px 2px 4px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.sheet-inner {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px calc(16px + var(--safe-bottom));
}

.sheet-header {
  display: grid;
  grid-template-columns: 44px 1fr 56px;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
  padding: 4px 0 8px;
}

.sheet-header h3 {
  margin: 0;
  font-size: 16px;
  text-align: center;
  font-weight: 600;
}

.sheet-back,
.sheet-done {
  border: 0;
  background: transparent;
  font-size: 15px;
  color: var(--accent);
  padding: 8px 4px;
}

.sheet-back { text-align: left; font-size: 22px; }
.sheet-done { text-align: right; font-weight: 600; }

#link-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  margin-bottom: 10px;
  background: #fff;
}

.link-cats {
  margin-bottom: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}

.link-cats .chip {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 12px;
}

.sheet-count {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.sub-page {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  transform: translate3d(100%, 0, 0);
  transition: transform 0.26s ease;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}

.sub-page.is-open {
  transform: translate3d(0, 0, 0);
  visibility: visible;
  pointer-events: auto;
}

.sub-page-top {
  z-index: 210;
}

body.sub-page-open {
  overflow: hidden;
}

.sub-page .detail-inner,
.sub-page .sheet-inner {
  height: 100%;
  touch-action: pan-y;
}

.badge.count {
  background: #f3f0ec;
  color: var(--muted);
}
.detail-meta {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}
.detail-meta label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.detail-meta input,
.detail-meta select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
}
.detail-meta label .hint {
  font-weight: 400;
  color: var(--accent);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  color: var(--text);
}

.chip.active {
  background: #fff0ec;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.card .seasons {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}
.card .linked {
  margin-top: 4px;
  font-size: 11px;
  color: var(--accent);
  line-height: 1.3;
}

.items-hint {
  background: #fff7f2;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}
.primary {
  margin-top: 8px;
  border: 0;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(31,26,23,0.88);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 99;
}
.toast.show { opacity: 1; }
