/* QR 掃描系統 共用樣式 */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #526079;
  --text-3: #8a96ab;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eaf1ff;
  --on-primary: #ffffff;
  --success: #15803d;
  --success-soft: #e9f8ef;
  --warning: #b45309;
  --warning-soft: #fff6e5;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  --font: "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131b2e;
    --surface-2: #18223a;
    --border: #26324d;
    --text: #e6ebf5;
    --text-2: #a4b0c8;
    --text-3: #6f7d98;
    --primary: #6b96ff;
    --primary-hover: #8aacff;
    --primary-soft: #1b2850;
    --on-primary: #0b1120;
    --success: #4ade80;
    --success-soft: #11291d;
    --warning: #fbbf24;
    --warning-soft: #2b2311;
    --danger: #f87171;
    --danger-soft: #311719;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::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.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon {
  width: 1.15em; height: 1.15em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
[data-icon] { display: inline-flex; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .88em; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 頂部選單 ---- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appbar-inner {
  max-width: 1120px; margin: 0 auto; height: 60px; padding: 0 16px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 1.02rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
}
.brand-mark .icon { width: 20px; height: 20px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 9px;
  color: var(--text-2); font-weight: 600; font-size: .92rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: .9rem; text-transform: uppercase;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-weight: 600; font-size: .9rem; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: .75rem; color: var(--text-2); }

/* ---- 版面 ---- */
.container { max-width: 1120px; margin: 0 auto; padding: 28px 16px 40px; }
.container.narrow { max-width: 560px; padding-top: 16px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 1.5rem; letter-spacing: .01em; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.stack { display: grid; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.card-head h2 { font-size: 1rem; }

/* ---- 按鈕 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-ghost.active { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-sm { height: 32px; padding: 0 11px; font-size: .84rem; border-radius: 8px; gap: 6px; }
.btn-lg { height: 48px; font-size: 1rem; }
.btn-block { width: 100%; }

/* ---- 表單 ---- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: .84rem; font-weight: 600; color: var(--text-2); }
.input {
  height: 40px; width: 100%; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .95rem;
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
select.input {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a96ab' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
select.input:disabled { cursor: not-allowed; opacity: .7; }
textarea.input { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.check-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px;
  max-height: 200px; overflow: auto; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.check-list .check { font-size: .9rem; }
.input-group { position: relative; }
.input-group .input { padding-right: 46px; }
.input-addon {
  position: absolute; right: 4px; top: 4px; width: 38px; height: 32px;
  border: none; background: none; color: var(--text-2); border-radius: 7px; cursor: pointer;
  display: grid; place-items: center;
}
.input-addon:hover { background: var(--surface-2); color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); margin: 0; }
.hint { font-size: .8rem; color: var(--text-3); }

/* ---- 標籤 ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge .icon { width: 12px; height: 12px; }
.badge.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge.success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---- 提示區塊 ---- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: .9rem; line-height: 1.5;
}
.alert > .icon { margin-top: 2px; }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.warning { background: var(--warning-soft); color: var(--warning); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert a { color: inherit; font-weight: 700; text-decoration: underline; }

/* ---- 表格 ---- */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  background: var(--surface-2); color: var(--text-2);
  font-weight: 600; font-size: .78rem; letter-spacing: .02em; text-align: left;
  padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .right { text-align: right; }
.table td.empty { padding: 48px 16px; text-align: center; color: var(--text-2); }
.table td.empty .icon { width: 32px; height: 32px; color: var(--text-3); display: block; margin: 0 auto 8px; }
.cell-sub { display: block; font-size: .78rem; color: var(--text-3); margin-top: 2px; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: nowrap; }

/* ---- 對話框 ---- */
dialog.modal {
  border: none; padding: 0; border-radius: var(--radius);
  width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28);
}
dialog.modal::backdrop { background: rgba(15, 23, 42, .5); }
dialog.modal.wide { width: min(620px, calc(100% - 32px)); }
dialog.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
dialog.modal form .modal-body { overflow-y: auto; }

/* ---- 分頁籤 ---- */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tab {
  appearance: none; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px;
  font: inherit; font-weight: 600; font-size: .92rem; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: .75rem; line-height: 20px; text-align: center;
  background: var(--surface-2); color: var(--text-2);
}
.tab.active .count { background: var(--primary-soft); color: var(--primary); }
.modal-body { padding: 22px 22px 18px; display: grid; gap: 14px; }
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-text { color: var(--text-2); margin-top: -6px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 14px 22px; background: var(--surface-2); border-top: 1px solid var(--border);
}

/* ---- 浮動提示 ---- */
.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none;
}
.toast {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px; border-radius: 11px;
  background: #111827; color: #f8fafc; font-size: .9rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: toast-in .2s ease-out;
}
.toast.success .icon { color: #4ade80; }
.toast.error .icon { color: #f87171; }
.toast.warning .icon { color: #fbbf24; }
.toast.info .icon { color: #93b4ff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- 登入頁 ---- */
body.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--primary-soft), transparent 70%),
    var(--bg);
}
.auth-wrap { width: min(400px, 100%); }
.auth-card { padding: 32px 28px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-mark { width: 52px; height: 52px; border-radius: 14px; margin: 0 auto 14px; }
.auth-brand .brand-mark .icon { width: 28px; height: 28px; }
.auth-brand h1 { font-size: 1.35rem; }
.auth-brand p { margin: 6px 0 0; }
.auth-foot { text-align: center; margin-top: 16px; }

/* ---- 手機 ---- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .appbar-inner { height: 56px; gap: 12px; }
  .hide-sm { display: none !important; }
  .user-role { display: none; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; gap: 4px;
  }
  .nav a { flex: 1; flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .72rem; justify-content: center; }
  .nav a .icon { width: 22px; height: 22px; }
  body.has-nav { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .container { padding-top: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 1.3rem; }

  /* 表格改為卡片 */
  .table-responsive thead { display: none; }
  .table-responsive, .table-responsive tbody, .table-responsive tr, .table-responsive td { display: block; width: 100%; }
  .table-responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table-responsive tbody tr:last-child { border-bottom: none; }
  .table-responsive tbody tr:hover td { background: none; }
  .table-responsive td { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 4px 0; border: none; text-align: right; }
  .table-responsive td::before { content: attr(data-label); color: var(--text-2); font-size: .8rem; text-align: left; flex: none; }
  .table-responsive td.lead { font-weight: 600; font-size: .98rem; text-align: left; justify-content: flex-start; padding-bottom: 6px; }
  .table-responsive td.lead::before, .table-responsive td.empty::before { display: none; }
  .table-responsive td.empty { display: block; }
  .table-responsive td:empty { display: none; }
  .table-responsive .actions { justify-content: flex-start; padding-top: 8px; flex-wrap: wrap; }
  .table-responsive td.actions-cell::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
