/* ── Settings tabs layout ───────────────────────────────────────────── */

/* Desktop: left tab rail + right content panel */
.settings-tabs-layout {
  display: flex;
  gap: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

/* ── Tab rail (desktop = vertical left column) ──────────────────────── */
.settings-tablist {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-3) var(--space-3) 0;
  border-right: 1px solid var(--divider);
  min-width: 130px;
  max-width: 160px;
  overflow-y: auto;
}

.settings-tablist__btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    color var(--transition),
    background var(--transition);
}

.settings-tablist__btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.settings-tablist__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.settings-tablist__btn[aria-selected="true"] {
  color: var(--text);
  background: var(--accent-dim);
  font-weight: 700;
}

/* ── Tab panel area ─────────────────────────────────────────────────── */
.settings-tab-panels {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  padding: var(--space-3) 0 var(--space-3) var(--space-4);
}

.settings-tab-panel {
  /* panels hide/show via [hidden] attribute, not display */
}

.settings-tab-panel[hidden] {
  display: none !important;
}

/* ── Tab panel inner spacing ────────────────────────────────────────── */
.settings-tab-panel__title {
  margin: 0 0 var(--space-1);
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.settings-tab-panel__lede {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-muted);
}

/* ── Setup tab: utility & danger blocks ─────────────────────────────── */
.settings-setup-block {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--divider);
  background: var(--surface-2);
}

.settings-setup-block--danger {
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.04);
}

.settings-setup-block__title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
}

/* ── Receipts (GREENFIELD D4) ────────────────────────────────────────
   The Google and AI panels open with what setup already collected, so the
   fields below read as "change this", not "fill this in". Selectors are
   scoped under .settings-receipt so `body.jb-v2 p` (0,1,1) cannot outrank
   the state line. ──────────────────────────────────────────────────── */
.settings-receipt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--divider);
  background: var(--surface-2);
}

.settings-receipt .settings-receipt__state {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

.settings-receipt .settings-receipt__state[data-connected="0"] {
  font-weight: 500;
  color: var(--text-muted, var(--text));
}

.settings-receipt .settings-receipt__btn {
  flex-shrink: 0;
}

/* ── Modal structure overrides for tabbed layout ────────────────────── */
.settings-modal--tabbed {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 900px);
}

.settings-modal--tabbed .settings-modal-head {
  flex-shrink: 0;
}

.settings-modal--tabbed .settings-modal-lede {
  flex-shrink: 0;
}

.settings-modal--tabbed .settings-form-error {
  flex-shrink: 0;
}

.settings-modal--tabbed .settings-tabs-layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.settings-modal--tabbed .settings-modal-actions {
  flex-shrink: 0;
  border-top: 1px solid var(--divider);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
}

/* ── jb-v2 toggle switch (Setup tab, Phase 4) ────────────────────────
   Token-only: uses --jb-* tokens from tokens-v2.css.
   The switch renders inside the legacy settings panel; tokens-v2 is
   loaded globally so --jb-* are resolvable here regardless of body.jb-v2.
   Visible state mirrors window.JB_V2.on; controller is in
   settings-jb-v2-tab.js. ─────────────────────────────────────────────── */
.jb-v2-toggle-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.jb-v2-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.jb-v2-switch__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.jb-v2-switch__track {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  background: var(--jb-line-soft);
  border-radius: var(--jb-radius-pill);
  transition: background var(--jb-transition-base);
}

.jb-v2-switch__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--jb-paper);
  border-radius: var(--jb-radius-pill);
  box-shadow: var(--jb-shadow-sticker);
  transition: transform var(--jb-transition-base);
}

.jb-v2-switch__input:checked + .jb-v2-switch__track {
  background: var(--jb-mint);
}

.jb-v2-switch__input:checked + .jb-v2-switch__track .jb-v2-switch__thumb {
  transform: translateX(16px);
}

.jb-v2-switch__input:focus-visible + .jb-v2-switch__track {
  box-shadow: var(--jb-shadow-focus);
}

.jb-v2-switch__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
}

/* ── Mobile: horizontal scroll tab strip ────────────────────────────── */
@media (max-width: 600px) {
  .settings-tabs-layout {
    flex-direction: column;
  }

  .settings-tablist {
    flex-direction: row;
    min-width: 0;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--divider);
    padding: var(--space-2) 0;
    gap: var(--space-1);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 0;
  }

  .settings-tablist::-webkit-scrollbar {
    display: none;
  }

  .settings-tablist__btn {
    flex-shrink: 0;
    padding: var(--space-1) var(--space-3);
  }

  /* UX01 C22 (SS-04, AX-18): at phone width every tab is reachable.
     The desktop rail's width:100% made each pill as wide as the list, so
     1 of 7 showed and the hidden scrollbar gave no cue. Wrap instead:
     all tabs visible, each a 44px touch target. */
  #settingsModal .settings-tablist {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  #settingsModal .settings-tablist .settings-tablist__btn {
    width: auto;
    min-height: 44px;
  }

  .settings-tab-panels {
    padding: var(--space-3) 0 0;
    overflow-y: auto;
  }
}

/* ── UX01 C21: sync bar — "Synced 2 min ago", Refresh, failure banner ──
   Built by sheets-read-load.js (#jbSyncBar) above the Today region.
   Lives here until lane A's CSS renames give states a sheet of their own.
   Scoped under .jb-sync so body.jb-v2 type rules cannot reach in. */
.jb-sync {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 1200px;
  margin: 8px auto 0;
  padding: 0 16px;
  font-family: var(--jb-font-body, inherit);
}

.jb-sync[hidden] {
  display: none;
}

.jb-sync .jb-sync__row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.jb-sync .jb-sync__label {
  margin: 0;
  font-size: 13px;
  color: var(--jb-ink-2, currentColor);
}

.jb-sync .jb-sync__refresh,
.jb-sync .jb-sync__btn {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--jb-navy, currentColor);
  text-decoration: none;
  background: var(--jb-paper, transparent);
  border: 1px solid var(--jb-line-strong, currentColor);
  border-radius: var(--jb-radius-pill, 999px);
  cursor: pointer;
}

.jb-sync .jb-sync__refresh[disabled] {
  cursor: progress;
  opacity: 0.7;
}

.jb-sync .jb-sync__refresh:focus-visible,
.jb-sync .jb-sync__btn:focus-visible {
  outline: 2px solid var(--jb-navy, currentColor);
  outline-offset: 2px;
}

.jb-sync .jb-sync__btn--primary {
  color: var(--jb-ink-inverse, Canvas);
  background: var(--jb-navy, CanvasText);
  border-color: var(--jb-navy, CanvasText);
}

.jb-sync .jb-sync__banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  color: var(--jb-ink, CanvasText);
  background: var(--jb-err-bg, Canvas);
  border: 1px solid var(--jb-err, currentColor);
  border-radius: var(--jb-radius-md, 10px);
}

.jb-sync .jb-sync__banner[hidden] {
  display: none;
}

.jb-sync[data-state="offline"] .jb-sync__banner {
  background: var(--jb-warn-bg, Canvas);
  border-color: var(--jb-warn, currentColor);
}

.jb-sync .jb-sync__banner-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 240px;
}

.jb-sync .jb-sync__banner-title {
  font-size: 15px;
  font-weight: 600;
}

.jb-sync .jb-sync__banner-detail {
  font-size: 13px;
  color: var(--jb-ink-2, currentColor);
}

.jb-sync .jb-sync__banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 600px) {
  .jb-sync .jb-sync__row {
    justify-content: space-between;
  }
  .jb-sync .jb-sync__refresh,
  .jb-sync .jb-sync__btn {
    min-height: 44px;
  }
}

/* ── UX01 C22 (SS-14): one save per tab ─────────────────────────────
   Fit Profile has its own "Save profile"; Upgrades has nothing to save.
   The footer Save beside them read as a second, competing save. */
#settingsModal[data-active-tab="fit_profile"] .settings-modal-actions,
#settingsModal[data-active-tab="upgrades"] .settings-modal-actions {
  display: none;
}

/* SS-17: file names and ports live behind a "Details" disclosure. */
#settingsModal .settings-field-details {
  margin-top: 4px;
  font-size: 13px;
}

#settingsModal .settings-field-details > summary {
  cursor: pointer;
  color: var(--jb-ink-2, currentColor);
}

/* SS-13: the raw provider error sits behind "Details". */
#settingsModal .settings-check-status__details {
  margin-top: 4px;
  font-size: 13px;
}

#settingsModal .settings-check-status__details > summary {
  cursor: pointer;
}

/* ── UX01 C22 (SS-21): setup check dialog, over the dashboard ──────── */
.jb-doctor-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  color: var(--jb-ink, CanvasText);
  background: var(--jb-paper, Canvas);
  border: 1px solid var(--jb-line-strong, currentColor);
  border-radius: var(--jb-radius-lg, 14px);
  box-shadow: var(--jb-shadow-card, none);
}

.jb-doctor-dialog::backdrop {
  background: color-mix(in srgb, var(--jb-ink, CanvasText) 40%, transparent);
}

.jb-doctor-dialog .jb-doctor-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--jb-line, currentColor);
}

.jb-doctor-dialog .jb-doctor-dialog__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.jb-doctor-dialog .jb-doctor-dialog__close {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  color: var(--jb-navy, currentColor);
  background: transparent;
  border: 1px solid var(--jb-line-strong, currentColor);
  border-radius: var(--jb-radius-pill, 999px);
  cursor: pointer;
}

.jb-doctor-dialog .jb-doctor-dialog__body {
  padding: 16px 20px 20px;
  overflow: auto;
}

.jb-doctor-dialog .doctor-panel__list,
#sheetAccessGateDoctorPanel .doctor-panel__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 12px;
  padding-left: 20px;
  font-size: 15px;
}

.jb-doctor-dialog .doctor-panel__writes,
#sheetAccessGateDoctorPanel .doctor-panel__writes {
  color: var(--jb-ink-2, currentColor);
  font-size: 13px;
}
