/* ═══════════════════════════════════════════════════════════
   SETTINGS VIEW
   ═══════════════════════════════════════════════════════════ */
.settings-view { display: grid; grid-template-rows: 48px 1fr; }
.settings-layout { display: grid; grid-template-columns: 220px 1fr; overflow: hidden; }
.settings-sidebar {
  background: var(--bg-base);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 10px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
/* .settings-nav-group*: removed — sidebar is flat 6 items (see docs/20-design-system.md) */
.settings-nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px;
  text-align: left;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  transition: all var(--trans-fast);
  width: 100%;
}
.settings-nav-btn:hover { background: var(--bg-surface); color: var(--text-primary); }
.settings-nav-btn.active { background: var(--accent-subtle); color: var(--accent); }
.settings-nav-btn span:first-child { font-size: 14px; width: 18px; text-align: center; }
/* v33: SVG icon variant — 第一 child 是 <svg class="ico">，不是 <span> */
.settings-nav-btn > svg.ico:first-child { width: 16px; height: 16px; flex-shrink: 0; }

.settings-content {
  overflow-y: auto;
  width: 100%;
}
.settings-page {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 40px;
}
.settings-page h2 {
  font-size: 22px;
  margin-bottom: 28px;
  letter-spacing: -0.02em;
}

/* SettingGroup (Cherry Studio inspired) */
.setting-group {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.setting-group.danger { border-color: color-mix(in srgb, var(--error) 25%, transparent); }
.setting-group > h3 { margin-bottom: 16px; }  /* typography from .label-micro--lg */

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}
.setting-row:last-child { border-bottom: none; }
.setting-row > div:first-child { min-width: 160px; flex: 1; }
.setting-label { font-size: 13.5px; color: var(--text-primary); }
.setting-desc { font-size: 12px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; }
.row-right { display: inline-flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 1; }
.row-right select { max-width: 320px; }
.setting-row .value { color: var(--text-secondary); font-size: 13px; }
.setting-row .value.mono { font-family: var(--font-mono); font-size: 12px; }

.setting-row input[type="text"],
.setting-row input[type="password"],
.setting-row input[type="number"],
.setting-row input[type="time"],
.setting-row input[type="email"],
.setting-row input[type="url"],
.setting-row select,
.input--field,
.input--select {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 7px 10px;
  font-size: 13px;
  min-width: 200px;
  transition: border-color var(--trans-fast);
  font-family: inherit;
}
.setting-row input.long { min-width: 320px; }
.setting-row input.input-narrow { min-width: 0; width: 70px; }
.setting-row input[type="text"]:focus,
.setting-row input[type="password"]:focus,
.setting-row input[type="number"]:focus,
.setting-row select:focus,
.input--field:focus,
.input--select:focus { outline: none; border-color: var(--accent-ring); }
.setting-row input[type="range"] { width: 160px; accent-color: var(--accent); }

/* Switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--bg-overlay);
  border-radius: 20px;
  transition: background var(--trans-fast);
  cursor: pointer;
}
.switch .slider::before {
  content: '';
  position: absolute;
  left: 2px; top: 2px;
  width: 16px; height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all var(--trans-fast);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { left: 18px; background: white; }

/* Pill */
.pill {
  display: inline-block;
  padding: 3px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 11.5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.pill.success { background: rgba(74,222,128,0.1); color: var(--success); border-color: rgba(74,222,128,0.25); }
.pill.perm-L0 { background: color-mix(in srgb, var(--info) 8%, transparent); color: var(--info); border-color: color-mix(in srgb, var(--info) 20%, transparent); }
.pill.perm-L1 { background: color-mix(in srgb, var(--warn) 8%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 20%, transparent); }
.pill.perm-L2 { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.pill.perm-L3 { background: color-mix(in srgb, var(--error) 12%, transparent); color: var(--error); border-color: color-mix(in srgb, var(--error) 30%, transparent); }

/* Buttons: use .btn + variants from style.css (see docs/20-design-system.md) */

/* Workspace editor */
.ws-editor {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-primary);
  line-height: 1.55;
  resize: vertical;
}
.ws-editor:focus { outline: none; border-color: var(--accent-ring); }
.ws-actions { margin-top: 12px; display: flex; gap: 8px; justify-content: flex-end; }

/* Skills list — default vertical; add .skills-list--grid for card grid */

/* Shortcut row */
.shortcut-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 13px;
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row div { display: flex; gap: 4px; }

/* doc-link-btn migrated → .btn.btn--pill. Margin helper for inline <a>/<button>.btn--pill in setting-desc: */
.setting-desc .btn--pill { margin-top: 8px; margin-right: 6px; text-decoration: none; }
.setting-desc a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-ring);
  transition: all var(--trans-fast);
}
.setting-desc a:hover { border-bottom-style: solid; color: var(--accent-hover); }

/* Docs viewer modal */
.docs-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 780px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: palette-in var(--trans-med) cubic-bezier(0.2, 0.8, 0.2, 1);
}
.docs-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.docs-header h3 { font-size: 14px; font-family: var(--font-mono); color: var(--text-secondary); font-weight: 500; }
.docs-body {
  padding: 24px 28px;
  overflow-y: auto;
  line-height: 1.7;
  font-size: 14px;
}
.docs-body h1 { font-size: 22px; margin-bottom: 16px; }
.docs-body h2 { font-size: 18px; margin: 20px 0 10px; color: var(--accent); }
.docs-body h3 { font-size: 15px; margin: 16px 0 8px; }
.docs-body p { margin-bottom: 10px; }
.docs-body ul, .docs-body ol { margin: 8px 0 12px 24px; }
.docs-body li { margin-bottom: 4px; }
.docs-body code { background: var(--bg-elevated); padding: 2px 6px; border-radius: 4px; font-size: 0.88em; }
.docs-body pre { background: var(--bg-base); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 12px; overflow-x: auto; margin: 10px 0; }
.docs-body pre code { background: transparent; padding: 0; }
.docs-body a { color: var(--accent); }
.docs-body blockquote { border-left: 2px solid var(--border-default); padding-left: 12px; color: var(--text-secondary); margin: 10px 0; }
.docs-body table { border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.docs-body th, .docs-body td { border: 1px solid var(--border-subtle); padding: 6px 10px; }
.docs-body th { background: var(--bg-elevated); }
.docs-body hr { border: none; border-top: 1px solid var(--border-subtle); margin: 14px 0; }

/* Integration grid (list view for 外部連結) */

/* Subtab nav (pill tabs at top of a settings page) */
.subtab-nav {
  display: flex; gap: 4px;
  padding-bottom: 14px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

/* Capability rows (AI → 用途 view) — 用途 + icon + right-side picker */

/* Provider cards (AI → 金鑰 view · Cherry Studio style) */

/* ─── Key pool: search + tile grid + modal (AI → 金鑰) ─── */

/* Section group */

/* Provider tile grid */

/* (2026-05-12 dead-code 砍：.onboarding-card / .onboarding-backdrop — 兩模式
   onboarding UI 在 BLUEPRINT 2026-04-26 決策時整個刪掉，CSS 沒清。grep 確認
   無 HTML 引用。) */

/* Brand logos via CSS mask — works for both Lobehub (currentColor) and SimpleIcons.
   The SVG is loaded as a mask (alpha shape only); color comes from background-color.
   Provider sets --icon-url via inline style; theme controls the color here. */

/* Modal */
/* Inner detail panels show their own sub-header pill — keep but slim */  /* avoid double header (modal head shows it) */

/* ─── Usage dashboard (AI → 用量) ─── */
.usage-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.usage-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.usage-stat--total { border-color: var(--accent-ring); background: var(--accent-subtle); }
.usage-stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-bottom: 6px; }
.usage-stat-value { font-size: 22px; color: var(--text-primary); font-weight: 600; font-family: var(--font-mono); letter-spacing: -0.01em; }
.usage-stat-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.usage-breakdown { display: flex; flex-direction: column; gap: 8px; }
.usage-bar-row { display: grid; grid-template-columns: 140px 1fr 180px; align-items: center; gap: 12px; font-size: 12.5px; }
.usage-bar-label { color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 11.5px; }
.usage-bar-track { height: 8px; background: var(--bg-elevated); border-radius: 4px; overflow: hidden; }
.usage-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width var(--trans-med); }
.usage-bar-value { color: var(--text-secondary); font-size: 11.5px; text-align: right; }

/* ─── Quota tier badge + monthly token bar ─── */
.quota-tier-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}
.quota-tier-badge--free { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-default); }
.quota-tier-badge--pro  { background: var(--accent-subtle); color: var(--accent); border: 1px solid var(--accent-ring); }
.quota-tier-badge--byo  { background: color-mix(in srgb, var(--info) 12%, transparent); color: var(--info); border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); }

.quota-bar { width: 100%; height: 8px; background: var(--bg-elevated); border-radius: 4px; overflow: hidden; }
.quota-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width var(--trans-med); }
.quota-bar-fill--warn { background: var(--warn); }
.quota-bar-fill--blocked { background: var(--error); }

.usage-sparkline { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-bottom: 18px; position: relative; }
.usage-spark-col { flex: 1; min-width: 16px; display: flex; flex-direction: column; align-items: center; height: 100%; cursor: default; }
.usage-spark-bar { width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; margin-top: auto; transition: background var(--trans-fast); min-height: 2px; }
.usage-spark-col:hover .usage-spark-bar { background: var(--accent-hover, var(--accent)); filter: brightness(1.2); }
.usage-spark-date { position: absolute; bottom: 0; font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); transform: translateY(2px); }
.usage-spark-col:hover .usage-spark-date { color: var(--text-primary); }

.usage-log { display: flex; flex-direction: column; gap: 2px; }
.usage-log-row {
  display: grid;
  grid-template-columns: 88px 140px 100px 80px 60px;
  gap: 10px;
  padding: 7px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  align-items: center;
}
.usage-log-row:nth-child(even) { background: var(--bg-base); }
.usage-log-time { color: var(--text-muted); font-size: 11px; }
.usage-log-model { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-log-tokens { color: var(--text-secondary); font-size: 11px; }
.usage-log-cost { color: var(--text-primary); text-align: right; }
.usage-log-dur { color: var(--text-muted); font-size: 11px; text-align: right; }

/* Theme segmented control (auto / light / dark) — 舊版（legacy；現在用 .theme-grid） */
.theme-seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-full); }
.theme-seg .btn--tab { border-radius: var(--radius-full); padding: 4px 14px; }

/* Theme picker — 卡片預覽版（2026-05-14）。
   每張卡 = mini swatch（bg + 2 條文字線 + 1 顆 accent dot）+ 標籤。
   active 用 accent ring 邊框 + 勾號 corner badge。auto-fill grid 在窄屏自動排
   3 欄、寬屏 6 欄一字排開。 */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.theme-card {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 6px;
  padding: 6px;
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--trans-fast), transform var(--trans-fast);
}
.theme-card:hover { transform: translateY(-1px); border-color: var(--border-default); }
.theme-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-ring);
}
.theme-card-preview {
  position: relative;
  height: 56px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  display: flex; flex-direction: column;
  justify-content: center;
  padding: 0 10px;
  gap: 5px;
}
.theme-card-text-line {
  height: 4px;
  width: 100%;
  border-radius: 2px;
  opacity: 0.55;
}
.theme-card-text-line--short { width: 60%; opacity: 0.35; }
.theme-card-accent-dot {
  position: absolute;
  right: 8px; bottom: 8px;
  width: 10px; height: 10px;
  border-radius: 50%;
}
.theme-card-label {
  font-size: 12px;
  text-align: center;
  color: var(--text-secondary);
}
.theme-card.is-active .theme-card-label { color: var(--accent); font-weight: 500; }

/* Accent picker */
.accent-picker { display: flex; flex-wrap: wrap; gap: 8px; row-gap: 8px; max-width: 280px; }
.accent-picker button {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  cursor: pointer;
  transition: all var(--trans-fast);
}
.accent-picker button.active { border-color: var(--text-primary); transform: scale(1.15); box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px currentColor; }
.accent-picker button:hover { transform: scale(1.1); }

/* v33 (2026-05-13): 全站設定搜尋 — top-level，所有 tab 共用 */

/* 連接 tab — unified search bar + results (Spotlight style) */

/* ═══════════════════════════════════════════════════════════
   📱 MOBILE — < 760px
   ═══════════════════════════════════════════════════════════
   這份檔案在 index.html 排在 style.css 之後載入，所以同選擇器的桌面規則
   會壓掉 style.css 裡的 mobile media query。把 settings 專屬的手機規則
   集中放在這裡（同檔同等特異度，後者贏），免得 220px sidebar 在手機上
   還在吃掉一半畫面、subtab pills 被擠到逐字換行。 */
@media (max-width: 760px) {
  /* 改成 icon-only 細條 rail（IG / Slack 桌面 rail 概念）— 8 個 tab 用
     ~52px 寬就放得下，內容區拿回 ~160px 空間。
     responsive.css 同檔有舊的 horizontal scroll-x 版本（line 229-238），
     源序在前會被這段覆蓋。 */
  .settings-layout { grid-template-columns: 52px 1fr; grid-template-rows: 1fr; }
  .settings-sidebar {
    flex-direction: column;
    overflow-x: visible;
    overflow-y: auto;
    padding: 8px 4px;
    border-right: 1px solid var(--border-subtle);
    border-bottom: none;
  }
  .settings-nav-btn {
    justify-content: center;
    gap: 0;
    padding: 12px 0;
  }
  .settings-nav-btn > span { display: none; }
  .settings-nav-btn > svg.ico:first-child { width: 22px; height: 22px; }
}

/* ─── 🛡 帳號 & 隱私 + audit log（2026-05-09）───────────────────── */
.danger-row { border-top: 1px solid color-mix(in srgb, var(--error) 20%, transparent); padding-top: 14px; margin-top: 4px; }
.audit-list {
  margin-top: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  max-height: 320px; overflow-y: auto;
}
.audit-entry {
  display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; align-items: center;
  padding: 8px 12px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.audit-entry:last-child { border-bottom: none; }
.audit-action {
  font-family: var(--font-mono); font-weight: 500;
  color: var(--accent);
  font-size: 11.5px;
}
.audit-resource { color: var(--text-secondary); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-time { color: var(--text-muted); font-size: 11px; font-family: var(--font-mono); white-space: nowrap; }
.audit-empty {
  margin-top: 12px;
  padding: 16px;
  text-align: center;
  color: var(--text-muted); font-size: 12.5px;
  background: var(--bg-elevated); border-radius: var(--radius-md);
}

/* ─── 🛡 Admin 後台 — stats grid + users 表（2026-05-09）──────── */
.admin-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-top: 12px;
}
.admin-stat-card {
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.admin-stat-label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }
.admin-stat-value { font-size: 22px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }

.admin-table-wrap {
  margin-top: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  overflow-x: auto;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.admin-table th, .admin-table td {
  padding: 8px 12px; text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}
.admin-table th { color: var(--text-muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; background: rgba(255, 255, 255, 0.02); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table td.mono { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-secondary); }
.admin-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.admin-audit-entry { grid-template-columns: 130px 90px 1fr auto; }
.audit-user { color: var(--text-secondary); font-size: 11px; }

/* ─── 重複帳號（同 email 多 UUID）合併 UI ─── */
.dup-group {
  margin-bottom: 14px;
  padding: 12px;
  background: color-mix(in srgb, var(--error) 4%, transparent);
  border: 1px solid color-mix(in srgb, var(--error) 20%, transparent);
  border-radius: var(--radius-md);
}
.dup-email {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 13.5px;
}
.dup-table { font-size: 11.5px; }
.dup-table th { background: rgba(255, 255, 255, 0.03); }

/* ─── Admin role badges + action buttons ─── */
.admin-user-cell { display: flex; flex-direction: column; gap: 2px; }
.admin-user-email { font-size: 10.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.admin-role {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10.5px; font-weight: 500;
  white-space: nowrap;
}
.admin-role-env   { background: rgba(255, 200, 100, 0.12); color: #ffc864; border: 1px solid rgba(255, 200, 100, 0.25); }
.admin-role-admin { background: rgba(91, 108, 255, 0.15);  color: #8a9bff; border: 1px solid rgba(91, 108, 255, 0.3); }
.admin-role-user  { background: rgba(255, 255, 255, 0.04); color: var(--text-muted); border: 1px solid rgba(255, 255, 255, 0.08); }
.admin-action-btn { padding: 3px 10px; font-size: 11.5px; }
.admin-row-self td { background: rgba(91, 108, 255, 0.04); }
