/* NewPeak 共用設計基底 — 嚴守 Apple HIG、modern-web-guidance 與使用者焦點偏好 */
:root {
  --bg: #0b1220;
  --bg-elev: #121c30;
  --bg-card: #162238;
  --bg-subtle: #1d2c47;
  --border: #273959;
  --border-strong: #374f78;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --gold: #eab308;
  --gold-soft: rgba(234, 179, 8, 0.14);
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.16);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: clip;
}

img, video {
  max-width: 100%;
  display: block;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* 使用者常設焦點偏好：滑鼠點擊不出現預設藍框；輸入框用產品色細邊框；按鈕只在鍵盤 :focus-visible 顯示清楚焦點環 */
button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
[tabindex]:focus:not(:focus-visible) {
  outline: none;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #14223a;
}

@media (forced-colors: active) {
  input:focus, select:focus, textarea:focus,
  button:focus-visible, a:focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

.num {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 全站按鈕系統 — 全部套用 Codex 八角倒角奢華金屬底板（CSS 9-slice border-image，44×44 到 700×60 等比零變形） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 20px;
  border-radius: 0;
  border: 1px solid transparent;
  border-image-source: url("/assets/ui/btn-art-slate.webp");
  border-image-slice: 69 69 69 69 fill;
  border-image-width: 14px;
  border-image-repeat: stretch;
  background: transparent;
  color: #f8fafc;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(2, 6, 23, 0.85);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.13);
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
  filter: brightness(0.96);
}

.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn-primary {
  border-image-source: url("/assets/ui/btn-art-primary.webp");
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(2, 6, 23, 0.9);
}

.btn-gold {
  border-image-source: url("/assets/ui/btn-art-gold.webp");
  color: #0b1220;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-plate-slate {
  border-image-source: url("/assets/ui/btn-art-slate.webp");
  color: #f8fafc;
}

.btn-danger {
  border-image-source: url("/assets/ui/btn-art-danger.webp");
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(2, 6, 23, 0.9);
}

.btn-ghost {
  border-image-source: url("/assets/ui/btn-art-slate.webp");
  border-image-width: 11px;
  color: #e2e8f0;
}

.btn-sm {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 15px;
  font-size: 0.875rem;
  border-image-width: 11px;
}

@media (forced-colors: active) {
  .btn, .btn-primary, .btn-gold, .btn-plate-slate, .btn-danger, .btn-ghost {
    border-image: none !important;
    border: 1px solid ButtonText !important;
    color: ButtonText;
    text-shadow: none;
  }
  dialog, .balance-card, .jp-hero, .jp-tier, .login-card, .admin-login-card,
  .store-card, .kpi-box, .ann-item, .ledger-row, .profile-card, .confirm-summary,
  .kiosk-bar, .kiosk-card, .kiosk-qr-panel {
    border-image: none !important;
    border: 1px solid CanvasText !important;
  }
}

.art-title {
  height: clamp(30px, 6vw, 48px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

/* 狀態標籤 */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: #86efac; }
.badge-warn { background: var(--warn-soft); color: #fcd34d; }
.badge-danger { background: var(--danger-soft); color: #fca5a5; }
.badge-info { background: var(--accent-soft); color: #93c5fd; }
.badge-gold { background: var(--gold-soft); color: #fde047; }

/* 訊息橫幅 */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 0.9375rem;
}
.alert-danger {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}
.alert-ok {
  background: var(--ok-soft);
  border-color: rgba(34, 197, 94, 0.45);
  color: #bbf7d0;
}
.alert-warn {
  background: var(--warn-soft);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

/* 表單群組 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #cbd5e1;
}

/* 原生 <dialog> 依 modern-web-guidance/dialog 規範（套用 Codex 藍寶石金屬細框） */
dialog {
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 0;
  border-image-source: url("/assets/ui/frame-card-sapphire.webp");
  border-image-slice: 96 96 96 96 fill;
  border-image-width: 24px;
  border-image-repeat: stretch;
  background: transparent;
  color: var(--text);
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.dialog-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* 響應式資料表 依 modern-web-guidance/responsive-table 規範 */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(640px, 72vh);
  border: 1px solid rgba(212, 175, 55, 0.36);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  container-type: inline-size;
}

.table-wrapper table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.table-wrapper caption {
  text-align: left;
  padding: 12px 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}

.table-wrapper thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--bg-elev);
}

.table-wrapper th,
.table-wrapper td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table-wrapper thead th {
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
}

.table-wrapper tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--bg-card);
  font-weight: 600;
  z-index: 1;
}

.table-wrapper th.num-col,
.table-wrapper td.num-col {
  text-align: right;
}

.table-wrapper tbody tr:hover td,
.table-wrapper tbody tr:hover th {
  background: #1b2a45;
}

@container (width < 600px) {
  .table-wrapper table,
  .table-wrapper caption,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper tfoot,
  .table-wrapper tr,
  .table-wrapper th,
  .table-wrapper td {
    display: block;
  }
  .table-wrapper caption {
    width: 100%;
  }
  .table-wrapper thead {
    display: none;
  }
  .table-wrapper tr {
    margin: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elev);
    overflow: hidden;
  }
  .table-wrapper tbody th {
    position: sticky;
    inset-block-start: 0;
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
  }
  .table-wrapper td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(39, 57, 89, 0.6);
  }
  .table-wrapper td:last-child {
    border-bottom: 0;
  }
  .table-wrapper td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
  }
}

/* Toast 輕量狀態通知（置於頂端安全區下方，不遮擋底部導覽與操作區） */
#toast-region {
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  pointer-events: auto;
}
.toast-ok { border-color: rgba(34, 197, 94, 0.6); }
.toast-danger { border-color: rgba(239, 68, 68, 0.65); }

.demo-ribbon {
  background: #78350f;
  color: #fef3c7;
  text-align: center;
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 600;
}
