/* 營運管理系統 —— 全域樣式（淺／深色主題，語意色與品牌色分離） */
:root {
  --bg: #f4f6f8; --panel: #ffffff; --panel-2: #f8fafb; --border: #dfe3e8; --border-strong: #c5ccd4;
  --text: #1b2430; --muted: #5f6b7a; --faint: #8a95a3;
  --brand: #1f5fbf; --brand-hover: #174c9c; --brand-soft: #e8f0fb; --on-brand: #fff;
  --ok: #17794a; --ok-soft: #e3f4ea; --warn: #a45a00; --warn-soft: #fcf0dc;
  --bad: #c0362c; --bad-soft: #fbe7e5; --info: #3b5b8a; --info-soft: #e9eef6;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 8px; --font: "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151a; --panel: #181d24; --panel-2: #1e242c; --border: #2b333d; --border-strong: #3a4450;
    --text: #e6eaef; --muted: #9ba6b3; --faint: #6f7a87;
    --brand: #5b9bf0; --brand-hover: #7aaef3; --brand-soft: #1b2a3f; --on-brand: #0b1220;
    --ok: #4cc38a; --ok-soft: #173327; --warn: #e3a54a; --warn-soft: #3a2a12;
    --bad: #f07167; --bad-soft: #3d1c1a; --info: #8fb0de; --info-soft: #1d2735;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151a; --panel: #181d24; --panel-2: #1e242c; --border: #2b333d; --border-strong: #3a4450;
  --text: #e6eaef; --muted: #9ba6b3; --faint: #6f7a87;
  --brand: #5b9bf0; --brand-hover: #7aaef3; --brand-soft: #1b2a3f; --on-brand: #0b1220;
  --ok: #4cc38a; --ok-soft: #173327; --warn: #e3a54a; --warn-soft: #3a2a12;
  --bad: #f07167; --bad-soft: #3d1c1a; --info: #8fb0de; --info-soft: #1d2735;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
[v-cloak] { display: none; }

/* ── 版面 ─────────────────────────────── */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--border); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-size: 14px; }
.nav-group { margin: 12px 0 4px; padding: 0 10px; font-size: 12.5px; color: var(--faint); letter-spacing: .06em; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); min-height: 38px; }
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .ico { width: 20px; text-align: center; opacity: .8; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.content { padding: 20px 24px 48px; }
.btn.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 50; left: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 8px 16px; }
}
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head .title { flex: 1; min-width: 200px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ── 卡片／格線 ────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13.5px; }
.stat .value { font: 600 22px/1.3 var(--mono); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 13px; color: var(--faint); margin-top: 2px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ── 表單 ─────────────────────────────── */
.form { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > label { font-size: 13.5px; color: var(--muted); }
.field > label .req { color: var(--bad); margin-left: 2px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border-strong); border-radius: 6px; padding: 8px 10px; min-height: 40px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--panel-2); color: var(--muted); }
input.num { text-align: right; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: 18px; height: 18px; min-height: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 220px; }

/* ── 按鈕 ─────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; min-height: 40px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }

/* ── 表格 ─────────────────────────────── */
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
.table-wrap.free { max-height: none; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th, table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table-wrap table.data td, .table-wrap table.data th { white-space: nowrap; }
table.edit td { white-space: normal; }
table.data th { position: sticky; top: 0; z-index: 2; background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 13.5px; white-space: nowrap; user-select: none; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { font-size: 11px; margin-left: 4px; color: var(--brand); }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tfoot td { font-weight: 700; background: var(--panel-2); position: sticky; bottom: 0; }
table.data td.num, table.data th.num { text-align: right; }
table.data .empty { text-align: center; color: var(--faint); padding: 32px; }
table.data tr.void td { color: var(--faint); text-decoration: line-through; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 2px; color: var(--muted); font-size: 13.5px; }
table.edit td { padding: 4px 6px; }
table.edit input, table.edit select { min-height: 36px; padding: 6px 8px; }

/* ── 標籤 ─────────────────────────────── */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.muted { background: var(--panel-2); color: var(--muted); }

/* ── 分頁籤 ───────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; min-height: 44px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ── Modal／Toast ─────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(10,16,24,.45); display: grid; place-items: center; z-index: 100; padding: 16px; }
/* min-width:0 不能省：modal 是 grid item，預設 min-width:auto，裡面放寬表格會把整個視窗撐爆 */
.modal { background: var(--panel); border-radius: 10px; width: min(640px, 100%); min-width: 0; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.lg { width: min(960px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; min-width: 0; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--panel); box-shadow: var(--shadow); max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ── 下拉挑選 ──────────────────────────── */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 2px); background: var(--panel); border: 1px solid var(--border-strong); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; z-index: 30; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 36px 16px; border: 2px dashed var(--border-strong); border-radius: var(--radius); cursor: pointer; background: var(--panel-2); }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.picker-list.float { position: fixed; right: auto; z-index: 300; }
.picker-list div { padding: 8px 10px; cursor: pointer; }
.picker-list div:hover, .picker-list div.hl { background: var(--brand-soft); }

/* ── 登入 ─────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); }
.alert { padding: 10px 12px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--info); }

/* ── 看板 ─────────────────────────────── */
.board { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board-col { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; min-height: 200px; }
.board-col h3 { display: flex; justify-content: space-between; padding: 4px 6px 8px; font-size: 14px; }
.board-card { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.board-card:hover { border-color: var(--brand); }

/* ── 長條圖 ───────────────────────────── */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 180px; }
.bars .col { display: flex; gap: 2px; align-items: end; height: 100%; }
.bars .bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .rev { background: var(--brand); } .bars .exp { background: var(--warn); }
.bars-x { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; font-size: 12px; color: var(--faint); text-align: center; margin-top: 4px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }

/* ── 列印 ─────────────────────────────── */
.print-doc { background: #fff; color: #111; padding: 32px; max-width: 900px; margin: 0 auto; }
.print-doc table { width: 100%; border-collapse: collapse; }
.print-doc th, .print-doc td { border: 1px solid #999; padding: 6px 8px; }
.print-doc th { background: #f0f0f0; }
@media print {
  body { background: #fff; }
  .side, .topbar, .no-print, .toasts { display: none !important; }
  .shell { display: block; } .content { padding: 0; }
  .card { border: 0; box-shadow: none; }
  .table-wrap { max-height: none; overflow: visible; border: 0; }
  .print-doc { padding: 0; }
}

/* ── 手機：表格改橫向捲動、不擠壓；頂列精簡 ─ */
table.edit { min-width: 680px; }
@media (max-width: 700px) {
  .card { min-width: 0; } .kv { grid-template-columns: max-content minmax(0, 1fr); }
  .topbar .muted, .topbar .badge { display: none; }
  .page-head .actions { width: 100%; }
}
