/* 恩芸 AI 智慧工作台 — 設計系統（手機優先，深淺色） */
:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --text: #1c2424;
  --muted: #5f6b6b;
  --border: #e3ded6;
  --brand: #0f3d3e;
  --brand-ink: #ffffff;
  --accent: #b8893b;
  --danger: #b3261e;
  --focus: #2b7a78;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416;
    --surface: #132124;
    --surface-2: #182a2e;
    --text: #e8eeee;
    --muted: #9fb0b0;
    --border: #24393d;
    --brand: #4fb3a9;
    --brand-ink: #062022;
    --accent: #d8b06a;
    --danger: #f2b8b5;
    --focus: #7fd6cc;
    --shadow: none;
    color-scheme: dark;
  }
}

/* 手動切換深色時也適用 */
:root[data-theme="dark"] {
  --bg: #0b1416;
  --surface: #132124;
  --surface-2: #182a2e;
  --text: #e8eeee;
  --muted: #9fb0b0;
  --border: #24393d;
  --brand: #4fb3a9;
  --brand-ink: #062022;
  --accent: #d8b06a;
  --danger: #f2b8b5;
  --focus: #7fd6cc;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) calc(32px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.header { margin: 8px 0 20px; }
.brand-mark { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: 0.08em; margin: 0; }
h1 { font-size: 24px; line-height: 1.3; margin: 4px 0 0; }
h2 { font-size: 18px; margin: 0; }
.subtitle { color: var(--muted); margin: 6px 0 0; font-size: 15px; }

/* 首頁功能卡片 */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  min-height: 112px; padding: 16px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  font: inherit; text-align: left; cursor: pointer;
}
.card-btn .icon { font-size: 26px; line-height: 1; }
.card-btn .name { font-weight: 700; font-size: 16px; }
.card-btn .hint { color: var(--muted); font-size: 13px; }
.card-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
}

/* 表單 */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px;
}
.panel > h2 { margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 15px; }
.req { color: var(--danger); margin-left: 2px; }
.help { color: var(--muted); font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px 以上避免 iOS 自動放大 */
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 104px; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px;
  font: inherit; font-weight: 700; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); width: 100%; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 15px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.back { margin-bottom: 8px; padding-left: 0; border: 0; color: var(--brand); }

/* 錯誤 */
.errors {
  border: 1px solid var(--danger); color: var(--danger);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px;
}
.errors ul { margin: 4px 0 0; padding-left: 20px; }

/* 結果 */
.notice { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.result-head .count { color: var(--muted); font-size: 13px; }
.result-text {
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin: 0 0 4px; font-family: inherit; font-size: 15px;
}

/* 輸入框單位 */
.with-suffix { position: relative; }
.with-suffix input { padding-right: 44px; }
.suffix {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}

/* 還款方式選擇 */
.segmented { border: 0; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.segmented legend { font-weight: 600; font-size: 15px; margin-bottom: 6px; padding: 0; }
.seg-option {
  position: relative; display: flex; flex-direction: column; gap: 2px;
  min-height: 64px; padding: 10px 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
}
.seg-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-name { font-weight: 700; font-size: 15px; }
.seg-hint { color: var(--muted); font-size: 13px; }
.seg-option:has(input:checked) { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.seg-option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* 試算結果 */
.section-title { margin: 24px 0 8px; }
.hero-label { margin: 0; color: var(--muted); font-size: 14px; }
.hero-number {
  margin: 2px 0 4px; font-size: 32px; font-weight: 800; line-height: 1.2;
  color: var(--brand); font-variant-numeric: tabular-nums;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 16px 0 0; }
.stat { min-width: 0; padding-top: 10px; border-top: 1px solid var(--border); }
.stat dt { color: var(--muted); font-size: 13px; }
.stat dd { margin: 2px 0 0; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
details.panel > summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.num-table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-table th, .num-table td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); }
.num-table th[scope="row"], .num-table thead th:first-child { text-align: left; }
.num-table thead th { color: var(--muted); font-weight: 600; }

/* 勾選框 */
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--brand); }
.field-help { margin: -6px 0 14px; }
details.panel > summary + * { margin-top: 8px; }

/* 自備款費用明細 */
.warn {
  margin: 10px 0 0; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px dashed var(--accent); font-size: 14px;
}
.cost-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
.cost-table th, .cost-table td { padding: 10px 0; border-top: 1px solid var(--border); vertical-align: top; }
.cost-table th { text-align: left; font-weight: 600; }
.cost-table td { text-align: right; white-space: nowrap; padding-left: 12px; font-weight: 700; }
.cost-name { display: block; }
.cost-basis { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.cost-table .is-missing td { color: var(--muted); font-weight: 400; }
.cost-total th, .cost-total td { border-top: 2px solid var(--text); }

/* 首頁：奇數張卡片時，最後一張在手機上佔滿一列 */
@media (max-width: 559px) { .grid > :last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 88px; } }
.spacer { height: 14px; }
.segmented:has(> label:nth-of-type(3):last-of-type) { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg-option { min-width: 0; }
.segmented + .check { margin-top: 10px; }

/* 重購退稅 */
.reveal { margin-top: 14px; }
.refund-badge {
  display: inline-block; margin: 2px 0 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--brand); color: var(--brand);
  font-size: 14px; font-weight: 700;
}
.cost-table .is-plus td { color: var(--brand); }

/* 提示訊息 */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px;
}

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
