/* 中央國寶部｜快速版 — 白金曙光・象牙典藏色票（沿用 design-system/jiu-da-mi-bao/MASTER.md） */
:root {
  color-scheme: light;
  --bg: #FCFBF8;
  --surface: #FFFFFF;
  --ivory: #F7F3EA;
  --cloud: #F5F4EF;
  --dawn: #FFF9EF;
  --platinum-300: #D7D6D1;
  --platinum-500: #A9A8A3;
  --line: rgba(172, 171, 165, .42);
  --text: #3C3B38;
  --text-2: #6C6963;
  --metal-ink: #78603C;
  --metal-mid: #B79456;
  --metal-light: #E2CDA5;
  --jade: #176F43;
  --cinnabar: #A8402F;
  --shadow: 0 1px 2px rgba(68, 47, 21, .05), 0 6px 18px rgba(68, 47, 21, .06);
  --radius: 12px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  min-height: 100dvh;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
:focus-visible { outline: 2px solid var(--metal-mid); outline-offset: 2px; }

/* ── 頂列 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--gutter) 10px;
  background: rgba(252, 251, 248, .92);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 17px; letter-spacing: .06em; color: var(--metal-ink); }
.org-name { flex: 1; min-width: 0; color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.screen { width: 100%; max-width: 1280px; margin: 0 auto; padding: 16px var(--gutter) calc(env(safe-area-inset-bottom) + 32px); }

/* ── 按鈕 ── */
.primary-btn, .ghost-btn, .text-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 10px; cursor: pointer;
  text-decoration: none; font-weight: 600; white-space: nowrap;
}
.primary-btn { background: var(--metal-ink); color: #fff; border: 0; }
.primary-btn:disabled { opacity: .55; cursor: progress; }
.ghost-btn { background: var(--surface); border: 1px solid var(--line); }
.text-btn { background: none; border: 0; color: var(--metal-ink); padding: 0 8px; min-height: 40px; font-weight: 500; }
@media (hover: hover) {
  .ghost-btn:hover { background: var(--dawn); }
  .text-btn:hover { text-decoration: underline; }
}

/* ── 提示列 ── */
.banner { max-width: 1280px; margin: 12px auto 0; padding: 10px 14px; border-radius: 10px; background: #FDF1EC; color: var(--cinnabar); border: 1px solid #EDC9BD; font-size: 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between; width: calc(100% - 2 * var(--gutter)); }
.banner button { background: none; border: 1px solid currentColor; border-radius: 8px; color: inherit; padding: 4px 10px; cursor: pointer; }

/* ── 登入 ── */
.login-screen { min-height: 100dvh; display: grid; place-items: center; }
.login-card {
  width: min(380px, 100%); display: grid; gap: 14px; justify-items: center;
  padding: 32px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 4px 0 0; font-family: var(--serif); letter-spacing: .12em; color: var(--metal-ink); font-size: 24px; }
.login-card p { margin: 0 0 6px; }
.login-card label { width: 100%; display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.login-card input { height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; color: var(--text); }
.login-card .primary-btn { width: 100%; margin-top: 4px; }
.form-error { margin: 0; width: 100%; color: var(--cinnabar); font-size: 14px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.org-picker { max-width: 440px; margin: 10vh auto; display: grid; gap: 10px; }
.org-picker h1 { margin: 0 0 6px; font-family: var(--serif); font-size: 20px; }
.org-picker button { justify-content: flex-start; width: 100%; }

/* ── 工具列 ── */
.toolbar { display: grid; gap: 10px; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--platinum-500); }
.search-wrap input {
  width: 100%; height: 46px; padding: 0 12px 0 40px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 16px;
}
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row select {
  flex: 1 1 0; min-width: 0; height: 40px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2378603C' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  appearance: none; -webkit-appearance: none; font-size: 14px;
}
.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); flex: none; }
.view-toggle button { width: 42px; height: 38px; border: 0; background: none; display: grid; place-items: center; color: var(--text-2); cursor: pointer; }
.view-toggle button[aria-pressed="true"] { background: var(--ivory); color: var(--metal-ink); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--dawn); border: 1px solid var(--metal-light); color: var(--metal-ink); font-size: 13px; cursor: pointer; }

.result-count { margin: 14px 2px 10px; font-size: 13px; color: var(--text-2); min-height: 20px; }

/* ── 圖卡 ── */
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 960px) { .card-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 1200px) { .card-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.item-card {
  display: flex; flex-direction: column; text-decoration: none; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.item-card:active { transform: scale(.985); }
@media (hover: hover) { .item-card:hover { border-color: var(--metal-light); } }
.thumb { position: relative; aspect-ratio: 1; background: var(--cloud); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .18s ease-out; }
.thumb img.loaded { opacity: 1; }
.thumb .no-photo { position: absolute; inset: 0; display: grid; place-items: center; color: var(--platinum-500); font-size: 12px; }
.card-body { padding: 10px 12px 12px; display: grid; gap: 3px; min-width: 0; }
.inv { font: 500 11.5px/1.3 var(--mono); color: var(--metal-ink); letter-spacing: .02em; overflow-wrap: anywhere; }
.card-body h3 { margin: 0; font-size: 14.5px; line-height: 1.35; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 6px; margin-top: 4px; min-width: 0; }
.cost { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cost:empty { display: none; }

/* ── 狀態徽章：文字＋色點，不只靠顏色 ── */
.status { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; white-space: nowrap; background: var(--cloud); color: var(--text-2); flex: none; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.draft { background: #F4F1EA; color: #7A6F5E; }
.status.on_display, .status.acquired { background: #EAF4ED; color: var(--jade); }
.status.in_storage { background: #EEF1F7; color: #3B537E; }
.status.on_loan, .status.consigned, .status.under_restoration { background: #FFF4E2; color: #8A5A00; }
.status.archived, .status.deleted, .status.disposed, .status.transferred_out { background: #F3EFEF; color: #7B5F5A; }

/* ── 表格 ── */
.item-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--ivory); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.item-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.item-table tr:last-child td { border-bottom: 0; }
.item-table tbody tr { cursor: pointer; }
@media (hover: hover) { .item-table tbody tr:hover td { background: var(--dawn); } }
.item-table .mini { width: 48px; height: 48px; border-radius: 8px; overflow: hidden; background: var(--cloud); }
.item-table .mini img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .18s ease-out; }
.item-table .mini img.loaded { opacity: 1; }
.item-table .name-cell a { text-decoration: none; font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* 手機表格：改為清單列，不橫向拖曳 */
@media (max-width: 719px) {
  .item-table thead { display: none; }
  .item-table, .item-table tbody { display: block; }
  .item-table tr { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .item-table tr:last-child { border-bottom: 0; }
  .item-table td { padding: 0; border: 0; min-width: 0; }
  .item-table td.c-thumb { grid-row: 1 / span 3; }
  .item-table td.c-inv { grid-column: 2; }
  .item-table td.c-name { grid-column: 2; }
  .item-table td.c-status { grid-column: 3; grid-row: 1; justify-self: end; }
  .item-table td.c-cat { grid-column: 2; font-size: 12.5px; color: var(--text-2); }
  .item-table td.c-cost { grid-column: 3; grid-row: 3; font-size: 12.5px; }
  .item-table td.c-date, .item-table td.c-loc { display: none; }
}

/* ── 骨架／空狀態 ── */
.skeleton { background: linear-gradient(90deg, var(--cloud) 0%, #FAF9F5 50%, var(--cloud) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-card { height: 0; padding-bottom: 150%; border-radius: var(--radius); }
.empty { padding: 48px 16px; text-align: center; color: var(--text-2); border: 1px dashed var(--platinum-300); border-radius: var(--radius); }
.list-footer { display: grid; place-items: center; padding: 20px 0; }
#list-sentinel { height: 1px; width: 100%; }

/* ── 詳情 ── */
.detail-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.back-link { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding-right: 12px; text-decoration: none; color: var(--metal-ink); font-weight: 500; }
.detail-layout { display: grid; gap: 20px; }
@media (min-width: 900px) { .detail-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 32px; align-items: start; } .gallery { position: sticky; top: 76px; } }
.gallery-main { aspect-ratio: 1; background: var(--cloud); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); display: grid; place-items: center; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.gallery-thumbs button { flex: none; width: 64px; height: 64px; padding: 0; border-radius: 8px; overflow: hidden; border: 2px solid transparent; background: var(--cloud); cursor: pointer; }
.gallery-thumbs button[aria-current="true"] { border-color: var(--metal-mid); }
.gallery-thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-head { display: grid; gap: 6px; }
.detail-head h1 { margin: 0; font-family: var(--serif); font-size: clamp(22px, 5vw, 30px); line-height: 1.3; letter-spacing: .02em; overflow-wrap: anywhere; }
.detail-head .alt { color: var(--text-2); font-size: 14px; }
.head-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; background: var(--ivory); color: var(--metal-ink); border: 1px solid var(--metal-light); text-decoration: none; }
.section { margin-top: 20px; }
.section h2 { font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--metal-ink); margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--metal-light); }
.fields { display: grid; grid-template-columns: 1fr; margin: 0; }
@media (min-width: 560px) { .fields { grid-template-columns: 1fr 1fr; column-gap: 24px; } }
.fields div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed var(--line); min-width: 0; }
.fields dt { color: var(--text-2); font-size: 13.5px; flex: none; }
.fields dd { margin: 0; text-align: right; font-size: 14px; overflow-wrap: anywhere; min-width: 0; }
.fields .total dd { font-weight: 700; color: var(--metal-ink); }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 14.5px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.timeline li { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.timeline time { color: var(--text-2); font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* ── 畫面切換：短淡入，減少動態偏好時關閉 ── */
.screen.enter { animation: enter .16s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  .screen.enter, .skeleton { animation: none; }
  .thumb img, .item-table .mini img { transition: none; }
}

/* ── 寫入功能：按鈕、清單工具列、詳情工具 ── */
.small-btn { min-height: 36px; padding: 0 14px; font-size: 14px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 2px 10px; flex-wrap: wrap; }
.list-head .result-count { margin: 0; }
.list-tools { display: flex; gap: 4px; }
.list-tools .text-btn { min-height: 36px; font-size: 14px; }
.detail-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#detail-actions { display: inline-flex; gap: 8px; }
#detail-actions[hidden] { display: none !important; }
label.ghost-btn, label.primary-btn { cursor: pointer; }
label[aria-busy="true"], button:disabled { opacity: .55; cursor: progress; pointer-events: none; }

/* ── 表單 ── */
.screen.narrow { max-width: 820px; }
.item-form { display: grid; gap: 14px; }
.form-head h1 { margin: 0 0 4px; font-family: var(--serif); font-size: 24px; letter-spacing: .04em; }
.form-head p { margin: 0; }
.form-section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.form-section h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--metal-ink); }
.f-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .f-grid { grid-template-columns: 1fr 1fr; } .f-wide, .f-dims { grid-column: 1 / -1; } }
.f { display: grid; gap: 5px; min-width: 0; }
.f > span { font-size: 13px; color: var(--text-2); }
.f input, .f select, .f textarea, .dims-row input, .dims-row select, .tag-editor input {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); font-size: 16px; color: var(--text); min-width: 0;
}
.f textarea { resize: vertical; line-height: 1.5; }
.f select:disabled { opacity: .6; }
.f.invalid input, .f.invalid select, .f.invalid textarea { border-color: var(--cinnabar); }
.f-err { color: var(--cinnabar); font-size: 12.5px; font-style: normal; }
.dims-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 76px; gap: 6px; }
.more summary { cursor: pointer; color: var(--metal-ink); font-size: 14px; padding: 4px 0; }
.more .f-grid { margin-top: 10px; }
.total-line { margin: 0; text-align: right; color: var(--text-2); font-size: 14px; }
.total-line strong { color: var(--metal-ink); font-size: 16px; font-variant-numeric: tabular-nums; }
.small { font-size: 12.5px; margin: 0; }
.tag-editor { display: grid; gap: 8px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chips:empty { display: none; }
.tag-chips .tag { display: inline-flex; align-items: center; gap: 4px; }
.tag-chips .tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 12px; line-height: 1; min-width: 20px; min-height: 20px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; padding: 12px 0 calc(env(safe-area-inset-bottom) + 4px); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.form-actions .primary-btn { min-width: 140px; }

/* 照片挑選 */
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.photo-previews:empty { display: none; }
.preview { position: relative; margin: 0; aspect-ratio: 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--cloud); }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview.is-primary { border: 2px solid var(--metal-mid); }
.preview figcaption { position: absolute; left: 4px; bottom: 4px; font-size: 11px; padding: 1px 6px; border-radius: 999px; background: var(--metal-ink); color: #fff; }
.preview button { position: absolute; right: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; font-size: 12px; }

/* 匯入 */
.import-panel { display: grid; gap: 16px; }
.import-summary { margin: 0; }
.table-scroll { overflow-x: auto; }
.import-table td { font-size: 13.5px; }
.import-table tbody tr { cursor: default; }
@media (max-width: 719px) {
  .import-table thead { display: table-header-group; }
  .import-table, .import-table tbody { display: table; }
  .import-table tbody { display: table-row-group; }
  .import-table tr { display: table-row; padding: 0; }
  .import-table td { display: table-cell; padding: 8px 10px; border-bottom: 1px solid var(--line); }
}
.good { color: var(--jade); }
.bad { color: var(--cinnabar); }
.warn { color: #8A5A00; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 14px; }

/* 提示 */
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.import-table td:nth-child(2) { min-width: 7em; }
.import-table td:nth-child(4) { white-space: nowrap; }
