/* UIJ Card — 沿用 UIJ Report（Ampersand 營運會議公版）的色票與字型 */
:root {
  --green: #193028;
  --green-2: #214036;
  --green-deep: #0e1f18;
  --copper: #8c7450;
  --copper-hi: #c8a875;
  --copper-deep: #6b5738;
  --orange: #da5312;
  --orange-press: #b94510;
  --ok: #2f6b54;
  --warn: #e8a55c;
  --warn-ink: #8a5a1c;
  --bad: #9e4a35;

  --paper: #ece6d6;
  --paper-2: #e2dac6;
  --card: #fbf8f1;
  --field: #fffdf8;
  --ink: #191919;
  --muted: #5e6a62;
  --heading: var(--green);
  --line: rgba(140, 116, 80, .34);
  --line-soft: rgba(140, 116, 80, .18);
  --crop: var(--copper);
  --shadow: 0 2px 8px rgba(25, 48, 40, .08);
  --bar-bg: var(--green);
  --bar-ink: #ece6d6;
  --bar-muted: #a6ab9f;
  --sel-bg: var(--green);
  --sel-ink: #ece6d6;
  --row-bg: rgba(140, 116, 80, .08);

  --disp: 'Rokkitt', 'Zen Old Mincho', 'Noto Serif TC', 'Songti TC', serif;
  --mincho: 'Zen Old Mincho', 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --sans: 'Noto Sans TC', '思源黑體', 'PingFang TC', 'Microsoft JhengHei', sans-serif;

  --top-h: 52px;
  --tab-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #142a22;
    --paper-2: #193028;
    --card: rgba(255, 255, 255, .05);
    --field: rgba(0, 0, 0, .22);
    --ink: #ece6d6;
    --muted: #a6ab9f;
    --heading: #ece6d6;
    --copper: #c8a875;
    --copper-deep: #c8a875;
    --line: rgba(200, 168, 117, .26);
    --line-soft: rgba(200, 168, 117, .14);
    --crop: #c8a875;
    --shadow: 0 14px 30px rgba(0, 0, 0, .30);
    --bar-bg: var(--green-deep);
    --sel-bg: rgba(200, 168, 117, .2);
    --row-bg: rgba(255, 255, 255, .04);
    --ok: #6fbf9a;
    --bad: #e08a72;
    --warn-ink: #e8a55c;
    color-scheme: dark;
  }
  body { background: linear-gradient(152deg, #214036 0%, #193028 48%, #0e1f18 100%) fixed; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.65 var(--sans);
  letter-spacing: .03em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--copper-deep); text-underline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; letter-spacing: inherit; }
img { display: block; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.num { font-family: 'Rokkitt', var(--sans); font-weight: 500; font-variant-numeric: tabular-nums lining-nums; letter-spacing: .02em; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* 裁切角：名片印刷的裁切線，也是相機取景框 */
.crop { position: relative; }
.crop::before {
  content: '';
  position: absolute;
  inset: -7px;
  pointer-events: none;
  --a: 14px;
  --t: 1.5px;
  background:
    linear-gradient(var(--crop), var(--crop)) top left / var(--a) var(--t) no-repeat,
    linear-gradient(var(--crop), var(--crop)) top left / var(--t) var(--a) no-repeat,
    linear-gradient(var(--crop), var(--crop)) top right / var(--a) var(--t) no-repeat,
    linear-gradient(var(--crop), var(--crop)) top right / var(--t) var(--a) no-repeat,
    linear-gradient(var(--crop), var(--crop)) bottom left / var(--a) var(--t) no-repeat,
    linear-gradient(var(--crop), var(--crop)) bottom left / var(--t) var(--a) no-repeat,
    linear-gradient(var(--crop), var(--crop)) bottom right / var(--a) var(--t) no-repeat,
    linear-gradient(var(--crop), var(--crop)) bottom right / var(--t) var(--a) no-repeat;
}

/* ---------- 按鈕 / 欄位 / 標籤 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--card); color: var(--heading);
  font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap;
  cursor: pointer; touch-action: manipulation;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { border-color: var(--copper); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-press); border-color: var(--orange-press); }
.btn.accent { background: var(--green); border-color: var(--green); color: #ece6d6; }
.btn.accent .ic { color: var(--copper-hi); }
.btn.accent:hover { background: var(--green-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--line-soft); }
.btn.ghost.danger { color: var(--bad); background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.small .ic { width: 17px; height: 17px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 3px; background: transparent; color: var(--heading); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--line-soft); }
.icon-btn.danger { color: var(--bad); }
.spinner { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: grid; gap: 4px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--field); color: var(--ink);
  font: 400 16px/1.5 var(--sans); letter-spacing: .02em;
}
textarea { resize: vertical; min-height: 0; }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--copper) 50%), linear-gradient(135deg, var(--copper) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(25, 48, 40, .14); }
@media (prefers-color-scheme: dark) {
  .btn.accent { background: rgba(200, 168, 117, .16); border-color: rgba(200, 168, 117, .5); color: #ece6d6; }
  .btn.accent:hover { background: rgba(200, 168, 117, .26); }
}
@media (prefers-color-scheme: dark) { input:focus, select:focus, textarea:focus { border-color: var(--copper-hi); box-shadow: 0 0 0 3px rgba(200, 168, 117, .2); } }
input[readonly], textarea[readonly], select:disabled { background: transparent; border-style: dashed; opacity: 1; color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
.field-lg input { font-family: var(--mincho); font-weight: 700; font-size: 20px; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; line-height: 1.6; padding: 0 7px; border-radius: 3px;
  background: var(--line-soft); color: var(--copper-deep); white-space: nowrap; font-weight: 500;
}
.tag.ok { background: rgba(47, 107, 84, .13); color: var(--ok); }
.tag.bad { background: rgba(158, 74, 53, .13); color: var(--bad); }
.tag.warn { background: rgba(232, 165, 92, .22); color: var(--warn-ink); }
.tag.brand { background: var(--green); color: #ece6d6; }
.note { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 12px; }
.none { font-size: 14px; color: var(--muted); padding: 4px 0; }
.label-sm { font-size: 12px; color: var(--muted); }
.link-sm { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.link-sm .ic { width: 16px; height: 16px; }

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 24px;
  height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bar-bg); color: var(--bar-ink);
}
.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  font: 800 22px/1 'Rokkitt', serif; letter-spacing: .04em; color: var(--copper-hi); text-decoration: none;
}
.wm-mark { width: 3px; height: 15px; background: var(--orange); }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { color: var(--bar-muted); text-decoration: none; padding: 6px 12px; border-radius: 3px; font-weight: 500; }
.topnav a:hover { color: var(--bar-ink); }
.topnav a.active { color: var(--bar-ink); background: rgba(236, 230, 214, .12); }
.who { display: flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--bar-ink); cursor: pointer; padding: 4px 6px; border-radius: 3px; }
.who img, .who-initial { width: 30px; height: 30px; border-radius: 50%; }
.who-initial { display: grid; place-items: center; background: var(--copper); color: #fff; font-weight: 700; font-size: 14px; }
.dev-banner { background: var(--warn); color: #3b2a12; text-align: center; font-size: 13px; padding: 5px 12px; }

.app { max-width: 1240px; margin: 0 auto; padding: 24px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }

/* ---------- 底部導覽（手機） ---------- */
.tabbar { display: none; }

/* ---------- 名片列表 ---------- */
.home { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start; }
.side { position: sticky; top: calc(var(--top-h) + 24px); display: grid; gap: 2px; }
.side-title { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 10px 4px; font: 700 13px/1.4 var(--sans); color: var(--muted); letter-spacing: .08em; }
.side-title a { font-weight: 400; font-size: 13px; }
.side-item { display: flex; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 3px; color: var(--ink); text-decoration: none; }
.side-item:hover { background: var(--line-soft); }
.side-item.active { background: var(--sel-bg); color: var(--sel-ink); font-weight: 700; }
.side-item.active .count { color: var(--copper-hi); }
.side-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-family: 'Rokkitt', serif; color: var(--muted); font-weight: 500; }
.side-none { font-size: 13px; color: var(--muted); padding: 4px 10px; }

.home-head { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.search { position: relative; flex: 1; }
.search .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--copper); pointer-events: none; }
.search input { padding-left: 42px; background: var(--card); }
.add-btns { display: flex; gap: 8px; }
.chips { display: none; }

.card-list { display: grid; gap: 8px; }
.item { position: relative; display: flex; align-items: center; gap: 8px; min-width: 0; background: var(--card); border-radius: 4px; box-shadow: var(--shadow); transition: box-shadow .15s; }
.item:hover { box-shadow: 0 6px 18px rgba(25, 48, 40, .14); }
.item-link {
  flex: 1; min-width: 0; display: grid; align-items: center; gap: 4px 20px;
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 2fr) minmax(0, 1.7fr) minmax(0, auto);
  padding: 14px 20px; color: var(--ink); text-decoration: none;
}
.item-main, .item-contact { display: grid; min-width: 0; }
.item-main > span, .item-contact > span, .item-org { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-name { font: 700 17px/1.45 var(--mincho); color: var(--heading); letter-spacing: .04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-alt { font: 500 14px var(--sans); color: var(--muted); margin-left: 8px; letter-spacing: .02em; }
.item-role, .item-org, .item-contact { font-size: 13px; color: var(--muted); }
.item-org { font-size: 14px; color: var(--ink); }
.item-tags { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.tag.img .ic { width: 14px; height: 14px; }
.tag-btn { border: 0; cursor: pointer; min-height: 30px; padding: 0 8px 0 7px; font-size: 13px; background: var(--sel-bg); color: var(--sel-ink); }
.tag-btn .ic { width: 15px; height: 15px; }
.tag-btn .tag-chev { width: 13px; height: 13px; transform: rotate(90deg); opacity: .8; }
.cat-pick.current { background: var(--sel-bg); }
.cat-pick.current strong, .cat-pick.current span { color: var(--sel-ink); }
.side-hint { font-size: 12px; color: var(--muted); padding: 14px 10px 0; }
.item[draggable="true"] { cursor: grab; }
.item.dragging { opacity: .45; }
body.dragging-card .side-item[data-drop] { background: var(--row-bg); }
body.dragging-card .side-item.active[data-drop] { background: var(--sel-bg); }
.side-item.drop-hover, body.dragging-card .side-item.drop-hover { background: var(--orange); color: #fff; }
.side-item.drop-hover .count { color: #fff; }
.item-call { display: none; }
.more { text-align: center; margin-top: 28px; }
.loading { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: center; align-items: center; color: var(--muted); padding: 48px 0; }

.empty { grid-column: 1 / -1; display: grid; justify-items: center; gap: 18px; text-align: center; padding: 56px 16px; color: var(--muted); }
.empty p { max-width: 26em; }
.empty-frame { width: 168px; aspect-ratio: 91 / 55; background: var(--card); border-radius: 3px; box-shadow: var(--shadow); }
.empty-frame::after { content: ''; position: absolute; left: 18px; right: 70px; top: 22px; height: 30px; background: linear-gradient(var(--line) 0 0) 0 0 / 60% 6px no-repeat, linear-gradient(var(--line-soft) 0 0) 0 16px / 100% 4px no-repeat, linear-gradient(var(--line-soft) 0 0) 0 26px / 80% 4px no-repeat; }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- 名片編輯 ---------- */
.ed-bar { display: flex; align-items: center; gap: 8px; margin: -8px 0 20px; }
.ed-title { flex: 1; min-width: 0; font: 900 28px/1.3 var(--mincho); color: var(--heading); letter-spacing: .05em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-bar-actions { display: flex; gap: 8px; align-items: center; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 36px; align-items: start; }
.ed-media { position: sticky; top: calc(var(--top-h) + 24px); display: grid; gap: 14px; padding: 7px; }
.photo {
  display: grid; place-items: center; overflow: visible;
  aspect-ratio: 91 / 55; border-radius: 3px;
  background: var(--card); box-shadow: var(--shadow);
  cursor: pointer;
}
.is-ro .photo { cursor: default; }
.photo img { width: 100%; height: 100%; object-fit: contain; border-radius: 3px; background: #fff; }
.photo.drag { background: var(--paper-2); }
.photo.loading { opacity: .6; }
.photo-hint { display: grid; justify-items: center; gap: 6px; padding: 16px; text-align: center; color: var(--muted); }
.photo-hint strong { font: 700 18px var(--mincho); color: var(--heading); }
.photo-hint span { font-size: 13px; }
.photo-ic { width: 34px; height: 34px; color: var(--orange); stroke-width: 1.5; }
.scan { position: absolute; inset: 0; overflow: hidden; border-radius: 3px; pointer-events: none; display: none; }
.photo.scanning .scan { display: block; background: rgba(25, 48, 40, .12); }
.photo.scanning .scan::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: var(--orange); box-shadow: 0 0 14px 3px rgba(218, 83, 18, .55);
  animation: scan 1.6s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 0; } to { top: calc(100% - 2px); } }
.media-actions { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.media-actions .btn { padding: 0 10px; }
.ed-media > .link-sm { justify-self: start; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
.grid-addr { display: grid; grid-template-columns: 1fr 1fr 1fr; column-gap: 12px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.list-block { margin: 4px 0 16px; }
.list-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.list-block .list-head { margin-bottom: 6px; }
.list-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.list-row select { flex: 0 0 88px; }
.list-row input[data-k="value"] { flex: 1; min-width: 0; }
.list-row .ext { flex: 0 0 76px; }
.row-go { color: var(--copper); }
.meta-line { font-size: 12px; color: var(--muted); margin-top: 4px; }

.ed-more { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 36px; align-items: start; }
.sec { background: var(--card); border-radius: 4px; box-shadow: var(--shadow); margin-bottom: 14px; scroll-margin-top: 130px; }
.ed-more .sec { margin-bottom: 0; }
.ed-form .sec { background: transparent; box-shadow: none; border-radius: 0; margin: 0 0 10px; }
.sec > summary {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 16px;
  cursor: pointer; list-style: none; user-select: none;
}
.ed-form .sec > summary { padding: 0; }
.sec > summary::-webkit-details-marker { display: none; }
.sec-title { display: inline-flex; align-items: center; gap: 8px; font: 700 17px/1.3 var(--mincho); color: var(--heading); letter-spacing: .05em; white-space: nowrap; }
.sec-title .ic { color: var(--copper); }
.ed-form .sec-title { font: 500 13px var(--sans); color: var(--muted); letter-spacing: .03em; }
.sec-hint { flex: 1; min-width: 0; text-align: right; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec > summary .chev { color: var(--copper); transition: transform .2s; margin-left: auto; }
.sec[open] > summary .chev { transform: rotate(90deg); }
.sec-body { padding: 4px 16px 18px; }
.ed-form .sec-body { padding: 4px 0 6px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.sec-body > .btn + .field, .sec-body > .field + .btn { margin-top: 14px; }
#btn-research { margin-top: 2px; }
.share { display: grid; gap: 14px; }
.share .note { margin: 0; }
.qr { display: grid; place-items: center; min-height: 140px; padding: 10px; background: #fff; border-radius: 3px; justify-self: center; width: min(240px, 100%); }
.qr svg { width: 100%; height: auto; display: block; }
.qr .none { color: #5e6a62; text-align: center; }
.sources { display: grid; gap: 4px; font-size: 13px; margin-bottom: 12px; }
.sources a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-actionbar { display: none; }

/* 商工登記 */
.reg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.reg-head strong { font: 700 18px var(--mincho); color: var(--heading); }
.reg-status { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 3px; color: #fff; }
.reg-status.ok { background: var(--ok); }
.reg-status.bad { background: linear-gradient(#a85138, #7e3b29); }
.callout { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: rgba(232, 165, 92, .2); border-radius: 3px; color: var(--ink); font-size: 14px; padding: 8px 10px; margin-bottom: 12px; }
.reg-list { display: grid; grid-template-columns: max-content 1fr; gap: 7px 16px; margin: 0 0 12px; font-size: 14px; }
.reg-list dt { color: var(--muted); }
.reg-list dd { margin: 0; overflow-wrap: anywhere; }
#btn-registry { margin-top: 4px; }

/* ---------- 對話框 / 底部面板 ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(14, 31, 24, .5); animation: fade .15s ease-out; }
.sheet { width: min(540px, 100%); max-height: 88vh; display: flex; flex-direction: column; background: var(--paper); color: var(--ink); border-radius: 6px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); outline: none; }
@media (prefers-color-scheme: dark) { .sheet { background: #193028; } }
.sheet-grip { display: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 10px 4px 20px; }
.sheet-head h2 { font: 900 20px/1.3 var(--mincho); color: var(--heading); letter-spacing: .05em; }
.sheet-body { padding: 8px 20px 18px; overflow: auto; overscroll-behavior: contain; }
.sheet-text { font-size: 15px; }
.sheet-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 20px calc(16px + var(--safe-b)); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.account-who { display: grid; gap: 2px; margin-bottom: 14px; }
.account-who strong { font: 700 18px var(--mincho); color: var(--heading); }
.account-who span:not(.tag) { font-size: 14px; color: var(--muted); }
.account-who .tag { justify-self: start; margin-top: 4px; }
.menu { display: grid; gap: 4px; }
.menu a, .menu button { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border: 0; border-radius: 3px; background: var(--card); color: var(--ink); text-decoration: none; text-align: left; cursor: pointer; font-size: 16px; }
.menu .ic { color: var(--copper); }
.menu span { flex: 1; }
.menu .chev { color: var(--muted); }

.pick-list { display: grid; gap: 8px; }
.pick-item { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 3px; background: var(--card); cursor: pointer; }
.pick-item:hover { border-color: var(--copper); }
.pick-item strong { font: 700 16px var(--mincho); color: var(--heading); }
.pick-item span { font-size: 13px; color: var(--muted); }

.saved { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 8px 0 4px; }
.saved-card { width: 190px; aspect-ratio: 91 / 55; background: var(--card); border-radius: 3px; box-shadow: var(--shadow); margin: 8px 0; }
.saved-card img { width: 100%; height: 100%; object-fit: cover; border-radius: 3px; }
.saved strong { font: 700 20px var(--mincho); color: var(--heading); }

.toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; width: max-content; max-width: calc(100% - 32px); pointer-events: none; }
.toast { background: var(--green); color: #ece6d6; padding: 11px 16px; border-radius: 3px; font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); transition: opacity .35s; }
.toast.success { background: var(--ok); }
.toast.error { background: linear-gradient(#a85138, #7e3b29); }
.toast.hide { opacity: 0; }

/* ---------- 管理頁 ---------- */
.page { display: grid; gap: 24px; max-width: 860px; }
.page-title { font: 900 28px/1.3 var(--mincho); color: var(--heading); letter-spacing: .05em; }
.block { background: var(--card); border-radius: 4px; box-shadow: var(--shadow); padding: 18px 22px 8px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.block-head h2 { font: 700 19px var(--mincho); color: var(--heading); letter-spacing: .05em; }
.mlist { list-style: none; margin: 4px 0 14px; padding: 0; display: grid; gap: 6px; }
.mrow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 12px 14px; border-radius: 3px; background: var(--row-bg); }
.mrow-main { flex: 1 1 220px; display: grid; gap: 1px; min-width: 0; }
.mrow-main strong { font-weight: 700; color: var(--heading); }
.mrow-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.mrow-perm .field { margin: 0; }
.mrow-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.mrow-actions select, .mrow-perm select { width: auto; min-width: 140px; }
.mrow.dim { opacity: .6; }
.field.compact { gap: 2px; }
.field.compact > span { font-size: 12px; }
.perm-add { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-top: 14px; }

/* ---------- 登入頁 ---------- */
.login-page { display: grid; place-items: center; padding: 24px 16px calc(24px + var(--safe-b)); background: linear-gradient(152deg, #214036 0%, #193028 48%, #0e1f18 100%); color: #ece6d6; }
.login-box { width: min(380px, 100%); padding: 40px 30px 32px; background: rgba(255, 255, 255, .05); border-radius: 4px; --crop: #c8a875; }
.login-box .wordmark { font-size: 30px; }
.login-box .wm-mark { height: 20px; }
.login-sub { margin: 12px 0 28px; color: #a6ab9f; font-size: 15px; }
.login-box .btn { width: 100%; }
.login-box .alert { margin-bottom: 16px; padding: 10px 12px; border-radius: 3px; font-size: 14px; background: rgba(255, 255, 255, .08); }
.login-box .alert.error { background: linear-gradient(#a85138, #7e3b29); color: #fff; }
.dev-login { display: grid; gap: 12px; margin-top: 30px; }
.dev-login label { display: grid; gap: 4px; font-size: 13px; color: #a6ab9f; }
.dev-login input { background: rgba(0, 0, 0, .25); color: #ece6d6; border-color: rgba(200, 168, 117, .3); }
.dev-tag { font-size: 12px; color: #3b2a12; background: var(--warn); padding: 4px 8px; border-radius: 3px; }
.login-box .btn.ghost-light { background: transparent; color: #ece6d6; border-color: rgba(200, 168, 117, .45); }

.desk-only { display: inline; }

/* ---------- 手機 ---------- */
@media (max-width: 899px) {
  body { font-size: 15px; padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
  .topbar { --top-h: 50px; gap: 12px; }
  .topnav, .who { display: none; }
  .app { padding: 14px 16px 28px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .desk-only { display: none; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
    height: calc(var(--tab-h) + var(--safe-b)); padding: 0 6px var(--safe-b);
    background: var(--bar-bg); color: var(--bar-muted);
  }
  .tabbar > a, .tabbar > button {
    display: grid; justify-items: center; align-content: center; gap: 3px; height: var(--tab-h);
    border: 0; background: none; color: inherit; text-decoration: none; font-size: 11px; letter-spacing: .06em; cursor: pointer; touch-action: manipulation;
  }
  .tabbar .ic { width: 23px; height: 23px; }
  .tabbar > .active { color: var(--bar-ink); }
  .tabbar > .active .ic { color: var(--copper-hi); }
  .tab-capture { color: var(--bar-ink) !important; }
  .capture-frame {
    position: relative; display: grid; place-items: center;
    width: 62px; height: 38px; margin-top: -22px; border-radius: 3px;
    background: var(--orange); color: #fff;
    box-shadow: 0 6px 16px rgba(218, 83, 18, .4), 0 0 0 4px var(--bar-bg);
  }
  .capture-frame::before {
    content: ''; position: absolute; inset: -9px; pointer-events: none;
    background:
      linear-gradient(var(--copper-hi), var(--copper-hi)) top left / 9px 1.5px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) top left / 1.5px 9px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) top right / 9px 1.5px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) top right / 1.5px 9px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) bottom left / 9px 1.5px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) bottom left / 1.5px 9px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) bottom right / 9px 1.5px no-repeat,
      linear-gradient(var(--copper-hi), var(--copper-hi)) bottom right / 1.5px 9px no-repeat;
  }
  .capture-frame .ic { width: 24px; height: 24px; }
  .tab-capture:active .capture-frame { background: var(--orange-press); }
  body[data-route="editor"] { padding-bottom: calc(72px + var(--safe-b)); }
  body[data-route="editor"] .tabbar, body.typing .tabbar, body.typing .ed-actionbar, body.has-sheet .tabbar { display: none; }
  body.typing { padding-bottom: 0; }

  /* 列表 */
  .home { display: block; }
  .side { display: none; }
  .home-head {
    position: sticky; top: calc(50px + var(--safe-t)); z-index: 20;
    margin: -14px -16px 0; padding: 10px 16px 8px; background: var(--paper);
  }
  @media (prefers-color-scheme: dark) { .home-head, .chips { background: #183026; } }
  .add-btns .btn.primary { display: none; }
  .add-btns .btn { width: 46px; padding: 0; }
  .add-btns .btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .chips {
    display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
    margin: 0 -16px 6px; padding: 2px 16px 12px; background: var(--paper);
    position: sticky; top: calc(50px + var(--safe-t) + 64px); z-index: 19;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex: none; display: inline-flex; align-items: center; gap: 5px; min-height: 36px; padding: 0 14px;
    border: 1px solid var(--line); border-radius: 3px; background: var(--card);
    color: var(--ink); text-decoration: none; font-size: 14px; scroll-snap-align: start; white-space: nowrap;
  }
  .chip small { font-size: 11px; color: var(--muted); }
  .chip.active { background: var(--green); border-color: var(--green); color: #ece6d6; }
  .chip.active small { color: var(--copper-hi); }

  .card-list { gap: 8px; }
  .item { padding-right: 10px; }
  .item-link { display: grid; grid-template-columns: 1fr; gap: 2px; padding: 12px 14px; }
  .item-contact { display: none; }
  .item-tags { justify-content: flex-start; margin-top: 4px; }
  .item-call {
    display: grid; place-items: center; flex: none; width: 46px; height: 46px;
    border: 1px solid var(--line); border-radius: 3px; color: var(--ok); background: var(--card);
  }
  .item-call:active { background: var(--line-soft); }

  /* 編輯 */
  .ed-bar {
    position: sticky; top: calc(50px + var(--safe-t)); z-index: 20;
    margin: -14px -16px 12px; padding: 4px 8px 4px 4px; background: var(--paper);
  }
  @media (prefers-color-scheme: dark) { .ed-bar { background: #183026; } }
  .ed-title { font-size: 19px; }
  .ed-bar-actions { display: none; }
  .is-ro .ed-bar-actions { display: flex; }
  .ed-grid { display: block; }
  .ed-media { position: static; padding: 7px 7px 0; margin-bottom: 18px; gap: 12px; }
  .media-actions { grid-template-columns: 1fr 1fr 1.25fr; }
  .grid-addr { grid-template-columns: 1fr 1fr; }
  .list-row select { flex-basis: 78px; }
  .list-row .ext { flex-basis: 68px; padding: 10px 8px; }
  .editor:not(.is-ro) .row-go { display: none; }
  .grid-addr .field:first-child { grid-column: 1 / -1; max-width: 50%; }
  .ed-more { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 18px; }
  .block-sm { width: 100%; }
  .btn-row .btn { flex: 1 1 auto; }
  .reg-list { grid-template-columns: 1fr; gap: 0; }
  .reg-list dt { font-size: 12px; margin-top: 8px; }
  .ed-actionbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; gap: 8px; align-items: center;
    padding: 10px 16px calc(10px + var(--safe-b));
    background: var(--paper);
    box-shadow: 0 -6px 18px rgba(25, 48, 40, .08);
  }
  @media (prefers-color-scheme: dark) { .ed-actionbar { background: #102219; } }
  .ed-actionbar .grow { flex: 1; min-height: 50px; font-size: 16px; }
  .ed-actionbar .icon-btn { width: 50px; height: 50px; border: 1px solid var(--line); }

  /* 面板 */
  .sheet-wrap { place-items: end stretch; padding: 0; }
  .sheet { width: 100%; max-height: 90vh; max-height: 90dvh; border-radius: 8px 8px 0 0; animation: rise .22s ease-out; }
  .sheet-grip { display: block; width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
  .sheet-head { padding-top: 6px; }
  .sheet-body { padding-bottom: calc(18px + var(--safe-b)); }
  .sheet-foot { padding-bottom: calc(14px + var(--safe-b)); }
  .sheet-foot .btn { flex: 1; min-height: 50px; }
  .sheet-wrap.center { place-items: center; padding: 20px max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left)); }
  .sheet-wrap.center .sheet { width: 100%; max-height: 80vh; max-height: 80dvh; border-radius: 6px; animation: pop .18s ease-out; }
  .sheet-wrap.center .sheet-grip { display: none; }
  .sheet-wrap.center .sheet-head { padding-top: 14px; }
  .sheet-wrap.center .sheet-body, .sheet-wrap.center .sheet-foot { padding-bottom: 18px; }
  .toast-root { bottom: calc(var(--tab-h) + var(--safe-b) + 12px); }
  body[data-route="editor"] .toast-root { bottom: calc(80px + var(--safe-b)); }

  /* 管理頁 */
  .page { gap: 18px; }
  .page-title { font-size: 23px; }
  .block { padding: 14px 16px 4px; }
  .mrow-actions, .mrow-perm { flex: 1 1 100%; }
  .mrow-actions select, .mrow-perm select { flex: 1; min-width: 0; width: 100%; }
}

@media (max-width: 380px) {
  .media-actions { grid-template-columns: 1fr 1fr; }
  .media-actions #btn-ocr { grid-column: 1 / -1; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 .span-2 { grid-column: auto; }
}

@media (hover: none) {
  .btn:hover { border-color: var(--line); }
  .btn.primary:hover { background: var(--orange); border-color: var(--orange); }
  .btn.accent:hover { background: var(--green); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .photo.scanning .scan::after { display: none; }
  .photo.scanning .scan { background: rgba(218, 83, 18, .12); }
}

/* 區塊讀取中 */
.sec .sec-body { transition: background-color .6s; }
.sec.is-loading .sec-body > :not(.sec-status) { opacity: .35; pointer-events: none; transition: opacity .2s; }
.sec-status { display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 14px; border-radius: 4px; background: #f3e6d2; color: var(--heading); position: relative; overflow: hidden; }
.sec-status .spinner { width: 20px; height: 20px; flex: none; color: var(--orange); }
.sec-status-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.sec-status-sub { font-size: 13px; color: var(--muted); }
.sec-status-sec { flex: none; font-size: 13px; color: var(--muted); }
.sec-status::after { content: ''; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.55) 50%, transparent 70%); transform: translateX(-100%); animation: sec-sheen 1.6s ease-in-out infinite; }
@keyframes sec-sheen { to { transform: translateX(100%); } }
.tag.busy { display: inline-flex; align-items: center; gap: 6px; }
.tag.busy .spinner { width: 11px; height: 11px; }
.sec.just-done .sec-body { animation: sec-done 1.6s ease-out; }
@keyframes sec-done { from { background-color: #f3e6d2; } }
@media (prefers-color-scheme: dark) {
  .sec-status { background: rgba(200, 168, 117, .14); }
  .sec-status::after { background: linear-gradient(100deg, transparent 30%, rgba(236, 230, 214, .08) 50%, transparent 70%); }
  .sec.just-done .sec-body { animation-name: sec-done-dark; }
}
@keyframes sec-done-dark { from { background-color: rgba(200, 168, 117, .2); } }

/* ---------- 名片檢視 ---------- */
.v-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 32px; align-items: start; }
.v-card { background: var(--card); border-radius: 4px; box-shadow: var(--shadow); padding: 24px 24px 12px; }
.v-name { font: 900 30px/1.3 var(--mincho); color: var(--heading); letter-spacing: .05em; }
.v-alt { font: 500 16px var(--sans); color: var(--muted); margin-left: 12px; letter-spacing: .02em; }
.v-role { font-size: 15px; color: var(--ink); margin-top: 6px; }
.v-org { font: 700 17px/1.5 var(--mincho); color: var(--heading); margin-top: 2px; }
.v-id .item-tags { justify-content: flex-start; margin-top: 12px; }
.v-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 22px 0 10px; }
.v-act {
  display: grid; justify-items: center; gap: 4px; padding: 12px 4px; border: 0; border-radius: 4px;
  background: var(--row-bg); color: var(--heading); text-decoration: none; font-size: 13px; cursor: pointer;
}
.v-act .ic { width: 24px; height: 24px; color: var(--copper); }
.v-act:hover { background: var(--line-soft); }
.v-act.off { opacity: .35; cursor: default; }
.v-rows { display: grid; gap: 2px; margin: 8px 0; }
.v-row { display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 8px 10px; border-radius: 4px; color: var(--ink); text-decoration: none; }
.v-row:hover { background: var(--row-bg); }
.v-row > .ic { color: var(--copper); }
.v-row-text { display: grid; min-width: 0; }
.v-row-label { font-size: 12px; color: var(--muted); }
.v-row-value { font-size: 16px; overflow-wrap: anywhere; }
.v-note { padding: 10px 10px 14px; }
.v-note p { white-space: pre-wrap; margin-top: 2px; }
.v-side { position: sticky; top: calc(var(--top-h) + 24px); display: grid; gap: 14px; padding: 7px; }
.v-photo { display: grid; place-items: center; aspect-ratio: 91 / 55; border-radius: 3px; background: var(--card); box-shadow: var(--shadow); }
.v-photo img { width: 100%; height: 100%; object-fit: contain; border-radius: 3px; background: #fff; }
.empty-photo { gap: 6px; align-content: center; color: var(--muted); font-size: 14px; }
.empty-photo .ic { width: 28px; height: 28px; color: var(--copper); opacity: .7; }
.v-h { font: 700 15px var(--mincho); color: var(--heading); margin: 14px 0 4px; }
.v-text { white-space: pre-wrap; font-size: 15px; line-height: 1.8; }
.v-text.draft { background: var(--row-bg); border-radius: 4px; padding: 14px 16px; margin-bottom: 12px; }
.callout.bad { background: rgba(158, 74, 53, .14); color: var(--ink); margin-bottom: 18px; }
.view .ed-actionbar .grow { min-height: 50px; font-size: 16px; }

/* 異動紀錄 */
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.hist-item { background: var(--row-bg); border-radius: 4px; padding: 12px 14px; }
.hist-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; font-size: 14px; }
.hist-head time { color: var(--muted); font-size: 14px; white-space: nowrap; }
.act-delete .hist-head strong + * { color: var(--bad); }
.hist-changes { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 10px 0 2px; font-size: 14px; }
.hist-changes dt { color: var(--muted); }
.hist-changes dd { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; overflow-wrap: anywhere; }
.hist-changes del { color: var(--muted); text-decoration-color: var(--bad); }
.hist-changes ins { text-decoration: none; font-weight: 500; color: var(--heading); }
.hist-changes .arrow .ic { width: 14px; height: 14px; color: var(--copper); vertical-align: -2px; }
.hist-changes dd del, .hist-changes dd ins { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hist-changes dd.list-diff { display: grid; gap: 4px; }
.list-diff > span { display: flex; align-items: baseline; gap: 8px; }
.list-diff del, .list-diff ins { -webkit-line-clamp: unset; }
.wide-page { max-width: 980px; }
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--row-bg); border-radius: 4px; justify-self: start; }
.seg a { padding: 8px 16px; border-radius: 3px; color: var(--ink); text-decoration: none; font-size: 15px; }
.seg a.active { background: var(--sel-bg); color: var(--sel-ink); font-weight: 700; }
.audit-filters { display: grid; grid-template-columns: 1fr 160px; gap: 8px; margin-bottom: 12px; }
.audit-filters input { padding-left: 42px; background: var(--card); }
.mrow-link { text-decoration: none; }
#v-history { grid-column: 1 / -1; }

@media (max-width: 899px) {
  body[data-route="view-edit"] { padding-bottom: calc(72px + var(--safe-b)); }
  body[data-route="view-edit"] .tabbar { display: none; }
  body[data-route="view-edit"] .toast-root { bottom: calc(80px + var(--safe-b)); }
  .view .ed-bar-actions { display: none; }
  .v-grid { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .v-side { position: static; padding: 7px 7px 0; }
  .v-card { padding: 18px 14px 8px; }
  .v-name { font-size: 26px; }
  .v-quick { margin: 18px 0 6px; }
  .v-act { min-height: 64px; }
  .ed-more { margin-top: 14px; }
  .audit-filters { grid-template-columns: 1fr; }
  .hist-changes { grid-template-columns: 1fr; gap: 0; }
  .hist-changes dt { margin-top: 8px; font-size: 12px; }
}

/* 權限設定 */
.modes { border: 0; margin: 0 0 16px; padding: 0; display: grid; gap: 6px; }
.modes legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.mode { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 4px; background: var(--row-bg); cursor: pointer; }
.mode input { width: 20px; height: 20px; min-height: 0; margin: 2px 0 0; accent-color: var(--green); flex: none; }
.mode span { display: grid; gap: 1px; }
.mode strong { font-size: 15px; color: var(--heading); }
.mode small { font-size: 13px; color: var(--muted); }
.mode.on { background: var(--sel-bg); }
.mode.on strong, .mode.on small { color: var(--sel-ink); }
@media (prefers-color-scheme: dark) { .mode input { accent-color: var(--copper-hi); } }
.perm-group { margin: 6px 0 18px; }
.perm-group h3 { display: flex; align-items: center; gap: 8px; font: 700 16px var(--mincho); color: var(--heading); margin-bottom: 2px; }
.count-badge { font: 500 12px var(--sans); background: var(--row-bg); color: var(--muted); border-radius: 3px; padding: 0 7px; }
.perm-group .note { margin-bottom: 8px; }
.people { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.people li { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 10px; border-radius: 4px; background: var(--card); }
.people-text { flex: 1; min-width: 0; display: grid; }
.people-text strong { font-size: 15px; font-weight: 500; }
.people-text small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-initial.sm { width: 30px; height: 30px; font-size: 13px; flex: none; }
.perm-group .perm-add { grid-template-columns: 1fr auto; margin-top: 0; }

/* 兩欄版面（檢視 / 編輯共用）：主欄由上往下排，側欄固定照片；只有一組欄線，邊緣對齊 */
.layout-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); gap: 28px; align-items: start; }
.col-main { grid-column: 1; grid-row: 1; display: grid; gap: 16px; min-width: 0; }
.col-side { grid-column: 2; grid-row: 1; position: sticky; top: calc(var(--top-h) + 20px); display: grid; gap: 14px; min-width: 0; padding: 0; }
.ed-more.stack { display: grid; grid-template-columns: 1fr; gap: 16px; margin: 0; }
.ed-more.stack .sec { margin: 0; }
#v-history { grid-column: auto; }
.view .ed-form, .editor .ed-form { background: var(--card); border-radius: 4px; box-shadow: var(--shadow); padding: 22px 24px 8px; }
.v-card { padding: 22px 24px 12px; }
.ed-bar { margin: -6px 0 18px; }
.media-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.media-actions .btn { padding: 0 8px; font-size: 14px; }
.v-quick { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (min-width: 900px) {
  .view .ed-title { visibility: hidden; }
  .ed-more.stack .sec > summary { padding: 0 24px; min-height: 56px; }
  .ed-more.stack .sec-body { padding: 2px 24px 22px; }
  .ed-more.stack .share { grid-template-columns: 200px minmax(0, 1fr); align-items: center; column-gap: 24px; }
  .ed-more.stack .share .qr { grid-row: span 2; justify-self: start; width: 200px; }
  .ed-more.stack .share .btn-row .btn { flex: 0 0 auto; }
  .ed-more.stack .share .btn-row { align-self: end; }
  .ed-more.stack .share .note { align-self: start; }
}
@media (max-width: 899px) {
  .layout-2 { display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .col-main { display: contents; }
  .col-side { position: static; }
  .view .v-card { order: 1; }
  .view .v-side { order: 2; padding: 7px 7px 0; }
  .view .ed-more.stack { order: 3; }
  .editor .ed-media { order: 1; padding: 7px 7px 0; }
  .editor .ed-form { order: 2; background: transparent; box-shadow: none; padding: 0; }
  .editor .ed-more.stack { order: 3; }
  .ed-more.stack { gap: 14px; }
}

/* 名片照片：圖片絕對定位填滿外框，原圖再大也只會在框內等比例縮放，不會撐開版面 */
.photo, .v-photo, .saved-card { position: relative; min-width: 0; min-height: 0; overflow: visible; }
.photo img, .v-photo img, .saved-card img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: contain; }
.saved-card img { object-fit: cover; }

/* 四角裁切 */
.scan-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.scan-status { font-size: 13px; color: var(--muted); }
.crop-sheet { width: min(760px, 100%); }
.crop-stage { position: relative; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; margin: 4px 0 12px; }
.crop-stage canvas#crop-canvas, .crop-svg { position: absolute; top: 0; border-radius: 3px; }
.crop-svg { pointer-events: none; overflow: visible; }
#crop-shade { fill: rgba(14, 31, 24, .45); }
#crop-poly { fill: none; stroke: var(--orange); stroke-width: 2; }
.crop-h {
  position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; z-index: 2;
}
.crop-h::after { content: ''; position: absolute; inset: 13px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 0 3px #fff, 0 2px 8px rgba(0, 0, 0, .4); }
.crop-h.on::after, .crop-h:focus-visible::after { inset: 10px; }
.crop-loupe { position: absolute; top: 8px; width: 120px; height: 120px; border-radius: 50%; box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(0, 0, 0, .4); z-index: 3; pointer-events: none; background: #fff; }
.crop-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.crop-rot { font-size: 13px; color: var(--muted); }
@media (max-width: 899px) {
  .sheet-wrap.center .crop-sheet { max-height: 94vh; max-height: 94dvh; }
  .sheet-wrap.center:has(.crop-sheet) { padding: 8px; }
}

.btn.add-row { background: var(--card); border-color: var(--line); color: var(--heading); min-height: 34px; padding: 0 12px 0 9px; }
.btn.add-row .ic { color: var(--copper); }
.btn.add-row:hover { border-color: var(--copper); background: var(--field); }
.list-block .list-head { margin-bottom: 8px; }

/* 首頁：左欄新增名片＋最近新增，右欄統計 */
.dash { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, 1fr); gap: 28px; align-items: start; }
.dash-l, .dash-r { display: grid; gap: 18px; min-width: 0; }
.dash-add { background: var(--green); color: #ece6d6; border-radius: 6px; padding: 26px 26px 20px; display: grid; gap: 14px; transition: box-shadow .15s; }
.dash-add.drop-on { box-shadow: 0 0 0 3px var(--copper-hi); }
.dash-add h1 { font: 900 26px/1.35 var(--mincho); letter-spacing: .04em; color: #ece6d6; }
.dash-lead { color: #c9cbbf; font-size: 15px; line-height: 1.7; max-width: 34em; }
.dash-shoot { min-height: 64px; font-size: 19px; font-weight: 700; letter-spacing: .08em; gap: 10px; }
.dash-shoot .ic { width: 26px; height: 26px; }
.dash-alt { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.ghost-light { background: rgba(255, 255, 255, .07); border-color: rgba(200, 168, 117, .45); color: #ece6d6; }
.btn.ghost-light .ic { color: var(--copper-hi); }
.btn.ghost-light:hover { background: rgba(255, 255, 255, .13); }
.dash-drop { font-size: 13px; color: #a6ab9f; }
.dash-search { flex: none; }
.dash-search input { width: 100%; }
.dash-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { display: grid; align-content: start; gap: 2px; background: var(--card); border-radius: 4px; box-shadow: var(--shadow); padding: 14px 14px 12px; color: var(--ink); text-decoration: none; min-width: 0; }
a.stat:hover { box-shadow: 0 0 0 1px var(--line), var(--shadow); }
.stat strong { font-size: 38px; line-height: 1; color: var(--heading); font-weight: 700; }
.stat span { font-size: 13px; color: var(--muted); }
.stat small { font-size: 12px; color: var(--muted); }
.dash .block { padding: 16px 18px 12px; }
.dash .block .card-list { margin-top: 4px; }
.dash .block .item { box-shadow: none; background: var(--row-bg); }
.todo { list-style: none; padding: 0; display: grid; gap: 6px; margin: 4px 0 4px; }
.todo a { display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-radius: 4px; background: var(--row-bg); color: var(--ink); text-decoration: none; min-height: 56px; }
.todo a:hover { background: var(--line-soft); }
.todo-n { min-width: 44px; text-align: center; font-size: 26px; font-weight: 700; color: var(--heading); }
.todo-n.bad { color: var(--bad); }
.todo-text { display: grid; flex: 1; min-width: 0; }
.todo-text strong { font-size: 15px; }
.todo-text small { font-size: 13px; color: var(--muted); }
.todo .chev { width: 18px; height: 18px; color: var(--muted); }
.bars { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; height: 150px; align-items: end; margin: 8px 0 6px; }
.bar-col { position: relative; display: grid; grid-template-rows: auto 1fr auto; height: 100%; align-items: end; justify-items: center; gap: 4px; outline: none; }
.bar-col .bar { width: min(28px, 100%); background: var(--copper); border-radius: 4px 4px 0 0; align-self: end; min-height: 0; }
.bar-col:hover .bar, .bar-col:focus-visible .bar { background: var(--orange); }
.bar-v { font-size: 14px; color: var(--ink); }
.bar-x { font-size: 12px; color: var(--muted); padding-top: 4px; width: 100%; text-align: center; box-shadow: 0 -1px 0 var(--line); }
.bar-col:hover::after, .bar-col:focus-visible::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); white-space: nowrap; background: var(--green-deep); color: #ece6d6; font-size: 12px; padding: 4px 8px; border-radius: 4px; pointer-events: none; z-index: 2; }
.dash-sub { font-size: 14px; color: var(--muted); font-weight: 500; margin: 14px 0 6px; }
.who-list, .cat-counts { list-style: none; padding: 0; display: grid; gap: 2px; margin-bottom: 4px; }
.who-list li { display: flex; justify-content: space-between; padding: 6px 2px; font-size: 15px; }
.cat-counts a { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 8px; border-radius: 4px; color: var(--ink); text-decoration: none; min-height: 44px; }
.cat-counts a:hover { background: var(--row-bg); }
.cat-counts small { margin-left: 6px; font-size: 12px; color: var(--muted); }
.cat-counts .num { color: var(--muted); }
.filter-note { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--row-bg); border-radius: 4px; padding: 8px 8px 8px 14px; margin-bottom: 12px; font-size: 14px; }
@media (prefers-color-scheme: dark) {
  .dash-add { background: rgba(0, 0, 0, .22); }
}
@media (max-width: 899px) {
  .dash { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
  .dash-l, .dash-r { display: contents; }
  .dash-add { order: 1; padding: 20px 18px 16px; }
  .dash-search { order: 2; }
  .dash-stats { order: 3; }
  .dash-todo { order: 4; }
  .dash-recent { order: 5; }
  .dash-trend { order: 6; }
  .dash-cats { order: 7; }
  .dash-add h1 { font-size: 22px; }
  .dash-drop { display: none; }
  .stat { padding: 12px 10px 10px; }
  .stat strong { font-size: 32px; }
}

/* 拖曳換分類：首頁分類清單當放置目標；手機長按拖曳的分類盤 */
body.dragging-card .cat-counts a[data-drop] { background: var(--row-bg); }
.cat-counts a.drop-hover, body.dragging-card .cat-counts a.drop-hover { background: var(--orange); color: #fff; }
.cat-counts a.drop-hover .num, .cat-counts a.drop-hover small { color: #fff; }
@media (pointer: coarse) {
  .item[draggable="true"] { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}
body.touch-dragging { overflow: hidden; }
.drag-tray { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--green); color: #ece6d6; padding: 14px 16px calc(16px + var(--safe-b)); border-radius: 12px 12px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .25); animation: tray-in .16s ease-out; }
.drag-tray p { font-size: 13px; color: #c9cbbf; margin-bottom: 10px; }
.drag-tray-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 40vh; overflow: auto; }
.drag-target { display: grid; gap: 2px; min-height: 60px; align-content: center; padding: 8px 12px; border-radius: 6px; border: 1px solid rgba(200, 168, 117, .45); background: rgba(255, 255, 255, .06); }
.drag-target small { font-size: 12px; color: #a6ab9f; }
.drag-target.drop-hover { background: var(--orange); border-color: var(--orange); color: #fff; }
.drag-target.drop-hover small { color: #fff; }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 61; pointer-events: none; margin: -46px 0 0 -40px; padding: 8px 14px; border-radius: 6px; background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); white-space: nowrap; max-width: 70vw; overflow: hidden; text-overflow: ellipsis; }
@keyframes tray-in { from { transform: translateY(100%); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .drag-tray { animation: none; } }

/* 拖曳把手：看得出哪裡可以拖 */
.item-grip { align-self: stretch; display: flex; align-items: center; justify-content: center; width: 30px; margin-right: -8px; color: var(--copper); cursor: grab; touch-action: none; border-radius: 4px 0 0 4px; flex: none; }
.item-grip .ic { width: 20px; height: 20px; }
.item:hover .item-grip { background: var(--row-bg); color: var(--copper-deep); }
.item-grip:active { cursor: grabbing; }
@media (pointer: coarse) { .item-grip { width: 36px; margin-right: -8px; } }
body.dragging-card .side-item[data-drop], body.dragging-card .cat-counts a[data-drop] { outline: 1.5px dashed var(--copper); outline-offset: -3px; }
body.dragging-card .side-item.drop-hover, body.dragging-card .cat-counts a.drop-hover { outline-color: transparent; }
.item-grip + .item-link { padding-left: 14px; }
@media (pointer: coarse) { .item-grip + .item-link { padding-left: 14px; } }

/* 名片上的 QR Code */
.qr-found { margin-top: 12px; padding: 12px 14px; border-radius: 4px; background: var(--card); box-shadow: var(--shadow); }
.qr-found-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--heading); margin: 0 0 8px; }
.qr-found-title .ic, .qr-found-title .spinner { width: 18px; height: 18px; flex: none; }
.qr-found-title.muted { color: var(--muted); font-weight: 400; margin: 0; }
.qr-found ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.qr-found li { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 14px; }
.qr-found .tag { flex: none; }
.qr-text { overflow-wrap: anywhere; color: var(--muted); }
