/* Klod settings — two-column form, cream palette */

.settings-main { overflow-y: auto; }

/* Anthropic-style layout: settings stretch nearly edge-to-edge with a max
   cap so on ultra-wide monitors content stays readable. Left nav is a stable
   240px column; right content expands to fill the rest. */
/* Settings as a centred DIALOG card over the app background: left column =
   search + icon nav, right column = scrollable panels, close X top-right. */
.settings {
  position: relative;
  width: min(960px, calc(100vw - 340px));
  margin: 48px auto 64px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 80px -16px rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  padding: 0;
}
:root[data-theme="dark"] .settings {
  box-shadow: 0 24px 80px -16px rgba(0, 0, 0, 0.65), 0 4px 16px rgba(0, 0, 0, 0.30);
}

.settings__title.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.settings__close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px; height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  z-index: 5;
  transition: background 120ms ease, color 120ms ease;
}
.settings__close:hover { background: var(--hover-bg); color: var(--text); }

.settings__body {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 0;
  align-items: stretch;
  height: min(720px, calc(100vh - 140px));
}

/* Left column: a slightly darker strip, like the original dialog */
.settings__sidecol {
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  background: rgba(31, 30, 28, 0.025);
  overflow-y: auto;
}
:root[data-theme="dark"] .settings__sidecol { background: rgba(0, 0, 0, 0.14); }

.settings__search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  margin-bottom: 14px;
  background: var(--bg);
}
.settings__search input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text);
}
.settings__search input::placeholder { color: var(--text-muted); }

.settings__nav-label {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 2px 12px 8px;
}

/* Right column scrolls on its own */
.settings__content {
  overflow-y: auto;
  padding: 28px 36px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.settings__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings__nav-item.is-filtered { display: none; }
.settings__nav-item svg { flex-shrink: 0; }
.settings__nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-soft);
  text-decoration: none;
  text-align: left;
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  width: 100%;
}
.settings__badge {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(31, 30, 28, 0.10);
  color: var(--text-soft);
  line-height: 1.2;
}
.settings__nav-item.is-active .settings__badge {
  background: rgba(245, 242, 234, 0.18);
  color: var(--btn-fg);
}
.settings__group-title .settings__badge {
  vertical-align: 4px;
  margin-left: 8px;
}

.settings__empty {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0 40px;
}
.settings__empty-text {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-soft);
  margin: 0;
}

/* ─── Usage panel ─── */
.settings__usage-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.settings__usage-head .settings__group-title { margin: 0; }
.settings__usage-plan-badge {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  line-height: 1.2;
}
/* Anthropic-style: fixed-width label column on the left (single line + a hint
   underneath), thin 4px bar in the middle taking most of the row, the percent
   reading on the far right. No row dividers — pure whitespace separates rows. */
.settings__usage-row {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 90px;
  gap: 32px;
  align-items: center;
  padding: 14px 0;
}
.settings__usage-rowhead {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.settings__usage-rowhead strong {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.settings__usage-rowhead .settings__hint {
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--text-soft);
  margin: 0;
}
.settings__usage-bar {
  /* Anthropic uses ~4px tall bars — matches their minimal aesthetic. Less
     visual weight than Klod's previous 6-8px bars; data still reads cleanly. */
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.settings__usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 420ms cubic-bezier(0.4, 0, 0.2, 1);
}
.settings__usage-fill.is-warning { background: #E8A23A; }
.settings__usage-fill.is-danger  { background: #C75A4D; }
.settings__usage-percent {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
}
.settings__usage-updated {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}
.settings__usage-refresh {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.settings__usage-refresh:hover {
  background: var(--hover-bg);
  color: var(--text);
}
.settings__usage-refresh.is-spinning svg {
  animation: settings-usage-spin 600ms linear;
}
@keyframes settings-usage-spin {
  to { transform: rotate(360deg); }
}

/* Mid-width screens (e.g. 880-1100px): label column shrinks but stays
   single-row layout so the bar doesn't pop below the label. */
@media (max-width: 1100px) {
  .settings__usage-row {
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) 80px;
    gap: 24px;
  }
}
@media (max-width: 720px) {
  .settings__usage-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .settings__usage-percent { text-align: left; min-width: 0; }
}

/* ─── Billing: plan card ─── */
.settings__plan-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.settings__plan-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings__plan-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.settings__plan-name {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.settings__plan-desc {
  font-size: 13.5px;
  color: var(--text-soft);
}
.settings__plan-renew {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Payment-method row ─── */
.settings__payment-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}
.settings__payment-line svg { color: var(--text-soft); }

/* ─── Invoices table ─── */
.settings__invoices {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.settings__invoices-empty {
  padding: 28px 20px;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-muted);
}
.settings__invoice {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.settings__invoice:last-child { border-bottom: 0; }
.settings__invoice--head {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--hover-bg);
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  padding: 10px 16px;
}
.settings__invoice-status {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
}
.settings__invoice-status.is-paid {
  background: rgba(52, 153, 95, 0.14);
  color: #2d7a4d;
}
:root[data-theme="dark"] .settings__invoice-status.is-paid {
  background: rgba(52, 153, 95, 0.18);
  color: #6fc78f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .settings__invoice-status.is-paid {
    background: rgba(52, 153, 95, 0.18);
    color: #6fc78f;
  }
}
.settings__invoice-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 14px;
  font-family: var(--font-sans);
}
.settings__invoice-link:hover { color: var(--text); }

/* ─── Cancel-plan modal ─── */
.settings__modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.settings__modal[hidden] { display: none; }
.settings__modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  animation: settings-modal-fade-in 180ms ease;
}
.settings__modal-content {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 32px 80px -20px rgba(0, 0, 0, 0.45);
  animation: settings-modal-pop 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.settings__modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.settings__modal-close:hover { background: var(--hover-bg); color: var(--text); }
.settings__modal-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
}
.settings__modal-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 540;
  letter-spacing: -0.015em;
  margin: 0;
  color: var(--text);
}
.settings__modal-text {
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text-soft);
  margin: 0;
}
.settings__modal-text strong {
  color: var(--text);
  font-weight: 600;
}
.settings__modal-subhead {
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  margin: 8px 0 0;
}
.settings__modal-suggestions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings__sugg {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--hover-bg);
  border-radius: 10px;
}
.settings__sugg-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.settings__sugg-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.settings__sugg-body strong {
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.settings__sugg-body span {
  font-size: 12.5px;
  color: var(--text-soft);
  line-height: 1.4;
}
.settings__modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.settings__modal-keep {
  flex: 1;
  height: 42px;
  padding: 0 18px;
}
.settings__modal-confirm {
  flex: 1;
  height: 42px;
  padding: 0 18px;
  font-size: 14.5px;
  font-weight: 500;
}

@keyframes settings-modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes settings-modal-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

@media (max-width: 720px) {
  .settings__plan-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .settings__plan-icon { align-self: flex-start; }
  .settings__invoice { grid-template-columns: 1fr 1fr; gap: 6px 12px; }
  .settings__invoice--head { display: none; }
  .settings__modal-content { padding: 22px; max-width: 100%; }
  .settings__modal-actions { flex-direction: column-reverse; }
}
.settings__nav-item:hover {
  background: rgba(31, 30, 28, 0.06);
  color: var(--text);
}
.settings__nav-item.is-active {
  background: var(--text);
  color: var(--btn-fg);
  font-weight: 500;
}

.settings__content {
  min-width: 0;
}
.settings__panel { display: none; }
.settings__panel.is-active {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.settings__group {
  display: flex;
  flex-direction: column;
}
/* Dialog section headers ("Profile", "Preferences") are calm sans semibold */
.settings__group-title {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  margin: 0 0 12px;
  color: var(--text);
}
.settings__group-title--danger { color: #B6483A; }

.settings__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.settings__row:last-child { border-bottom: 0; }
.settings__row--col {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.settings__row--toggle .settings__rowhead { flex: 1; }

.settings__rowhead {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.settings__label {
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}
.settings__hint {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-soft);
  max-width: 480px;
}

.settings__input,
.settings__select,
.settings__textarea {
  font-family: var(--font-sans);
  font-size: 14.5px;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 10px 12px;
  outline: none;
  width: 280px;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.settings__input:focus,
.settings__select:focus,
.settings__textarea:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 3px rgba(31, 30, 28, 0.06);
}
.settings__select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none'><path d='M6 9l6 6 6-6' stroke='%236B6A66' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  padding-right: 36px;
  cursor: pointer;
}
.settings__textarea {
  width: 100%;
  resize: vertical;
  min-height: 110px;
  font-family: var(--font-serif);
  font-size: 15.5px;
  line-height: 1.55;
}

.settings__avatar {
  width: 38px;
  height: 38px;
  font-size: 15px;
  flex-shrink: 0;
}

.settings__readonly {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-soft);
  text-align: right;
}

.settings__code {
  font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 12.5px;
  color: var(--text);
  background: var(--hover-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 120ms ease, border-color 120ms ease;
  text-align: left;
}
.settings__code:hover { background: var(--accent-soft); border-color: var(--accent); }
.settings__code.is-copied { color: var(--accent); }

/* Active sessions table */
.settings__sessions-intro { margin: 4px 0 16px; }

.settings__sessions {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  /* overflow:hidden removed so action-menu can spill out;
     corner-rounding is reapplied on first/last rows below */
}
.settings__sessions > :first-child {
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}
.settings__sessions > :last-child {
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

.settings__sessions-empty {
  padding: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
}

.settings__session {
  display: grid;
  grid-template-columns: 2.2fr 1.4fr 1fr 1fr 36px;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.settings__session:last-child { border-bottom: 0; }
.settings__session--head {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--hover-bg);
  padding: 10px 16px;
}

.settings__session-device {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  min-width: 0;
}
.settings__session-device > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.settings__session-current {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.settings__session-meta {
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings__session-actions {
  position: relative;
  justify-self: end;
}
.settings__session-menu-trigger {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: transparent;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.settings__session-menu-trigger:hover,
.settings__session-menu-trigger.is-open {
  background: var(--hover-bg);
  color: var(--text);
}
.settings__session-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--card-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 4px;
  display: none;
  flex-direction: column;
  min-width: 140px;
  z-index: 20;
  box-shadow: 0 14px 40px -18px rgba(0, 0, 0, 0.45);
}
.settings__session-menu.is-open { display: flex; }
.settings__session-menu.is-up {
  top: auto;
  bottom: calc(100% + 4px);
}
.settings__session-menu-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 14px;
  text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text);
  transition: background 120ms ease;
}
.settings__session-menu-item:hover { background: var(--hover-bg); }
.settings__session-menu-item.is-danger { color: #C75A4D; }
.settings__session-menu-item.is-danger:hover { background: rgba(199, 90, 77, 0.10); }
.settings__session-menu-item:disabled { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 880px) {
  .settings__session {
    grid-template-columns: 1fr 32px;
    grid-template-areas:
      "device kill"
      "loc loc"
      "created created"
      "updated updated";
    gap: 4px 8px;
    padding: 12px 14px;
  }
  .settings__session--head { display: none; }
  .settings__session-device { grid-area: device; }
  .settings__session-kill { grid-area: kill; }
  .settings__session-meta:nth-of-type(1) { grid-area: loc; }
  .settings__session-meta:nth-of-type(2) { grid-area: created; }
  .settings__session-meta:nth-of-type(3) { grid-area: updated; }
  .settings__session-meta::before {
    content: attr(data-label) ": ";
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: 0.04em;
    margin-right: 6px;
  }
}

.settings__seg {
  display: inline-flex;
  background: var(--hover-bg);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.settings__seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 30px;
  padding: 0 10px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.settings__seg-btn svg { display: block; }
.settings__seg-btn:hover:not(.is-active) {
  background: var(--card-bg);
  color: var(--text);
}
.settings__seg-btn.is-active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.settings__switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.settings__switch input {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 100%;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 180ms ease;
  margin: 0;
}
.settings__switch input::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #FBF4EE;
  top: 3px;
  left: 3px;
  transition: transform 180ms cubic-bezier(0.5, 0.05, 0.25, 1);
}
.settings__switch input:checked { background: var(--accent); }
.settings__switch input:checked::before { transform: translateX(18px); }

.settings__btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease;
}
.settings__btn-secondary:hover { background: var(--hover-bg); border-color: var(--text); }

.settings__btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: #B6483A;
  background: transparent;
  border: 1px solid rgba(182, 72, 58, 0.35);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.settings__btn-danger:hover {
  background: rgba(182, 72, 58, 0.08);
  border-color: #B6483A;
}

.settings__actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
}
.settings__save { width: auto; padding: 0 28px; height: 44px; }

/* Legal docs list inside Privacy panel */
.settings__doclist {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.settings__doclist li {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings__doclist li::before {
  content: "→";
  color: var(--accent);
  font-weight: 600;
  width: 14px;
  display: inline-block;
}
.settings__doclist a {
  color: var(--text);
  font-size: 14.5px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease, color 120ms ease;
}
.settings__doclist a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ─── API keys panel ─── */
.settings__api-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 16px;
}

.settings__btn-primary {
  background: var(--accent);
  color: #FBF4EE;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 16px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 120ms ease;
}
.settings__btn-primary:hover { opacity: 0.9; }
.settings__btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.settings__api-keys {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.settings__api-key {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.settings__api-key__main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.settings__api-key__name {
  font-size: 14px;
  font-weight: 540;
  color: var(--text);
}
.settings__api-key__prefix {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-soft);
}
.settings__api-key__meta {
  font-size: 12px;
  color: var(--text-muted);
}
.settings__api-key__revoke {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--alert-fg);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: var(--font-sans);
  cursor: pointer;
  align-self: center;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.settings__api-key__revoke:hover {
  background: rgba(182, 72, 58, 0.08);
  border-color: var(--alert-fg);
}

.settings__codeblock {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0;
}
.settings__codeblock--key {
  user-select: all;
  word-break: break-all;
  white-space: pre-wrap;
  font-size: 13px;
}

/* ═══ API balance — premium dashboard ═══════════════════════════════ */

.bal-page { display: flex; flex-direction: column; gap: 28px; }
.bal-group { padding: 0; }              /* group-level padding handled inside */
.bal-group--hero { padding: 0; }

/* ── HEAD: title + status pill + refresh ───────────────────────────── */
.bal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.bal-head-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.bal-head-left .settings__group-title { margin: 0; }

.bal-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 9px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
  letter-spacing: 0.01em;
}
.bal-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4FA365;
  box-shadow: 0 0 0 3px rgba(79, 163, 101, 0.18);
}
.bal-status.is-low .bal-status-dot {
  background: #D9A14C;
  box-shadow: 0 0 0 3px rgba(217, 161, 76, 0.20);
}
.bal-status.is-empty .bal-status-dot {
  background: #B6483A;
  box-shadow: 0 0 0 3px rgba(182, 72, 58, 0.20);
}

.bal-refresh {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 13px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.bal-refresh:hover {
  background: var(--hover-bg);
  border-color: var(--text-soft);
  color: var(--text);
}
.bal-refresh:disabled { opacity: 0.5; cursor: default; }
.bal-refresh svg { flex-shrink: 0; }

/* ── HERO: ring + main amount + meta ───────────────────────────────── */
.bal-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 36px;
  align-items: center;
  padding: 28px 30px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}
.bal-hero::before {
  /* subtle radial wash behind ring side */
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 280px;
  background: radial-gradient(circle at 25% 50%, var(--accent-soft) 0%, transparent 68%);
  opacity: 0.55;
  pointer-events: none;
}
.bal-hero > * { position: relative; z-index: 1; }

/* Circular progress ring (pure conic-gradient) */
.bal-ring {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background:
    conic-gradient(
      var(--accent) calc(var(--p) * 1%),
      var(--bg-soft) calc(var(--p) * 1%) 100%
    );
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  transition: background 480ms ease;
}
.bal-ring::after {
  /* outer faint hairline */
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid var(--border);
  pointer-events: none;
}
.bal-ring-inner {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.bal-ring-pct {
  font-family: var(--font-serif);
  font-size: 34px;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.bal-ring-cap {
  font-family: var(--font-sans);
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Center amount block */
.bal-amount-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.bal-eyebrow {
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.bal-amount {
  display: flex;
  align-items: baseline;
  gap: 6px;
  color: var(--text);
  font-family: var(--font-serif);
  line-height: 0.92;
}
.bal-amount-cur {
  font-size: 30px;
  color: var(--text-soft);
  font-weight: 400;
}
.bal-amount-val {
  font-size: 60px;
  font-weight: 400;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.bal-amount-of {
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}
.bal-amount-usd {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.bal-topup-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 8px 16px;
  background: var(--accent);
  color: #FBF4EE;
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 540;
  text-decoration: none;
  transition: opacity 120ms ease, transform 120ms ease;
  align-self: flex-start;
}
.bal-topup-cta:hover { opacity: 0.92; transform: translateY(-1px); }
.bal-topup-cta svg { flex-shrink: 0; }

/* Meta block */
.bal-meta {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 0;
  padding-left: 24px;
  border-left: 1px solid var(--border);
  min-width: 200px;
}
.bal-meta-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bal-meta-row dt {
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}
.bal-meta-row dd {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  font-weight: 540;
  font-variant-numeric: tabular-nums;
}
.bal-meta-row--forecast dd {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 400;
  color: var(--accent);
}

/* ── SECTION HEAD (used in tiles / breakdown / log) ───────────────── */
.bal-section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 16px;
}
.bal-section-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 400;
  color: var(--text);
}
.bal-group > .bal-section-title { margin: 0 0 16px; }

/* ── TILES: 4 stat cards ──────────────────────────────────────────── */
.bal-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.bal-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 0;
  position: relative;
  transition: border-color 160ms ease, transform 160ms ease;
}
.bal-tile:hover {
  border-color: var(--border-strong);
}
.bal-tile-label {
  font-family: var(--font-sans);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--text-muted);
}
.bal-tile-value {
  font-family: var(--font-serif);
  font-size: 30px;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  letter-spacing: -0.02em;
}
.bal-tile-sub {
  font-family: var(--font-sans);
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── TOKEN BREAKDOWN: stacked bar + legend ────────────────────────── */
.bal-stack {
  display: flex;
  width: 100%;
  height: 16px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bal-stack-seg {
  height: 100%;
  transition: width 360ms ease;
  min-width: 0;
}
/* segment colors — coral-family tonal scale + neutral output */
.bal-stack-seg--input  { background: #D97757; }
.bal-stack-seg--cc     { background: #E5A487; }
.bal-stack-seg--cr     { background: #F0C8B3; }
.bal-stack-seg--output { background: var(--text-soft); }

.bal-legend {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px 18px;
  margin-top: 14px;
}
.bal-legend-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.bal-legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: center;
}
.bal-legend-dot--input  { background: #D97757; }
.bal-legend-dot--cc     { background: #E5A487; }
.bal-legend-dot--cr     { background: #F0C8B3; }
.bal-legend-dot--output { background: var(--text-soft); }
.bal-legend-label {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  flex: 1;
}
.bal-legend-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── KEYS: per-key cards with mini bars ───────────────────────────── */
.bal-keys {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bal-keys-empty {
  padding: 20px 18px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.bal-key {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px 24px;
  align-items: center;
  padding: 16px 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  position: relative;
  transition: border-color 160ms ease;
}
.bal-key:hover { border-color: var(--border-strong); }
.bal-key-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.bal-key-name {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  font-weight: 540;
}
.bal-key-prefix {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-soft);
}
.bal-key-meta {
  font-family: var(--font-sans);
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}
.bal-key-meta-sep { padding: 0 4px; color: var(--border-strong); }
.bal-key-amount {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
}
.bal-key-spent {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.bal-key-limit {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.bal-key-limit--exceeded { color: #B6483A; font-weight: 540; }
.bal-key-spent-lab { font-family: var(--font-sans); font-size: 11px; color: var(--text-muted); letter-spacing: 0.01em; }
.bal-key-limit-block { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 7px; padding-top: 13px; border-top: 1px solid var(--border); }
.bal-key-limit-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.bal-key-limit-lab { font-family: var(--font-sans); font-size: 12.5px; color: var(--text-soft); }
.bal-key-limit-val { font-family: var(--font-sans); font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.bal-key-limit-val--exceeded { color: #B6483A; font-weight: 540; }
.bal-key-limit-pct { font-family: var(--font-sans); font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.bal-key-nolimit { grid-column: 1 / -1; font-family: var(--font-sans); font-size: 12px; color: var(--text-muted); padding-top: 12px; border-top: 1px solid var(--border); }
.bal-key-bar {
  grid-column: 1 / -1;
  position: relative;
  height: 4px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.bal-key-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 320ms ease, background 200ms ease;
}
.bal-key-bar-fill.is-low { background: #D9A14C; }
.bal-key-bar-fill.is-exceeded { background: #B6483A; }
.bal-key-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}
.bal-key-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 5px 11px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.bal-key-edit:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ── LOG: tabs + table ────────────────────────────────────────────── */
.bal-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.bal-tab {
  background: transparent;
  border: none;
  padding: 5px 14px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.bal-tab:hover { color: var(--text); }
.bal-tab.is-active {
  background: var(--card-bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(31, 30, 28, 0.06);
}

.bal-table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card-bg);
  overflow: hidden;
}
.bal-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 13px;
}
.bal-table th {
  text-align: left;
  font-family: var(--font-sans);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--text-muted);
  padding: 12px 18px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bal-table th.bal-num,
.bal-table td.bal-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.bal-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 120ms ease;
}
.bal-table tbody tr:last-child { border-bottom: none; }
.bal-table tbody tr:hover { background: var(--hover-bg); }
.bal-table td {
  padding: 13px 18px;
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
}
.bal-table td.is-num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text-soft);
}
.bal-table td.is-time {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
}
.bal-table td.is-model {
  font-weight: 540;
  color: var(--text);
}
.bal-table td.is-cost {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text);
  font-weight: 540;
}
.bal-table td.is-negative {
  color: #B6483A;
  font-weight: 540;
}
.bal-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--bg-soft);
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.bal-pill--api {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.bal-empty {
  padding: 36px 24px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
}

.bal-empty-state {
  padding: 40px 36px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
}

/* ── RESPONSIVE ───────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .bal-tiles { grid-template-columns: repeat(2, 1fr); }
  .bal-legend { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .bal-hero {
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 22px 22px 24px;
    text-align: center;
  }
  .bal-hero::before { display: none; }
  .bal-ring { margin: 0 auto; }
  .bal-amount { justify-content: center; }
  .bal-amount-val { font-size: 52px; }
  .bal-meta {
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 18px 0 0;
    text-align: left;
  }
  .bal-meta-row { align-items: flex-start; }
  .bal-section-head { flex-direction: column; align-items: stretch; }
  .bal-tabs { align-self: flex-start; }
  .bal-table-wrap { overflow-x: auto; }
  .bal-tile-value { font-size: 26px; }
}
@media (max-width: 540px) {
  .bal-tiles { grid-template-columns: 1fr; }
  .bal-legend { grid-template-columns: 1fr; }
  .bal-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}

@media (max-width: 880px) {
  /* Dialog card → full-width sheet on phones (desktop width formula
     `calc(100vw - 340px)` would collapse to ~50px here). */
  .settings {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    /* clip ≠ hidden: hidden-боксы скроллятся программно — браузерный
       scroll-on-focus при тапе по полускрытому табу сдвигал ВЕСЬ лист
       (scrollLeft=279), и вернуть пальцем нельзя. clip запрещает скролл. */
    overflow: hidden;
    overflow: clip;
  }
  .settings__body {
    grid-template-columns: 1fr;
    height: auto;          /* page scrolls naturally, no inner fixed height */
  }
  /* Left column stacks on top: search + horizontally scrollable icon nav.
     min-width:0 + max-width:100% обязательны: без них min-content ленты
     табов (~960px) раздувает 1fr-трек грида до 961px → контент ВСЕХ
     вкладок уезжает за правый край экрана (баг аудита 2026-06-13). */
  .settings__sidecol {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    padding: 14px 16px 10px;
    overflow: visible;
    min-width: 0;
    max-width: 100%;
  }
  .settings__nav-label { display: none; }
  .settings__nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
    gap: 4px;
    scrollbar-width: none;
  }
  .settings__nav::-webkit-scrollbar { display: none; }
  .settings__nav-item { white-space: nowrap; flex-shrink: 0; width: auto; }
  .settings__content {
    overflow: visible;
    padding: 20px 16px 72px;
  }
  /* Keep the close X clear of the drawer hamburger */
  .settings__close { top: 10px; right: 10px; }

  .settings__row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .settings__row--toggle { flex-direction: row; }
  .settings__input,
  .settings__select { width: 100%; }
  .settings__readonly { text-align: left; }

  /* iOS zooms the page when a focused input is <16px — keep all fields at 16px */
  .settings__input,
  .settings__select,
  .settings__textarea,
  .settings__search input { font-size: 16px; }
}

/* ═══════════════════════════════════════════════════════════════ */
/*  Billing — premium Claude.ai-style layout (replaces old cards)  */
/* ═══════════════════════════════════════════════════════════════ */

/* Section blocks separate by generous vertical rhythm. NO dividers — Anthropic
   uses pure whitespace + bold section titles to chunk content.
   Parent .settings__panel.is-active has gap:32px between children, so my own
   padding-bottom would compound — keep section padding at 0 and let panel gap
   handle the rhythm. Hero gets extra room (it's the visual anchor). */
.bill-section {
  display: block;
}
.bill-section--hero {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 4px 0 8px;
}
.bill-section__title {
  margin: 0 0 14px;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.bill-section__title--danger { color: #B6483A; }
.bill-section__hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Plan hero block ─── */
.bill-plan-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent, #d97757);
  margin-top: 2px;
}
.bill-plan-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bill-plan-name {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.005em;
  line-height: 1.3;
}
.bill-plan-desc {
  margin: 2px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-soft);
}
.bill-plan-renew {
  margin: 2px 0 0;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ─── Buttons (outline pill style, matches Anthropic) ─── */
.bill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, opacity 120ms ease;
  white-space: nowrap;
  flex-shrink: 0;
}
.bill-btn:hover {
  background: var(--hover-bg);
  border-color: var(--text-muted);
}
.bill-btn:active { transform: scale(0.97); }
.bill-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.bill-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.bill-btn--danger {
  background: #B6483A;
  border-color: #B6483A;
  color: #fff;
}
.bill-btn--danger:hover {
  background: #a23b2d;
  border-color: #a23b2d;
  color: #fff;
}
.bill-btn--danger[disabled] {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

/* ─── Payment row (inline, flat) ─── */
.bill-payment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.bill-payment__line {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-sans);
  font-size: 14.5px;
  color: var(--text);
  min-width: 0;
  word-break: break-word;
}
.bill-payment__icon { color: var(--text-soft); flex-shrink: 0; }
.bill-payment__text { font-weight: 500; }

/* ─── Autopay toggle ─── */
.bill-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.bill-toggle__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.bill-toggle__title {
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}
.bill-toggle__hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Invoices table ─── */
.bill-invoices {
  display: flex;
  flex-direction: column;
}
.bill-invoices__head,
.bill-invoices__row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 100px;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
}
.bill-invoices__head {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-top: 0;
  padding-bottom: 14px;
}
.bill-invoices__row {
  border-bottom: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
}
.bill-invoices__row:last-child { border-bottom: 0; }
.bill-invoices__date { color: var(--text); }
.bill-invoices__total { font-variant-numeric: tabular-nums; font-weight: 500; }
.bill-invoices__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
}
.bill-invoices__status--paid { color: #2c8a4a; }
.bill-invoices__status--failed { color: #B6483A; }
.bill-invoices__status--refunded { color: var(--text-muted); }
.bill-invoices__action {
  color: var(--accent, #d97757);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  font-size: 13.5px;
}
.bill-invoices__action:hover { color: var(--text); }
.bill-invoices__empty {
  padding: 24px 0;
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: left;
}

/* ─── Cancellation section ─── */
.bill-cancel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.bill-cancel__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.bill-cancel__title {
  font-family: var(--font-sans);
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
}
.bill-cancel__hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Mobile (≤ 760px) ─── */
@media (max-width: 760px) {
  .bill-section { padding: 22px 0; }
  .bill-section--hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .bill-section--hero .bill-btn { align-self: stretch; }
  .bill-payment,
  .bill-toggle,
  .bill-cancel {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .bill-invoices__head,
  .bill-invoices__row {
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
  }
  .bill-invoices__head .bill-invoices__date,
  .bill-invoices__head .bill-invoices__total { grid-column: span 1; }
  .bill-invoices__head .bill-invoices__status,
  .bill-invoices__head .bill-invoices__action-col { display: none; }
  .bill-invoices__row .bill-invoices__action { grid-column: 2; justify-self: end; }
}
.bal-key-usage-bar { margin: 1px 0; }


/* Settings as a Claude-style modal over a dimmed + blurred backdrop */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px) saturate(1.05);
  -webkit-backdrop-filter: blur(10px) saturate(1.05);
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px 64px;
  animation: settings-overlay-fade 200ms ease;
}
@keyframes settings-overlay-fade { from { opacity: 0 } to { opacity: 1 } }
.settings-overlay .settings { width: min(960px, 100%); margin: 0; }
/* Usage log table: never clip the cost column — scroll if narrow, tighter cells */
.bal-table-wrap { overflow-x: auto; }
.bal-table th, .bal-table td { padding-left: 12px; padding-right: 12px; }