/* ============================================================================
   金尚品不銹鋼製作管理系統 — 設計系統
   設計語言：「拉絲鋼與烤漆」

   視覺語彙取自金尚品自己的物質世界，不是通用後台模板：
     鋼墨   #1A1F24  不銹鋼在陰影裡的顏色 —— 側欄、標題
     拉絲面 #EEF1F3  髮絲紋不銹鋼的冷灰 —— 頁面底色
     鍍鈦   #A67C3D  PVD 鍍鈦香檳金 —— 品牌與關鍵旗標
     安全橙 #C2410C  工廠的警示色 —— 逾期紅燈

   三個必須遵守的原則
   ① 金額與數量一律等寬對齊（.num）。採購一天要核對幾百列，
      比例字體的數字對不齊會逼使用者重新定位視線。
   ② 鍍鈦金只用在三個地方：品牌標記、側欄目前位置、會影響交期的關鍵旗標。
      用多了就失去作用。
   ③ 中文段落不在原始碼換行 —— HTML 會把換行當空白插進中文字之間。
   ============================================================================ */

/* ── 設計權杖 ────────────────────────────────────────────────────────────── */
:root {
    --ink: #1A1F24;
    --ink-2: #2C343C;
    --steel: #5A6672;
    --steel-3: #8A949E;
    --brushed: #EEF1F3;
    --brushed-2: #F7F9FA;
    --surface: #FFFFFF;
    --line: #DAE0E5;
    --line-soft: #E9EDF0;

    --titanium: #A67C3D;
    --titanium-soft: #F7F0E4;

    --alert: #C2410C;
    --alert-soft: #FDF0E8;
    --ok: #2F7D5E;
    --ok-soft: #EBF5F0;
    --warn: #B45309;
    --warn-soft: #FDF6E8;
    --info: #1E5A8A;
    --info-soft: #EAF1F7;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei",
            "PingFang TC", "Noto Sans TC", sans-serif;
    --font-num: "SF Mono", Consolas, "Roboto Mono", "Courier New", monospace;

    --r: 4px;
    --r-lg: 6px;
    --shadow: 0 1px 2px rgba(26, 31, 36, .06), 0 1px 3px rgba(26, 31, 36, .04);
    --shadow-lg: 0 4px 16px rgba(26, 31, 36, .12);

    --sidebar-w: 232px;
    --topbar-h: 52px;

    /* Telerik 元件跟著同一組色，避免自寫畫面與 Grid 各長各的 */
    --kendo-color-primary: #A67C3D;
    --kendo-color-primary-hover: #8E6932;
    --kendo-color-error: #C2410C;
    --kendo-color-success: #2F7D5E;
    --kendo-color-warning: #B45309;
    --kendo-font-family: var(--font);
    --kendo-font-size: 13px;
    --kendo-border-radius: 4px;
}

/* ── 基礎 ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ink);
    background: var(--brushed);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.35; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* 數字一律等寬且靠右。金額、數量、日期、編號都用它 */
.num {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    text-align: right;
    white-space: nowrap;
}

.muted { color: var(--steel); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
/* !important 是必要的：.btn 等元件的 display 定義在後面，同權重會蓋掉這條 */
.only-mobile { display: none !important; }

/* ── 版面 ────────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--ink);
    color: #C9D1D9;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .18) transparent;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    height: var(--topbar-h);
    padding: 0 16px;
    flex: 0 0 var(--topbar-h);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

/* 鍍鈦金的第一個用途：品牌標記 */
.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    background: linear-gradient(140deg, var(--titanium), #C9A063);
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--ink);
    flex: 0 0 auto;
}

.brand-text { font-size: 13px; font-weight: 600; color: #F0F3F5; letter-spacing: .02em; }
.brand-sub { font-size: 10.5px; color: #7D8894; letter-spacing: .04em; }

.nav { padding: 8px 0 20px; flex: 1 1 auto; }
.nav-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding: 6px 0; }
.nav-group { margin-bottom: 2px; }

.nav-group-title {
    padding: 12px 16px 5px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .08em;
    color: #6E7A87;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 16px;
    color: #C9D1D9;
    font-size: 13px;
    border-left: 2px solid transparent;
    transition: background .12s, color .12s;
}

.nav-item:hover { background: rgba(255, 255, 255, .05); color: #FFF; text-decoration: none; }

/* 鍍鈦金的第二個用途：目前所在位置 */
.nav-item.is-active {
    background: rgba(166, 124, 61, .14);
    border-left-color: var(--titanium);
    color: #FFF;
    font-weight: 600;
}

.nav-item .icon { flex: 0 0 16px; opacity: .8; }
.nav-item.is-active .icon { opacity: 1; }

/* 合約模組編號標記。驗收時要能指著功能說「這是附件一的 M7」 */
.nav-tag {
    margin-left: auto;
    font-size: 9.5px;
    font-family: var(--font-num);
    color: #6E7A87;
    letter-spacing: .03em;
}

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    flex: 0 0 var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 18px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* Vue 島嶼掛載前先藏起來，不讓使用者看到 {{ }} 閃一下 */
[v-cloak] { display: none; }

.hamburger {
    display: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--surface);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.content { padding: 18px; flex: 1 1 auto; }

/* ── 卡片與面板 ──────────────────────────────────────────────────────────── */
/* panel 不裁切內容（overflow visible）—— 搜尋式選擇器的下拉清單會超出 panel 邊界。
   圓角改由 panel-head 與 panel-body 自己收，不靠 overflow:hidden */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    margin-bottom: 14px;
}

.panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 15px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--brushed-2);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
}
.panel > :last-child { border-radius: 0 0 var(--r-lg) var(--r-lg); }
.panel > .panel-body.tight { overflow: hidden; }   /* 表格類的緊貼內容仍裁圓角 */

.panel-title { font-size: 13.5px; font-weight: 600; }
.panel-head .spacer { margin-left: auto; }
/* 面板標題下的一句話說明：獨占一行，手機也不會擠到標題旁 */
.panel-head { flex-wrap: wrap; }
.panel-sub { flex-basis: 100%; font-size: 12px; color: var(--steel-3); line-height: 1.5; }
.panel-body { padding: 15px; }
.panel-body.tight { padding: 0; }

/* 數量不定的卡片（多案並陳）用 auto-fit，依寬度自動排 */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 12px;
}

/* 固定四格的統計列用明確欄數：桌機／平板一排四個、手機兩排。
   auto-fit 對固定數量的磚不可靠 —— 差幾個 px 就會變成 3＋1 孤掉一個 */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

/* ── 統計磚 ──────────────────────────────────────────────────────────────── */
.stat {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 13px 15px;
}

.stat-label { font-size: 11.5px; color: var(--steel); letter-spacing: .02em; }
.stat-value { font-family: var(--font-num); font-size: 24px; font-weight: 600; line-height: 1.25; }
.stat-foot { font-size: 11.5px; color: var(--steel-3); }

/* ── 按鈕 ────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 13px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: #FFF;
    background: var(--ink-2);
    border: 1px solid var(--ink-2);
    border-radius: var(--r);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}

.btn:hover { background: var(--ink); text-decoration: none; color: #FFF; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--ghost { color: var(--ink); background: var(--surface); border-color: var(--line); }
.btn--ghost:hover { background: var(--brushed); color: var(--ink); }

.btn--danger { background: var(--alert); border-color: var(--alert); }
.btn--danger:hover { background: #A5360A; }

.btn--sm { height: 27px; padding: 0 9px; font-size: 12px; }
.btn--block { width: 100%; }

/* ── 表單 ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: 12px; }

.field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--steel);
    margin-bottom: 4px;
}

.field .req { color: var(--alert); margin-left: 2px; }

.input, .select, .textarea {
    width: 100%;
    height: 33px;
    padding: 0 9px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    transition: border-color .12s, box-shadow .12s;
}

.textarea { height: auto; min-height: 68px; padding: 7px 9px; line-height: 1.6; resize: vertical; }

.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--titanium);
    box-shadow: 0 0 0 3px rgba(166, 124, 61, .12);
}

.input.num-input { font-family: var(--font-num); text-align: right; }
.input[readonly] { background: var(--brushed-2); color: var(--steel); }

.field-error { font-size: 11.5px; color: var(--alert); margin-top: 3px; }
.field-hint { font-size: 11.5px; color: var(--steel-3); margin-top: 3px; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--alert); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(194, 65, 12, .12); }

.check-group { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 4px 0; }
.check input[type="radio"] { accent-color: var(--titanium); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 0 14px;
}

.form-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-row .span-2 { grid-column: span 2; }
.form-row .span-all { grid-column: 1 / -1; }

.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
/* 多個核取方塊各佔一行（.check 本身是 inline-flex，連著寫會擠在同一行） */
.check-stack { display: flex; flex-direction: column; gap: 8px; }
.check input { width: 15px; height: 15px; accent-color: var(--titanium); cursor: pointer; }

/* 查詢列。清單頁一律用這個，換頁時條件保留 */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 9px;
    padding: 12px 15px;
    background: var(--brushed-2);
    border-bottom: 1px solid var(--line-soft);
}

.filter-bar .field { margin-bottom: 0; min-width: 150px; }
.filter-bar .grow { flex: 1 1 200px; }

/* ── 表格 ────────────────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }

.tbl thead th {
    padding: 8px 11px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--steel);
    letter-spacing: .02em;
    background: var(--brushed-2);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.tbl tbody td {
    padding: 8px 11px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.tbl tbody tr:hover { background: var(--brushed-2); }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl .col-act { width: 1%; white-space: nowrap; text-align: right; }

.tbl-wrap { overflow-x: auto; }

/* 清單表格給最小寬度。固定 px 的欄位加總超過容器時，讓表格橫向捲動，
   而不是把沒設寬的那一欄（通常是名稱）壓成一個字一行 */
.tbl.to-cards { min-width: 680px; }
.tbl .col-name { min-width: 150px; }

.hide-tablet { }

.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--steel-3);
    font-size: 13px;
}

/* 子表格：逐列 inline 輸入（聯絡人、明細）。輸入框比一般表單矮一點，列才不會太高 */
.sub-tbl td { padding: 5px 6px; vertical-align: top; }
.sub-tbl th { padding: 7px 6px; }
.sub-tbl .input { height: 30px; font-size: 13px; }
.sub-tbl input[type="radio"] { width: 16px; height: 16px; margin-top: 7px; accent-color: var(--titanium); cursor: pointer; }
.sub-tbl .field-error { margin-top: 2px; }

/* ── 搜尋式選擇器（x-picker）─────────────────────────────────────────
   會成長的主檔不做 <select>。清單只列辨識需要的摘要：名稱 ＋ 編號 ＋ 一個副資訊。 */
.picker { position: relative; }
.picker-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 3px);
    z-index: 40;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
}
.picker-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 11px;
    font-size: 13px;
    cursor: pointer;
}
.picker-item.is-active { background: var(--titanium-soft); }
.picker-name { flex: 1 1 auto; }
.picker-sub { font-size: 11.5px; color: var(--steel-3); text-align: left; }
.picker-extra { font-size: 11.5px; color: var(--steel); }

/* ── 權限矩陣（角色權限頁）────────────────────────────────────────── */
.matrix .matrix-flag { text-align: center; width: 56px; padding-left: 4px; padding-right: 4px; }
.matrix .matrix-check { justify-content: center; }
.matrix .matrix-check input { width: 17px; height: 17px; }
.matrix tr.matrix-group td { background: var(--brushed-2); padding: 6px 11px; border-top: 1px solid var(--line); }
.matrix-group-row { display: flex; align-items: center; gap: 10px; }
.matrix-group-row .spacer { flex: 1 1 auto; }
.matrix tr.is-granted .matrix-func { font-weight: 600; }
.matrix .matrix-quick .btn { padding: 0 7px; }
.matrix .matrix-quick .btn + .btn { margin-left: 2px; }

/* 一次顯示的密碼框 */
.pwd-box {
    text-align: left;
    font-size: 18px;
    letter-spacing: .06em;
    background: var(--brushed);
    border: 1px dashed var(--titanium);
    border-radius: var(--r);
    padding: 12px 14px;
    user-select: all;
}

/* Logo 上傳區 */
.logo-box { display: flex; align-items: center; gap: 14px; padding: 12px; border: 1px dashed var(--line); border-radius: var(--r); background: var(--brushed-2); flex-wrap: wrap; }
.logo-preview { max-height: 72px; max-width: 240px; object-fit: contain; background: #FFF; padding: 4px; border-radius: 3px; border: 1px solid var(--line-soft); }
.logo-actions { display: flex; gap: 6px; }

/* 操作紀錄 */
.audit-tbl td { font-size: 12.5px; }

/* ── 頁籤：同一功能內的分頁切換（分類主檔的五種分類）。目前頁籤用鍍鈦金底線 ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; scrollbar-width: none; }
.tab {
    padding: 8px 14px;
    font-size: 13px;
    color: var(--steel);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.is-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--titanium); }

/* 整頁編輯的分類表格 */
.sort-cell { display: flex; gap: 2px; }
.sort-cell .btn { width: 26px; padding: 0; min-height: 26px; height: 26px; }
.code-tbl tr.is-inactive .input { color: var(--steel-3); }
.only-mobile-inline { display: none; }

/* ── 標籤與狀態 ──────────────────────────────────────────────────────────── */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 20px;
    padding: 0 7px;
    font-size: 11.5px;
    font-weight: 500;
    border-radius: 3px;
    background: var(--brushed);
    color: var(--steel);
    white-space: nowrap;
}

.tag--ok { background: var(--ok-soft); color: var(--ok); }
.tag--warn { background: var(--warn-soft); color: var(--warn); }
.tag--info { background: var(--info-soft); color: var(--info); }

/* 鍍鈦金的第三個用途：會影響交期的關鍵旗標 */
.tag--key { background: var(--titanium-soft); color: var(--titanium); }

/* 逾期紅燈。M7 看板的核心視覺，不可移作他用 */
.tag--alert { background: var(--alert-soft); color: var(--alert); font-weight: 600; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

/* ── 簽名式元件：製令階段軌條 ────────────────────────────────────────────
   下料 → 到料 → 裁切 → 折料 → 加工 → 送漆 → 包裝 → 出貨
   客戶最痛的問題是「東西現在在哪、多久會好」，這條軌就是答案本身。
   一眼要能看出：走到哪一站、是不是卡住了。
   ────────────────────────────────────────────────────────────────────── */
.stage-track { display: flex; align-items: center; gap: 0; min-width: 0; }

.stage {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    padding: 0 2px;
}

.stage-dot {
    width: 11px;
    height: 11px;
    margin: 0 auto 4px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--line);
    position: relative;
    z-index: 1;
}

.stage-label {
    font-size: 10.5px;
    color: var(--steel-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 連接線畫在圓點的垂直中心，用左右兩段避免蓋住圓點 */
.stage::before,
.stage::after {
    content: "";
    position: absolute;
    top: 5px;
    height: 2px;
    background: var(--line);
}

.stage::before { left: 0; right: 50%; }
.stage::after { left: 50%; right: 0; }
.stage:first-child::before,
.stage:last-child::after { display: none; }

.stage.is-done .stage-dot { background: var(--ok); border-color: var(--ok); }
.stage.is-done .stage-label { color: var(--steel); }
.stage.is-done::before, .stage.is-done::after { background: var(--ok); }

.stage.is-current .stage-dot {
    background: var(--titanium);
    border-color: var(--titanium);
    box-shadow: 0 0 0 3px rgba(166, 124, 61, .2);
}

.stage.is-current .stage-label { color: var(--titanium); font-weight: 600; }
.stage.is-current::before { background: var(--ok); }

.stage.is-late .stage-dot {
    background: var(--alert);
    border-color: var(--alert);
    box-shadow: 0 0 0 3px rgba(194, 65, 12, .18);
}

.stage.is-late .stage-label { color: var(--alert); font-weight: 600; }

/* ── 建置進度條 ──────────────────────────────────────────────────────────── */
.meter { height: 5px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--titanium); border-radius: 3px; }
.meter.is-full > span { background: var(--ok); }

/* ── 訊息 ────────────────────────────────────────────────────────────────── */
.note {
    padding: 11px 14px;
    border-radius: var(--r);
    border-left: 3px solid var(--info);
    background: var(--info-soft);
    color: var(--ink-2);
    font-size: 12.5px;
    line-height: 1.7;
    margin-bottom: 14px;
}

.note--warn { border-left-color: var(--warn); background: var(--warn-soft); }
.note--alert { border-left-color: var(--alert); background: var(--alert-soft); }

.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    background: var(--ink);
    color: #FFF;
    padding: 10px 18px;
    border-radius: var(--r);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: toast-in .18s ease-out;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* ── 分頁 ────────────────────────────────────────────────────────────────── */
.pager {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 11px 15px;
    border-top: 1px solid var(--line-soft);
    font-size: 12.5px;
}

.pager .info { color: var(--steel); margin-right: auto; }

.pager a, .pager span.pg {
    min-width: 29px;
    height: 29px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: var(--r);
    color: var(--ink);
    background: var(--surface);
}

.pager a:hover { background: var(--brushed); text-decoration: none; }
.pager .pg.is-current { background: var(--ink-2); border-color: var(--ink-2); color: #FFF; font-weight: 600; }
.pager .pg.is-disabled { color: var(--steel-3); background: var(--brushed-2); }

/* ── 登入頁 ──────────────────────────────────────────────────────────────── */
.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(160deg, #1A1F24 0%, #2C343C 52%, #3A444E 100%);
}

.auth-card {
    width: 100%;
    max-width: 372px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
    padding: 30px 30px 26px;
}

.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .brand-mark { width: 30px; height: 30px; font-size: 13px; }
.auth-title { font-size: 15px; font-weight: 600; }
.auth-sub { font-size: 11.5px; color: var(--steel-3); }
.auth-foot { margin-top: 20px; text-align: center; font-size: 11px; color: var(--steel-3); }

.validation-summary {
    background: var(--alert-soft);
    color: var(--alert);
    border-radius: var(--r);
    padding: 9px 12px;
    font-size: 12.5px;
    margin-bottom: 14px;
}

.validation-summary ul { margin: 0; padding-left: 16px; }

/* ── Telerik 元件的協調 ──────────────────────────────────────────────────── */
.k-grid { border-radius: var(--r-lg); border-color: var(--line); font-family: var(--font); }
.k-grid .k-table-th { background: var(--brushed-2); color: var(--steel); font-size: 11.5px; font-weight: 600; }
.k-grid td { font-size: 13px; }
.k-grid .num, .k-grid .k-table-td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* ── 響應式斷點 ────────────────────────────────────────────────────────────
   四種裝置都要「版面合適」，不是「縮小不爆版」：

     手機   ≤ 640px   側欄抽屜、表格轉卡片、表單單欄、軌條橫捲
     平板   ≤ 1024px  側欄抽屜、表格保持表格（橫向捲動）、表單雙欄
     桌機   > 1024px  側欄常駐

   平板這一段是獨立的：768px 已經放得下七欄表格，轉成卡片會讓九列資料變成
   一整頁要捲的高牆；但 768px 放不下常駐側欄 ＋ 內容，所以側欄收成抽屜。
   ────────────────────────────────────────────────────────────────────── */

/* ── 平板與手機共用（≤ 1024px）：側欄抽屜 ─────────────────────────────── */
@media (max-width: 1024px) {
    .hamburger { display: inline-flex; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.is-open { transform: translateX(0); }

    .content { padding: 14px; }

    /* 三欄表單在平板降為兩欄，欄位不會窄到看不見內容 */
    .form-row.cols-3 { grid-template-columns: repeat(2, 1fr); }

    /* 平板寬度有限，次要欄位讓位給主要欄位；點進明細就看得到 */
    .hide-tablet { display: none !important; }
}

/* ── 手機（≤ 640px）：表格轉卡片、單欄 ─────────────────────────────────
   清單只顯示摘要 —— 十來個欄位攤在清單裡，十列疊起來就是一面看不懂的表單牆。
   ────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .only-mobile { display: block !important; }
    .btn.only-mobile { display: inline-flex !important; }
    .hide-mobile { display: none !important; }

    .content { padding: 12px; }

    .form-row, .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
    .form-row .span-2 { grid-column: auto; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); }

    /* 查詢列在手機是單欄，「查詢」按鈕上方那個對齊用的空 label 會變成一行空白 */
    .filter-bar .field-actions label { display: none; }
    .filter-bar .field-actions .btn { flex: 1 1 auto; }

    /* 表格轉卡片：欄位標題由 data-label 帶出，同一份 DOM 不另做一份 */
    .tbl.to-cards { min-width: 0; }
    .tbl.to-cards thead { display: none; }
    /* 卡片模式每列都是完整資料，平板隱藏的欄位要回來 —— 且要回到卡片的 flex 排版，不是 revert 到 table-cell */
    .tbl.to-cards tbody td.hide-tablet { display: flex !important; }
    .tbl.to-cards thead th.hide-tablet { display: none !important; }
    .tbl.to-cards tbody tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--r-lg);
        margin-bottom: 9px;
        padding: 4px 0;
    }

    .tbl.to-cards tbody td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        border: none;
        padding: 5px 13px;
        text-align: right;
    }

    .tbl.to-cards tbody td::before {
        content: attr(data-label);
        font-size: 11.5px;
        color: var(--steel);
        text-align: left;
        flex: 0 0 auto;
    }

    .tbl.to-cards tbody td.col-act {
        width: auto;                 /* 表格模式的 width:1% 在 block 下會把按鈕擠出卡片 */
        justify-content: flex-end;
        gap: 6px;
        padding-top: 8px;
        border-top: 1px solid var(--line-soft);
        margin-top: 4px;
    }
    .tbl.to-cards tbody td.col-act::before { display: none; }

    /* 卡片模式下進度條沒有固有寬度，space-between 會把它壓成一條線 */
    .tbl.to-cards tbody td .meter { flex: 1 1 auto; min-width: 110px; align-self: center; }

    /* 子表格在手機也轉卡片，但輸入框要撐滿、label 在上方 —— 逐列橫向 inline 在 390px 寬擠不下 */
    .sub-tbl thead { display: none; }
    .sub-tbl tbody tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: var(--r-lg);
        margin: 9px 12px;
        padding: 8px 12px 4px;
    }
    .sub-tbl tbody td { display: block; border: none; padding: 4px 0; }
    .sub-tbl tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: 11.5px;
        color: var(--steel);
        margin-bottom: 3px;
    }
    .sub-tbl tbody td.col-act { width: auto; text-align: right; padding-top: 6px; border-top: 1px solid var(--line-soft); margin-top: 4px; }
    .sub-tbl tbody td.col-act::before { display: none; }
    .sub-tbl .input { height: 38px; }
    .sub-tbl input[type="radio"] { margin-top: 0; }
    .sub-tbl td[data-label="預設窗口"] { display: flex; align-items: center; gap: 8px; }
    .sub-tbl td[data-label="預設窗口"]::before { margin: 0; }

    .only-mobile-inline { display: inline; }

    /* 權限矩陣在手機：每個功能一張卡，八個旗標換行排列 */
    .matrix thead { display: none; }
    .matrix tbody { display: block; }
    .matrix tr { display: block; }
    .matrix tr.matrix-group td { display: block; }
    .matrix-group-row { flex-wrap: wrap; }
    .matrix tr:not(.matrix-group) { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
    .matrix tr:not(.matrix-group) td { display: block; border: none; padding: 2px 0; width: auto; }
    .matrix .matrix-func { flex: 1 1 100%; padding-bottom: 4px !important; }
    .matrix .matrix-flag { flex: 0 0 auto; text-align: left; }
    .matrix .matrix-quick { flex: 1 1 100%; padding-top: 6px !important; }
    .matrix .matrix-quick .btn { min-height: 34px; }
    .sub-tbl td[data-label="排序"], .sub-tbl td[data-label="啟用"] { display: flex; align-items: center; gap: 8px; }
    .sub-tbl td[data-label="排序"]::before, .sub-tbl td[data-label="啟用"]::before { margin: 0; min-width: 40px; }
    .sort-cell .btn { width: 40px; min-height: 36px; height: 36px; }

    /* 階段軌條橫向捲動，不壓縮成看不清的一團。捲軸用細的 —— 原生粗捲軸在手機上很突兀 */
    .stage-track { overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
    .stage-track::-webkit-scrollbar { height: 4px; }
    .stage-track::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
    .stage { flex: 0 0 62px; }

    .pager { flex-wrap: wrap; }
    .pager .info { flex: 1 1 100%; margin-bottom: 6px; }

    .excel-steps { grid-template-columns: 1fr; }
    .preview-tbl tr.row--error { border-left: 3px solid var(--alert); }
    /* 卡片模式的「內容」格有多行：標籤獨占一行，每一行變更／錯誤各占一行靠左（預設的 space-between 會把它們排成一橫排） */
    .preview-tbl tbody td[data-label="內容"] { flex-wrap: wrap; }
    .preview-tbl tbody td[data-label="內容"]::before { flex: 1 1 100%; }
    .preview-tbl tbody td[data-label="內容"] > * { flex: 1 1 100%; text-align: left; }

    /* 觸控目標：手機上按鈕與輸入框至少 40px 高，手指才點得準 */
    .btn { min-height: 40px; }
    .btn--sm { min-height: 34px; }
    .input, .select { height: 40px; }
}

/* ── 主檔 Excel 匯入／匯出（/{主檔}/Excel）────────────────────────────────
   入口頁兩個步驟並排（手機疊起來）；預覽頁的統計磚可以點，當作篩選。
   ────────────────────────────────────────────────────────────────────── */
.excel-steps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 14px; }
.excel-steps .panel { margin-bottom: 0; }
.step-no {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--ink); color: #FFF;
    font-family: var(--font-num); font-size: 12px; font-weight: 600; flex: 0 0 auto;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.rule-list { margin: 0; padding-left: 22px; font-size: 13px; line-height: 1.8; }
.rule-list li + li { margin-top: 4px; }
.spec-tbl td { vertical-align: top; }

.stat--btn { text-align: left; cursor: pointer; font: inherit; color: inherit; transition: border-color .15s, box-shadow .15s; }
.stat--btn:hover { border-color: var(--steel-3); }
.stat--btn.is-on { border-color: var(--titanium); box-shadow: 0 0 0 2px var(--titanium-soft); }

.preview-tbl td { vertical-align: top; }
.preview-tbl tr.row--error td { background: var(--alert-soft); }
.preview-tbl tr.row--unchanged td { color: var(--steel-3); }
.err-line { color: var(--alert); }
.warn-line { color: var(--warn); }
.chg-line { color: var(--ink-2); }
.chg-line + .chg-line, .err-line + .err-line { margin-top: 2px; }

/* 遮罩：側欄抽屜與底部面板共用。所有尺寸都定義 —— 底部面板在桌機也會開 */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(26, 31, 36, .45);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
.scrim.is-open { opacity: 1; pointer-events: auto; }

/* 多欄位輸入用底部面板，不用置中彈窗 ——
   手機鍵盤升起時會把置中彈窗推到看不見，貼著底邊的面板不會。 */
.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    background: var(--surface);
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -6px 24px rgba(26, 31, 36, .2);
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    max-height: 86vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform .2s ease-out;
}

.sheet.is-open { transform: translateY(0); }
.sheet-head { display: flex; align-items: center; margin-bottom: 12px; }
.sheet-title { font-size: 14px; font-weight: 600; }
.sheet-head .close { margin-left: auto; }

@media print {
    .sidebar, .topbar, .filter-bar, .pager, .btn { display: none !important; }
    .content { padding: 0; }
    .panel { border: none; box-shadow: none; }
    body { background: #FFF; }
}
