/* 行動優先。桌面版是同一套樣式放大，不另外分岔。 */

:root {
  --bg: #12151c;
  --panel: #1b2029;
  --panel-2: #232a36;
  --text: #e8ebf0;
  --muted: #93a0b4;
  --accent: #4f8ef7;
  --good: #38c172;
  --bad: #e3564f;
  --warn: #e5a13c;
  --border: #2e3745;
  --bar-bg: rgba(18, 21, 28, .92);
  --alert-bg: #331a1a; --alert-bd: #5c2626; --alert-fg: #ffb4ae;
  --info-bg: #10262b; --info-bd: #164650; --info-fg: #cfe9f0;
  --warnb-bg: #2b2410; --warnb-bd: #4a3d12; --warnb-fg: #f3d47a;
  --law-bg: #182236; --law-bd: #2b3f63;
  --sel-bg: #23324a;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  /* iOS 沒有 Segoe UI 也沒有微軟正黑體，要明確指定 PingFang */
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC",
               "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  overscroll-behavior-y: none;
}

/* ── 頂列 ───────────────────────────────────────── */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
#topbar h1 { font-size: 17px; font-weight: 600; }
.icon-btn {
  width: 32px; height: 32px; min-height: 32px; border-radius: 50%; flex: 0 0 32px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}

/* ── 內容 ───────────────────────────────────────── */
#main { padding: 14px 14px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
@media (min-width: 700px) { #main { max-width: 860px; margin: 0 auto; padding-inline: 20px; } }

.tab { display: none; }
.tab.active { display: block; }

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; margin-bottom: 12px;
}
.panel h2 { font-size: 14px; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.panel h3 { font-size: 13px; color: var(--muted); font-weight: 500; margin: 14px 0 8px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.hint.warn { color: var(--warn); }
.hidden { display: none !important; }

/* ── 表單：字級一律 ≥16px，否則 iOS focus 會自動放大整頁且不縮回 ── */
input, select, textarea, button { font-family: inherit; font-size: 16px; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 10px;
  -webkit-appearance: none; appearance: none;
}
textarea { font-family: ui-monospace, "SF Mono", Consolas, monospace;
           font-size: 13px; line-height: 1.5; resize: vertical; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                           linear-gradient(135deg, var(--muted) 50%, transparent 50%);
         background-position: right 16px center, right 11px center;
         background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }

.field-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.field-row label { flex: 0 0 88px; color: var(--muted); font-size: 13px; }
.field-row input, .field-row select { flex: 1; min-width: 0; }

.check { display: flex; align-items: flex-start; gap: 10px; margin-top: 4px; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.check span { font-size: 13px; color: var(--muted); }

/* ── 按鈕：觸控目標 ≥44px ────────────────────────── */
button { border: none; border-radius: 12px; cursor: pointer; min-height: 44px;
         padding: 11px 18px; background: var(--panel-2); color: var(--text);
         border: 1px solid var(--border); }
button.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 500; }
button.ghost { background: transparent; }
button.big { width: 100%; margin-bottom: 12px; font-size: 16px; }
button:disabled { opacity: .45; }
button.danger { color: var(--bad); }
@media (hover: hover) {   /* iOS 上 hover 會「黏住」，要隔離 */
  button:hover { filter: brightness(1.12); }
}
button:active { transform: scale(.985); }

.row-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.row-actions button { flex: 1; min-width: 96px; }

/* ── 策略選擇 ───────────────────────────────────── */
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker label {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  min-height: 44px;
}
.picker input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.picker span { font-size: 14px; }

/* ── 進度 ───────────────────────────────────────── */
.progress { margin-bottom: 12px; }
.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }

.alert { background: var(--alert-bg); border: 1px solid var(--alert-bd); color: var(--alert-fg);
         border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 13.5px;
         white-space: pre-wrap; word-break: break-word; }

/* ── KPI 卡 ─────────────────────────────────────── */
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
       padding: 13px 14px; margin-bottom: 10px; border-top: 3px solid var(--accent); }
.kpi h3 { font-size: 14px; margin-bottom: 9px; color: var(--text); font-weight: 600; }
.kpi dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; }
.kpi dt { color: var(--muted); font-size: 12.5px; }
.kpi dd { font-variant-numeric: tabular-nums; font-size: 13.5px; text-align: right; }
.v-good { color: var(--good); } .v-bad { color: var(--bad); } .v-warn { color: var(--warn); }

/* ── 圖表 ───────────────────────────────────────── */
.chart-panel { padding: 12px 8px 8px; }
.chart-panel h2 { padding-inline: 6px; }
.chart { width: 100%; height: min(58vw + 140px, 320px); }

/* ── 卡片清單 ───────────────────────────────────── */
.card-list { display: grid; gap: 10px; }
@media (min-width: 700px) { .card-list { grid-template-columns: 1fr 1fr; } }
.s-card { background: var(--panel); border: 1px solid var(--border);
          border-radius: 14px; padding: 13px 14px; }
.s-card h3 { font-size: 15px; margin-bottom: 5px; }
.s-card p { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }

/* ── 表格：一律包在可橫捲的容器裡 ────────────────── */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch;
             margin-inline: -14px; padding-inline: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-top: 1px solid var(--border);
         white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
tr.tap:active { background: var(--panel-2); }
tr.sel { background: var(--sel-bg); }

/* ── 參數 ───────────────────────────────────────── */
.pgroup summary { padding: 12px 14px; font-size: 14px; cursor: pointer; }
.pgroup { background: var(--panel); border: 1px solid var(--border);
          border-radius: 14px; margin-bottom: 10px; overflow: hidden; }
.prow { display: flex; align-items: center; gap: 10px; padding: 9px 14px;
        border-top: 1px solid var(--border); }
.prow .k { flex: 1; min-width: 0; font-size: 12.5px; color: var(--muted);
           overflow-wrap: anywhere; }
.prow input { width: 108px; flex: none; padding: 7px 9px; text-align: right; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 9px; flex: none; }
.badge.default { background: #2e3745; color: var(--muted); }
.badge.override { background: #45301d; color: var(--warn); }

/* ── 底部 tab bar ───────────────────────────────── */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tab-btn {
  background: none; border: none; border-radius: 0; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 11px; padding: 6px 0;
}
.tab-btn .ico { font-size: 17px; line-height: 1; }
.tab-btn.active { color: var(--accent); }

/* ── 說明面板 ───────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .55);
         display: flex; align-items: flex-end; }
.sheet-body { background: var(--panel); width: 100%; max-height: 88vh; overflow-y: auto;
              border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + var(--safe-b));
              border-top: 1px solid var(--border); }
.sheet-body h2 { font-size: 17px; margin-bottom: 12px; }
.sheet-body p { font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }
.sheet-body p.warn { color: var(--warn); }
@media (min-width: 700px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-body { max-width: 520px; border-radius: 18px; }
}

/* ── 授權 ─────────────────────────────────────────── */
.license-chip { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; }
.license-chip .lic-text { display:flex; flex-direction:column; gap:2px; min-width:0; }
.license-chip .lic-text b { font-size:15px; }
.license-chip .lic-text b.ok { color:var(--good, #38c172); }
.license-chip .lic-text .hint { font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.license-chip button { flex:none; min-height:40px; padding:0 16px; }
.device-row { display:flex; align-items:center; gap:10px; margin:6px 0 4px; }
.device-row code { font-size:20px; letter-spacing:1px; padding:8px 12px; background:var(--panel-2, #232a36);
                   border:1px solid var(--border); border-radius:8px; font-variant-numeric:tabular-nums; }
.device-row button { min-height:40px; }
#ls-key { width:100%; font-size:13px; font-family:ui-monospace, Menlo, monospace; word-break:break-all; }
table.pricing { width:100%; border-collapse:collapse; font-size:13px; margin:6px 0 4px; }
table.pricing th { text-align:left; white-space:nowrap; padding:6px 10px 6px 0; color:var(--accent); vertical-align:top; }
table.pricing td { padding:6px 0; color:var(--muted); border-top:1px solid var(--border); }
table.pricing tr:first-child td { border-top:none; }
.hint.ok { color:var(--good, #38c172); }
button.locked::after { content:" 🔒"; }

/* ── 情境／建立器／meta 表單 ─────────────────────────── */
.intro p { font-size:14px; color:var(--muted); line-height:1.6; }
.sheet-body.wide { max-height:92vh; }
.sc-group { margin:12px 0 4px; font-size:13px; color:var(--muted); letter-spacing:1px; }
.sc-card { display:block; width:100%; text-align:left; background:var(--panel-2); border:1px solid var(--border);
           border-radius:12px; padding:12px 14px; margin:8px 0; color:var(--text); }
.sc-card b { display:block; font-size:15px; margin-bottom:3px; }
.sc-card span { font-size:13px; color:var(--muted); line-height:1.5; }
.meta-form .mrow { display:flex; flex-direction:column; gap:4px; padding:10px 0; border-bottom:1px solid var(--border); }
.meta-form .mrow label, .step .mrow label { font-size:14px; color:var(--text); }
.mrow .unit { color:var(--muted); font-size:12px; margin-left:6px; }
.mrow .help { font-size:12.5px; color:var(--muted); line-height:1.5; }
.mrow input[type=number], .mrow select { width:100%; }
.law-chips { display:flex; flex-wrap:wrap; gap:6px; margin:6px 0 4px; }
details.law { background:var(--law-bg); border:1px solid var(--law-bd); border-radius:8px; padding:4px 10px; font-size:12.5px; max-width:100%; }
details.law summary { color:#8fb4ff; cursor:pointer; list-style:none; }
details.law p { color:var(--text); margin:6px 0; line-height:1.5; }
details.law a { color:var(--accent); }
.profile-box { background:var(--panel-2); border:1px solid var(--border); border-radius:12px; padding:8px 12px; margin:8px 0; }
.profile-box summary { cursor:pointer; font-size:14px; }
.builder .step { background:var(--panel-2); border:1px solid var(--border); border-radius:12px; padding:10px 12px; margin:10px 0; }
.step-head { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.step-head code { font-size:12px; color:var(--muted); }
.step-head .spacer { flex:1; }
button.tiny { min-height:32px; padding:0 10px; font-size:13px; }
.step .mrow { display:flex; flex-direction:column; gap:4px; padding:6px 0; }
.step details { margin-top:6px; }
.step details summary { font-size:13.5px; color:var(--accent); cursor:pointer; }
.branch { margin:6px 0; font-size:13px; }
.branch > span { display:block; color:var(--muted); margin-bottom:2px; }
label.check.small { font-size:13px; padding:4px 0; }
.advanced summary { color:var(--muted); font-size:13px; cursor:pointer; margin-top:8px; }
.advanced h4 { font-size:13px; margin:10px 0 4px; color:var(--muted); }
#sc-preview { margin:10px 0; }
#sc-preview li { margin:4px 0; }
.kpi dt .q { display:inline-block; width:16px; height:16px; line-height:16px; text-align:center; border-radius:50%;
             background:var(--panel-2); border:1px solid var(--border); color:var(--muted); font-size:11px; margin-left:4px; cursor:help; }
.kpi-help { font-size:12.5px; color:var(--muted); line-height:1.5; margin:4px 0 8px; display:none; }
.kpi-help.show { display:block; }

/* ── 顧問版 ─────────────────────────────────────── */
.client-bar { display:flex; align-items:center; gap:8px; padding:10px 14px; }
.client-bar label { font-size:13px; color:var(--muted); }
.client-bar select { flex:1; }
.wl { margin-left:auto; margin-right:10px; font-size:13px; color:var(--muted); }
#advisor-box input[type=file] { font-size:13px; }

/* ── 假設與依據 ───────────────────────────────────── */
.pcard { background:var(--panel-2); border:1px solid var(--border); border-radius:12px; padding:12px 14px; margin:8px 0; }
.pcard.overridden { border-color:var(--warn); }
.pcard .ptop { display:flex; align-items:center; gap:8px; font-size:15px; }
.pcard .pval { font-size:16px; color:var(--accent); margin:2px 0 4px; font-variant-numeric:tabular-nums; }
.pcard .help { font-size:13px; color:var(--muted); line-height:1.5; }
.pcard .psrc { font-size:12px; color:var(--muted); margin-top:6px; }
.pcard .psrc a { color:var(--accent); }
.pcard .pedit { display:flex; align-items:center; gap:8px; margin-top:8px; }
.pcard .pedit label { font-size:12px; color:var(--muted); white-space:nowrap; }
.pcard .pedit input { flex:1; min-width:0; }
.pgroup > summary { font-size:15px; padding:10px 0; }

/* 頂列語言切換 */
#topbar .lang { margin-left: auto; margin-right: 8px; font-size: 13px; padding: 4px 6px; border-radius: 8px;
  background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.18); min-height: 0; width: auto; }
#topbar .lang.hidden { display: none; }

/* 頂部提示條（微信／新版本） */
.banner { display:flex; align-items:center; gap:10px; padding:10px 14px; font-size:14px;
  background:var(--warnb-bg); color:var(--warnb-fg); border-bottom:1px solid var(--warnb-bd); }
.banner.update { background:var(--info-bg); color:var(--info-fg); border-bottom-color:var(--info-bd); justify-content:center; }
.banner.hidden { display:none; }
.banner span { flex:1; }
/* 首次使用三卡 */
.cards3 { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(220px,100%),1fr)); gap:10px; margin:8px 0 12px; }
.card3 { background:var(--panel-2); border:1px solid var(--border); border-radius:12px; padding:12px; font-size:14px; }
.card3 b { display:block; margin-bottom:6px; }
.card3 p { margin:0; color:var(--muted, #93a0b4); line-height:1.5; }
.alert.info { background:var(--info-bg); color:var(--info-fg); border-color:var(--info-bd); display:flex; align-items:center; gap:10px; }
.alert.info.hidden { display:none; }
.alert.info span { flex:1; }
.primary.tiny { padding:6px 10px; font-size:13px; min-height:0; }

.pricing .price { display:block; color:var(--accent); font-weight:600; font-size:13px; margin-top:2px; }
.qr-row { display:flex; gap:14px; flex-wrap:wrap; margin:6px 0 10px; }
.qr-row figure { margin:0; text-align:center; font-size:12px; color:var(--muted); }
.qr-row img { width:132px; height:132px; border-radius:10px; background:#fff; display:block; margin-bottom:4px; }

.verdict { border-left: 3px solid var(--accent); }
.verdict #verdict-text { font-size: 15px; line-height: 1.65; }
.verdict #verdict-text p { margin: 0 0 6px; }
.verdict #verdict-hints { margin-top: 6px; }
.verdict #verdict-hints button { margin-left: 6px; }
.money-hint { display:block; font-size:12px; color:var(--muted); margin-top:2px; min-height:14px; }

/* ── 淺色主題（設定 → 外觀；或跟隨系統） ── */
:root[data-theme="light"] {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #eef1f6; --text: #1a1f29; --muted: #5d6878;
  --accent: #2f6fe0; --good: #1f9d55; --bad: #d43f3a; --warn: #b8770f; --border: #d9dee7;
  --bar-bg: rgba(255,255,255,.92);
  --alert-bg: #fdecec; --alert-bd: #f3b9b6; --alert-fg: #8a1f1b;
  --info-bg: #e7f3f7; --info-bd: #b9dbe6; --info-fg: #114455;
  --warnb-bg: #fff6d6; --warnb-bd: #f0d78a; --warnb-fg: #6a4b00;
  --law-bg: #eef3fb; --law-bd: #c9d8f2; --sel-bg: #e3ecfb;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f4f6fa; --panel: #ffffff; --panel-2: #eef1f6; --text: #1a1f29; --muted: #5d6878;
    --accent: #2f6fe0; --good: #1f9d55; --bad: #d43f3a; --warn: #b8770f; --border: #d9dee7;
    --bar-bg: rgba(255,255,255,.92);
    --alert-bg: #fdecec; --alert-bd: #f3b9b6; --alert-fg: #8a1f1b;
    --info-bg: #e7f3f7; --info-bd: #b9dbe6; --info-fg: #114455;
    --warnb-bg: #fff6d6; --warnb-bd: #f0d78a; --warnb-fg: #6a4b00;
    --law-bg: #eef3fb; --law-bd: #c9d8f2; --sel-bg: #e3ecfb;
    color-scheme: light;
  }
}
