:root {
  --bg: #f5f4ef; --card: #ffffff; --ink: #1f2420; --muted: #6b716c; --line: #e2e0d8;
  --accent: #2f6b4f; --accent-ink: #fff; --accent-soft: #e7f0eb; --warn: #b4432a; --warn-soft: #fbe9e4;
  --yellow: #fff5cc; --blue: #e3eefa; --pink: #c2185b; --hl: #fff1b8; --nav: #1f2a24; --nav-ink: #dfe7e1;
  --radius: 10px;
}
/* JY 2026-10-21：系統固定用淺色，不跟電腦的深色模式 */
:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0; } h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--warn); font-size: 14px; min-height: 1.4em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }

/* 按鈕與表單 */
.btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--warn); border-color: var(--warn); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.icon { padding: 4px 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--ink); font-size: 15px; }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; }
.form-grid .wide { grid-column: span 2; } .form-grid .full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; } .row > .btn, .row > .shrink { flex: 0 0 auto; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 8px; font-weight: 600; }
.req::before { content: "* "; color: var(--warn); }
.hint { font-size: 12px; color: var(--warn); }

/* 登入 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card label { margin-top: 12px; }
.login-card .btn { margin-top: 16px; }

/* 版面 */
.app { display: flex; min-height: 100vh; }
.nav { width: 200px; background: var(--nav); color: var(--nav-ink); flex: 0 0 auto; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 16px; font-weight: 700; } .brand small { display: block; font-weight: 400; opacity: .6; font-size: 12px; }
.nav a { display: block; padding: 9px 16px; color: var(--nav-ink); text-decoration: none; font-size: 14px; border-left: 3px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.05); }
.nav a.on { background: rgba(255,255,255,.08); border-left-color: #7fd1a6; color: #fff; }
.nav .badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: #e5322d; color: #fff; font-size: 11px; font-weight: 700; text-align: center; vertical-align: 1px; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h2 { flex: 0 0 auto; }
.speed { flex: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.speed b { color: var(--accent); }
.who { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.who select { width: auto; padding: 3px 6px; font-size: 13px; }
.nav-toggle { display: none; }
.nav-toggle { position: relative; } .nav-toggle.has-badge::after { content: ''; position: absolute; top: 2px; right: 2px; width: 9px; height: 9px; border-radius: 50%; background: #e5322d; }
#pages { padding: 16px; }
.page { max-width: 1280px; margin: 0 auto; }

/* 表格 */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--card); position: sticky; top: 0; }
th.sortable { cursor: pointer; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--accent-soft); }
table.wide th, table.wide td { white-space: nowrap; }
.recipe div { line-height: 1.6; } .recipe .num { display: inline-block; min-width: 72px; }
tr.dim td { color: var(--muted); text-decoration: line-through; }
tr.detail > td { background: var(--accent-soft); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
table.edit td { padding: 4px; } table.edit input, table.edit select { padding: 5px 8px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 4px; background: var(--accent-soft); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.blue { background: var(--blue); } .tag.pink { background: var(--pink); color: #fff; } .tag.yellow { background: var(--yellow); }
.kpis { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.kpis .card { flex: 1 1 150px; padding: 10px 14px; }
.kpis b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.grid-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; }
.grid-info span { display: block; font-size: 12px; color: var(--muted); }
.grid-info p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 14px; font: inherit; color: var(--muted); border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* 業績表 */
.perf-day { margin-bottom: 10px; }
.perf-day .day-head { font-weight: 600; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.perf-day .dnum { background: #dc3545; color: #fff; border-radius: 4px; padding: 0 6px; font-size: 16px; }
.perf-day.off { color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
table.perf { table-layout: fixed; min-width: 1100px; }
table.perf th, table.perf td { padding: 4px 5px; font-size: 13px; border: 1px solid var(--line); }
table.perf td.c { text-align: right; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
table.perf td.neg { color: #dc3545; } table.perf td.lbl-rt { background: #cce5ff; color: #1a1a1a; }
table.perf td.lbl-promo { background: #c2185b; color: #fff; } table.perf td.supp { background: #fff3cd; color: #856404; }
table.perf td.leave { background: #F1EFE8; color: #5F5E5A; font-weight: 400; text-align: left; }
table.perf .sub { background: #FFFDE7; } table.perf .prev { background: #EAF3DE; } table.perf .tot { background: #E6F1FB; }
table.perf th.sub { background: #FFF9C4; } table.perf th.prev { background: #C0DD97; } table.perf th.tot { background: #B5D4F4; }
table.perf .sub, table.perf .prev, table.perf .tot { color: #1a1a1a; text-align: right; font-variant-numeric: tabular-nums; }
table.perf tr.sum td { border-top: 3px double var(--ink); font-weight: 700; }
.alert-bar { background: #dc3545; color: #fff; padding: 8px 14px; border-radius: 8px; margin-bottom: 10px; cursor: pointer; }
body.shot .nav, body.shot .topbar, body.shot .alert-bar, body.shot .no-shot { display: none !important; }
body.shot #pages { padding: 8px; } body.shot .page { max-width: none; }
.shot-head { display: none; } body.shot .shot-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--bg); padding: 6px 0; z-index: 3; }

/* 彈窗、提示 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 760px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
#modal-body { padding: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--warn); color: #fff; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.history { font-size: 13px; color: var(--muted); }
.adj-line { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.loading { color: var(--muted); padding: 20px; text-align: center; }

/* 列印 */
@media print {
  .nav, .topbar, .no-print, .modal-head { display: none !important; }
  .modal { position: static; background: none; padding: 0; } .modal-box { max-height: none; box-shadow: none; }
  body { background: #fff; color: #000; }
}

/* 手機 */
@media (max-width: 760px) {
  .nav { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .nav-toggle { display: inline-block; }
  .speed { display: none; }
  .who #who-name { display: none; }
  #pages { padding: 10px; }
  .hide-sm { display: none; }
  .form-grid .wide { grid-column: 1 / -1; }
  th, td { padding: 7px 6px; }
}
