/* settings: page styles on top of the design-system primitives in /styles.css.
   Tokens only (var(--...)); no hex, no rgba, no new hues.
   Covers the Settings dialog (screens/settings.js) and the screens it embeds:
   advisors/seats (agents.js), billing (billing.js), AI usage (ai-usage.js).
   The permission grid (.perm-*) is also used by screens/client-accounts.js. */

/* ── Frame: a fixed rail of sections + a scrolling content column ── */
.dlg.dlg--settings {
  width: min(1000px, 100%); height: min(700px, 90vh); max-height: none;
  display: grid; grid-template-columns: 228px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
  overflow: clip; /* only the content column scrolls, even under scrollIntoView / focus */
}
.dlg--settings > .dlg-body { display: contents; }
.dlg--settings > .dlg-head { grid-column: 2; grid-row: 1; padding: 20px 20px 12px 32px; }
.set-rail {
  grid-column: 1; grid-row: 1 / span 2; min-height: 0;
  display: flex; flex-direction: column; gap: 3px;
  padding: 20px 12px; background: var(--bg); border-right: 1px solid var(--line-2);
  overflow-y: auto; scrollbar-width: none;
}
.set-rail::-webkit-scrollbar { display: none; }
.set-rail-title { padding: 2px 10px 14px; font-size: var(--fs-section); font-weight: 700; letter-spacing: -0.01em; }
.set-rail-list { display: flex; flex-direction: column; gap: 3px; }
.set-rail-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  height: 40px; padding: 0 10px; flex: none; border-radius: var(--r-sm);
  font-size: var(--fs-body); font-weight: 500; color: var(--ink-2); text-align: left; white-space: nowrap;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), box-shadow 160ms var(--ease-out), transform 120ms var(--ease-out);
}
.set-rail-item svg { color: var(--ink-3); transition: color 160ms; }
.set-rail-item:hover { background: var(--soft); color: var(--ink); }
.set-rail-item:active { transform: scale(.98); }
.set-rail-item[aria-current="page"] { background: var(--panel); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.set-rail-item[aria-current="page"] svg { color: var(--ink); }
.set-main { grid-column: 2; grid-row: 2; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.set-body { padding: 4px 32px 32px; }
.set-body [hidden] { display: none !important; }

/* ── Content parts ───────────────────────────────────────────────── */
.set-group + .set-group, .set-group + .set-actions--foot { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line-2); }
.set-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.set-group-head .set-h { margin: 0; }
.set-h { font-size: var(--fs-body); font-weight: 600; margin: 0 0 6px; }
.set-h--lead { font-size: var(--fs-section); font-weight: 700; }
.set-sub { font-size: var(--fs-meta); color: var(--ink-3); margin: 0 0 16px; max-width: 72ch; }
.set-gap { margin-top: 12px; }
.set-gap-b { margin-bottom: 16px; }
.set-narrow { max-width: 420px; }
.set-narrow-lg { max-width: 600px; }
.set-back { margin: 0 0 14px -10px; }
.set-with-ic { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.set-with-ic > svg { color: var(--ink-3); }
.set-inline { display: flex; gap: 8px; }
.set-inline > input { flex: 1; min-width: 0; }
.set-msg { font-size: var(--fs-meta); color: var(--ink-3); margin: 6px 0 0; min-height: 0; }
.set-msg:empty { display: none; }
.set-msg.is-ok { color: var(--good-ink); }
.set-msg.is-err { color: var(--alert-ink); }
.set-note--caution { color: var(--caution-ink); }
.set-note--alert { color: var(--alert-ink); }
.set-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.set-actions .set-msg { margin: 0 auto 0 0; }
.set-actions--start { justify-content: flex-start; margin-top: 16px; }
.set-actions--foot { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.set-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.set-toolbar .set-sub { margin: 0; }
.set-search { display: flex; gap: 8px; margin-bottom: 12px; }
.set-search .search-input { flex: 1; min-width: 0; }
/* 6-digit authenticator codes */
.set-code { font-family: var(--font-mono); font-size: 20px; letter-spacing: .4em; text-align: center; max-width: 240px; }
.set-secret { font-size: var(--fs-meta); letter-spacing: .08em; }
.set-lock { width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--soft); color: var(--ink-2); margin-bottom: 14px; }

/* Key / value rows (firm details, cost previews) */
.set-kv { display: grid; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr); margin: 0; }
.set-kv > dt, .set-kv > dd { margin: 0; padding: 12px 0; border-bottom: 1px solid var(--line-2); font-size: var(--fs-body); }
.set-kv > dt { color: var(--ink-3); padding-right: 16px; }
.set-kv > dt:last-of-type, .set-kv > dd:last-of-type { border-bottom: 0; }
.set-kv--tight > dt, .set-kv--tight > dd { padding: 10px 0; }

/* Rows on dividers (factors, folders, notifications, advisors) */
.set-list { display: flex; flex-direction: column; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line-2); min-width: 0; }
.set-row:last-child { border-bottom: 0; }
.set-row-ic { flex: none; width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--soft); color: var(--ink-2); }
.set-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.set-row-title { font-size: var(--fs-body); font-weight: 500; color: var(--ink); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }
.set-row-meta { font-size: var(--fs-meta); color: var(--ink-3); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.set-row-actions { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.set-row--switch { cursor: pointer; margin: 0; font-weight: 400; }

/* Tables inside settings: actions stay on one line (.table-wrap scrolls) */
.set-table td { vertical-align: middle; }
.set-table .set-row-actions { flex-wrap: nowrap; }
.set-table .tag + .set-cell-meta { margin-top: 4px; }
/* Figures sit in a ~700px column: four fit on one row. */
.set-body .figures { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.set-body .figures .figure { font-size: 24px; }
.set-sub + .set-group { margin-top: 28px; }
.set-cell-title { font-weight: 500; }
.set-cell-meta { font-size: var(--fs-meta); color: var(--ink-3); }

/* Switch (notification preferences) */
input.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative;
  width: 40px; height: 24px; padding: 0; margin: 0; border-radius: 99px; cursor: pointer;
  background: var(--line); border: 0; box-shadow: none;
  transition: background 180ms var(--ease-out);
}
input.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel); box-shadow: var(--shadow);
  transition: transform 220ms var(--ease-spring);
}
input.switch:checked { background: var(--ink); }
input.switch:checked::after { transform: translateX(16px); }
input.switch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* QR code: scanners need dark modules on a light ground in both themes. */
.set-enroll { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 16px; }
.set-qr { flex: none; padding: 12px; border-radius: var(--r-md); color-scheme: light; background: Canvas; border: 1px solid var(--line); }
.set-qr img { display: block; width: 180px; height: 180px; }
.set-enroll-side { flex: 1 1 220px; min-width: 200px; }

/* Allowlist pickers (team form) */
.set-picker { margin-top: 14px; }
.set-picker-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.set-picker-bar .search-input { flex: 1; min-width: 180px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; max-height: 320px; overflow-y: auto; padding: 2px; }
.pick-empty { grid-column: 1 / -1; margin: 6px 0; }
.pick {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel);
  cursor: pointer; font-weight: 400; color: var(--ink);
  transition: border-color 160ms var(--ease-out), background 160ms var(--ease-out);
}
.pick:hover { background: var(--soft); }
.pick:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.pick:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.pick-avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--soft); border: 1px solid var(--line); color: var(--ink-2); font-size: var(--fs-min); font-weight: 600; }
.pick:has(input:checked) .pick-avatar { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.pick-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-name { font-size: var(--fs-ui); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-meta { font-size: var(--fs-min); color: var(--ink-3); }
.pick-check { flex: none; color: var(--ink); opacity: 0; transition: opacity 140ms; }
.pick:has(input:checked) .pick-check { opacity: 1; }

/* Permission grid: one block per section, one chip per permission */
.perm-grid { display: flex; flex-direction: column; gap: 10px; }
.perm-block { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-md); }
.perm-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.perm-title { font-size: var(--fs-ui); font-weight: 600; }
.perm-desc { font-size: var(--fs-meta); color: var(--ink-3); margin: 2px 0 10px; }
.perm-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.perm-desc + .perm-chips { margin-top: 0; }
.perm-chip {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  height: 32px; padding: 0 12px 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  font-size: var(--fs-min); font-weight: 500; cursor: pointer; user-select: none;
  transition: background 140ms var(--ease-out), border-color 140ms var(--ease-out), color 140ms var(--ease-out), transform 120ms;
}
.perm-chip:hover { background: var(--soft); }
.perm-chip:active { transform: scale(.97); }
.perm-chip svg { color: var(--ink-3); }
.perm-on { display: none; }
.perm-off, .perm-on { line-height: 0; }
.perm-chip:has(input:checked) { background: var(--soft); border-color: var(--ink-2); color: var(--ink); }
.perm-chip:has(input:checked) .perm-on { display: inline-flex; }
.perm-chip:has(input:checked) .perm-off { display: none; }
.perm-chip:has(input:checked) svg { color: var(--ink); }
.perm-chip--sensitive { color: var(--alert-ink); }
.perm-chip--sensitive svg { color: var(--alert); }
.perm-chip--sensitive:has(input:checked) { background: var(--tint-r); border-color: transparent; color: var(--alert-ink); }
.perm-chip--sensitive:has(input:checked) svg { color: var(--alert-ink); }
.perm-chip:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Google Drive accounts and folder choosers */
.drive-acc { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 4px 20px; margin-bottom: 12px; }
.drive-acc-head { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.fold-list { border: 1px solid var(--line); border-radius: var(--r-md); max-height: 300px; overflow-y: auto; }
.fold-item, .fold-open {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px;
  text-align: left; color: var(--ink); transition: background 120ms var(--ease-out);
}
.fold-item + .fold-item, .fold-row + .fold-row { border-top: 1px solid var(--line-2); }
.fold-item:hover, .fold-open:hover { background: var(--soft); }
.fold-item[aria-pressed="true"] { background: var(--soft); }
.fold-check { flex: none; color: var(--ink); opacity: 0; }
.fold-item[aria-pressed="true"] .fold-check { opacity: 1; }
.fold-row { display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.fold-open { flex: 1; min-width: 0; }
.fold-chev { color: var(--ink-3); flex: none; }
.fold-row .status { flex: none; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-height: 28px; margin-bottom: 8px; }
.crumb { padding: 3px 6px; border-radius: 6px; font-size: var(--fs-meta); color: var(--ink-2); }
.crumb:hover:not(:disabled) { background: var(--soft); color: var(--ink); }
.crumb:disabled { color: var(--ink); font-weight: 600; cursor: default; }
.crumb-sep { color: var(--ink-3); }

/* Vault: test-data rows carry a faint caution stripe */
tr.is-mock td { background: repeating-linear-gradient(45deg, transparent 0 8px, color-mix(in oklch, var(--caution) 7%, transparent) 8px 16px); }

/* Advisors (seat roster) */
.seat-bulk {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 8px; border-radius: var(--r-md); background: var(--soft);
}
.seat-row { padding: 12px 0; }
.seat-check { flex: none; width: 20px; display: grid; place-items: center; }
.seat-row .set-row-actions .status { margin-right: 4px; }
.seat-row .dot-sep { margin: 0 2px; }

/* AI usage */
.aiu-month { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.aiu-month label { margin: 0; }
.aiu-month input { width: auto; }
.aiu-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.aiu-notes { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-meta); color: var(--ink-3); }
.aiu-override { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.aiu-override .field { margin: 0; width: 160px; }
.aiu-override .aiu-reason { flex: 1; min-width: 200px; }
.meter { position: relative; height: 10px; border-radius: 99px; background: var(--line-2); overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--ink); border-radius: inherit; transition: width 600ms var(--ease-out); }
.meter.is-caution .meter-fill { background: var(--caution); }
.meter.is-alert .meter-fill { background: var(--alert); }
.meter-tick { position: absolute; left: 80%; top: 0; bottom: 0; width: 2px; background: var(--panel); }

/* ── Phone width: the rail becomes a scrolling row above the content ── */
@media (max-width: 640px) {
  .dlg.dlg--settings { height: 92vh; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .dlg--settings > .dlg-head { grid-column: 1; padding: 16px 12px 8px 20px; }
  .set-rail { grid-column: 1; grid-row: 2; flex-direction: row; padding: 4px 12px 10px; background: transparent; border-right: 0; border-bottom: 1px solid var(--line-2); overflow-x: auto; }
  .set-rail-title { display: none; }
  .set-rail-list { flex-direction: row; }
  .set-rail-item { width: auto; height: 36px; }
  .set-main { grid-column: 1; grid-row: 3; }
  .set-body { padding: 16px 20px 28px; }
  .set-kv { grid-template-columns: minmax(0, 1fr); }
  .set-body .figures { grid-template-columns: minmax(0, 1fr); }
  .set-kv > dt { padding-bottom: 0; border-bottom: 0; }
  .set-row { flex-wrap: wrap; }
  .set-row-actions { width: 100%; justify-content: flex-start; padding-left: 46px; }
  .seat-row .set-row-actions { padding-left: 32px; }
  .set-inline { flex-wrap: wrap; }
}
