/* PCM 圖說查詢 — 網頁端共用樣式（大地色系，淺色／深色自動切換） */
:root {
  --bg: #f7f2e9;
  --surface: #fffbf3;
  --sand: #efe6d5;
  --line: #e0d4be;
  --text: #4a3728;
  --muted: #8a7968;
  --brown: #8b5e3c;
  --brown-d: #6f4a2d;
  --olive: #6b7a4f;
  --amber: #c47a2c;
  --brick: #a8452f;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(74, 55, 40, .08), 0 4px 14px rgba(74, 55, 40, .06);
  --radius: 12px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a15;
    --surface: #2a231c;
    --sand: #352c23;
    --line: #4a3e32;
    --text: #efe6d5;
    --muted: #b3a38f;
    --brown: #c99a6b;
    --brown-d: #d9ae82;
    --olive: #9db07a;
    --amber: #e0a255;
    --brick: #e07a63;
    --on-accent: #1f1a15;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 var(--font);
}
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; color: var(--text); }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--brown-d); }
code { background: var(--sand); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
[hidden] { display: none !important; }

/* 版面 */
main, .wrap { max-width: 1120px; margin: 0 auto; padding: 16px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.top { align-items: flex-start; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* 導覽列 */
#app-header { background: var(--brown); color: var(--on-accent); position: sticky; top: 0; z-index: 20; }
#app-header .nav { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
#app-header .brand { color: var(--on-accent); font-weight: 700; text-decoration: none; font-size: 1.05rem; }
#app-header .nav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#app-header .nav-links a { color: var(--on-accent); text-decoration: none; padding: 4px 12px; border-radius: 999px; opacity: .85; }
#app-header .nav-links a:hover { opacity: 1; background: rgba(255, 255, 255, .14); }
#app-header .nav-links a.active { opacity: 1; background: rgba(255, 255, 255, .22); font-weight: 600; }
#app-header .nav-user { color: var(--on-accent); opacity: .8; font-size: .85rem; }
.mock-banner { background: var(--amber); color: #fff; text-align: center; padding: 6px 12px; font-size: .85rem; }

/* 按鈕 */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--sand); color: var(--text);
  padding: 7px 14px; border-radius: 10px; font: inherit; cursor: pointer; line-height: 1.4;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover:not(:disabled) { border-color: var(--brown); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brown); border-color: var(--brown); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--brown-d); }
.btn.danger { background: var(--brick); border-color: var(--brick); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 10px; font-size: .85rem; border-radius: 8px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--brown); outline-offset: 2px;
}

/* 表單 */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-size: .85rem; color: var(--muted); }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=email], select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 80px; }
.hint { font-size: .8rem; color: var(--muted); }
.error-text { color: var(--brick); font-size: .85rem; }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: var(--sand); font-weight: 600; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--sand) 55%, transparent); }

/* 徽章 */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; color: #fff; background: var(--muted); white-space: nowrap; }
.badge.olive { background: var(--olive); }
.badge.amber { background: var(--amber); }
.badge.brick { background: var(--brick); }
.badge.brown { background: var(--brown); color: var(--on-accent); }
.badge.muted { background: var(--muted); }
.badge.soft { background: var(--sand); color: var(--text); border: 1px solid var(--line); }

/* 分頁籤 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; margin-bottom: 14px; }
.tab { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; padding: 8px 14px; cursor: pointer; border-bottom: 3px solid transparent; }
.tab:hover { color: var(--text); }
.tab[aria-selected=true] { color: var(--brown-d); border-bottom-color: var(--brown); font-weight: 600; }

/* KPI */
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .num { font-size: 1.8rem; font-weight: 700; color: var(--brown-d); line-height: 1.1; }
.kpi .lbl { color: var(--muted); font-size: .85rem; }

/* 進度條 */
.progress { height: 8px; background: var(--sand); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--olive); transition: width .2s; }

/* 對話框與提示 */
.overlay { position: fixed; inset: 0; background: rgba(20, 14, 8, .5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.dialog { max-width: 420px; width: 100%; }
.dialog-msg { white-space: pre-wrap; margin-bottom: 14px; }
.toast-host { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 120; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--olive); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); }
.toast.warn { border-left-color: var(--amber); }
.toast.error { border-left-color: var(--brick); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--brown); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 28px; color: var(--muted); }

@media (max-width: 640px) {
  main, .wrap { padding: 12px; }
  .table th, .table td { padding: 8px; }
  #app-header .nav-user { display: none; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .progress > span { transition: none; } }
