:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f4f3f1;
  --border: #e7e5e2;
  --text: #1c1a19;
  --muted: #78716c;
  --accent: #7a1227;   /* 和 logo 同一個紅 */
  --accent-soft: #f6e9ee;
  --up: #15803d;
  --down: #b91c1c;
  --warn-bg: #fff7e6;
  --warn: #8a5a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141212;
    --surface: #1c1a1a;
    --surface-2: #252222;
    --border: #322e2e;
    --text: #efeceb;
    --muted: #a39d9a;
    --accent: #d9738f;
    --accent-soft: #3a2029;
    --up: #4ade80;
    --down: #f87171;
    --warn-bg: #2e2412;
    --warn: #f0c270;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* ── 頂部 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px max(16px, calc((100vw - 1200px) / 2));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { height: 26px; width: auto; display: block; }
.signin-box .brand img { height: 34px; }
.tabs { display: flex; gap: 2px; flex: 1; }
.tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { color: var(--text); background: var(--surface-2); font-weight: 600; }

.lang-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px 8px; border-radius: 8px; font-size: 13px;
}
.lang-btn:hover { color: var(--text); background: var(--surface-2); }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 9px;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
a.btn { text-decoration: none; color: inherit; display: inline-block; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 40px; }
.view { display: none; }
.view.active { display: block; }

.notice { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }

/* ── 酒窖切換 ── */
.cellar-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
.cellar-pill { position: relative; display: flex; align-items: center; border-radius: 10px; flex: none; }
.cellar-pill.active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border), var(--shadow); }
.cellar-select { border: 0; background: none; cursor: pointer; padding: 7px 12px; font-size: 14px; color: var(--muted); border-radius: 10px; white-space: nowrap; }
.cellar-select:hover { color: var(--text); }
.cellar-pill.active .cellar-select { color: var(--text); font-weight: 600; padding-right: 4px; }
.cellar-select .n { margin-left: 6px; font-size: 12px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.cellar-more { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px 8px 4px 4px; border-radius: 6px; font-size: 15px; line-height: 1; }
.cellar-more:hover { color: var(--text); }
.cellar-add { border: 1px dashed var(--border); background: none; cursor: pointer; color: var(--muted); padding: 6px 12px; border-radius: 10px; font-size: 13px; flex: none; white-space: nowrap; }
.cellar-add:hover { color: var(--accent); border-color: var(--accent); }
.menu {
  position: fixed; z-index: 60; min-width: 140px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--down); }
.modal.small-modal { width: min(420px, calc(100vw - 32px)); }
.modal.small-modal input { width: 100%; }
.drop-hero .into { color: var(--accent); font-weight: 550; margin: -4px 0 8px; }
.target { display: inline-flex; align-items: center; gap: 6px; }
.target select, .target input { padding: 5px 8px; font-size: 13px; }
.target input { width: 150px; }

/* ── 統計卡 ── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ── 工具列 ── */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1; min-width: 0; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 11px; cursor: pointer; font-size: 13px;
}
.chip .n { color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.active .n { color: inherit; opacity: .7; }

/* ── 表格 ── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.wines { width: 100%; border-collapse: collapse; }
.wines th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.wines td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.wines tr:last-child td { border-bottom: 0; }
.wines tbody tr { cursor: pointer; }
.wines tbody tr:hover { background: var(--surface-2); }
.num, .wines th.num { text-align: right; font-variant-numeric: tabular-nums; }
.wines th.sel, .wines td.sel { width: 36px; padding-right: 0; }
.wines td.sel input, .wines th.sel input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); margin: 0; }
.wines tbody tr.selected { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.bulk-bar {
  position: sticky; top: 64px; z-index: 15; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 8px 10px 8px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.bulk-bar .spacer { flex: 1; }
.bulk-bar .link-btn { color: inherit; text-decoration: underline; font-size: 13px; }
.bulk-bar .btn { padding: 5px 12px; }
.bulk-bar .btn:not(.danger-solid) { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 35%, transparent); }
.bulk-bar .btn:not(.danger-solid):hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }
.btn.danger-solid { background: var(--down); border-color: var(--down); color: #fff; }
.btn.danger-solid:hover { filter: brightness(1.08); background: var(--down); }
.wines th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.wines th[data-sort]:hover { color: var(--text); }
.wines th.sorted { color: var(--text); font-weight: 600; }
.wines th.sorted::after { content: " ↓"; color: var(--accent); }
.wines th.sorted[data-dir="asc"]::after { content: " ↑"; }
.wine-cell { display: flex; align-items: center; gap: 12px; }
.thumb { width: 36px; height: 48px; border-radius: 6px; object-fit: contain; background: var(--surface-2); flex: none; display: block; }
.thumb.empty { background: var(--surface-2); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 2px; border: 0; border-radius: 99px; padding: 0 8px; font-size: 11.5px; line-height: 20px;
  background: var(--accent-soft); color: var(--accent); cursor: pointer;
}
.tag:hover { filter: brightness(.96); }
.tag-row { margin-top: -6px; align-items: center; }
.tag-row > .muted { margin-right: 2px; }
.tag-chip { font-size: 12.5px; }
.pager { display: flex; align-items: center; gap: 6px; padding: 12px 2px; flex-wrap: wrap; }
.pager select { padding: 4px 8px; font-size: 13px; }
.pager .spacer { flex: 1; }
.page {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.page:hover:not(:disabled) { background: var(--surface-2); }
.page.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.page:disabled { opacity: .4; cursor: default; }
.pager .gap { color: var(--muted); padding: 0 2px; }
.wine-name { font-weight: 550; }
.wine-sub { color: var(--muted); font-size: 12.5px; }
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ── 空狀態 / 拖放 ── */
.drop-hero {
  border: 1.5px dashed var(--border); border-radius: 18px; background: var(--surface);
  padding: 64px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.drop-hero h2 { margin: 6px 0 0; font-size: 22px; letter-spacing: -.01em; }
.drop-hero p { margin: 0 0 8px; color: var(--muted); max-width: 440px; }
.drop-icon { width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); font-size: 26px; display: grid; place-items: center; }
.empty-filter { text-align: center; padding: 48px; }
.drop-overlay {
  position: fixed; inset: 0; z-index: 100; display: none; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); backdrop-filter: blur(3px);
}
.drop-overlay > div {
  border: 2px dashed var(--accent); border-radius: 20px; padding: 60px 90px; background: var(--surface);
  font-size: 20px; font-weight: 600; color: var(--accent); pointer-events: none;
}
.drop-overlay.show { display: grid; }

/* ── 視窗 ── */
.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 64px); background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.2);
}
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(20, 16, 16, .35); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; overflow: auto; flex: 1; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.modal-foot:empty { display: none; }
.modal-foot .spacer { flex: 1; }

.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.progress.indeterminate > div { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.steps li { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.steps li.done { color: var(--text); }
.steps li.active { color: var(--text); font-weight: 550; }
.steps li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.steps li.done::before { background: var(--up); }
.steps li.active::before { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }

.ai-summary { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; }
.ai-summary b { color: var(--accent); }
.preview-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 52vh; }
.preview { width: 100%; border-collapse: collapse; font-size: 13px; }
.preview th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 500; color: var(--muted); padding: 7px 10px; white-space: nowrap; }
.preview td { padding: 7px 10px; border-top: 1px solid var(--border); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.preview tr.excluded td { opacity: .35; text-decoration: line-through; }
.preview .issue { color: var(--warn); font-size: 12px; white-space: normal; }
/* 確認欄位 */
.questions { border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); background: var(--warn-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.questions-title { font-weight: 600; color: var(--warn); margin-bottom: 8px; }
.question { background: var(--surface); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }
.q-text { font-weight: 550; margin-bottom: 4px; }
.q-col { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.q-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.q-controls select, .map-table select { padding: 4px 8px; font-size: 13px; }
.sample { display: inline-block; background: var(--surface-2); border-radius: 5px; padding: 0 6px; margin: 1px 4px 1px 0; font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.map-table td { white-space: normal; max-width: none; vertical-align: middle; }
.map-table td.samples { max-width: 320px; }
.map-table .price-cell { white-space: nowrap; }
.map-table tr.unsure td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.map-table tr.ignored td { opacity: .5; }
.map-table tr.ignored td:nth-child(3) { opacity: 1; }
.badge-q { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; }
.map-sheet { margin-top: 12px; }
.map-sheet-title { margin-bottom: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

/* ── 抽屜 ── */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(20,16,16,.25); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.drawer-backdrop.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.drawer.show { transform: none; }
.drawer-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h3 { margin: 0; font-size: 17px; line-height: 1.35; }
.photo { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; }
.photo-img { width: 72px; height: 96px; border-radius: 8px; object-fit: contain; background: var(--surface-2); display: block; }
.photo-actions { display: flex; flex-direction: column; align-items: center; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 1px 4px; }
.link-btn.muted { color: var(--muted); }
.tag-editor-wrap { margin-bottom: 12px; }
.tag-editor {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--border); border-radius: 9px;
  padding: 6px 8px; background: var(--surface); min-height: 38px;
}
.tag-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-editor .tag { cursor: default; font-size: 12.5px; line-height: 24px; }
.tag-editor .tag button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 0 0 2px; font-size: 14px; line-height: 1; opacity: .7; }
.tag-editor input { border: 0; box-shadow: none !important; padding: 2px; flex: 1; min-width: 120px; color: var(--text); }
.drawer-body { padding: 16px 20px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.drawer-foot .spacer { flex: 1; }
.price-box { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.price-box .big { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.field input, .field select, .field textarea { color: var(--text); font-size: 14px; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; margin: 12px 0; }
.field.inline input { width: 90px; }
.section-title { font-size: 12.5px; color: var(--muted); margin: 20px 0 8px; font-weight: 500; }
.history { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.history li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.history li:last-child { border: 0; }
.spark { width: 100%; height: 56px; display: block; margin-bottom: 6px; }

/* ── 問答 ── */
#view-ask.active { display: flex; flex-direction: column; min-height: calc(100vh - 140px); max-width: 780px; margin: 0 auto; }
.chat { flex: 1; }
.chat-intro { text-align: center; padding: 48px 0 24px; }
.chat-intro h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 24px; text-align: left; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 11px 14px; cursor: pointer; text-align: left; }
.suggestions button:hover { border-color: var(--accent); }
.msg { margin: 18px 0; display: flex; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--text); color: var(--bg); border-radius: 16px 16px 4px 16px; padding: 9px 14px; max-width: 80%; white-space: pre-wrap; }
.msg.assistant .bubble { max-width: 100%; overflow-x: auto; }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0 12px; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.bubble th { background: var(--surface-2); font-weight: 550; }
.bubble ul, .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.bubble h4 { margin: 12px 0 6px; font-size: 14px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.thinking { color: var(--muted); display: inline-flex; gap: 4px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse .7s infinite alternate; }
.thinking i:nth-child(2) { animation-delay: .2s; }
.thinking i:nth-child(3) { animation-delay: .4s; }
.composer {
  position: sticky; bottom: 16px; display: flex; gap: 8px; align-items: flex-end; margin-top: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; box-shadow: var(--shadow);
}
.composer textarea { flex: 1; border: 0; resize: none; max-height: 160px; box-shadow: none !important; }

/* ── 價格 ── */
.pricing-head { text-align: center; padding: 24px 0 28px; }
.pricing-head h2 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.02em; }
.pricing-head p { margin: 0 0 20px; }
.billing-toggle { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.billing-toggle button { border: 0; background: none; cursor: pointer; padding: 6px 16px; border-radius: 8px; color: var(--muted); font-size: 13.5px; }
.billing-toggle button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.billing-toggle .save { color: var(--up); font-size: 12px; font-weight: 500; }
.plans { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: stretch; }
.plan {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px 20px;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.plan.featured { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.plan-eq { min-height: 1.5em; }
.plan-badge {
  position: absolute; top: -11px; left: 20px; background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 2px 10px; border-radius: 99px;
}
.plan h3 { margin: 0; font-size: 17px; }
.plan-for { margin: 2px 0 16px; min-height: 2.6em; }
.plan-price { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.plan-price .amount { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.plan-price .per { color: var(--muted); font-size: 13px; }
.plan-eq { margin: 2px 0 16px; }
.plan-cta { width: 100%; margin-bottom: 18px; }
.plan-cta:disabled { opacity: .55; }
.plan-features { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.plan-features li { position: relative; padding-left: 20px; }
.plan-features li::before { content: "✓"; position: absolute; left: 0; color: var(--accent); font-weight: 700; }
.services-title { margin: 36px 0 12px; font-size: 16px; }
.services { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.service {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
}
.service-price { white-space: nowrap; font-weight: 600; font-size: 13.5px; }
.pricing-note { text-align: center; margin-top: 28px; }

/* ── 設定 ── */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .field { margin-top: 12px; }
.usage-row { margin-top: 12px; }
.usage-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.usage-row .progress { margin: 0; }

.fx { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.fx input { min-width: 0; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 14px; }
.card.wide { grid-column: 1 / -1; }
.providers { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin: 14px 0 12px; }
.provider { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.provider.is-ready { border-color: color-mix(in srgb, var(--up) 45%, var(--border)); }
.provider-head { display: flex; align-items: center; gap: 8px; }
.provider-head input { flex: 1; min-width: 0; font-weight: 600; border-color: transparent; padding: 3px 6px; margin-left: -6px; }
.provider-head input:hover { border-color: var(--border); }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.provider .field { margin: 0; }
.provider .key-row { display: flex; gap: 6px; }
.provider .key-row input { flex: 1; min-width: 0; }
.provider .actions { display: flex; gap: 6px; align-items: center; }
.provider .actions .msg { font-size: 12px; color: var(--muted); flex: 1; }
.provider .actions .msg.err { color: var(--down); }
.provider .actions .msg.ok { color: var(--up); }
.provider .btn { padding: 4px 10px; font-size: 13px; }
.routes { display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 8px 12px; align-items: center; }
.routes .label { font-weight: 550; }
.route-hint { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); margin-top: 1px; max-width: 16em; }
.routes .now { font-size: 12px; color: var(--muted); white-space: nowrap; }
.routes select, .routes input { min-width: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .25s; z-index: 200;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .topbar { gap: 10px; flex-wrap: wrap; }
  .tabs { order: 3; flex-basis: 100%; }
  .stats { grid-template-columns: 1fr 1fr; }
  .hide-sm { display: none; }
  .settings, .suggestions, .form-grid { grid-template-columns: 1fr; }
  .routes { grid-template-columns: 1fr 1fr; }
  .plans, .services { grid-template-columns: 1fr; }
  .plan-for { min-height: 0; }
  .routes .label { grid-column: 1 / -1; margin-top: 6px; }
  .wines td, .wines th { padding: 10px; }
}

@media (min-width: 761px) and (max-width: 1040px) {
  .plans { grid-template-columns: 1fr 1fr; row-gap: 22px; }
  .services { grid-template-columns: 1fr; }
}

/* ── 登入 ── */
.signin { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: var(--bg); padding: 16px; overflow: auto; }
.signin-box { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px 26px; box-shadow: var(--shadow); text-align: center; }
.signin-box .brand { justify-content: center; margin-bottom: 18px; }
.signin-box h2 { margin: 0 0 4px; font-size: 20px; }
.signin-box p { margin: 0 0 18px; }
.signin-box form { display: grid; gap: 8px; }
.signin-box input { width: 100%; }
.btn.google { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
.signin .divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin: 14px 0; }
.signin .divider::before, .signin .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.signin-box .btn.primary { width: 100%; }
.signin-links { display: flex; justify-content: space-between; margin-top: 12px; }
.signin-error { color: var(--down); font-size: 13px; margin-top: 10px; min-height: 1.2em; }

/* ── 帳號 ── */
.account-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-btn:hover { background: var(--surface-2); }
.menu-label { padding: 6px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.card.wide.locked .providers, .card.wide.locked .routes, .locked { opacity: .55; pointer-events: none; }

/* ── 分享 ── */
.share-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.share-list li { display: flex; align-items: center; gap: 6px; }
.share-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.share-list select, .share-add select { padding: 4px 8px; font-size: 13px; }
.share-add { display: flex; gap: 6px; margin-bottom: 10px; }
.share-add input { flex: 1; min-width: 0; }

/* ── 管理後台 ── */
.admin-table td { vertical-align: middle; }
.admin-table select { padding: 4px 8px; font-size: 13px; }
.admin-table .usage-cell { font-size: 12.5px; line-height: 1.5; white-space: nowrap; }
.admin-table .admin-actions { display: flex; gap: 6px; justify-content: flex-end; }
.admin-table .admin-actions .btn { padding: 4px 10px; font-size: 13px; }
.admin-table tr.disabled-row td:not(.admin-actions) { opacity: .45; }
#view-admin .stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
#adminNote { margin-top: 14px; }

/* 匯入視窗內的錯誤橫幅（要壓過 .notice 的樣式） */
.notice.modal-error {
  margin-bottom: 14px;
  background: color-mix(in srgb, var(--down) 12%, var(--surface));
  color: var(--down);
}

.welcome-note { color: var(--up); margin-top: 4px; }

/* 訂閱到期提醒 */
.expiry-chip {
  font: inherit; font-size: 12.5px; cursor: pointer; white-space: nowrap;
  border-radius: 99px; padding: 4px 12px; border: 1px solid transparent;
}
.expiry-chip.soon { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.expiry-chip.expired { background: color-mix(in srgb, var(--down) 14%, var(--surface)); color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, transparent); }
.expiry-chip:hover { filter: brightness(.97); }
.warn-text { color: var(--warn); }
.admin-table .expiry-cell input[type=date] {
  font: inherit; font-size: 12.5px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}

/* ── 出入庫紀錄 ───────────────────────────────────────────────── */
.log-head { margin-bottom: 12px; }
.log-head h2 { margin: 0 0 2px; font-size: 20px; }
.log-head p { margin: 0; }
.log-table tbody tr { cursor: default; }
.log-table tbody tr.clickable { cursor: pointer; }
.log-table .badge { font-size: 11.5px; }
.badge.kind-out { background: color-mix(in srgb, var(--down) 14%, transparent); color: var(--down); }
.badge.kind-in, .badge.kind-add { background: color-mix(in srgb, var(--up) 14%, transparent); color: var(--up); }
.badge.kind-delete { background: color-mix(in srgb, var(--down) 10%, transparent); color: var(--down); }
.badge.kind-import, .badge.kind-create { background: var(--accent-soft); color: var(--accent); }

/* 酒款抽屜裡的庫存動作 */
.stock-box {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; background: var(--surface-2);
}
.stock-now { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.stock-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.stock-actions input[type=number] { width: 72px; }
.stock-actions input[type=text] { flex: 1; min-width: 120px; }
.move-history li b { font-variant-numeric: tabular-nums; }

/* 分享視窗裡的升級提示 */
.notice.upsell { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin: 10px 0; }

/* 平台管理後台（獨立頁面） */
.admin-link {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px;
}
.admin-link:hover { color: var(--text); background: var(--surface-2); }
.admin-badge { background: var(--accent-soft); color: var(--accent); }
.admin-page .brand { gap: 8px; }

/* 頁尾 */
.footer {
  max-width: 1200px; margin: 0 auto; padding: 18px 16px 28px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px;
}
.footer .spacer { flex: 1; }
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--text); text-decoration: underline; }
.footer #footerContact::before { content: "·"; margin-right: 10px; color: var(--border); }

/* ── 統計報表 ─────────────────────────────────────────────────── */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.report-card { padding: 14px 16px 16px; }
.report-card.wide { grid-column: span 2; }
@media (max-width: 760px) { .report-card.wide { grid-column: span 1; } }
.report-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.report-card-head h3 { margin: 0; font-size: 15px; flex: 1; }
.report-card-head .icon-btn { opacity: .35; }
.report-card:hover .report-card-head .icon-btn { opacity: 1; }
.report-error { color: var(--down); font-size: 13px; }
.report-empty { padding: 20px 0; text-align: center; }
.report-hidden { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 14px; }

/* 圓餅 / 甜甜圈 */
.chart-pie { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.pie-svg { width: 150px; height: 150px; flex: none; }
.chart-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 150px; font-size: 12.5px; }
.chart-legend li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.chart-legend.inline { display: flex; gap: 14px; margin-bottom: 4px; }
.chart-legend .key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-legend .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-legend .val { font-variant-numeric: tabular-nums; }

/* 橫向長條 */
.chart-bars { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.bar-row { display: grid; grid-template-columns: 84px 1fr auto; align-items: center; gap: 8px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-track { display: flex; gap: 2px; background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; }

/* 折線 */
.chart-line { width: 100%; height: auto; }
.chart-line .grid { stroke: var(--border); stroke-width: 1; }
.chart-line .axis { fill: var(--muted); font-size: 10px; }

/* 數字與表格 */
.report-stats { display: flex; gap: 18px; flex-wrap: wrap; }
.report-stat .label { color: var(--muted); font-size: 12px; }
.report-stat .value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.report-table { font-size: 12.5px; }
.report-table tbody tr { cursor: default; }

/* 沒有照片時的標籤卡（SVG 自己帶圓角與底色） */
.label-card { background: none; }
.thumb.label-card, .photo-img.label-card { object-fit: fill; }

/* ── 拍照新增 ─────────────────────────────────────────────────── */
.hero-or { color: var(--muted); font-size: 12.5px; margin: 14px 0 8px; }
.photo-list { display: flex; flex-direction: column; gap: 10px; }
.photo-item { display: grid; grid-template-columns: 56px 22px 1fr; align-items: start; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
.photo-item.waiting, .photo-item.reading { opacity: .7; }
.photo-item.failed { border-color: color-mix(in srgb, var(--down) 40%, var(--border)); }
.photo-item > img { width: 56px; height: 75px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.photo-item .photo-keep { display: flex; justify-content: center; padding-top: 6px; }
.photo-item.waiting .photo-fields, .photo-item.reading .photo-fields, .photo-item.failed .photo-fields { grid-column: 2 / -1; padding-top: 6px; }
.photo-fields { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.photo-fields input, .photo-fields select { width: 100%; }
.photo-row { display: grid; grid-template-columns: 1fr 80px 64px 110px; gap: 6px; }
@media (max-width: 620px) { .photo-row { grid-template-columns: 1fr 1fr; } }

/* ── 登入頁的動態背景 ────────────────────────────────────────────
   設計原則：不要讓「整片畫面」持續位移。滿版的規則格子只要一直移動，
   眼睛會把它當成自己在動（vection），看久了就會暈。
   所以格線與光點完全靜止，動的只有「亮度」與一道偶爾經過的掃描線。
   全部用 CSS 漸層畫出來，不載任何圖片或影片（gzip 後約 1.4KB）。 */
/* 只換背景；文字顏色維持卡片自己的設定，否則白底白字 */
.signin { background: #150a11; }
.cellar-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }

/* 酒色暈光：兩層交替淡入淡出，位置固定不移動 */
.cellar-bg::before,
.cellar-bg::after {
  content: ""; position: absolute; inset: -20%;
  animation: cellarGlow 34s ease-in-out infinite;
  will-change: opacity;
}
.cellar-bg::before {
  background:
    radial-gradient(44% 44% at 26% 32%, rgba(122, 18, 39, .60), transparent 70%),
    radial-gradient(36% 36% at 74% 70%, rgba(72, 22, 78, .38), transparent 70%);
}
.cellar-bg::after {
  background:
    radial-gradient(42% 42% at 62% 24%, rgba(150, 30, 58, .42), transparent 70%),
    radial-gradient(40% 40% at 32% 76%, rgba(60, 24, 72, .40), transparent 70%);
  animation-delay: -17s;   /* 和前一層錯開，變成交替呼吸 */
}

/* 酒架格線：完全靜止 */
.cellar-bg .rack {
  position: absolute; inset: 0;
  --cell: 58px;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  mask-image: radial-gradient(74% 74% at 50% 45%, #000 50%, transparent 100%);
  -webkit-mask-image: radial-gradient(74% 74% at 50% 45%, #000 50%, transparent 100%);
}

/* 瓶位光點：位置不動，只有亮度緩慢起伏 */
.cellar-bg .rack::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 50% 50%, rgba(255, 186, 205, .22) 2px, transparent 2.6px);
  background-size: var(--cell) var(--cell);
  animation: dotBreathe 12s ease-in-out infinite alternate;
  will-change: opacity;
}

/* 盤點掃描線：每 18 秒經過一次，其餘時間完全不在畫面上 */
.cellar-bg .scan {
  position: absolute; top: -10%; bottom: -10%; left: -40%; width: 30%;
  background: linear-gradient(90deg,
    transparent,
    rgba(255, 255, 255, .035) 40%,
    rgba(255, 196, 214, .10) 50%,
    rgba(255, 255, 255, .035) 60%,
    transparent);
  filter: blur(6px);
  opacity: 0;
  animation: cellarScan 18s linear infinite;
  will-change: transform, opacity;
}

.signin-box { position: relative; z-index: 1; }

@keyframes cellarGlow {
  0%, 100% { opacity: 1; }
  50%      { opacity: .35; }
}
@keyframes dotBreathe {
  from { opacity: .55; }
  to   { opacity: 1; }
}
@keyframes cellarScan {
  0%            { transform: translateX(0); opacity: 0; }
  6%            { opacity: 1; }
  44%           { opacity: 1; }
  50%           { transform: translateX(460%); opacity: 0; }
  100%          { transform: translateX(460%); opacity: 0; }   /* 後半段休息，畫面完全靜止 */
}

/* 使用者在系統設定裡關閉動態效果時，只留靜態的背景 */
@media (prefers-reduced-motion: reduce) {
  .cellar-bg::before, .cellar-bg::after, .cellar-bg .rack::after, .cellar-bg .scan { animation: none; }
  .cellar-bg::after { opacity: .5; }
  .cellar-bg .scan { opacity: .5; transform: translateX(200%); }
}
