/* ════════════════════════════════════════════════════════════════════
   利善美主計系統 — styles.css
   嚴格綁定公司既有設計 token（accent #B91C1C / 深 #0F172A /
   Inter+Noto Sans TC+Space Grotesk / 金額 JetBrains Mono 右對齊 /
   卡片圓角 20px、按鈕圓角 10px）。所有顏色僅自 :root 變數取用。
   ════════════════════════════════════════════════════════════════════ */
:root {
  /* 色彩 */
  --bg:           #F8FAFC;
  --surface:      #FFFFFF;
  --surface-2:    #F1F5F9;
  --fg:           #0F172A;
  --muted:        #64748B;
  --border:       #E5E7EB;
  --border-soft:  #EEF2F6;

  --accent:       #B91C1C;
  --accent-hover: #7F1D1D;
  --accent-bright:#EF4444;
  --accent-soft:  #FEE2E2;

  --dark:         #0F172A;
  --darker:       #020617;
  --dark-line:    #1E293B;
  --dark-fg:      #E2E8F0;
  --dark-muted:   #94A3B8;

  --success:      #10B981;
  --success-soft: #DCFCE7;
  --warn:         #F59E0B;
  --warn-soft:    #FEF3C7;
  --info:         #2563EB;
  --info-soft:    #DBEAFE;

  /* 字體 */
  --font-display: 'Space Grotesk', 'Noto Sans TC', -apple-system, system-ui, sans-serif;
  --font-body:    'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* 圓角 / 陰影 */
  --r-card: 20px;
  --r-btn:  10px;
  --r-sm:   8px;
  --r-pill: 999px;
  --shadow-1: 0 1px 2px rgba(15,23,42,.05);
  --shadow-2: 0 6px 24px -8px rgba(15,23,42,.18);
  --shadow-pop: 0 16px 48px -12px rgba(15,23,42,.32);

  --sidebar-w: 248px;
  --maxw: 1600px;
}

* , *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; line-height: 1.2; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; color: inherit; }
svg { display: block; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; letter-spacing: -0.02em; }
[hidden] { display: none !important; }

/* ─── 按鈕 ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; min-height: 44px;
  border-radius: var(--r-btn); border: 1px solid transparent;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, transform .05s ease, color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); background: var(--surface-2); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-danger-soft { background: var(--accent-soft); color: var(--accent); }
.btn-danger-soft:hover { background: #fecaca; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.iconbtn {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  border-radius: var(--r-btn); border: 1px solid transparent; background: transparent; color: var(--fg);
}
.iconbtn:hover { background: var(--surface-2); }

/* ─── 表單 ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .field > label { font-size: 13px; font-weight: 500; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; min-height: 44px;
  border: 1px solid var(--border); border-radius: var(--r-btn);
  background: var(--surface); color: var(--fg); font: inherit; font-size: 15px;
}
.textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: 3px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-color: var(--accent);
}
.input.mono { font-family: var(--font-mono); text-align: right; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }

/* ════════════════ 登入頁 ════════════════ */
.login {
  min-height: 100dvh; display: grid; grid-template-columns: 1.1fr .9fr;
  background: var(--bg);
}
.login-card {
  display: flex; flex-direction: column; justify-content: center;
  padding: clamp(28px, 6vw, 88px); max-width: 560px; margin-inline: auto; width: 100%;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.brand-mark {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  background: var(--accent); color: #fff; border-radius: 12px;
  font-family: var(--font-display); font-weight: 700; font-size: 22px;
}
.brand-mark.sm { width: 34px; height: 34px; font-size: 17px; border-radius: 9px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.login-title { font-size: clamp(26px, 4vw, 34px); font-weight: 700; }
.login-hint { color: var(--muted); margin-top: 8px; margin-bottom: 26px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.role-pick { border: 0; padding: 0; margin: 4px 0 4px; display: grid; gap: 9px; }
.role-pick legend { font-size: 13px; font-weight: 500; color: var(--muted); padding: 0; margin-bottom: 4px; }
.role-opt {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--r-btn); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.role-opt:hover { border-color: var(--muted); }
.role-opt input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.role-opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.role-opt-body { display: flex; flex-direction: column; }
.role-opt-body strong { font-size: 15px; }
.role-opt-body small { color: var(--muted); font-size: 12px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 6px; }

.login-aside {
  background: linear-gradient(160deg, var(--dark), var(--darker));
  color: var(--dark-fg); padding: clamp(28px, 5vw, 64px);
  display: flex; flex-direction: column; justify-content: center; gap: 28px;
}
.aside-eyebrow { font-family: var(--font-mono); font-size: 12px; letter-spacing: .06em; color: var(--dark-muted); text-transform: uppercase; }
.aside-num { font-family: var(--font-mono); font-size: clamp(34px, 5vw, 52px); font-weight: 600; margin: 8px 0 2px; text-align: left; }
.aside-label { color: var(--dark-muted); font-size: 14px; }
.aside-rows { display: grid; gap: 1px; background: var(--dark-line); border-radius: 14px; overflow: hidden; }
.aside-rows > div { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,.02); padding: 14px 18px; }
.aside-rows span { color: var(--dark-muted); font-size: 13px; }
.aside-rows b { font-family: var(--font-mono); font-weight: 500; font-size: 15px; }

/* ════════════════ App 框架 ════════════════ */
.shell { display: flex; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--dark); color: var(--dark-fg);
  display: flex; flex-direction: column; padding: 20px 14px;
  position: sticky; top: 0; height: 100dvh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.side-brand .brand-name { color: #fff; }
.side-brand .brand-sub { color: var(--dark-muted); }

.role-switcher { background: rgba(255,255,255,.04); border: 1px solid var(--dark-line); border-radius: 14px; padding: 12px; margin-bottom: 16px; }
.rs-label { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; color: var(--dark-muted); text-transform: uppercase; }
.rs-seg { display: flex; gap: 4px; background: var(--darker); border-radius: 9px; padding: 3px; margin: 8px 0 8px; }
.rs-btn { flex: 1; padding: 7px 4px; border: 0; border-radius: 6px; background: transparent; color: var(--dark-muted); font-size: 12.5px; font-weight: 600; }
.rs-btn[aria-selected="true"] { background: var(--accent); color: #fff; }
.rs-btn:not([aria-selected="true"]):hover { color: #fff; }
.rs-name { font-size: 12px; color: var(--dark-muted); }

.side-nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; padding-top: 4px; }
.side-link {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 11px 12px; border: 0; background: transparent; color: var(--dark-muted);
  border-radius: var(--r-btn); font-size: 14px; font-weight: 500; text-align: left;
  position: relative;
}
.side-link svg { flex: none; opacity: .9; }
.side-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.side-link.active { background: rgba(185,28,28,.16); color: #fff; }
.side-link.active::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--accent-bright); }
.side-link .nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-family: var(--font-mono); font-size: 11px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); display: grid; place-items: center; }
.side-cat { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--dark-muted); padding: 14px 12px 6px; }
.side-foot { padding-top: 12px; border-top: 1px solid var(--dark-line); margin-top: 8px; }
.side-link.logout:hover { background: rgba(239,68,68,.14); color: var(--accent-bright); }

.appbar { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 40; }

/* ─── 內容區 ─────────────────────────────────────────── */
.view { flex: 1; min-width: 0; padding: 30px clamp(16px, 4vw, 44px) 64px; }
.view:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head .eyebrow { font-family: var(--font-mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.page-head h1 { font-size: clamp(22px, 3vw, 28px); font-weight: 700; margin-top: 4px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.maxw { max-width: var(--maxw); }

/* ─── 卡片 / 區塊 ─────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-1); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.card-head h3 { font-size: 16px; font-weight: 600; }
.card-head .meta { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }

.grid { display: grid; gap: 18px; }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1000px){ .g-4 { grid-template-columns: repeat(2,1fr); } .g-3, .g-2-1, .g-1-2 { grid-template-columns: 1fr; } }

/* ─── KPI 卡 ─────────────────────────────────────────── */
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kpi-num { font-family: var(--font-mono); font-size: 27px; font-weight: 600; letter-spacing: -.02em; text-align: left; }
.kpi-num small { font-size: 14px; color: var(--muted); font-weight: 400; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.trend-up { color: var(--success); font-weight: 600; }
.trend-down { color: var(--accent); font-weight: 600; }

/* ─── 狀態徽章 ───────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; line-height: 1.5; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok   { background: var(--success-soft); color: #047857; }
.badge-wait { background: var(--warn-soft); color: #B45309; }
.badge-back { background: var(--accent-soft); color: var(--accent); }
.badge-paid { background: var(--info-soft); color: var(--info); }
.badge-muted{ background: var(--surface-2); color: var(--muted); }
.badge-cat  { background: var(--surface-2); color: var(--fg); border-radius: 7px; font-weight: 500; }
.badge-cat::before { display: none; }

/* ─── 資料表 ─────────────────────────────────────────── */
.tablewrap { width: 100%; overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.dt th, .dt td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
.dt th { font-family: var(--font-mono); font-size: 11.5px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.dt tbody tr:hover { background: var(--surface-2); }
.dt .amt { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
.dt .who { display: flex; align-items: center; gap: 9px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #fff; flex: none; font-family: var(--font-display); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
tfoot td { font-weight: 700; background: var(--surface-2); }
tfoot .amt { font-size: 15px; }

/* ─── 圖表（純 CSS / SVG） ───────────────────────────── */
.bars { display: flex; flex-direction: column; gap: 14px; padding: 4px 2px; }
.bar-row { display: grid; grid-template-columns: 92px 1fr 88px; align-items: center; gap: 12px; }
.bar-row .bl { font-size: 13px; color: var(--fg); }
.bar-track { background: var(--surface-2); border-radius: var(--r-pill); height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: var(--r-pill); background: var(--accent); transition: width .8s cubic-bezier(.2,0,0,1); }
.bar-row .amt { font-family: var(--font-mono); font-size: 13px; text-align: right; color: var(--muted); }

.donut-wrap { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }
.donut { --val: 0; width: 168px; height: 168px; flex: none; position: relative; }
.donut svg { transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center b { font-family: var(--font-mono); font-size: 20px; }
.donut-center span { font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-direction: column; gap: 11px; flex: 1; min-width: 180px; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.legend-row .sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.legend-row .lg-amt { margin-left: auto; font-family: var(--font-mono); font-size: 13px; color: var(--muted); }

/* ─── 我的薪資 條列 ─────────────────────────────────── */
.payslip { display: grid; gap: 1px; background: var(--border-soft); border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.payslip .pr { display: flex; justify-content: space-between; align-items: center; padding: 13px 18px; background: var(--surface); }
.payslip .pr span { font-size: 14px; }
.payslip .pr b { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.payslip .pr.deduct b { color: var(--accent); }
.payslip .pr.total { background: var(--dark); color: #fff; }
.payslip .pr.total b { font-size: 18px; }
.payslip .pr.sub { background: var(--surface-2); font-weight: 600; }

/* ─── 新增核銷表單 ───────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 720px){ .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.upload {
  border: 1.5px dashed var(--border); border-radius: 14px; padding: 26px; text-align: center;
  color: var(--muted); background: var(--surface-2); transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; min-height: 44px;
}
.upload:hover, .upload.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.upload svg { width: 30px; height: 30px; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.thumb { width: 72px; height: 72px; border-radius: 12px; border: 1px solid var(--border); display: grid; place-items: center; font-family: var(--font-mono); font-size: 11px; color: var(--muted); background: var(--surface); position: relative; }
.thumb b { position: absolute; top: -6px; right: -6px; background: var(--accent); color: #fff; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; }
.live-amt { font-family: var(--font-mono); font-size: 30px; font-weight: 600; text-align: right; color: var(--fg); }

/* ─── 月度報表（貼近 Word 版式） ─────────────────────── */
.report-doc { background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow-2); max-width: 920px; margin-inline: auto; padding: clamp(20px, 4vw, 52px); color: #111; }
.rpt-title { text-align: center; font-family: var(--font-display); }
.rpt-title h2 { font-size: 24px; font-weight: 700; letter-spacing: .04em; }
.rpt-title .co { font-size: 14px; color: #333; margin-top: 4px; letter-spacing: .1em; }
.rpt-title .period { font-family: var(--font-mono); font-size: 13px; color: #555; margin-top: 6px; }
.rpt-meta { display: flex; justify-content: space-between; font-size: 12px; color: #555; border-bottom: 2px solid #111; padding-bottom: 8px; margin: 18px 0 26px; font-family: var(--font-mono); }
.rpt-sec { margin-bottom: 28px; }
.rpt-sec > h3 { font-size: 15px; font-weight: 700; border-left: 4px solid var(--accent); padding-left: 9px; margin-bottom: 10px; font-family: var(--font-display); }
.rpt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rpt-table th, .rpt-table td { border: 1px solid #bbb; padding: 7px 11px; }
.rpt-table th { background: #f1f1f1; font-weight: 600; text-align: left; font-size: 12px; }
.rpt-table td.amt, .rpt-table th.amt { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rpt-table tr.sum td { font-weight: 700; background: #fafafa; }
.rpt-table tr.grand td { font-weight: 700; background: #1f1f1f10; border-top: 2px solid #111; }
.rpt-signoff { display: grid; grid-template-columns: repeat(3,1fr); gap: 0; border: 1px solid #111; margin-top: 34px; }
.rpt-signoff div { border-right: 1px solid #111; text-align: center; }
.rpt-signoff div:last-child { border-right: 0; }
.rpt-signoff .sg-label { background: #f1f1f1; border-bottom: 1px solid #111; padding: 7px; font-size: 12px; font-weight: 600; }
.rpt-signoff .sg-name { padding: 22px 7px 10px; font-size: 15px; font-family: var(--font-display); }
.rpt-signoff .sg-date { font-family: var(--font-mono); font-size: 11px; color: #555; padding-bottom: 8px; }

/* ─── 權限阻擋頁 ─────────────────────────────────────── */
.denied { max-width: 460px; margin: 8vh auto; text-align: center; }
.denied .lock { width: 66px; height: 66px; border-radius: 18px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 18px; }
.denied h2 { font-size: 20px; margin-bottom: 8px; }
.denied p { color: var(--muted); margin-bottom: 20px; }

/* ─── 空白 / 提示 / 類別管理 ─────────────────────────── */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.cat-list { display: grid; gap: 10px; }
.cat-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.cat-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.cat-item .nm { font-weight: 600; font-size: 14px; }
.cat-item .desc { font-size: 12.5px; color: var(--muted); }
.cat-item .amt { margin-left: auto; font-family: var(--font-mono); font-size: 13px; color: var(--muted); text-align: right; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); min-height: 38px; }
.seg button.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-1); }

/* ─── Modal / Toast ──────────────────────────────────── */
.modal { border: 0; border-radius: 18px; padding: 0; max-width: 440px; width: 92vw; box-shadow: var(--shadow-pop); }
.modal::backdrop { background: rgba(2,6,23,.5); backdrop-filter: blur(2px); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-body h3 { font-size: 18px; }
.modal-body p { color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(8px);
  background: var(--dark); color: #fff; padding: 12px 20px; border-radius: var(--r-pill);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow-pop); z-index: 90;
  display: flex; align-items: center; gap: 9px; opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast .ic { color: var(--success); }

/* ════════════════ 響應式 ════════════════ */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-aside { order: -1; flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; padding: 22px clamp(20px,6vw,44px); flex-wrap: wrap; }
  .aside-rows { display: none; }
  .login-card { padding: 28px clamp(20px,6vw,44px) 40px; max-width: none; }
}
@media (max-width: 880px) {
  .appbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 10px;
  }
  .appbar-title { font-family: var(--font-display); font-weight: 600; font-size: 16px; flex: 1; }
  .role-chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 7px 14px; font-size: 13px; font-weight: 600; min-height: 38px; }
  .shell { display: block; }
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50; height: 100dvh; width: 280px;
    transform: translateX(-100%); transition: transform .25s cubic-bezier(.2,0,0,1);
    box-shadow: var(--shadow-pop);
  }
  .sidebar.open { transform: translateX(0); }
  .view { padding: 18px 16px 56px; }
  .page-head { margin-bottom: 18px; }
  .g-2, .g-2-1, .g-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .g-4 { grid-template-columns: 1fr 1fr; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }
  /* 表格在小螢幕仍可橫向捲動；報表表格縮字 */
  .rpt-table { font-size: 11.5px; }
  .rpt-table th, .rpt-table td { padding: 5px 6px; }
  .donut-wrap { justify-content: center; }
}
@media print {
  /* 只印報表本體：隱藏 App chrome 與報表頁的工具列/上傳區/歷史清單。
     #reportDoc 維持正常文件流，跨頁列印才不會被截斷或多出空白頁。 */
  .appbar, .sidebar, .scrim, .head-actions, .seg,
  .page-head, .rpt-toolbar, .stamp-card, .no-print { display: none !important; }
  .view { padding: 0; }
  .maxw { max-width: none; }
  .report-doc { box-shadow: none; border: 0; max-width: none; margin: 0; }
  body { background: #fff; }
}
/* ════════════════ v1.1：登入改版 · 公司 logo · 系統管理 ════════════════ */
/* 公司 logo（取自官網 assets/logo.png） */
.brand-logo { height: 46px; width: auto; flex: none; display: block; }
.brand-logo.sm { height: 34px; }

/* 登入：錯誤提示 */
.login-error {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  padding: 11px 14px; border-radius: var(--r-btn); font-size: 13px; font-weight: 500;
}

/* 登入：示範帳號 */
.login-demo-toggle {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px;
  cursor: pointer; padding: 4px; align-self: center; text-decoration: underline; text-underline-offset: 3px;
}
.login-demo-toggle:hover { color: var(--accent); }
.login-demo { display: grid; gap: 8px; margin-top: 2px; }
/* 群暉 SSO 登入：分隔線 + 盾牌圖示按鈕 */
#ssoBlock { display: flex; flex-direction: column; gap: 14px; }
.sso-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.sso-divider::before, .sso-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-sso { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn-sso svg { color: var(--accent); flex: none; }
.btn-sso:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.cf-turnstile-box:not(:empty) { display: flex; justify-content: center; margin: 2px 0; }
.demo-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--r-btn);
  background: var(--surface); cursor: pointer; text-align: left; transition: border-color .15s, background .15s;
}
.demo-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.demo-item b { font-size: 13.5px; font-weight: 600; }
.demo-item span { font-size: 12px; color: var(--muted); }

/* 登入右側：系統介紹（取代財務速覽） */
.aside-headline { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 3.4vw, 38px); line-height: 1.25; margin-top: 10px; }
.aside-features { display: grid; gap: 16px; }
.af { display: flex; gap: 14px; align-items: flex-start; }
.af-ic {
  flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-family: var(--font-mono); font-weight: 600; font-size: 14px;
}
.af b { display: block; font-size: 15px; color: var(--dark-fg); }
.af small { color: var(--dark-muted); font-size: 13px; }
.aside-note { color: var(--dark-muted); font-size: 13px; border-top: 1px solid var(--dark-line); padding-top: 18px; }

/* 側欄：登入者身分卡（取代切換器） */
.user-card {
  display: flex; align-items: center; gap: 11px; margin: 4px 8px 14px; padding: 11px 12px;
  background: rgba(255,255,255,.04); border: 1px solid var(--dark-line); border-radius: 14px;
}
.uc-avatar {
  flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
}
.uc-info { display: flex; flex-direction: column; min-width: 0; }
.uc-name { color: #fff; font-weight: 600; font-size: 14px; }
.uc-role { color: var(--dark-muted); font-size: 12px; }

/* 系統狀態：資訊列 */
.info-rows { display: grid; gap: 1px; background: var(--border); border-radius: 12px; overflow: hidden; }
.info-rows > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--surface); padding: 12px 14px; }
.info-rows span { color: var(--muted); font-size: 13px; }
.info-rows b { font-size: 14px; }

/* 用戶管理：角色徽章 */
.badge-role { font-weight: 600; }
.role-admin { background: var(--warn-soft); color: var(--warn); }
.role-manager { background: var(--accent-soft); color: var(--accent); }
.role-accountant { background: var(--info-soft); color: var(--info); }
.role-employee { background: var(--success-soft); color: var(--success); }

.mono-cell { font-family: var(--font-mono); }
/* 審核表：用途欄限寬截斷（完整內容在 title 與「明細」），避免把金額/按鈕推到畫面外 */
.dt td.desc-cell { max-width: 260px; }
.dt td.desc-cell .desc-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt td.nowrap { white-space: nowrap; }
.dt td.nowrap .row-actions { flex-wrap: nowrap; }
.link-btn {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  color: var(--accent); text-decoration: underline; text-underline-offset: 3px;
  font-family: var(--font-mono); font-size: 12.5px;
}
.link-btn:hover { color: var(--accent-strong, var(--accent)); }

/* 出納「本月未結」總覽 */
.pend-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pend-item {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r-btn);
  background: var(--surface); font: inherit; width: 100%;
}
button.pend-item { cursor: pointer; transition: border-color .15s, background .15s; }
button.pend-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.pend-item.hot { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.pend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.pend-body { flex: 1; min-width: 0; }
.pend-label { font-size: 13px; color: var(--muted); }
.pend-meta { font-size: 14px; font-weight: 600; }
.pend-meta b { font-family: var(--font-mono); font-size: 17px; }
.pend-amt { font-family: var(--font-mono); font-size: 15px; font-weight: 600; white-space: nowrap; }
@media (max-width: 760px) { .pend-grid { grid-template-columns: 1fr; } }

/* 使用教學 */
.hp-roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.hp-role { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-btn); background: var(--surface); }
.hp-role b { display: block; margin-bottom: 4px; }
.hp-role span { display: block; font-size: 12.5px; line-height: 1.6; }
.hp-steps { list-style: none; display: grid; gap: 12px; }
.hp-steps li { display: flex; gap: 12px; align-items: flex-start; }
.hp-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; font-family: var(--font-mono); }
.hp-steps li b { display: block; margin-bottom: 2px; }
.hp-steps li .meta { line-height: 1.6; }
.hp-block { padding: 14px 0; border-top: 1px solid var(--border-soft); }
.hp-block:first-of-type { border-top: 0; padding-top: 4px; }
.hp-block > b { display: block; margin-bottom: 8px; }
.hp-faq { padding: 9px 0; border-top: 1px solid var(--border-soft); }
.hp-faq:first-of-type { border-top: 0; }
.hp-faq b { display: block; margin-bottom: 3px; }
.hp-faq .meta { line-height: 1.6; }
@media (max-width: 760px) { .hp-roles { grid-template-columns: 1fr; } }

/* ════════════════ v1.2：報表歷史 · 用印留存 · 溯源 · 操作紀錄 ════════════════ */
/* 報表工具列：月份切換 + 狀態 */
.rpt-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.rpt-months { display: flex; gap: 8px; flex-wrap: wrap; }
.rpt-month {
  font: inherit; font-size: 13px; font-weight: 600; padding: 7px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); color: var(--muted);
  transition: all .15s;
}
.rpt-month:hover { border-color: var(--accent); color: var(--accent); }
.rpt-month.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.rpt-state { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }

/* 可溯源列 */
.trace-row { cursor: pointer; transition: background .12s; }
.trace-row:hover { background: var(--accent-soft); }
.trace-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.trace-go { color: var(--accent); font-weight: 700; text-align: right; }

/* 用印留存卡 */
.stamp-card { border: 1px solid var(--border); }
.stamp-file { display: flex; align-items: center; gap: 14px; }
.stamp-ic { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--success-soft); color: var(--success); font-weight: 700; }

/* 核銷詳情 modal */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); border-radius: 12px; overflow: hidden; margin: 6px 0 14px; }
.detail-grid > div { background: var(--surface); padding: 11px 14px; display: flex; flex-direction: column; gap: 3px; }
.detail-grid > div.full { grid-column: 1 / -1; }
.detail-grid span { font-size: 12px; color: var(--muted); }
.detail-grid b { font-size: 14px; }
.detail-receipt { display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
.receipt-thumb { flex: none; width: 56px; height: 56px; border-radius: 9px; display: grid; place-items: center; text-align: center; font-size: 11px; line-height: 1.3; color: var(--muted); background: repeating-linear-gradient(45deg, #fff, #fff 6px, var(--surface) 6px, var(--surface) 12px); border: 1px dashed var(--border); }
.detail-sub { font-size: 14px; font-weight: 600; margin: 6px 0 10px; }

/* 變更歷程時間軸 */
.timeline { display: grid; gap: 0; position: relative; }
.tl-item { display: flex; gap: 12px; padding: 0 0 16px 0; position: relative; }
.tl-item::before { content: ""; position: absolute; left: 5px; top: 14px; bottom: -2px; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; z-index: 1; background: var(--muted); }
.tl-dot.ok { background: var(--success); }
.tl-dot.back { background: var(--accent); }
.tl-dot.wait { background: var(--warn); }
.tl-dot.info { background: var(--info); }
.tl-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tl-head b { font-size: 14px; }

/* 操作紀錄徽章配色（獨立 class，不覆蓋類別徽章 .badge-cat） */
.badge-info { background: var(--info-soft); color: var(--info); }

/* 登入頁手機版：單欄、隱藏右側介紹 */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}
@media (max-width: 640px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* v1.3：報表即時彙總提示 */
.rpt-live-note { font-size: 12px; color: var(--muted); background: var(--info-soft); border-radius: 8px; padding: 8px 12px; margin: 0 24px 14px; }

/* v1.3：表格搜尋框 */
.search-input { max-width: 340px; min-height: 38px; padding: 8px 12px; font-size: 14px; }

/* v1.4：通知中心 */
.notif-list { display: grid; gap: 2px; }
.notif-item { display: flex; gap: 12px; align-items: flex-start; padding: 14px 12px; border-radius: 10px; }
.notif-item.unread { background: var(--accent-soft); }
.notif-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; background: var(--border); }
.notif-item.unread .notif-dot { background: var(--accent); }

/* v1.5：可點通知 + 收據 PDF/照片縮圖 */
.notif-item[data-trace] { cursor: pointer; }
.notif-item[data-trace]:hover { background: var(--accent-soft); }
.notif-go { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; align-self: center; }
.receipt-grid { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 2px; }
.receipt-thumb.img, .receipt-thumb.pdf {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  width: auto; min-width: 116px; height: 74px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; transition: border-color .15s;
}
.receipt-thumb.img:hover, .receipt-thumb.pdf:hover { border-color: var(--accent); }
.receipt-thumb.img > span, .receipt-thumb.pdf > span { font-family: var(--font-mono); font-weight: 700; font-size: 12px; padding: 2px 9px; border-radius: 5px; }
.receipt-thumb.img > span { background: var(--info-soft); color: var(--info); }
.receipt-thumb.pdf > span { background: var(--accent-soft); color: var(--accent); }
.receipt-thumb.img > small, .receipt-thumb.pdf > small { color: var(--muted); font-size: 11px; }
/* 收據圖片內嵌預覽卡 */
.receipt-card { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: zoom-in; transition: border-color .15s; max-width: 150px; }
.receipt-card:hover { border-color: var(--accent); }
.receipt-img { width: 132px; height: 100px; object-fit: cover; border-radius: 7px; background: var(--surface-2, #eef2f7); display: block; }
.receipt-card > small { color: var(--muted); font-size: 11px; max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
