/* Settings-specific refinements */
/* .form-grid mobile collapse now lives in components.css (shared). */

/* RiskDeck import preview: a list of rows that wrap, not a table. A
   four-column table did not fit a dialog - its last column, the list that
   links an account, was cut off at the dialog's edge. */
.rd-list {
  display: flex;
  flex-direction: column;
}

.rd-list__label {
  font-size: var(--fs-caption);
  color: var(--color-text-secondary);
  padding-bottom: var(--space-2);
}

.rd-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.rd-row__what {
  flex: 1 1 240px;
  min-width: 0;
}

.rd-row__name {
  color: var(--color-text-primary);
  font-size: var(--fs-footnote);
  overflow-wrap: anywhere;
}

.rd-row__meta {
  color: var(--color-text-secondary);
  font-size: var(--fs-caption);
}

.rd-row__where {
  flex: 0 1 240px;
  min-width: 0;
}

.rd-row__where .select,
.rd-row__where .cselect {
  width: 100%;
}

.rd-list--files {
  margin-top: var(--space-2);
}

.rd-list--files .rd-row__where {
  flex: 0 1 auto;
}

/* Narrow: the row has wrapped, so the control takes the whole line. */
@media (max-width: 600px) {
  .rd-row__where {
    flex-basis: 100%;
  }
}

/* ==========================================================================
   Settings (look stage 4: grouped lists, as in iOS / macOS Settings)

   A quiet list of sections, and the open section as groups. A group is a
   header (title left, quiet meta right), a rounded block of rows (radius 12,
   the row's name and a 13px line under it, the value at the right, hairlines
   inset from the left) and a footnote in 13px --text-2 with a "More" link
   in --lead. No cards, no eyebrows. Computer (881px and up): the list on the
   left, the section on the right, both in one recessed window (radius 22).
   Phone (880px and down): the list is the screen; a row opens its section
   under a round back button.

   Every class here is set-*. Colours are tokens: the window is --window,
   the segmented control and the switch read form.css's --seg-track,
   --seg-thumb and --switch-off. The view's own aliases below pick the group
   surface per theme (a raised tile on the dark window, white on the light
   one), as iOS does.
   ========================================================================== */

.set-layout {
  --set-win: var(--window);
  --set-group: var(--tile);
  --set-field: var(--tile-2);
  --set-search: var(--tile-2);
  color: var(--text-1);
}

:root[data-theme="light"] .set-layout {
  --set-group: var(--desk);
  --set-field: var(--tile);
  --set-search: var(--desk);
}

.set-wrap {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 28px;
  padding: 20px;
  background: var(--set-win);
  border-radius: 22px;
  box-shadow: var(--window-edge);
  align-items: start;
}

/* ---- The list of sections ---- */
.set-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.set-side__title {
  padding: 2px 10px 12px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.set-search {
  margin-bottom: 8px;
}

.set-search__input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--set-search);
  color: var(--text-1);
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  appearance: none;
  -webkit-appearance: none;
}

.set-search__input::placeholder {
  color: var(--text-2);
}

.set-search__input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.set-search__input:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

.set-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.set-navgrp {
  display: contents;
}

.set-navgrp[hidden],
.set-nav__item[hidden],
.set-group[hidden],
.set-rw[hidden],
.set-empty[hidden] {
  display: none;
}

.set-nav .set-navrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: none;
  border-radius: 0;
  overflow: visible;
}

.set-nav__item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.set-nav__item:hover {
  background: color-mix(in srgb, var(--text-1) 5%, transparent);
  color: var(--text-1);
}

.set-nav__item.is-active {
  background: var(--set-group);
  color: var(--text-1);
}

.set-nav__item:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

/* ---- The open section ---- */
.set-main {
  max-width: 720px;
  min-width: 0;
}

.set-head {
  display: flex;
  align-items: center;
}

.set-back,
.set-head__end {
  display: none;
}

.set-h {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-1);
}

/* Group header: the title left, a quiet meta right (like a window's header). */
.set-gh-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 4px 10px;
}

.set-gh {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

.set-gm {
  font-size: 13px;
  color: var(--text-2);
  text-align: right;
}

/* The first group of the panel only: a group that is the first child of a slot inside the panel (the demo row) keeps its full gap. */
[data-settings-panel] > .set-group:first-child .set-gh-row {
  padding-top: 12px;
}

.set-gf {
  max-width: 620px;
  padding: 10px 4px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
}

.set-gf p {
  margin: 0 0 8px;
}

.set-gf code {
  font: inherit;
  color: inherit;
}

/* A group without a title (the accounts list, Technical details) still gets the gap a header would. */
.set-group > .set-rows:first-child {
  margin-top: 22px;
}

[data-settings-panel] > .set-group:first-child > .set-rows:first-child {
  margin-top: 12px;
}

.set-empty {
  margin: 0;
  padding: 16px 4px;
  font-size: 15px;
  color: var(--text-2);
}

/* "More": the long explanation behind a link in --lead, at the foot of the group. */
.set-more {
  margin-top: 8px;
}

.set-more > summary {
  display: inline-block;
  list-style: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--lead);
  cursor: pointer;
}

.set-more > summary::-webkit-details-marker {
  display: none;
}

.set-more > summary:hover {
  text-decoration: underline;
}

.set-more > summary:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
  border-radius: 10px;
}

.set-more[open] > summary {
  margin-bottom: 8px;
}

.set-more__body p:last-child {
  margin-bottom: 0;
}

.set-rows {
  display: flex;
  flex-direction: column;
  background: var(--set-group);
  border-radius: 12px;
  overflow: hidden;
}

/* A second block of rows in the same group (the actions under a status). */
.set-rows--next {
  margin-top: 12px;
}

.set-rw {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 16px;
  box-sizing: border-box;
  font-size: 14px;
  color: var(--text-1);
}

/* Hairlines between rows, inset from the left like iOS. */
.set-rows > * + *,
.set-fold {
  position: relative;
}

.set-rows > * + *::before,
.set-fold__body--rows > .set-rw::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 1px;
  background: var(--line);
  pointer-events: none;
}

.set-rw__l {
  display: block;
  min-width: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.set-sub {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-2);
}

.set-sub--label {
  margin: 0 0 6px;
}

.set-sp {
  flex: 1;
}

.set-rw__c {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.set-v {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.set-go {
  margin-left: 2px;
  font-size: 20px;
  line-height: 1;
  color: var(--text-3);
}

/* A value in the warning tone: .set-v above loads after base.css's .text-warning
   at the same specificity and used to win, so the warning read as plain grey. */
.set-v.text-warning {
  color: var(--color-warning);
}

/* A long value drops under its label. */
.set-rw--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 16px;
}

.set-rw--stack .set-rw__c {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.set-rw--block {
  display: block;
  padding: 14px 16px;
}

/* A row that leads somewhere or does something. */
.set-rw--action {
  width: 100%;
  border: 0;
  border-radius: 0;
  background: none;
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

a.set-rw--action {
  color: inherit;
  text-decoration: none;
}

.set-rw--action:hover {
  background: color-mix(in srgb, var(--text-1) 4%, transparent);
}

.set-rw--action:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: -2px;
}

.set-rw--action:disabled {
  opacity: 0.5;
  cursor: default;
}

.set-rw--action.is-danger .set-rw__l {
  color: var(--loss);
}

.set-rw__l svg {
  display: inline-block;
  vertical-align: -2px;
}

/* A row that folds open (a dictionary, the technical details). */
.set-fold > summary {
  list-style: none;
}

.set-fold > summary::-webkit-details-marker {
  display: none;
}

.set-fold__body {
  padding: 4px 16px 16px;
  border-top: 1px solid var(--line);
}

/* The folded rows are rows of the group itself: no inner padding, and no border of the body - the first row's own hairline (.set-fold__body--rows > .set-rw::before) is the one line under the summary. */
.set-fold__body--rows {
  padding: 0;
  border-top: 0;
}

.set-chev {
  display: inline-block;
  margin-left: 6px;
  font-size: 20px;
  line-height: 1;
  color: var(--text-3);
  transition: transform 0.15s ease;
}

.set-chev::before {
  content: "\203A";
}

.set-fold[open] > summary .set-chev {
  transform: rotate(90deg);
}

.set-check {
  color: var(--lead);
  visibility: hidden;
}

.set-choice.is-active .set-check {
  visibility: visible;
}

.set-link {
  color: inherit;
  text-decoration: none;
}

.set-link:hover {
  text-decoration: underline;
}

.set-link:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
  border-radius: 10px;
}

.set-acts {
  display: inline-flex;
  gap: 2px;
}

.set-rw--account.is-archived .set-rw__l {
  color: var(--text-2);
}

/* ---- Controls ---- */

/* The Apple switch: 51 x 31, a 27px thumb, off grey, on green. */
.set-switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--switch-off);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.set-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16), 0 3px 1px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease;
}

.set-switch.is-on {
  background: var(--gain);
}

.set-switch.is-on .set-switch__thumb {
  transform: translateX(20px);
}

.set-switch:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

/* Apple segmented control: a capsule track, a raised thumb on the one selected segment. */
.set-seg {
  display: inline-flex;
  gap: 0;
  padding: 2px;
  border-radius: 999px;
  background: var(--seg-track);
}

.set-seg__opt {
  min-height: 30px;
  padding: 4px 16px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-1);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.set-seg__opt.is-active {
  background: var(--seg-thumb);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.set-seg__opt:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 1px;
}

.set-rw--block:has(> .set-sws) {
  padding: 18px 16px 14px;
}

/* Accent options: an even row, a round swatch over its name. */
.set-sws {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px 8px;
}

.set-sw {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.set-sw.is-active {
  color: var(--text-1);
}

.set-sw:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 4px;
  border-radius: 12px;
}

.set-sw__dot {
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--line);
}

.set-sw.is-active .set-sw__dot {
  box-shadow: 0 0 0 2px var(--set-group), 0 0 0 4px var(--text-1);
}

.set-sw__dot--seaglass { background: var(--sw-seaglass); }
.set-sw__dot--heather { background: var(--sw-heather); }
.set-sw__dot--champagne { background: var(--sw-champagne); }
.set-sw__dot--platinum { background: var(--sw-platinum); }
.set-sw__dot--cobalt { background: var(--sw-cobalt); }
.set-sw__dot--lagoon { background: var(--sw-lagoon); }
.set-sw__dot--orchid { background: var(--sw-orchid); }
.set-sw__dot--rose { background: var(--sw-rose); }
.set-sw__dot--copper { background: var(--sw-copper); }
.set-sw__dot--slate { background: var(--sw-slate); }

.set-input {
  width: 120px;
  min-height: 36px;
  box-sizing: border-box;
  padding: 6px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--set-field);
  color: var(--text-1);
  font: inherit;
  font-size: 14px;
  text-align: right;
}

.set-input::placeholder {
  color: var(--text-2);
}

.set-input:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

.set-rw__c .vbar {
  width: 100%;
}

.set-rw__c .cselect,
.set-rw__c .select:not(.cselect__native) {
  width: auto;
  min-width: 96px;
}

.set-rw__c .select:not(.cselect__native),
.set-rw__c .cselect__trigger {
  min-height: 36px;
  padding-top: 6px;
  padding-bottom: 6px;
  border: 0;
  border-radius: 10px;
  background-color: var(--set-field);
}

/* ---- Computer: the list beside the section ---- */
/* Phone-only and computer-only parts of one piece of markup. */
@media (min-width: 881px) {
  .set-only-phone,
  .set-nav__item .set-chev {
    display: none;
  }

  /* The sections column is a list of pills, not rows: the rows' hairlines
     (.set-rows above) drew a line under some sections and not under others
     (the group's last one, the open one's pill) - the operator 21.10. */
  .set-nav .set-rows > * + *::before {
    content: none;
  }
}

/* ---- Phone (880px and down): the list is the screen ----
   A plain #/settings shows the sections as two groups of rows (Preferences,
   Your data), each with its value and a chevron; a row opens its section
   under a round back button; the back button returns to the list. The
   handlers are the computer's - only the layout and the .is-list state
   (settings.view.js listOpen) differ. */
@media (max-width: 880px) {
  .set-only-desk {
    display: none;
  }

  .set-wrap {
    display: block;
    padding: 0;
    background: none;
    border-radius: 0;
    box-shadow: none;
  }

  .set-layout.is-list .set-main,
  .set-layout:not(.is-list) .set-side {
    display: none;
  }

  /* The screen carries its own big title, so the top bar's is not repeated above it. */
  .main:has(.set-layout) .topbar__title {
    display: none;
  }

  .set-side__title {
    padding: 4px 4px 8px;
    /* 28px, not 34 (the operator 21.10: a size down on a phone or tablet). */
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.01em;
  }

  .set-search {
    display: none;
  }

  .set-nav {
    gap: 0;
  }

  .set-navgrp {
    display: block;
  }

  /* A group of one has no heading (settings.view.js navHtml), so it keeps
     the gap a heading would give; without it Data sat flush under Risk and
     the two groups read as one (the operator 21.10). */
  .set-navgrp:not([hidden]) + .set-navgrp:not(:has(.set-gh)) {
    margin-top: 22px;
  }

  .set-nav .set-navrows {
    gap: 0;
    background: var(--set-group);
    border-radius: 12px;
    overflow: hidden;
  }

  .set-nav__item {
    position: relative;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 0;
    color: var(--text-1);
  }

  .set-nav__item + .set-nav__item::before {
    content: "";
    position: absolute;
    top: 0;
    left: 16px;
    right: 0;
    height: 1px;
    background: var(--line);
  }

  .set-nav__item.is-active {
    background: transparent;
  }

  .set-nav__val {
    color: var(--text-2);
  }

  .set-nav__item .set-chev {
    margin-left: 0;
  }

  .set-nav .set-gh {
    padding: 22px 4px 8px;
  }

  .set-head {
    justify-content: space-between;
    gap: 12px;
    padding: 0 0 6px;
  }

  .set-back,
  .set-head__end {
    display: flex;
    width: 44px;
    height: 44px;
    flex: none;
  }

  .set-back {
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--set-group);
    color: var(--text-1);
    cursor: pointer;
  }

  .set-back:focus-visible {
    outline: 2px solid var(--lead);
    outline-offset: 2px;
  }

  .set-h {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0;
    text-align: center;
  }

  .set-gf {
    max-width: none;
  }

  .set-input {
    width: 110px;
    font-size: 16px;
  }

  .set-seg__opt {
    min-height: 36px;
  }

  .set-rw__c .select:not(.cselect__native),
  .set-rw__c .cselect__trigger {
    min-height: 44px;
  }

  .set-sws {
    gap: 4px;
  }

  .set-rw--block:has(> .set-sws) {
    padding: 18px 8px 14px;
  }
}

/* The import wizard (js/views/settings/import-dialog.js). */
.modal.imp-panel {
  max-width: 780px;
}

.imp-steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  list-style: none;
  margin: 0 0 var(--space-4);
  padding: 0;
  font-size: var(--fs-caption);
  color: var(--color-text-tertiary);
}

.imp-steps .is-done {
  color: var(--color-text-secondary);
}

.imp-steps .is-current {
  color: var(--color-text-primary);
  font-weight: 600;
}

.imp-from {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

:root[data-look] .imp-from__opt.is-active {
  border-color: var(--color-text-primary);
  box-shadow: inset 0 0 0 1px var(--color-text-primary);
}

.imp-error {
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.imp-error p {
  margin: var(--space-1) 0 0;
}

.imp-tally {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.imp-tally__item {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.imp-tally__n {
  font-size: var(--fs-title3);
  font-weight: 600;
  line-height: 1.2;
}

.imp-tally__label {
  font-weight: 600;
}

.imp-why {
  margin-top: var(--space-3);
}

.imp-panel .data-table td[data-label="Date"] {
  white-space: nowrap;
}

.imp-why ul {
  margin: var(--space-1) 0 0;
  padding-left: var(--space-4);
  color: var(--color-text-secondary);
}
