/* ============================================================
   今天穿什麼：全站樣式
   主色：米白（背景）+ 深灰（文字、按鈕）
   ============================================================ */

:root {
  --bg: #F6F3EE;          /* 米白 */
  --surface: #FFFFFF;
  --surface-2: #EEEAE3;
  --ink: #2B2B2B;         /* 深灰 */
  --ink-2: #5E5B57;
  --ink-3: #9A968F;
  --line: #E2DDD4;
  --danger: #A8322A;
  --danger-bg: #FBF1EF;

  --radius: 4px;
  --topbar-h: 52px;
  --tabbar-h: 60px;
  --max-w: 560px;

  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang TC",
          "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }

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

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 32px; height: 32px; stroke-width: 1.3; }

/* ---------- 上方標題列 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: rgba(246, 243, 238, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: var(--max-w);
  height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-decoration: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-right: -8px;
  color: var(--ink-2);
  border-radius: 50%;
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.active { color: var(--ink); }

/* ---------- 主要內容 ---------- */

.view {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 24px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 32px);
  outline: none;
}

.page-head { margin-bottom: 20px; }

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.block { margin-top: 32px; }

.section-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.14em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.muted { color: var(--ink-2); margin: 0; font-size: 14px; }

.note {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

.alert {
  padding: 14px 16px;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 14px;
}
.alert p { margin: 0 0 10px; }
.alert p:last-child { margin-bottom: 0; }

/* ---------- 按鈕 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.btn-outline { background: transparent; color: var(--ink); }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.alert .btn { border-color: var(--danger); color: var(--danger); }

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn-row .btn { flex: 1; }

/* ---------- 場合標籤 ---------- */

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

.chip {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
}
.chip.is-disabled { color: var(--ink-3); }

/* ---------- 天氣卡片 ---------- */

.loc {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  color: var(--ink-2);
  font-size: 14px;
}
.loc-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
/* 隱形的下拉選單蓋在地點文字上，點下去就會跳出選單 */
.loc-select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* 避免 iPhone 點選時自動放大 */
}
.loc:focus-within { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 2px; }

.weather-main {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-top: 16px;
}

.temp {
  font-size: 64px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.02em;
}
.temp .unit {
  font-size: 22px;
  margin-left: 2px;
  color: var(--ink-2);
  vertical-align: top;
}

.cond {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--ink-2);
}

.weather-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.weather-meta div { text-align: center; }
.weather-meta div + div { border-left: 1px solid var(--line); }
.weather-meta dt { font-size: 12px; color: var(--ink-3); letter-spacing: 0.04em; }
.weather-meta dd { margin: 2px 0 0; font-size: 16px; }

.weather .alert { margin-top: 16px; }

.weather-loading {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.skeleton {
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, #F6F3EE 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- 設定頁的清單 ---------- */

.card.list { padding: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--ink);
  flex: none;
}
.row-text { display: flex; flex-direction: column; }
.row-title { font-size: 15px; }
.row-sub { font-size: 12px; color: var(--ink-3); }

.select {
  margin-left: auto;
  min-width: 120px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px;
}

/* 分段選擇（男 / 女） */
.seg {
  display: flex;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg label { flex: 1; }
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg span {
  display: block;
  padding: 12px 0;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
  background: var(--surface);
}
.seg label + label span { border-left: 1px solid var(--ink); }
.seg input:checked + span { background: var(--ink); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: -4px; }

/* ---------- 空白頁 ---------- */

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-icon {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.empty p { margin: 12px 0 0; font-size: 14px; }

/* ---------- 底部導覽列 ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tabbar a {
  position: relative;
  flex: 1;
  max-width: 140px;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-3);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: 0.1em;
}
.tabbar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar a.active { color: var(--ink); font-weight: 700; }
.tabbar a.active::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 30%;
  right: 30%;
  height: 2px;
  background: var(--ink);
}

/* ---------- 通用表單元件 ---------- */

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 16px; /* 避免 iPhone 點選時自動放大 */
}
.input:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: var(--ink); }

.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.btn .icon { width: 18px; height: 18px; }
.btn-danger { color: var(--danger); border-color: var(--line); }

.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* 可點選的標籤 */
.chip-option { position: relative; }
.chip-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.chip-option .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.chip-option input:checked + .chip {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.chip-option input:focus-visible + .chip { outline: 2px solid var(--ink); outline-offset: 2px; }

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
}
.swatch-multi {
  background: conic-gradient(#C0392B, #F1C40F, #4E8B57, #4A7FC1, #8E6BB0, #C0392B) !important;
}

/* 開關 */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  margin: 0 0 0 auto;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.switch:checked { background: var(--ink); border-color: var(--ink); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.row-stack { flex-direction: column; align-items: stretch; gap: 4px; cursor: default; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form .btn { flex: none; min-height: 44px; }

.ai-status { margin-left: auto; font-size: 14px; color: var(--ink-3); text-align: right; }
.ai-status.is-ok { color: #2F6B3A; }
.ai-status.is-ok::before { content: "● "; }
.ai-status.is-error { color: var(--danger); }

/* 轉圈圈 */
.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm { width: 18px; height: 18px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 衣櫃頁 ---------- */

.add-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.add-actions .btn { cursor: pointer; }

.filter-bar {
  display: flex;
  gap: 20px;
  margin: 28px -16px 0;
  padding: 0 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter {
  flex: none;
  padding: 10px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--ink-3);
  font-size: 14px;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.filter span { margin-left: 4px; font-size: 12px; }
.filter.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px 10px;
  margin-top: 16px;
}
.item-card { text-decoration: none; min-width: 0; }
.item-card[hidden] { display: none; }
.item-thumb {
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.item-thumb img { width: 100%; height: 100%; object-fit: contain; }
.item-name {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--ink-2);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ---------- 新增 / 編輯衣服 ---------- */

.sub-head { margin-bottom: 16px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin: -6px 0 8px -6px;
  padding: 6px;
  font-size: 14px;
  color: var(--ink-2);
  text-decoration: none;
}

.photo-stage {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
/* 去背後顯示淡淡的棋盤格，看得出哪裡是透明的 */
.photo-stage.is-cutout {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #F1EEE8 25%, transparent 25%),
    linear-gradient(-45deg, #F1EEE8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #F1EEE8 75%),
    linear-gradient(-45deg, transparent 75%, #F1EEE8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.photo { width: 100%; height: 100%; object-fit: contain; padding: 12px; }

.photo-status {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(43, 43, 43, 0.86);
  color: #fff;
  border-radius: var(--radius);
  font-size: 13px;
}
.photo-status[hidden] { display: none; }
.photo-status .spinner { border-color: rgba(255, 255, 255, 0.3); border-top-color: #fff; }

.progress {
  flex-basis: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  overflow: hidden;
}
.progress i { display: block; width: 0; height: 100%; background: #fff; transition: width 0.2s; }

.photo-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-top: 8px;
}
.photo-tools [hidden] { display: none; }
.seg-sm label { flex: none; }
.seg-sm span { padding: 6px 18px; font-size: 13px; letter-spacing: 0.1em; white-space: nowrap; }

.ai-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}
.ai-banner:empty { display: none; }
.ai-banner .icon { width: 18px; height: 18px; }
.ai-banner.is-loading { background: var(--surface-2); color: var(--ink-2); }
.ai-banner.is-loading .icon { animation: pulse 1.2s ease-in-out infinite; }
.ai-banner.is-ok { background: #EEF3EC; color: #2F6B3A; }
.ai-banner.is-warn { background: #FBF5E6; color: #7A5A12; }
.ai-banner.is-info { background: var(--surface-2); color: var(--ink-2); }
.ai-banner.is-error { background: var(--danger-bg); color: var(--danger); }
.ai-banner.is-error .link-btn { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.item-form { margin-top: 8px; }
.field { padding: 20px 0; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  letter-spacing: 0.1em;
}
.field-label em {
  margin-left: 6px;
  font-style: normal;
  font-weight: 400;
  color: var(--ink-3);
  letter-spacing: 0;
}

/* 儲存按鈕固定在底部導覽列上方 */
.sticky-actions {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  gap: 10px;
  margin: 8px -16px 0;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(246, 243, 238, 0), var(--bg) 30%);
}

/* ---------- 提示訊息 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .spinner,
  .ai-banner.is-loading .icon { animation: none; }
  .toast,
  .switch,
  .switch::after { transition: none; }
}
