/* ==========================================================================
   Dezctop HRMS — 樣式表
   斷點（改這裡就能整批調整）
     ≤ 440px   手機版：單欄、分頁列橫向捲動、表單全部堆疊
     ≤ 640px   表格轉卡片式（table.cards）
     ≥ 900px   桌面版：左側邊欄 + 內容區
     最大寬度   1440px
   ========================================================================== */

/* ---------- 設計 token ---------- */
:root {
    /* 色彩：以 logo 的近黑 #0F1219 為主色，藍色作為互動點綴 */
    --ink:        #0f1219;
    --ink-2:      #3d444d;
    --sub:        #6b7280;
    --line:       #e5e8ec;
    --line-2:     #eef1f4;
    --bg:         #f4f6f8;
    --card:       #ffffff;

    --brand:      #2563eb;
    --brand-ink:  #1d4ed8;
    --brand-soft: #eff5ff;
    --brand-line: #d3e2fe;

    --ok:         #15803d;  --ok-soft:   #e9f7ee;  --ok-line:   #bfe6cd;
    --warn:       #b45309;  --warn-soft: #fef6e7;  --warn-line: #f5d9a8;
    --bad:        #dc2626;  --bad-soft:  #fdecec;  --bad-line:  #f6c9c9;

    /* 圓角 */
    --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-full: 999px;

    /* 陰影 */
    --sh-1: 0 1px 2px rgba(15,18,25,.04), 0 1px 3px rgba(15,18,25,.05);
    --sh-2: 0 4px 14px rgba(15,18,25,.07), 0 1px 3px rgba(15,18,25,.04);
    --sh-3: 0 12px 32px rgba(15,18,25,.12), 0 2px 8px rgba(15,18,25,.06);

    /* 版面 */
    --app-max:  1440px;
    --rail-w:   240px;
    --pad:      20px;

    --font: system-ui, -apple-system, "Noto Sans TC", "PingFang TC",
            "Microsoft JhengHei", sans-serif;
}

/* ---------- 基礎 ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; margin: 18px 0 8px; color: var(--ink-2); }
p  { margin: 0 0 10px; }

a { color: var(--brand-ink); }

.muted  { color: var(--sub); font-size: 13px; }
.hidden { display: none !important; }
.num    { font-variant-numeric: tabular-nums; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

::selection { background: var(--brand-soft); }

/* ---------- 登入頁 ---------- */
.login {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(1100px 520px at 50% -8%, #e8eefb 0%, rgba(232,238,251,0) 60%),
        var(--bg);
}

.login-box { width: 100%; max-width: 400px; }

.login-head { text-align: center; margin-bottom: 20px; }
.login-head .logo { width: 168px; margin: 0 auto 14px; }
.login-head h1 { font-size: 21px; }
.login-head p  { margin: 4px 0 0; }

.login-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-2);
    padding: 22px;
}

.login-foot {
    text-align: center;
    margin-top: 16px;
    font-size: 12px;
    color: var(--sub);
}

/* ---------- App 骨架 ---------- */
.app {
    max-width: var(--app-max);
    margin: 0 auto;
    min-height: 100dvh;
    display: grid;
    grid-template-areas: "appbar" "nav" "content";
    grid-template-rows: auto auto 1fr;
    background: var(--bg);
}

/* 頂列 */
.appbar {
    grid-area: appbar;
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
    background: rgba(255,255,255,.9);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.ab-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ab-brand .logo { height: 19px; width: auto; display: block; }
.ab-sys {
    font-size: 12px; font-weight: 600; color: var(--sub);
    padding-left: 10px; border-left: 1px solid var(--line);
    white-space: nowrap;
}

.ab-right { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }

.ab-clock {
    font-variant-numeric: tabular-nums;
    font-size: 13px; font-weight: 600; color: var(--ink-2);
    padding: 5px 10px;
    background: var(--line-2);
    border-radius: var(--r-full);
    white-space: nowrap;
}

.ab-user { display: flex; align-items: center; gap: 8px; min-width: 0; }

.ab-avatar {
    flex: 0 0 auto;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: var(--r-full);
    background: var(--ink);
    color: #fff;
    font-size: 13px; font-weight: 650;
}

.ab-who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ab-who #hello  { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ab-who #whoami { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 導覽（手機＝橫向捲動的 pill；桌面＝左側邊欄） */
.nav {
    grid-area: nav;
    position: sticky;
    top: 53px;
    z-index: 20;
    display: flex;
    gap: 6px;
    padding: 8px max(14px, env(safe-area-inset-left));
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    background: rgba(244,246,248,.94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    scroll-padding-inline: 14px;
}
.nav::-webkit-scrollbar { display: none; }

.nav-group { display: none; }

.nav-item {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: var(--r-full);
    background: #fff;
    color: var(--ink-2);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 550;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: var(--sh-1);
    transition: background .15s, color .15s, border-color .15s;
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 auto; opacity: .75; }
.nav-item:hover { background: #fff; color: var(--ink); border-color: var(--line); }
.nav-item.active {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
    box-shadow: var(--sh-2);
}
.nav-item.active svg { opacity: 1; }

/* 內容區 */
.content {
    grid-area: content;
    padding: 16px max(14px, env(safe-area-inset-right))
             calc(28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    min-width: 0;
}

/* ---------- 卡片 ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-1);
    padding: 18px;
    margin: 0 0 14px;
}

/* 表單型分頁不要拉太寬；data-wide 的清單／表格分頁維持滿版 */
.tab { max-width: 860px; }
.tab[data-wide] { max-width: none; }

.card > h3 + .muted { margin-top: -4px; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.topbar h3 { margin: 0; }

/* ---------- 表單 ---------- */
label {
    display: block;
    margin-top: 12px;
    margin-bottom: 4px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: #fff;
    color: var(--ink);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #9aa1ac; }

input:hover, select:hover, textarea:hover { border-color: #cfd5dd; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

textarea { resize: vertical; min-height: 84px; }

/* iOS Safari 的原生日期／時間欄位有自己的最小寬度，不吃 width:100% 的收縮，
   會把欄位撐出卡片、造成整頁可以左右滑。關掉原生外觀並允許收縮才會乖乖跟著容器。 */
input[type="date"],
input[type="month"],
input[type="time"],
input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
    min-width: 0;
    max-width: 100%;
}
/* 值的區塊在 iOS 預設置中且不肯縮，改為靠左並拿掉內距 */
input::-webkit-date-and-time-value { text-align: left; min-width: 0; margin: 0; }
input::-webkit-datetime-edit { min-width: 0; padding: 0; }
input::-webkit-datetime-edit-fields-wrapper { padding: 0; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.row > * { flex: 1 1 0; min-width: 190px; }
.row label:first-child { margin-top: 0; }
h3 + .row, p + .row, .balbox + .row { margin-top: 14px; }

details > summary {
    cursor: pointer;
    color: var(--brand-ink);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 0;
    list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
    content: "▸";
    display: inline-block;
    margin-right: 6px;
    transition: transform .15s;
}
details[open] > summary::before { transform: rotate(90deg); }

/* 自訂 24 小時制時間選擇器 */
.timefield { display: flex; align-items: center; gap: 8px; }
.timefield select { flex: 1 1 0; min-width: 0; }
.timefield .tf-sep { color: var(--sub); font-weight: 700; }

/* ---------- 按鈕 ---------- */
button {
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    padding: 10px 16px;
    min-height: 42px;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    background: var(--ink);
    color: #fff;
    transition: filter .15s, background .15s, border-color .15s;
}
button:hover:not(:disabled)  { filter: brightness(1.35); }
button:active:not(:disabled) { filter: brightness(.9); }
button:disabled { opacity: .45; cursor: default; }

button.ghost {
    background: #fff;
    color: var(--ink-2);
    border-color: var(--line);
    box-shadow: var(--sh-1);
}
button.ghost:hover:not(:disabled) { filter: none; background: var(--line-2); color: var(--ink); }

button.ok  { background: var(--ok); }
button.bad { background: var(--bad); }

button.sm { padding: 7px 12px; min-height: 34px; font-size: 13px; }

.btn-block { width: 100%; margin-top: 16px; }
/* 費用申請：存檔＋送出審核並排，送出佔較寬 */
.exp-actions { display: flex; gap: 10px; margin-top: 16px; }
.exp-actions > button { flex: 1 1 0; }
.exp-actions > #expSubmit { flex: 2 1 0; }

/* ---------- 打卡主畫面 ---------- */
.punch-hero { text-align: center; padding: 26px 18px 22px; }

.punch-greet { font-size: 15px; color: var(--sub); margin-bottom: 2px; }

.punch-time {
    font-variant-numeric: tabular-nums;
    font-size: clamp(44px, 13vw, 64px);
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.05;
    margin: 6px 0 2px;
}
.punch-time .pt-sec { font-size: .45em; font-weight: 600; color: var(--sub); margin-left: 4px; }

.punch-date { font-size: 13.5px; color: var(--sub); margin-bottom: 20px; }

.punch-actions { display: flex; gap: 12px; }
.punch-actions > button { flex: 1 1 0; }

.btn-punch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 18px 12px;
    min-height: 92px;
    border-radius: var(--r);
    font-size: 16px;
    font-weight: 650;
}
.btn-punch svg { width: 24px; height: 24px; }
.btn-punch .bp-sub { font-size: 11.5px; font-weight: 500; opacity: .8; }
.btn-punch.in  { background: var(--ok); }
.btn-punch.out { background: var(--warn); }

.punch-msg {
    margin: 16px 0 0;
    min-height: 20px;
    font-size: 13.5px;
    color: var(--ink-2);
}

/* ---------- 假別餘額 ---------- */
.balbox { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

.balcard {
    flex: 1 1 120px;
    background: var(--brand-soft);
    border: 1px solid var(--brand-line);
    border-radius: var(--r);
    padding: 12px 14px;
}
.balcard .lbl { font-size: 11.5px; font-weight: 600; color: var(--sub); }
.balcard .big {
    font-size: 26px; font-weight: 700; line-height: 1.15;
    color: var(--brand-ink);
    font-variant-numeric: tabular-nums;
}
/* 「12天4小時」的單位字級收小，讓數字仍是視覺主體 */
.balcard .big .unit {
    font-size: 13px; font-weight: 600;
    color: var(--sub);
    margin: 0 4px 0 2px;
}
.balcard .big .unit:last-child { margin-right: 0; }

/* ---------- 表格 ---------- */
.rtable {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: #fff;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

/* 短又不該被拆行的欄位（姓名、日期）。表格本身在 .rtable 裡可以橫向捲，
   所以擋掉換行不會撐破版面。 */
td.nowrap, th.nowrap { white-space: nowrap; }

/* 報表日期後面的（五）。做小一號讓主體仍是日期本身；
   週末用紅字標出來，一眼看出假日還有出勤或加班。
   只針對 .wk，不要寫成 td span —— 那會縮到全站表格裡所有的 span。 */
.dw     { white-space: nowrap; }
.wk     { font-size: .92em; color: var(--sub); }
.wk-end { color: var(--bad); }

/* 已離職那一列淡化：還看得到（要查歷史），但一眼分得出不是在職員工 */
tr.row-left > td { opacity: .62; }
tr.row-left > td.actions { opacity: 1; }

/* 特休剩餘低於三成 —— 快用完的人才是需要注意的，數字直接標紅 */
td.low b, td.low { color: var(--bad); }

th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-2); }

th {
    background: #fafbfc;
    color: var(--sub);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

/* 只用來讓按鈕在桌面版與同列的輸入框對齊；手機版堆疊時不需要 */
.lbl-spacer { visibility: hidden; }

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfd; }

/* 不要在 td 上用 flex：那會讓儲存格脫離表格排版，相鄰的操作欄就會疊在一起、對不到欄位標題。
   按鈕本來就是 inline-block，用 margin 撐開間距即可，換行行為也保留。
   （手機的卡片式模式另外把 td 改成 flex，見 ≤640px 區塊，不受這裡影響） */
td.actions { white-space: normal; }
td.actions > button { margin: 2px 6px 2px 0; }
td.actions > button:last-child { margin-right: 0; }

.money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- 標籤 / 徽章 ---------- */
.pill {
    display: inline-block;
    padding: 3px 9px;
    border-radius: var(--r-full);
    border: 1px solid transparent;
    font-size: 11.5px;
    font-weight: 650;
    white-space: nowrap;
}
.pill.pending      { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.pill.approved     { background: var(--ok-soft);   color: var(--ok);   border-color: var(--ok-line); }
.pill.rejected     { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad-line); }
.pill.cancelled    { background: var(--line-2);    color: var(--sub);  border-color: var(--line); }
.pill.confidential { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad-line); }
/* 已匯款刻意用品牌藍而非綠：綠色是「已核准」，兩者要能一眼分辨還沒付 vs 已付 */
.pill.paid         { background: var(--brand-soft); color: var(--brand-ink); border-color: var(--brand-line); }
.pill.draft        { background: var(--line-2);    color: var(--sub);  border-color: var(--line); border-style: dashed; }
/* 內容驗證失敗這種一定要被看到的警示 */
.pill.bad-pill     { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad-line); font-weight: 600; }

.tag { font-size: 11.5px; color: var(--sub); }
/* 驗證碼要等寬字才好逐段比對 */
.tag.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; letter-spacing: .04em; }

/* 稽核軌跡清單 */
ol.audit { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
ol.audit > li {
    border: 1px solid var(--line); border-radius: var(--r-sm);
    padding: 10px 12px; background: var(--line-2);
}
.audit-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 2px; }

/* ---------- 申請清單（審核頁） ---------- */
.req {
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 14px;
    margin-bottom: 10px;
    background: #fff;
}
.req:last-child { margin-bottom: 0; }
.req-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.req-head b { font-size: 14.5px; }
.req-body { font-size: 14px; margin-bottom: 4px; }

.req-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line-2);
}
.req-actions input  { flex: 1 1 220px; min-width: 0; }
.req-actions button { flex: 0 0 auto; }

/* 左邊資訊、右邊按鈕。按鈕一律靠右對齊，待審核與已審核的列看起來才一致；
   窄畫面時按鈕會換到自己那一行，仍然靠右。 */
.req-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.req-btns {
    flex: 0 1 auto; margin-left: auto;
    display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
}
/* 窄畫面時讓整顆按鈕換行，不要把「標記已匯款」折成兩行字 */
.req-btns button { white-space: nowrap; }

.receipts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- 審核：類型篩選與月份分組 ---------- */
.filterbar {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin: 0 0 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line-2);
}
.filter-item {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px; min-height: 32px;
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: #fff;
    color: var(--ink-2);
    font-size: 13px; font-weight: 550;
}
.filter-item:hover:not(:disabled) { filter: none; background: var(--line-2); }
.filter-item.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.filter-item:disabled { opacity: .4; }
.filter-n {
    font-size: 11.5px; font-weight: 700;
    padding: 1px 6px; border-radius: var(--r-full);
    background: var(--line-2); color: var(--sub);
    font-variant-numeric: tabular-nums;
}
.filter-item.active .filter-n { background: rgba(255,255,255,.22); color: #fff; }

.month-group { margin-bottom: 18px; }
.month-group:last-child { margin-bottom: 0; }
.month-head {
    display: flex; align-items: baseline; gap: 8px;
    margin-bottom: 8px;
    font-size: 13px; font-weight: 700; color: var(--ink-2);
}

/* ---------- 費用申請：收據縮圖與類別維護 ---------- */
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.thumbs:empty { display: none; }

.thumb {
    position: relative;
    width: 88px; height: 88px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    overflow: hidden;
    background: var(--line-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-pdf {
    width: 100%; height: 100%;
    display: grid; place-items: center;
    font-size: 13px; font-weight: 700; color: var(--sub);
}
.thumb-x {
    position: absolute; top: 3px; right: 3px;
    width: 22px; height: 22px; min-height: 0;
    padding: 0; border-radius: var(--r-full);
    background: rgba(15, 18, 25, .75); color: #fff;
    font-size: 15px; line-height: 1;
}
.thumb-size {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 2px 4px;
    background: rgba(15, 18, 25, .6); color: #fff;
    font-size: 10.5px; text-align: center;
}

/* 費用明細列 */
.exp-item {
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 12px 14px 14px;
    margin-top: 10px;
    background: #fcfcfd;
}
.exp-item-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 2px;
}
.exp-no { font-size: 12.5px; font-weight: 700; color: var(--sub); }

.totals {
    display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
    margin-top: 14px; padding-top: 12px;
    border-top: 1px solid var(--line);
}
.totals:empty { display: none; }
.totals-label { font-size: 12.5px; font-weight: 600; color: var(--sub); }
.totals-amt {
    font-size: 20px; font-weight: 700;
    color: var(--ink); font-variant-numeric: tabular-nums;
}

/* 表格內的勾選欄位 */
.chk {
    display: inline-flex; align-items: center; gap: 6px;
    margin: 0; font-size: 13px; font-weight: 400; color: var(--ink);
    cursor: pointer; white-space: nowrap;
}
.chk input[type="checkbox"] { width: auto; margin: 0; flex: 0 0 auto; }
.chk input:disabled + span { color: var(--sub); }

.catrow {
    display: flex; align-items: center; gap: 10px;
    margin: 0; padding: 8px 0;
    border-bottom: 1px solid var(--line-2);
    font-size: 14px; font-weight: 400; color: var(--ink);
    cursor: pointer;
}
.catrow:last-child { border-bottom: 0; }
.catrow input[type="checkbox"] { width: auto; margin: 0; flex: 0 0 auto; }
.catrow .tag { margin-left: auto; }

/* 檔案選擇欄位 */
input[type="file"] {
    padding: 9px 12px;
    font-size: 14px;
    background: #fff;
}
input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--line-2);
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

/* ---------- 金額摘要 / 提醒框 ---------- */
.sumbox {
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 16px;
    margin-top: 12px;
    background: linear-gradient(180deg, #fbfcfe 0%, #fff 100%);
}
.sumbox .headline {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    margin: 2px 0 4px;
}
.sumbox dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    margin: 12px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--line-2);
}
.sumbox dt { color: var(--sub); font-size: 13px; }
.sumbox dd { margin: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }

.warnbox {
    background: var(--warn-soft);
    border: 1px solid var(--warn-line);
    color: var(--warn);
    border-radius: var(--r-sm);
    padding: 10px 14px;
    margin-top: 12px;
    font-size: 13px;
}
.warnbox ul { margin: 0; padding-left: 18px; }

/* ---------- 對話框（核准／簽名） ---------- */
.dlg {
    width: min(520px, calc(100vw - 28px));
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-3);
    background: var(--card);
    color: var(--ink);
}
.dlg::backdrop { background: rgba(15, 18, 25, .45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dlg-head h3 { margin: 0; }
.dlg .btn-block { width: 100%; }

/* 生日祝賀彈窗 */
.dlg.bday { text-align: center; max-width: 380px; }
.dlg.bday h3 { font-size: 22px; margin-bottom: 6px; }
.bday-emoji { font-size: 56px; line-height: 1; margin-bottom: 6px; }
.dlg.bday .btn-block { margin-top: 18px; }

/* 簽名畫布 */
.sigpad {
    position: relative;
    margin-top: 8px;
    border: 1px dashed var(--line);
    border-radius: var(--r-sm);
    background: #fcfcfd;
    height: 170px;
}
.sigpad canvas {
    display: block;
    width: 100%; height: 100%;
    /* 不設這個的話，手機上簽名會變成捲動頁面 */
    touch-action: none;
    cursor: crosshair;
}
.sigpad-hint {
    position: absolute; left: 0; right: 0; bottom: 10px;
    text-align: center; font-size: 12px; color: #b7bec8;
    pointer-events: none;
}

/* ---------- Toast ---------- */
#toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(8px);
    z-index: 100;
    max-width: min(90vw, 420px);
    padding: 11px 18px;
    border-radius: var(--r-full);
    background: var(--ink);
    color: #fff;
    font-size: 14px;
    box-shadow: var(--sh-3);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   手機版 ≤ 440px：表單一律堆疊、間距收斂
   ========================================================================== */
@media (max-width: 440px) {
    body { font-size: 14.5px; }

    .content { padding-top: 12px; }
    .card { padding: 15px; border-radius: var(--r); }

    /* 欄位一律整行，避免兩欄擠在一起 */
    .row > * { flex: 1 1 100%; min-width: 100%; }
    .timefield { display: flex; }
    .timefield select { flex: 1 1 0; min-width: 0; }

    .ab-clock { display: none; }          /* 打卡頁已有大時鐘 */
    .ab-sys   { display: none; }
    .ab-who #whoami { display: none; }

    .punch-hero { padding: 22px 14px 18px; }
    .punch-actions { flex-direction: column; }
    .btn-punch { min-height: 74px; flex-direction: row; gap: 10px; }

    .balcard { flex: 1 1 100%; }

    /* 審核按鈕在手機上平分一行，好按 */
    .req-actions input  { flex: 1 1 100%; }
    .req-actions button { flex: 1 1 0; }

    /* 欄位堆疊後不需要對齊用的空白 label；同列的動作按鈕改滿版 */
    .lbl-spacer { display: none; }
    .row > div > button { width: 100%; }
}

/* ==========================================================================
   ≤ 640px：表格改卡片式堆疊
   ========================================================================== */
@media (max-width: 640px) {
    /* 卡片式堆疊時外框交給每個 tr；仍保留橫向捲動，避免非 .cards 的寬表格撐破版面 */
    .rtable { border: 0; border-radius: 0; background: transparent; }

    table.cards thead {
        position: absolute; width: 1px; height: 1px;
        overflow: hidden; clip: rect(0 0 0 0);
    }
    table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }

    table.cards tr {
        border: 1px solid var(--line);
        border-radius: var(--r);
        background: #fff;
        box-shadow: var(--sh-1);
        padding: 6px 14px;
        margin-bottom: 10px;
    }
    table.cards tr:hover td { background: transparent; }

    table.cards td {
        border: 0;
        border-bottom: 1px solid var(--line-2);
        padding: 8px 0;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 14px;
        text-align: right;
    }
    table.cards tr td:last-child { border-bottom: 0; }

    table.cards td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        text-align: left;
        color: var(--sub);
        font-size: 11.5px;
        font-weight: 650;
    }
    table.cards td:empty { display: none; }

    table.cards td.actions { flex-wrap: wrap; justify-content: flex-start; }
    table.cards td.actions::before { flex: 1 0 100%; margin-bottom: 4px; }
    /* 不撐滿：避免落單的「刪除」變成整行紅色按鈕而容易誤觸 */
    table.cards td.actions button { flex: 0 1 auto; }
}

/* ==========================================================================
   桌面版 ≥ 900px：左側邊欄
   ========================================================================== */
@media (min-width: 900px) {
    .app {
        grid-template-columns: var(--rail-w) minmax(0, 1fr);
        grid-template-areas:
            "appbar appbar"
            "nav    content";
        grid-template-rows: auto 1fr;
    }

    .appbar { padding: 12px 24px; gap: 16px; }
    .appbar .ab-brand .logo { height: 21px; }

    /* 側邊欄 */
    .nav {
        position: sticky;
        top: 57px;
        align-self: start;
        height: calc(100dvh - 57px);
        flex-direction: column;
        flex-wrap: nowrap;
        gap: 2px;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 16px 12px 24px;
        background: transparent;
        backdrop-filter: none;
        border-bottom: 0;
        border-right: 1px solid var(--line);
    }

    .nav-group {
        display: block;
        margin: 14px 0 6px;
        padding: 0 10px;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: .08em;
        color: #9aa1ac;
        text-transform: uppercase;
    }
    .nav-group:first-child { margin-top: 0; }

    .nav-item {
        width: 100%;
        justify-content: flex-start;
        gap: 10px;
        padding: 9px 10px;
        border-radius: var(--r-sm);
        background: transparent;
        box-shadow: none;
        font-size: 14px;
    }
    .nav-item:hover { background: #fff; border-color: var(--line); }
    .nav-item.active { background: var(--ink); border-color: var(--ink); }

    .content { padding: 24px 28px 48px; }

    .card { padding: 22px; margin-bottom: 18px; }

    /* 桌面版按鈕不要撐滿整行（登入卡例外，滿版比較好按） */
    .btn-block { width: auto; min-width: 200px; }
    .login-card .btn-block { width: 100%; }

    .punch-hero { padding: 40px 28px 34px; }
    .punch-actions { max-width: 460px; margin: 0 auto; }
}

/* ==========================================================================
   列印：A4 申請書
   平時整份藏起來，只有列印時才顯示，並把介面本體隱藏。
   ========================================================================== */
.print-sheet { display: none; }

@media print {
    /* 只留申請書，其餘介面一律不上紙 */
    .app, #loginView, #toast, .dlg { display: none !important; }
    .print-sheet { display: block !important; }

    html, body { background: #fff; }
    body { font-size: 12pt; color: #000; }

    @page { size: A4; margin: 16mm; }
}

.sheet { max-width: 178mm; margin: 0 auto; color: #000; }

.sheet-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 16px; padding-bottom: 10px; border-bottom: 2px solid #000;
}
.sheet-logo { height: 26px; width: auto; }
.sheet-title { text-align: right; }
.sheet-title h1 { margin: 0; font-size: 19pt; letter-spacing: .06em; }
.sheet-no { font-size: 9pt; color: #444; margin-top: 2px; }

.sheet-table { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: 11pt; }
.sheet-table th, .sheet-table td {
    border: 1px solid #999; padding: 7px 10px; text-align: left; vertical-align: top;
}
.sheet-table th {
    width: 32%; background: #f2f3f5; font-weight: 600; white-space: nowrap; color: #000;
}
/* app 的表格有「最後一列不畫底線」的規則（只作用在 td），會讓申請書右下角缺一條線。
   申請書是正式表單，框線要完整，這裡蓋回來。 */
.sheet-table tbody tr:last-child td,
.sheet-items tbody tr:last-child td { border-bottom: 1px solid #999; }
.sheet-table tbody tr:hover td,
.sheet-items tbody tr:hover td { background: transparent; }

/* 費用單的明細表 */
.sheet-items { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 9.5pt; }
.sheet-items th, .sheet-items td {
    border: 1px solid #999; padding: 5px 7px; text-align: left; vertical-align: top;
}
.sheet-items thead th { background: #f2f3f5; font-weight: 600; white-space: nowrap; }
.sheet-items .n { text-align: center; white-space: nowrap; }
.sheet-items .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet-items tfoot td { background: #fafafa; }

.sheet-sigs { display: flex; gap: 14px; margin-top: 22px; }
.sheet-sig { flex: 1 1 0; }
.sig-label { font-size: 9.5pt; color: #444; margin-bottom: 4px; }
.sig-box {
    border: 1px solid #999; border-radius: 3px;
    height: 34mm; padding: 8px 10px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; text-align: center;
}
.sig-img { max-width: 100%; max-height: 20mm; object-fit: contain; }
.sig-text { font-size: 12pt; }
.sig-empty { font-size: 11pt; color: #888; }
.sig-meta { font-size: 8.5pt; color: #555; }

/* 驗證戳章。左邊是像印章的方框，右邊是驗證碼與說明。
   刻意不做成傾斜的仿橡皮章——那只是裝飾，驗證碼才是能被檢查的東西。 */
.sheet-verify {
    display: flex; align-items: center; gap: 12px;
    margin-top: 14px; padding: 8px 10px;
    border: 1px solid #999; border-radius: 3px; background: #fafafa;
}
.verify-mark {
    flex: 0 0 auto; text-align: center;
    border: 2px solid #0f1219; border-radius: 3px; padding: 4px 8px;
}
.verify-mark-t { font-size: 11pt; font-weight: 700; letter-spacing: .12em; }
.verify-mark-b { font-size: 6.5pt; letter-spacing: .08em; color: #333; }
.verify-body { flex: 1 1 auto; min-width: 0; }
.verify-code {
    font-size: 13pt; font-weight: 700; letter-spacing: .1em;
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.verify-note { font-size: 7.5pt; color: #555; line-height: 1.4; margin-top: 2px; }
/* 內容與簽核當時不符時，整塊改成明顯的警示框 */
.sheet-verify.bad { border-width: 2px; border-color: #000; background: #fff; }
.sheet-verify.bad .verify-note { color: #000; font-weight: 700; font-size: 8.5pt; }
.sheet-verify.bad .verify-code { text-decoration: line-through; }

.sheet-foot {
    margin-top: 16px; padding-top: 8px; border-top: 1px solid #ccc;
    font-size: 8.5pt; color: #666; text-align: right;
}

/* 一張單就是一頁，避免表格被切斷 */
.sheet, .sheet-table, .sheet-sigs, .sheet-verify { page-break-inside: avoid; break-inside: avoid; }

/* ---------- 動態偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- 假日曆（清單式）與月報表的放假日列 ---------- */
.cal-tools { display: flex; align-items: center; gap: 8px; }
.cal-tools select { width: auto; min-width: 110px; }
.cal-wd-head { margin: 22px 0 0; }
.cal-wd-head h4 { margin: 0; }
.cal-wd-form { align-items: flex-end; margin-bottom: 10px; }
.cal-err { color: var(--bad); font-size: 13px; margin: 8px 0 0; }
/* 月報表：放假日用淡色 pill 寫出原因，整列底色淡一點；補班日用警示色小標 */
.pill.holiday { background: var(--line-2); color: var(--sub); border-color: var(--line); font-weight: 600; margin-left: 4px; }
.pill.workday { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); margin-left: 4px; }
tr.row-holiday > td { background: var(--bg, #f7f8fa); }
