/* Settings page (#/settings): sections with the title on the left and a card on the right (stacked on
   smaller screens). Page-only classes use the set- prefix; colours come from tokens. The two theme
   previews deliberately show fixed light/dark colours: they picture the themes, not the current one. */

.set-sections { display: flex; flex-direction: column; min-width: 0; }
.set-section {
  display: grid; grid-template-columns: minmax(200px, 260px) minmax(0, 1fr); gap: var(--space-4) var(--space-10);
  padding: var(--space-8) 0; border-top: 1px solid var(--border); min-width: 0;
}
.set-section:first-child { padding-top: var(--space-2); border-top: 0; }
.set-section-head { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }
.set-section-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); letter-spacing: -0.005em; }
.set-section-text { font-size: var(--fs-sm); line-height: 1.5; color: var(--text-muted); max-width: 40ch; }
.set-section-body { min-width: 0; max-width: 780px; }
@media (max-width: 1100px) {
  .set-section { grid-template-columns: minmax(0, 1fr); gap: var(--space-3); padding: var(--space-6) 0; }
  .set-section-text { max-width: 68ch; }
}

.set-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.set-fine { font-size: var(--fs-xs); line-height: 1.5; color: var(--text-muted); }

/* ---------------------------------------------------------------- appearance */

.set-theme-body { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-6); }
.set-theme-body > .stack { flex: 1 1 260px; }
.segmented.set-theme { align-self: flex-start; }
.segmented.set-theme .segmented-item span { min-height: 32px; padding: 0 var(--space-4); font-size: var(--fs-base); }
.set-theme-note { font-size: var(--fs-sm); color: var(--text-muted); }

.set-previews { display: flex; gap: var(--space-4); flex: none; }
.set-preview { display: flex; flex-direction: column; align-items: center; gap: var(--space-1-5); }
.set-preview-window {
  display: flex; width: 124px; height: 80px; overflow: hidden; border-radius: var(--radius);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-xs);
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.set-preview.is-active .set-preview-window { border-color: var(--primary-text); box-shadow: 0 0 0 2px var(--primary-text); }
.set-preview-side { display: flex; flex-direction: column; gap: 5px; width: 30px; padding: 8px 6px; }
.set-preview-side i { display: block; height: 4px; border-radius: 2px; }
.set-preview-side i:first-child { background: var(--green-600) !important; width: 10px; height: 10px; border-radius: 3px; margin-bottom: 2px; }
.set-preview-main { display: flex; flex-direction: column; gap: 5px; flex: 1; padding: 9px 8px; }
.set-preview-main i { display: block; border-radius: 2px; height: 4px; }
.set-preview-title { width: 55%; height: 6px !important; }
.set-preview-line.is-short { width: 70%; }
.set-preview-total { width: 40%; height: 8px !important; margin-top: auto; background: var(--lime-500) !important; }
.set-preview-label { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-muted); }
.set-preview.is-active .set-preview-label { color: var(--primary-text); font-weight: var(--fw-semibold); }

.set-preview.is-light .set-preview-window { background: #f6f7f9; }
.set-preview.is-light .set-preview-side { background: #ffffff; border-right: 1px solid #e3e8ef; }
.set-preview.is-light .set-preview-side i, .set-preview.is-light .set-preview-line { background: #dfe4eb; }
.set-preview.is-light .set-preview-title { background: #0f1722; }
.set-preview.is-dark .set-preview-window { background: #0b0f14; }
.set-preview.is-dark .set-preview-side { background: #0e1319; border-right: 1px solid #252d38; }
.set-preview.is-dark .set-preview-side i, .set-preview.is-dark .set-preview-line { background: #2a3340; }
.set-preview.is-dark .set-preview-title { background: #e7ebf0; }

@media (max-width: 640px) {
  .set-theme-body { gap: var(--space-5); }
  .segmented.set-theme { display: flex; width: 100%; }
  .segmented.set-theme .segmented-item { flex: 1; }
  .segmented.set-theme .segmented-item span { flex: 1; padding: 0 var(--space-2); }
  .set-previews { width: 100%; justify-content: center; }
  .set-preview-window { width: 112px; height: 72px; }
}

/* ---------------------------------------------------------------- Telegram (a pointer to its page) */

.set-link { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3) var(--space-4); }
.set-link-icon {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius);
  background: var(--primary-soft); color: var(--primary-text); border: 1px solid var(--primary-border);
}
.set-link-text { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.set-link-title { font-weight: var(--fw-medium); color: var(--text); }
.set-link-btn { flex: none; }
.set-link-more { border-top: 1px solid var(--border-subtle); }
@media (max-width: 640px) {
  .set-link { align-items: flex-start; }
  .set-link-text { flex-basis: calc(100% - 56px); }
  .set-link-btn { width: 100%; }
}

/* ---------------------------------------------------------------- CSV separator */

.set-csv-head { position: relative; min-width: 0; }
.set-save-state {
  position: absolute; top: 0; right: 0; display: inline-flex; align-items: center; gap: var(--space-1-5);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-muted); line-height: 20px;
}
.set-save-state.is-saved { color: var(--success-text); }
.set-sep {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: var(--radius-xs);
  background: var(--surface-3); border: 1px solid var(--border); font-family: var(--font-mono); font-size: var(--fs-md);
  font-weight: var(--fw-bold); line-height: 1; color: var(--text);
}
/* .is-checked (set by ui.radioCards) for browsers without :has(); separate rules, so neither drops the other */
.radio-card.is-checked .set-sep { background: var(--surface); border-color: var(--primary-border); color: var(--primary-text); }
.radio-card:has(.radio:checked) .set-sep { background: var(--surface); border-color: var(--primary-border); color: var(--primary-text); }
.set-csv-desc { display: flex; flex-direction: column; gap: var(--space-2-5); }
.set-csv-sample {
  display: block; width: fit-content; max-width: 100%; overflow-x: auto; padding: var(--space-1-5) var(--space-2-5);
  font-size: 12px; line-height: 1.55; white-space: nowrap; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- password */

.set-meter { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-1); height: 4px; }
.set-meter-bar { border-radius: 2px; background: var(--surface-3); transition: background-color var(--dur) var(--ease); }
.set-meter[data-tone="danger"] .set-meter-bar.is-on { background: var(--danger-text); }
.set-meter[data-tone="warning"] .set-meter-bar.is-on { background: var(--warning); }
.set-meter[data-tone="success"] .set-meter-bar.is-on { background: var(--success); }
.set-strength-text { font-weight: var(--fw-medium); }
.set-strength-text.text-muted { color: var(--text-muted); }
.set-footer-note { display: inline-flex; align-items: center; gap: var(--space-1-5); }
.set-footer-note .icon { flex: none; color: var(--text-subtle); }
.set-password-card .form-grid { align-items: start; }
@media (max-width: 640px) {
  .set-password-card .card-footer > .btn { width: 100%; }
}

/* ---------------------------------------------------------------- storage */

.set-paths { display: grid; grid-template-columns: minmax(100px, max-content) minmax(0, 1fr); gap: var(--space-4) var(--space-5); margin: 0; }
.set-paths dt { padding-top: 8px; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
.set-paths dd { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; margin: 0; }
.set-path {
  display: flex; align-items: center; gap: var(--space-1); min-height: var(--control-h); min-width: 0;
  padding: 3px 3px 3px var(--space-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.set-path-text {
  flex: 1 1 auto; min-width: 0; padding: 0; border: 0; background: none; font-size: 12.5px; line-height: 1.45;
  color: var(--text); overflow-wrap: anywhere; word-break: break-all;
}
@media (max-width: 560px) {
  .set-paths { grid-template-columns: minmax(0, 1fr); gap: var(--space-1-5); }
  .set-paths dt { padding-top: 0; }
  .set-paths dd { margin-bottom: var(--space-3); }
}

.set-tree-wrap { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.set-tree { list-style: none; margin: 0; padding: 0; min-width: 0; }
.set-tree.is-root { padding: var(--space-2) var(--space-4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.set-tree .set-tree { margin-left: 8px; padding-left: var(--space-4); border-left: 1px solid var(--border-strong); }
.set-tree-row { position: relative; padding: 5px 0 5px 24px; min-width: 0; line-height: 1.45; }
.set-tree-icon { position: absolute; left: 0; top: 6px; display: inline-flex; color: var(--text-subtle); }
.set-tree-name {
  margin-right: var(--space-2); font-family: var(--font-mono); font-size: 12.5px; font-weight: var(--fw-semibold);
  color: var(--text); overflow-wrap: anywhere;
}
.set-tree-text { font-size: var(--fs-sm); color: var(--text-muted); }
@media (max-width: 640px) {
  .set-tree.is-root { padding: var(--space-2) var(--space-3); }
  .set-tree-name { display: block; margin-right: 0; }
  .set-about > .logo-mark { width: 40px; height: 40px; }
}

/* ---------------------------------------------------------------- about */

.set-about { display: flex; align-items: flex-start; gap: var(--space-4); }
.set-about > .logo-mark { flex: none; width: 48px; height: 48px; }
.set-about-text { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }
.set-about-name { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.set-about-desc { color: var(--text-muted); max-width: 66ch; }

.set-error { padding-top: var(--space-6); border-top: 1px solid var(--border); }

/* ---------------------------------------------------------------- sign-in (settings-signin.js) */

.set-signin > .card-body + .set-provider, .set-provider + .set-provider, .set-provider + .card-body { border-top: 1px solid var(--border); }
.set-signin-error { padding-top: 0; }
.set-signin-error:empty { display: none; }
.set-env-badge { margin-left: var(--space-1); }

.set-provider { min-width: 0; }
.set-provider-head { display: flex; align-items: flex-start; gap: var(--space-3) var(--space-4); padding: var(--space-4) var(--space-5); }
.set-provider-logo {
  flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius);
  background: #ffffff; border: 1px solid var(--border); box-shadow: var(--shadow-xs);
}
.set-provider-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.set-provider-title { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.set-provider-desc { font-size: var(--fs-sm); color: var(--text-muted); }
.set-provider-access { margin-top: 2px; font-size: var(--fs-xs); line-height: 1.5; color: var(--text-muted); }
.set-provider-access[hidden] { display: none; }
.set-provider-access .icon { vertical-align: -2px; color: var(--text-subtle); }
.set-provider-access strong { font-weight: var(--fw-semibold); }
.set-provider-you { display: inline-flex; align-items: center; gap: var(--space-1-5); margin-top: 2px; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--success-text); }
.set-provider-toggle { flex: none; align-self: center; }
.set-provider-toggle .icon { transition: transform var(--dur) var(--ease); }
.set-provider-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }
.set-provider-body {
  display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-1) var(--space-5) var(--space-5) calc(var(--space-5) + 40px + var(--space-4));
  animation: page-in var(--dur) var(--ease);
}
.set-provider-body .form-grid { align-items: start; }
.set-rule-note:empty { display: none; }
/* "Connection" / "Who may sign in" inside a provider */
.set-subhead {
  display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-2); font-size: var(--fs-xs);
  font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-subtle);
}
.set-subhead::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }
.set-subhead:first-child { margin-top: 0; }

/* a switch with an error line (and notes) under it */
.set-switch-field { gap: var(--space-2); }
.set-whole-warning { margin-top: var(--space-2); }
.set-whole-warning:empty { display: none; }
.set-whole-note { padding-left: 48px; }
.set-whole-note .icon { vertical-align: -2px; color: var(--success-text); }
.set-guide-layers .icon { color: var(--success-text) !important; }

.set-copy-box .set-path-text.is-empty { font-family: var(--font-sans); color: var(--text-muted); word-break: normal; }
.set-chips-static { display: flex; flex-wrap: wrap; gap: var(--space-1-5); min-height: var(--control-h); align-items: center; padding: 4px 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.set-secret .input-group .btn { flex: none; }
.set-secret-kept::placeholder { color: var(--text-muted); }
.set-secret-remove { color: var(--text-muted); text-decoration: underline; }
.set-secret-remove:hover { color: var(--danger-text); }
.set-narrow .input { max-width: 360px; }

.set-test { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
.set-test-result:empty { display: none; }

/* "How to set it up": a native disclosure */
.set-guide { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.set-guide-summary {
  display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2-5) var(--space-3); cursor: pointer; list-style: none;
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); border-radius: var(--radius);
}
.set-guide-summary::-webkit-details-marker { display: none; }
.set-guide-summary > .icon:first-child { color: var(--primary-text); }
.set-guide-summary > .icon:last-child { margin-left: auto; color: var(--text-subtle); transition: transform var(--dur) var(--ease); }
.set-guide[open] > .set-guide-summary > .icon:last-child { transform: rotate(180deg); }
.set-guide-summary:hover { background: var(--surface-3); }
.set-guide-summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.set-guide-body { display: flex; flex-direction: column; gap: var(--space-3); padding: 0 var(--space-4) var(--space-4) var(--space-4); }
.set-guide-steps { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding-left: var(--space-5); font-size: var(--fs-sm); line-height: 1.5; }
.set-guide-steps li::marker { color: var(--text-subtle); font-weight: var(--fw-semibold); }
.set-guide-body .set-fine .icon { vertical-align: -2px; color: var(--text-subtle); }

.set-guard:empty { display: none; }
.set-guard .set-fine { padding-left: 48px; }
.set-guard .set-fine .icon { vertical-align: -2px; }

@media (max-width: 640px) {
  .set-provider-head { flex-wrap: wrap; padding: var(--space-4); }
  .set-provider-text { flex-basis: calc(100% - 56px); }
  .set-provider-toggle { width: 100%; }
  .set-provider-body { padding: 0 var(--space-4) var(--space-4); }
  .set-signin .card-footer .cluster { width: 100%; }
  .set-signin .card-footer .cluster > .btn { flex: 1 1 auto; }
  .set-guard .set-fine, .set-whole-note { padding-left: 0; }
}
