/* ============================================================
   水電初心者（sd.novice.tw）— 主樣式
   ------------------------------------------------------------
   設計調性：水（藍綠）＋ 銅（暖橘）＋ 工程精準
   沿用鋼鐵手冊的資訊架構與元件命名，讓兩站可以互相對照維護。
   深色模式由 <html data-theme="dark"> 驅動（JS 在 head 內先決定）。
   ============================================================ */

:root {
    /* 水藍：主色 */
    --w-900: #062a35;
    --w-800: #0b3d4c;
    --w-700: #11596c;
    --w-600: #0e6f8c;
    --w-500: #17879f;
    --w-400: #4ea8bd;
    --w-300: #9dd3de;
    --w-200: #cfe9ef;
    --w-100: #e8f4f7;
    --w-50:  #f4fafb;

    /* 銅：強調（規格數值、警示前綴） */
    --copper:    #b45309;
    --copper-lt: #fef3c7;
    --copper-bd: #fcd34d;

    --accent:    #0e6f8c;
    --accent-dk: #0b5a72;
    --accent-lt: #e0f2f6;

    --ok:    #047857;
    --ok-lt: #d1fae5;
    --warn:  #b45309;
    --warn-lt: #fef3c7;
    --bad:   #b91c1c;
    --bad-lt: #fee2e2;

    --surface: #ffffff;
    --surface-2: #f7fafb;
    --bg:      #f1f6f8;
    --line:    #dbe6ea;
    --line-2:  #c8d9df;

    --ink:     #0f172a;
    --body:    #24404a;
    --muted:   #5c7683;

    --radius:    12px;
    --radius-sm: 8px;
    --shadow:    0 1px 3px rgba(6, 42, 53, .07), 0 1px 2px rgba(6, 42, 53, .04);
    --shadow-lg: 0 12px 32px rgba(6, 42, 53, .12);

    --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;

    --header-h: 66px;
}

/* ---------------- 深色模式 ---------------- */
html[data-theme="dark"] {
    --surface: #12242b;
    --surface-2: #16303a;
    --bg:      #0b1a20;
    --line:    #23424e;
    --line-2:  #2d5462;

    --ink:   #eef7f9;
    --body:  #c6dbe1;
    --muted: #8fb0bb;

    --w-50:  #10262e;
    --w-100: #163541;
    --w-200: #1d4a58;
    --w-300: #2b6675;
    --w-700: #8fd3e2;

    --accent:    #4ec3dd;
    --accent-dk: #7ad6ea;
    --accent-lt: #123a46;

    --copper:    #fbbf24;
    --copper-lt: #3a2c0a;
    --copper-bd: #6b5210;

    --ok:    #34d399;
    --ok-lt: #0c332a;
    --warn:  #fbbf24;
    --warn-lt: #3a2c0a;
    --bad:   #f87171;
    --bad-lt: #3d1515;

    --shadow:    0 1px 3px rgba(0, 0, 0, .35);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Microsoft JhengHei', sans-serif;
    background: var(--bg);
    color: var(--body);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'tnum';
    transition: background .18s ease, color .18s ease;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 0 1rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { color: var(--ink); line-height: 1.35; font-weight: 700; }

.skip-link {
    position: absolute; left: -9999px; top: 0; z-index: 200;
    background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ============================================================
   頁首
   ============================================================ */
.site-header {
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 50;
}
.header-inner {
    display: flex; align-items: center; gap: 1rem;
    height: var(--header-h); flex-wrap: nowrap;
}
.brand {
    display: flex; align-items: center; gap: .65rem;
    color: var(--ink); text-decoration: none; flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-icon {
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 10px;
    background: linear-gradient(135deg, var(--w-700), var(--w-500));
    color: #fff; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(14, 111, 140, .25);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1.04rem; letter-spacing: .01em; }
.brand-text small { color: var(--muted); font-size: .72rem; font-weight: 400; }

.site-nav {
    display: flex; gap: .1rem; margin-left: auto;
    flex-wrap: nowrap; align-items: center;
}
.site-nav > a,
.nav-group-btn {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .5rem .68rem; border-radius: var(--radius-sm);
    color: var(--body); font-size: .9rem; font-weight: 500;
    background: none; border: 0; cursor: pointer; font-family: inherit;
    white-space: nowrap; transition: background .15s, color .15s;
    text-decoration: none;
}
.site-nav > a:hover,
.nav-group-btn:hover { background: var(--w-100); color: var(--ink); text-decoration: none; }
.site-nav > a.active,
.nav-group.active > .nav-group-btn {
    background: var(--accent-lt); color: var(--accent-dk); font-weight: 600;
}

.nav-group { position: relative; }
.nav-caret {
    width: 0; height: 0;
    border-left: 4px solid transparent; border-right: 4px solid transparent;
    border-top: 5px solid currentColor; opacity: .65;
    transition: transform .15s;
}
.nav-group.open .nav-caret { transform: rotate(180deg); }
.nav-drop {
    position: absolute; top: calc(100% + 6px); left: 0;
    min-width: 208px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); padding: .35rem;
    display: none; flex-direction: column; gap: .05rem; z-index: 60;
}
.nav-group.open .nav-drop { display: flex; }
@media (min-width: 701px) {
    .nav-group:hover .nav-drop,
    .nav-group:focus-within .nav-drop { display: flex; }
}
.nav-drop a {
    padding: .5rem .7rem; border-radius: 6px;
    color: var(--body); font-size: .9rem; white-space: nowrap;
}
.nav-drop a:hover { background: var(--w-100); color: var(--ink); text-decoration: none; }
.nav-drop a.active { background: var(--accent-lt); color: var(--accent-dk); font-weight: 600; }

.nav-toggle {
    display: none; margin-left: auto;
    width: 40px; height: 38px; border: 1px solid var(--line);
    border-radius: var(--radius-sm); background: var(--surface);
    cursor: pointer; padding: 0; place-items: center; gap: 4px;
    grid-template-rows: repeat(3, 2px);
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--body); border-radius: 2px; }

.theme-toggle {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px; margin-left: .35rem;
    border: 1px solid var(--line); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--body); cursor: pointer;
    transition: border-color .15s, color .15s;
}
.theme-toggle:hover { border-color: var(--w-400); color: var(--accent); }
.theme-toggle .ti-moon { display: none; }
html[data-theme="dark"] .theme-toggle .ti-sun { display: none; }
html[data-theme="dark"] .theme-toggle .ti-moon { display: block; }

/* 手機選單 */
@media (max-width: 860px) {
    .nav-toggle { display: grid; }
    .site-nav {
        position: fixed; inset: var(--header-h) 0 auto 0;
        flex-direction: column; align-items: stretch;
        background: var(--surface); border-bottom: 1px solid var(--line);
        padding: .5rem .75rem 1rem; gap: .1rem;
        box-shadow: var(--shadow-lg);
        max-height: calc(100vh - var(--header-h));
        overflow-y: auto;
        display: none;
    }
    .site-nav.open { display: flex; }
    .site-nav > a { padding: .75rem .8rem; font-size: 1rem; }
    .nav-group { width: 100%; }
    .nav-group-btn { width: 100%; justify-content: space-between; padding: .75rem .8rem; font-size: 1rem; }
    .nav-drop {
        position: static; box-shadow: none; border: 0;
        padding: 0 0 .25rem .8rem; min-width: 0;
        display: none;
    }
    .nav-group.open .nav-drop { display: flex; }
    .nav-drop a { font-size: .95rem; }
    .theme-toggle { margin: .5rem 0 0; justify-self: start; }
}

/* ============================================================
   主內容
   ============================================================ */
.main { padding: 1.25rem 1rem 3rem; }

.breadcrumb { margin: 0 0 .85rem; font-size: .82rem; color: var(--muted); }
.breadcrumb ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .35rem; }
.breadcrumb li { display: flex; align-items: center; gap: .35rem; }
.breadcrumb li:not(:last-child)::after { content: '/'; color: var(--line-2); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb li[aria-current] { color: var(--body); font-weight: 600; }

/* ---------------- Hero ---------------- */
.hero {
    background: linear-gradient(135deg, var(--w-800), var(--w-600) 62%, var(--w-500));
    border-radius: var(--radius);
    padding: 1.9rem 1.6rem 1.7rem;
    color: #fff; margin-bottom: 1.5rem;
    position: relative; overflow: hidden;
}
.hero::after {
    content: '';
    position: absolute; right: -70px; top: -70px;
    width: 240px; height: 240px; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.16), transparent 68%);
    pointer-events: none;
}
.hero h1 { color: #fff; font-size: clamp(1.4rem, 3.2vw, 1.95rem); margin: 0 0 .6rem; }
.hero p { color: var(--w-200); font-size: .98rem; margin: 0 0 1.2rem; max-width: 660px; }
.hero-stats { display: flex; gap: 1.8rem; flex-wrap: wrap; }
.hero-stat b { display: block; font-size: 1.45rem; color: #fff; font-family: var(--mono); line-height: 1.2; }
.hero-stat span { color: var(--w-300); font-size: .78rem; }

.page-head { margin-bottom: 1.25rem; }
.page-head h1 {
    font-size: clamp(1.35rem, 2.9vw, 1.75rem);
    margin: 0 0 .5rem;
}
.page-head .lead { margin: 0; color: var(--body); font-size: .96rem; max-width: 760px; }
.page-badge {
    display: inline-block; margin: 0 0 .5rem; padding: .16rem .6rem;
    background: var(--accent-lt); color: var(--accent-dk);
    border-radius: 999px; font-size: .74rem; font-weight: 600;
}

.section-title {
    display: flex; align-items: baseline; gap: .7rem;
    margin: 2rem 0 .85rem; flex-wrap: wrap;
}
.section-title h2 { font-size: 1.18rem; margin: 0; }
.section-title .count { color: var(--muted); font-size: .82rem; }

/* ---------------- 搜尋 / 篩選 ---------------- */
.filter-bar {
    display: flex; gap: .6rem; flex-wrap: wrap; align-items: center;
    margin: 0 0 1rem;
}
.filter-bar input[type="search"] {
    flex: 1 1 220px; min-width: 0;
    padding: .6rem .8rem; border: 1px solid var(--line-2);
    border-radius: var(--radius-sm); background: var(--surface);
    color: var(--ink); font-family: inherit; font-size: .95rem;
}
.filter-bar input[type="search"]:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-lt);
}
.chip-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
    padding: .38rem .78rem; border-radius: 999px;
    border: 1px solid var(--line-2); background: var(--surface);
    color: var(--body); font-size: .84rem; cursor: pointer;
    font-family: inherit; transition: all .14s;
}
.chip:hover { border-color: var(--w-400); color: var(--accent); }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.filter-count { font-size: .8rem; color: var(--muted); margin: 0 0 .6rem; }

/* ---------------- 一鍵帶入（preset） ---------------- */
.preset-row { display: flex; gap: .4rem; flex-wrap: wrap; margin: 0 0 .9rem; }
.preset {
    padding: .34rem .66rem; border-radius: 999px;
    border: 1px dashed var(--line-2); background: var(--surface);
    color: var(--body); font-size: .78rem; cursor: pointer;
    font-family: inherit; transition: all .14s;
}
.preset:hover { border-color: var(--accent); color: var(--accent-dk); background: var(--accent-lt); }
.preset b { font-weight: 700; }

/* 表格內的標記（客訂、非庫存等） */
.tag {
    display: inline-block; margin-left: .3rem; padding: .02rem .34rem;
    border-radius: 4px; font-size: .66rem; font-weight: 700;
    background: var(--warn-lt); color: var(--warn);
    border: 1px solid var(--copper-bd); white-space: nowrap;
}
.tag--muted { background: var(--surface-2); color: var(--muted); border-color: var(--line-2); }

/* 表格工具列（互動篩選） */
.table-tools {
    display: flex; gap: .6rem; flex-wrap: wrap; align-items: end;
    margin: 0 0 .8rem;
}
.table-tools .field { margin: 0; flex: 0 1 190px; }
.table-tools .field > label { font-size: .76rem; }
.table-tools .field select { padding: .4rem .5rem; font-size: .86rem; }

/* ---------------- 表格 ---------------- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.25rem;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.spec {
    width: 100%; border-collapse: collapse;
    font-size: .88rem;
}
table.spec thead th {
    position: sticky; top: 0; z-index: 2;
    background: var(--w-100);
    color: var(--w-800);
    font-size: .78rem; font-weight: 700; letter-spacing: .02em;
    padding: .6rem .55rem; text-align: left;
    border-bottom: 1px solid var(--line-2);
    white-space: nowrap;
}
html[data-theme="dark"] table.spec thead th { color: var(--w-700); }

table.spec td {
    padding: .55rem .55rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.spec tbody tr:last-child td { border-bottom: 0; }
table.spec tbody tr:hover { background: var(--w-50); }

table.spec td.num,
table.spec th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

table.spec td.model { font-weight: 600; color: var(--ink); white-space: nowrap; }
table.spec td.hi { font-family: var(--mono); font-weight: 700; color: var(--accent-dk); }

/* 即時換算後的安培值：不是法規原表數字，用底色標出來 */
table.spec td.amp-derived { background: var(--warn-lt); color: var(--warn); font-weight: 700; }

/* 俗稱 / 吋稱呼 這種輔助欄位縮小一點 */
table.spec td.alias { color: var(--copper); font-weight: 600; white-space: nowrap; }
table.spec .sub { display: block; font-size: .74rem; color: var(--muted); font-weight: 400; }
/* 法規禁用／限制的補充說明：用警示色，避免被當成一般備註忽略 */
table.spec .sub--warn { color: var(--warn); font-weight: 600; }

/* ---- 表格在手機改卡片（.spec-cards）：說明欄不再被 nowrap 表頭壓成細條 ---- */
/* 桌機預設隱藏卡片；卡片是「手機專用替代視圖」，資料與表格共用同一份 PHP 陣列。 */
.spec-cards { display: none; }

.tbl-note {
    margin: 0; padding: .7rem 1rem;
    font-size: .8rem; color: var(--muted);
    background: var(--surface-2); border-top: 1px solid var(--line);
}
.tbl-note a { color: var(--accent); }

/* 手機：凍結第一欄 */
@media (max-width: 768px) {
    table.spec { font-size: .82rem; }
    table.spec th:first-child,
    table.spec td:first-child {
        position: sticky; left: 0; z-index: 3;
        background: var(--surface);
        box-shadow: 1px 0 0 var(--line-2);
    }
    table.spec thead th:first-child { background: var(--w-100); z-index: 4; }
    table.spec tbody tr:hover td:first-child { background: var(--w-50); }

    /* 帶說明欄的表格：欄位標頭原本 nowrap，「PVC 管 3 條以下」會鎖住 128px，
       把「典型用途」擠到 69px。平板寬度先讓標頭換行，手機則把表格換成卡片。 */
    .spec-with-cards table.spec thead th { white-space: normal; }
}

/* 手機：帶說明欄的表格改卡片，說明文字不放在 69px 的窄欄裡折成五行。
   卡片放在 .table-card 內部（表格之後），這樣 .tbl-note 的法規說明不會跟著消失。 */
@media (max-width: 640px) {
    .spec-with-cards .table-scroll { display: none; }
    .spec-cards {
        display: grid; gap: .55rem;
        list-style: none; margin: 0; padding: .65rem;
    }
    .spec-card {
        background: var(--surface);
        border: 1px solid var(--line-2);
        border-radius: var(--radius);
        padding: .6rem .75rem .65rem;
    }
    .spec-card--warn { background: var(--warn-lt); border-color: var(--copper-bd); }
    .spec-card__head { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
    .spec-card__title { flex-shrink: 0; font-family: var(--mono); font-weight: 700; font-size: 1rem; }
    .spec-card__head .tag { margin-left: 0; }
    .spec-card__value { margin-left: auto; font-family: var(--mono); font-size: .78rem; color: var(--muted); white-space: nowrap; }
    .spec-card__value b { font-size: 1.05rem; font-weight: 700; color: var(--ink); margin-right: .1rem; }
    .spec-card__value.hi b { color: var(--accent-dk); }
    .spec-card__value.is-legal { color: var(--ok, #15803d); font-weight: 600; font-family: inherit; }
    .spec-card__swatch {
        display: inline-block; width: 14px; height: 14px; border-radius: 3px;
        vertical-align: -2px; margin-right: 6px; border: 1px solid rgba(0, 0, 0, .25);
    }
    .spec-card__text { margin: .15rem 0 .35rem; font-size: .87rem; line-height: 1.55; }
    .spec-card__text:last-child { margin-bottom: 0; }
    .spec-card__label { display: block; margin: .4rem 0 .05rem; font-size: .72rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
    .spec-card__kv {
        display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap;
        margin: 0; font-size: .78rem; color: var(--muted);
    }
    .spec-card__head + .spec-card__kv { margin-top: .3rem; }
    .spec-card__kv b, .spec-card__kv .spec-card__val { font-weight: 600; color: var(--ink); }
    .spec-card__kv b { font-family: var(--mono); }
    .spec-card__note { margin: .3rem 0 0; font-size: .76rem; font-weight: 600; color: var(--warn); line-height: 1.5; }
    .spec-card__note.is-plain { color: var(--ink); font-weight: 400; font-size: .82rem; }
}

/* 條號標籤：表格與卡片共用。條號是這一頁的公信力來源，要能被一眼掃到。 */
.ref {
    display: inline-block;
    margin: .12rem .22rem 0 0;
    padding: .04rem .38rem;
    font-family: inherit; font-size: .71rem; font-weight: 600; line-height: 1.65;
    color: var(--accent-dk); background: var(--accent-lt);
    border: 1px solid var(--w-300); border-radius: 5px;
    white-space: nowrap;
}
td .ref, .spec-card .ref { vertical-align: 1px; }

/* 表格下方的圖例 */
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin: .5rem 0 1rem; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------------- 快速卡 ---------------- */
.quick-grid {
    display: grid; gap: .75rem;
    grid-template-columns: repeat(auto-fill, minmax(228px, 1fr));
    margin-bottom: 1.5rem;
}
.quick-card {
    display: flex; flex-direction: column; gap: .25rem;
    padding: .9rem 1rem; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); color: var(--body);
    transition: border-color .15s, transform .15s, box-shadow .15s;
}
.quick-card:hover {
    text-decoration: none; border-color: var(--accent);
    transform: translateY(-1px); box-shadow: var(--shadow-lg);
}
.quick-card b { font-size: .97rem; color: var(--ink); }
.quick-card span { font-size: .8rem; line-height: 1.55; color: var(--muted); }
.quick-card:hover b { color: var(--accent-dk); }

/* ---------------- 提示框 ---------------- */
.note {
    border-radius: var(--radius-sm);
    padding: .85rem 1rem; margin: 1rem 0;
    font-size: .88rem; line-height: 1.7;
    border: 1px solid var(--line-2);
    background: var(--surface-2);
}
/* 只有「提示框開頭的那個標題 strong」要獨占一行；
   句子中間的 <strong> 是行內強調，一旦 display:block 就會把句子拆成
   好幾段（實測「外徑 15.88 mm (5/8″)」與「接不起來」各自斷行）。 */
.note > strong:first-child { display: block; margin-bottom: .2rem; color: var(--ink); }
.note--info { background: var(--accent-lt); border-color: var(--w-300); }
.note--info strong { color: var(--accent-dk); }
.note--warn { background: var(--warn-lt); border-color: var(--copper-bd); }
.note--warn strong { color: var(--warn); }
.note--bad { background: var(--bad-lt); border-color: var(--bad); }
.note--bad strong { color: var(--bad); }
.note--ok { background: var(--ok-lt); border-color: var(--ok); }
.note--ok strong { color: var(--ok); }
.note a { font-weight: 600; }

/* ---------------- 法規依據 ---------------- */
.legal-refs {
    margin: 1.5rem 0 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: .2rem .2rem;
}
.legal-refs > summary {
    cursor: pointer; padding: .7rem .9rem;
    font-size: .88rem; font-weight: 600; color: var(--ink);
    list-style: none; display: flex; align-items: center; gap: .4rem;
}
.legal-refs > summary::-webkit-details-marker { display: none; }
.legal-refs > summary::before {
    content: ''; width: 6px; height: 6px;
    border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
    transform: rotate(-45deg); transition: transform .15s;
}
.legal-refs[open] > summary::before { transform: rotate(45deg); }
.legal-refs ul { margin: 0; padding: 0 1.2rem .6rem 2rem; font-size: .84rem; color: var(--body); }
.legal-refs li { margin-bottom: .3rem; }
.legal-note { margin: 0; padding: 0 .9rem .8rem; font-size: .78rem; color: var(--muted); }

/* ---------------- 計算器 ---------------- */
.calc-layout {
    display: grid; gap: 1.25rem;
    grid-template-columns: minmax(0, 340px) minmax(0, 1fr);
    align-items: start;
}
@media (max-width: 880px) {
    .calc-layout { grid-template-columns: minmax(0, 1fr); }
}
.calc-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.1rem 1.25rem;
    box-shadow: var(--shadow);
}
.calc-panel h3 { font-size: .95rem; margin: 0 0 .8rem; }

.field { margin-bottom: .85rem; }
.field > label { display: block; font-size: .82rem; font-weight: 600; color: var(--body); margin-bottom: .28rem; }
.field .hint { display: block; font-size: .74rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }

.field input[type="number"],
.field input[type="text"],
.field select {
    width: 100%; padding: .55rem .65rem;
    border: 1px solid var(--line-2); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink);
    font-family: inherit; font-size: .95rem;
}
.field input:focus, .field select:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-lt);
}
.field-row { display: flex; gap: .6rem; }
.field-row > .field { flex: 1; margin-bottom: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    width: 100%; padding: .7rem 1rem;
    background: var(--accent); color: #fff;
    border: 0; border-radius: var(--radius-sm);
    font-family: inherit; font-size: .95rem; font-weight: 600;
    cursor: pointer; transition: background .15s;
}
.btn:hover { background: var(--accent-dk); }
.btn--ghost {
    background: var(--surface); color: var(--body);
    border: 1px solid var(--line-2);
}
.btn--ghost:hover { background: var(--w-100); color: var(--accent-dk); }
.btn--sm { width: auto; padding: .42rem .9rem; font-size: .84rem; }

.result-area { min-height: 60px; }

/* 結果卡 */
.kv-list { display: grid; gap: .5rem; margin: 0; }
.kv {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    padding: .5rem 0; border-bottom: 1px dashed var(--line);
}
.kv:last-child { border-bottom: 0; }
.kv dt { font-size: .84rem; color: var(--muted); }
.kv dd { margin: 0; font-size: 1rem; font-weight: 700; color: var(--ink); font-family: var(--mono); text-align: right; }
.kv dd small { font-size: .74rem; font-weight: 400; color: var(--muted); margin-left: .18rem; }

/* 統計卡 */
.stat-grid {
    display: grid; gap: .7rem;
    grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
    margin-bottom: 1rem;
}
.stat {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .75rem .85rem;
}
.stat-label { display: block; font-size: .76rem; color: var(--muted); margin-bottom: .18rem; }
.stat-value { display: block; font-size: 1.32rem; font-family: var(--mono); color: var(--ink); line-height: 1.2; }
.stat-value small { font-size: .72rem; font-weight: 400; color: var(--muted); margin-left: .14rem; }
.stat-hint { display: block; font-size: .72rem; color: var(--muted); margin-top: .18rem; }

/* 狀態列 */
/* 狀態列：用 block 而不是 flex。
   flex 會把文字節點與 <b> 各自變成 flex item，中間插上 gap，
   數字與單位還會被拆到兩行（實測「6.44」在上、「元」掉到下一行）。 */
.verdict {
    padding: .7rem .85rem; border-radius: var(--radius-sm);
    font-size: .88rem; margin: .75rem 0;
    border: 1px solid transparent;
}
.verdict b { font-weight: 700; white-space: nowrap; }
.verdict--ok { background: var(--ok-lt); border-color: var(--ok); color: var(--ok); }
.verdict--warn { background: var(--warn-lt); border-color: var(--copper-bd); color: var(--warn); }
.verdict--bad { background: var(--bad-lt); border-color: var(--bad); color: var(--bad); }
.verdict--info { background: var(--accent-lt); border-color: var(--w-300); color: var(--accent-dk); }

/* 下料：母材堆疊圖 */
.bar-list { display: grid; gap: .6rem; margin: 1rem 0; }
.bar-item { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.bar-head {
    display: flex; justify-content: space-between; gap: .6rem;
    padding: .4rem .7rem; background: var(--surface-2);
    font-size: .78rem; color: var(--muted); font-family: var(--mono);
}
.bar-track { display: flex; height: 30px; background: var(--w-50); }
.bar-seg {
    display: grid; place-items: center;
    font-size: .68rem; font-family: var(--mono); color: #fff;
    border-right: 1px solid rgba(255,255,255,.35);
    overflow: hidden; white-space: nowrap;
}
.bar-seg--waste { background: repeating-linear-gradient(45deg, var(--line-2), var(--line-2) 4px, var(--line) 4px, var(--line) 8px); color: var(--muted); }

/* 下料需求列 */
.demand-row {
    display: flex; gap: .45rem; align-items: flex-end;
    margin-bottom: .5rem;
}
.demand-row .dr-field { flex: 1; min-width: 0; }
.demand-row label { font-size: .74rem; color: var(--muted); display: block; margin-bottom: .18rem; }
.demand-row input {
    width: 100%; padding: .48rem .55rem;
    border: 1px solid var(--line-2); border-radius: 6px;
    background: var(--surface); color: var(--ink);
    font-family: var(--mono); font-size: .9rem;
}
.del-btn {
    flex-shrink: 0; width: 34px; height: 36px;
    border: 1px solid var(--line-2); border-radius: 6px;
    background: var(--surface); color: var(--muted);
    cursor: pointer; font-size: 1rem; line-height: 1;
}
.del-btn:hover { color: var(--bad); border-color: var(--bad); }

/* ---------------- 複製 ---------------- */
.copy-btn {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .22rem .5rem; border-radius: 6px;
    border: 1px solid var(--line-2); background: var(--surface);
    color: var(--muted); font-size: .74rem; cursor: pointer;
    font-family: inherit; transition: all .14s;
}
.copy-btn:hover { background: var(--accent-lt); color: var(--accent-dk); border-color: var(--accent-lt); }

.copy-toast {
    position: fixed; left: 50%; bottom: 28px;
    transform: translate(-50%, 12px);
    background: var(--w-800); color: #fff;
    padding: .55rem 1.1rem; border-radius: 999px;
    font-size: .86rem; opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s; z-index: 100;
    box-shadow: var(--shadow-lg);
}
.copy-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 頁尾 ---------------- */
.site-footer {
    background: var(--w-900);
    color: var(--w-200);
    margin-top: 2rem;
}
html[data-theme="dark"] .site-footer { background: #071820; }
.footer-inner {
    display: grid; gap: 1.6rem;
    grid-template-columns: 1.6fr 1fr 1fr 1fr;
    padding: 2rem 1rem 1.4rem;
}
@media (max-width: 768px) {
    .footer-inner { grid-template-columns: 1fr; gap: 0; padding: 1.2rem 1rem 1rem; }
}
.footer-col h4 { color: #fff; font-size: .92rem; margin: 0 0 .6rem; }
.footer-desc { font-size: .8rem; line-height: 1.7; color: var(--w-300); margin: 0 0 .7rem; }
.footer-meta { font-size: .74rem; color: var(--w-400); margin: 0 0 .9rem; line-height: 1.7; }
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin-bottom: .35rem; }
.footer-col a { color: var(--w-300); font-size: .84rem; }
.footer-col a:hover { color: #fff; }

.footer-col--nav > summary { list-style: none; cursor: pointer; }
.footer-col--nav > summary::-webkit-details-marker { display: none; }
@media (min-width: 769px) {
    .footer-col--nav > summary { pointer-events: none; }
    .footer-col--nav > summary .footer-col-h { margin: 0; }
}
@media (max-width: 768px) {
    .footer-col--nav { border-top: 1px solid rgba(255,255,255,.1); padding: .7rem 0; }
    .footer-col--nav > summary .footer-col-h { display: flex; justify-content: space-between; align-items: center; }
    .footer-col--nav > summary .footer-col-h::after {
        content: '+'; color: var(--w-400); font-size: 1rem;
    }
    .footer-col--nav[open] > summary .footer-col-h::after { content: '−'; }
    .footer-col--nav ul { margin-top: .5rem; }
}

.share-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.share-lead { font-size: .74rem; color: var(--w-400); }
.share-btn {
    padding: .3rem .65rem; border-radius: 999px;
    border: 1px solid rgba(255,255,255,.18); background: transparent;
    color: var(--w-200); font-size: .74rem; cursor: pointer;
    font-family: inherit; transition: all .14s;
}
.share-btn:hover { background: rgba(255,255,255,.1); color: #fff; }

.footer-bottom {
    display: flex; justify-content: space-between; gap: 1rem;
    flex-wrap: wrap; padding: .9rem 1rem 1.4rem;
    border-top: 1px solid rgba(255,255,255,.1);
}
.copyright { margin: 0; font-size: .74rem; color: var(--w-400); }
.footer-legal { display: flex; gap: .9rem; flex-wrap: wrap; }
.footer-legal a { color: var(--w-300); }

.footer-counter { display: none; }

/* ---------------- FAQ ---------------- */
.faq-list { display: grid; gap: .6rem; margin: 1rem 0 1.4rem; }
.faq-item {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.faq-item > summary {
    cursor: pointer; list-style: none;
    padding: .85rem 1rem;
    font-size: .95rem; font-weight: 600; color: var(--ink);
    display: flex; align-items: flex-start; gap: .55rem;
    line-height: 1.55;
}
.faq-item > summary::-webkit-details-marker { display: none; }
.faq-item > summary::before {
    content: 'Q';
    flex: 0 0 auto;
    font-family: var(--mono); font-size: .78rem; font-weight: 700;
    color: var(--accent); background: var(--accent-lt);
    border-radius: 4px; padding: .05rem .32rem;
    margin-top: .12rem;
}
.faq-item[open] > summary { border-bottom: 1px dashed var(--line); }
.faq-item[open] > summary::before { content: 'A'; color: #fff; background: var(--accent); }
.faq-body {
    padding: .85rem 1rem .95rem 1.9rem;
    font-size: .9rem; line-height: 1.85; color: var(--body);
}
.faq-body a { font-weight: 600; }

/* 內文表格卡片（條列式說明用） */
.table-card > h3 + p, .table-card p:last-child { margin-bottom: 0; }

/* 計算器：結果區的表格與長文字 */
.result-area .kv + .kv { margin-top: 0; }
.calc-panel .btn + .btn { margin-top: .5rem; }

.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.text-muted { color: var(--muted); }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* 列印 */
@media print {
    .site-header, .site-footer, .calc-panel, .filter-bar, .copy-btn, .theme-toggle { display: none !important; }
    body { background: #fff; }
    .table-card { box-shadow: none; }
}
