/* 智能外撥問卷系統：色票、基礎元件（按鈕、表單、表格、徽章、對話框…）。外殼與各頁面樣式在 app.css */
:root {
  --bg: #f3f4f1;
  --paper: #ffffff;
  --ink: #18222c;
  --muted: #5b6a77;
  --faint: #8794a0;
  --line: #dde2df;
  --line-soft: #eceff0;
  --night: #11202b;
  --night-raise: #1b3141;
  --night-ink: #e9f1f4;
  --night-muted: #8fa4b1;
  --accent: #0c7c7a;
  --accent-strong: #095f5e;
  --accent-soft: #dff1ef;
  --accent-glow: #35d0c2;
  --info: #2b6cb0;
  --info-soft: #e3eefb;
  --ok: #2f855a;
  --ok-soft: #e1f3e8;
  --warn: #a8660b;
  --warn-soft: #fbefd5;
  --danger: #c0392b;
  --danger-soft: #fbe5e2;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --shadow: 0 1px 2px rgba(17, 32, 43, .06), 0 4px 14px -6px rgba(17, 32, 43, .12);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.6 var(--font);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- 按鈕 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px;
  font: 500 14px/1.4 var(--font); color: var(--ink); background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--r-sm); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f4f7f6; border-color: #c4ccc9; text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.danger { color: var(--danger); border-color: #e7bcb6; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.solid:hover { background: #a02e22; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--line-soft); color: var(--ink); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.icon { padding: 5px 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---- 表單 ---- */
.field { display: grid; gap: 4px; margin-bottom: 12px; font-size: 14px; }
.field > .lbl { font-weight: 500; color: var(--ink); }
.field .hint { font-size: 13px; color: var(--muted); font-weight: 400; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=datetime-local], input[type=tel], input[type=email], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink); background: var(--paper);
  border: 1px solid #cdd4d1; border-radius: var(--r-sm); padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
input[disabled], select[disabled], textarea[disabled] { background: #f1f3f2; color: var(--muted); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex: none; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check.block { display: flex; padding: 4px 0; }
.form-error { margin: 0; min-height: 0; font-size: 14px; color: var(--danger); }
.form-error:empty { display: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; }

/* ---- 卡片、區塊 ---- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-body { padding: 16px 18px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin-right: auto; }
.stack { display: grid; gap: 16px; }
.stack.sm { gap: 10px; }

/* ---- 徽章 ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 12.5px;
  font-weight: 500; line-height: 1.6; background: #eceff0; color: #475561; white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: #22633f; }
.badge.info { background: var(--info-soft); color: #1f4f86; }
.badge.warn { background: var(--warn-soft); color: #7d4a05; }
.badge.danger { background: var(--danger-soft); color: #922a1f; }
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---- 提示 ---- */
.alert { padding: 10px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: #f5f7f6; font-size: 14px; }
.alert.info { background: var(--info-soft); border-color: #c3d8f1; color: #1f4f86; }
.alert.warn { background: var(--warn-soft); border-color: #efd69e; color: #6b4004; }
.alert.error { background: var(--danger-soft); border-color: #efc0ba; color: #8a2a20; }
.alert.ok { background: var(--ok-soft); border-color: #bfe2cd; color: #1f5a39; }
.alert ul { margin: 4px 0 0; padding-left: 20px; }
.alert strong { font-weight: 700; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 15px; color: var(--ink); margin-bottom: 4px; font-weight: 500; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl th { background: #f6f8f7; color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; position: sticky; top: 0; }
.tbl tbody tr:hover { background: #fafbfa; }
.tbl tr.click { cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--ink); }
.tbl th .arrow { color: var(--accent); margin-left: 3px; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions .btn + .btn { margin-left: 4px; }

/* ---- 進度條 ---- */
.progress { height: 8px; border-radius: 999px; background: #e6ebe9; overflow: hidden; position: relative; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.progress.thin { height: 5px; }
.progress .layer2 { position: absolute; inset: 0 auto 0 0; background: #8bd3cc; }
.progress-label { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 3px; gap: 8px; flex-wrap: wrap; }

/* ---- 分頁籤 ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabs button {
  padding: 9px 16px; background: none; border: 0; border-bottom: 2px solid transparent; font: 500 14.5px var(--font);
  color: var(--muted); cursor: pointer; white-space: nowrap; margin-bottom: -1px;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); }
.section-tabs { margin: -6px 0 18px; }

/* ---- 對話框 ---- */
dialog.dlg {
  border: 0; padding: 0; border-radius: var(--r-lg); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  box-shadow: 0 24px 70px -18px rgba(10, 20, 30, .5); color: var(--ink); background: var(--paper);
}
dialog.dlg.wide { width: min(760px, calc(100vw - 24px)); }
dialog.dlg.xwide { width: min(1000px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(10, 22, 30, .52); }
dialog.dlg > form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { padding: 16px 20px 6px; display: flex; align-items: center; gap: 10px; }
.dlg-head h2 { flex: 1; font-size: 18px; }
.dlg-body { padding: 8px 20px 12px; overflow-y: auto; }
.dlg-foot { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line-soft); }
.dlg-body .form-error { margin-top: 6px; }

/* ---- 提示訊息 ---- */
.toast-box { position: fixed; z-index: 1000; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; padding: 10px 16px; background: var(--night); color: #fff; border-radius: var(--r-sm);
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, .5); font-size: 14.5px; animation: toast-in .18s ease-out;
}
.toast.error { background: #8d2a20; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
