/* 共用樣式：色彩、字型、按鈕、表單、標籤、對話框、提示 */
:root {
  --primary: #0b5c8a;
  --primary-hover: #094b71;
  --primary-soft: #e7f1f8;
  --primary-line: #b9d5e8;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #1c2533;
  --text-2: #475467;
  --muted: #6b7686;
  --border: #e1e6ed;
  --border-strong: #cbd3de;
  --ok: #17804f;
  --ok-soft: #e6f4ec;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --danger: #b4282e;
  --danger-soft: #fdecec;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Heiti TC", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 7px 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: background-color .12s, border-color .12s;
  white-space: nowrap;
}
.btn:focus-visible { outline: 3px solid var(--primary-line); outline-offset: 1px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #962126; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn-lg { min-height: 48px; padding: 10px 24px; font-size: 16px; }

/* 表單 */
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { min-height: 96px; resize: vertical; }
.field { display: grid; gap: 6px; }
.field > label { font-weight: 600; font-size: 14px; color: var(--text-2); }
.field-hint { font-size: 13px; color: var(--muted); }

/* 標籤 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; line-height: 1.6; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cf; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #f2d899; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: #f3c1c3; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-line); }
.badge-muted { background: #eef1f5; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* 提示區塊 */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
}
.alert-ok { background: var(--ok-soft); border-color: #bfe3cf; color: #0f5c38; }
.alert-warn { background: var(--warn-soft); border-color: #f2d899; color: #6e4700; }
.alert-danger { background: var(--danger-soft); border-color: #f3c1c3; color: #8a1d22; }
.alert-info { background: var(--primary-soft); border-color: var(--primary-line); color: #084266; }
.alert-icon { flex: none; font-weight: 700; }

/* 對話框 */
.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
}
.modal-wide { width: min(760px, 100%); }
.modal-head { padding: 18px 20px 0; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 14px 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; flex-wrap: wrap; }

/* 提示訊息 */
.toast-wrap { position: fixed; z-index: 200; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast { padding: 10px 14px; border-radius: var(--radius-sm); background: #1c2533; color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; }
.toast-ok { background: var(--ok); }
.toast-danger { background: var(--danger); }
.toast-warn { background: #8a5a00; }

/* 本機預覽標示 */
.preview-ribbon {
  background: repeating-linear-gradient(-45deg, #fff4dc, #fff4dc 10px, #ffeec4 10px, #ffeec4 20px);
  color: #6e4700; border-bottom: 1px solid #f2d899;
  font-size: 13px; padding: 4px 16px; text-align: center; font-weight: 600;
}

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
