.profile-toolbar {
  position: relative;
  width: calc(100% - 20px);
  margin: 0 10px 6px;
}

.profile-summary {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 7px 12px;
  align-items: center;
  gap: 9px;
  text-align: start;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.profile-summary:hover,
.profile-summary[aria-expanded="true"] {
  background: var(--surface-hover);
}

.profile-current-dot {
  width: 6px;
  height: 6px;
  background: var(--mint);
  border-radius: 999px;
}

.profile-summary > span:nth-child(2) {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 6px;
}

.profile-summary strong { flex: 0 0 auto; white-space: nowrap; color: var(--text); font-size: var(--font-size-secondary); }

.profile-summary small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: calc(11px * var(--font-scale));
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Shared quota is one native modal dialog: a large overlay on wide screens,
 * the complete visible app rectangle on narrow ones (responsive.css). The
 * list body is its only scroll Owner; the header stays in place. */
.profile-menu {
  width: min(1120px, calc(var(--content-width) - 48px));
  max-width: none;
  max-height: calc(var(--app-height, 100dvh) - 48px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgb(0 0 0 / 45%);
}

.profile-menu[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.profile-menu::backdrop { background: rgb(0 0 0 / 62%); }
/* Wide overlays center on the residual-safe content, like other top-layer boxes. */
@media (min-width: 821px) {
  html.native-content-geometry .profile-menu { inset-inline: var(--content-left) var(--content-right); }
}

.quota-detail-title {
  display: flex;
  min-height: 52px;
  padding: 4px 6px 4px 16px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
}

.quota-detail-title > span {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.quota-detail-title strong { font-size: calc(16px * var(--font-scale)); }
.quota-detail-title small { color: var(--muted); font-size: var(--font-size-secondary); overflow-wrap: anywhere; }
.quota-panel-close { flex: 0 0 auto; }
.quota-panel-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.quota-panel-close:focus-visible { outline: 2px solid var(--mint); outline-offset: -2px; }

.quota-panel-body {
  min-height: 0;
  padding: 4px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The collapsed explanation and the full-detail entry share one row; an open
 * explanation takes the full width and moves the entry below its text. */
.quota-panel-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0 8px;
  margin-bottom: 8px;
}
.quota-explanation { flex: 1 1 auto; min-width: 0; font-size: calc(11px * var(--font-scale)); }
.quota-explanation[open] { flex-basis: 100%; }
.quota-explanation summary {
  display: list-item;
  min-height: 44px;
  align-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}
.quota-explanation summary:focus-visible { outline: 2px solid var(--mint); outline-offset: -2px; }
.quota-explanation-body { color: var(--muted); line-height: 1.65; overflow-wrap: anywhere; }
.quota-explanation-body dl { margin: 0; }
.quota-explanation-body dt { margin-top: 10px; color: var(--text-secondary); font-weight: 700; }
.quota-explanation-body dd { margin: 4px 0 10px; }
.quota-explanation-body ul { padding-inline-start: 18px; }
.quota-detail-title time { white-space: nowrap; }

/* Provider groups flow into two columns only where both stay readable. */
.quota-panel-groups { columns: 2 440px; column-gap: 20px; }

.quota-provider-group {
  --quota-control-columns: max(44px, calc(43px * var(--font-scale)));
  margin-bottom: 14px;
  break-inside: avoid-column;
}

.quota-provider-group[data-credit-column] {
  --quota-control-columns: max(44px, calc(43px * var(--font-scale))) calc(82px * var(--font-scale));
}

.quota-group-heading,
.quota-detail-profile {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--quota-control-columns);
  column-gap: 6px;
  padding-inline: 10px 6px;
}

.quota-group-heading {
  min-height: 38px;
  align-items: baseline;
  align-content: center;
  background: var(--bg-soft);
  border-block-end: 1px solid var(--line);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  break-after: avoid;
}

.quota-group-heading > span:first-child {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
}

.quota-group-heading h3 {
  margin: 0;
  font-size: calc(13px * var(--font-scale));
  font-weight: 750;
}

.quota-group-heading small { color: var(--muted); font-size: calc(10px * var(--font-scale)); font-weight: 600; }

.quota-fable-toggle {
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  font-size: calc(11px * var(--font-scale));
  font-weight: 650;
  cursor: pointer;
}

.quota-fable-toggle > span {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
}

.quota-fable-toggle:hover > span { background: var(--surface-hover); }
.quota-fable-toggle[aria-pressed="true"] > span {
  color: var(--mint-bright);
  background: color-mix(in srgb, var(--mint) 18%, var(--surface));
}
.quota-fable-toggle:focus-visible { outline-offset: -2px; }

.quota-column-label {
  justify-self: center;
  color: var(--muted);
  font-size: calc(10px * var(--font-scale));
  white-space: nowrap;
}

.quota-detail-profile {
  grid-template-areas: "content ." "content pref" "meta meta";
  padding-block: 5px;
  row-gap: 3px;
  border-block-end: 1px solid var(--line-soft);
  break-inside: avoid;
}

.quota-provider-group[data-credit-column] .quota-detail-profile {
  grid-template-areas: "content . ." "content pref credits" "meta meta meta";
}

.quota-profile-reset:not([hidden]) {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow-wrap: normal;
}

.quota-reset-count {
  position: relative;
  min-width: 18px;
  min-height: 18px;
  padding: 0 4px;
  border: 1px solid var(--mint);
  border-radius: 5px;
  color: var(--mint-bright);
  background: color-mix(in srgb, var(--mint) 18%, var(--surface));
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.quota-reset-count::before {
  position: absolute;
  inset: -3px;
  content: "";
}

.quota-reset-count[data-retained] { border-style: dashed; }
.quota-reset-count:hover, .quota-reset-count[aria-expanded="true"] { background: var(--surface-hover); }
.quota-reset-count:focus-visible, .quota-reset-card-popover:focus-visible { outline: 2px solid var(--mint); }

.quota-reset-card-popover {
  position: absolute;
  z-index: 1;
  box-sizing: border-box;
  width: max-content;
  max-width: min(18rem, calc(100% - 16px));
  padding: 8px 10px;
  overflow: auto;
  overscroll-behavior: contain;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 5px 18px rgb(0 0 0 / 30%);
  font-size: var(--font-size-secondary);
  overflow-wrap: anywhere;
}

.quota-reset-card-content ul { display: grid; gap: 4px; list-style: none; padding: 0; margin: 6px 0; }
.quota-reset-card-content li, .quota-reset-card-buttons { display: flex; align-items: center; justify-content: space-between; gap: 4px 8px; }
.quota-reset-card-buttons { justify-content: end; margin-top: 8px; }
.quota-reset-card-content button {
  min-height: 32px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: var(--bg-soft);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.quota-reset-card-content button:focus-visible { outline: 2px solid var(--mint); }
.quota-reset-card-content [data-quota-reset-confirm] { border-color: var(--mint); color: var(--mint-bright); }
.quota-reset-status { color: var(--text-secondary); padding-inline: 6px; }
.quota-reset-card-content time, .quota-reset-card-content p { color: var(--muted); }
.quota-reset-card-content p { margin: 3px 0; }

.quota-profile-content {
  display: grid;
  grid-area: content;
  grid-template-areas: "name name name" "status track remaining";
  grid-template-columns: minmax(0, auto) minmax(14px, 1fr) minmax(0, auto);
  grid-template-rows: subgrid;
  min-width: 0;
  align-items: center;
  column-gap: 8px;
  line-height: 1.3;
}

.quota-profile-main { display: contents; }

.quota-profile-main strong {
  grid-area: name;
  font-size: calc(12px * var(--font-scale));
  font-weight: 650;
  overflow-wrap: anywhere;
}

.quota-profile-status {
  grid-area: status;
  color: var(--text-secondary);
  font-size: calc(10px * var(--font-scale));
  font-weight: 700;
  overflow-wrap: anywhere;
}
.quota-profile-status[data-tone="warning"] { color: var(--amber); }
.quota-profile-status[data-tone="blocked"] { color: var(--red); }
.quota-profile-status[data-tone="off"] { color: var(--muted); }

.quota-profile-remaining {
  grid-area: remaining;
  font-size: calc(12px * var(--font-scale));
  font-variant-numeric: tabular-nums;
  text-align: end;
  overflow-wrap: anywhere;
}

.quota-detail-track {
  --quota-fill: color-mix(in srgb, hsl(var(--quota-hue, 120deg) 52% 40%), var(--text) 15%);
  display: block;
  grid-area: track;
  width: 100%;
  height: 3px;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  accent-color: var(--quota-fill);
  background: var(--line-soft);
  border: 0;
  border-radius: 999px;
}

.quota-detail-track::-webkit-progress-bar { background: var(--line-soft); }
.quota-detail-track::-webkit-progress-value {
  background: var(--quota-fill);
  border-radius: 999px;
}
.quota-detail-track::-moz-progress-bar {
  background: var(--quota-fill);
  border-radius: 999px;
}

.quota-detail-meta {
  display: flex;
  grid-area: meta;
  min-width: 0;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 3px 12px;
  color: var(--muted);
  font-size: calc(10px * var(--font-scale));
  line-height: 1.35;
}
.quota-detail-meta > span { overflow-wrap: anywhere; }
.quota-profile-activity {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}
.quota-profile-activity[data-active="true"] {
  padding: 1px 5px;
  color: var(--mint-bright);
  background: color-mix(in srgb, var(--mint) 12%, transparent);
  border-radius: 4px;
}
.quota-detail-meta .quota-profile-note { color: var(--amber); }

.quota-profile-preference {
  display: grid;
  grid-area: pref;
  min-width: 0;
  min-height: 44px;
  /* Share the row spacing while keeping the full checkbox target. */
  margin-block: -6px;
  grid-template-rows: minmax(1.2em, 1fr) 18px minmax(1.2em, 1fr);
  align-items: center;
  justify-items: center;
  font-size: calc(11px * var(--font-scale));
  line-height: 1.2;
  cursor: pointer;
}
.quota-profile-credits { grid-area: credits; }
.quota-profile-preference input {
  grid-row: 2;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--mint);
}
.quota-profile-credits b {
  grid-row: 3;
  max-width: 100%;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quota-profile-preference:has(input:focus-visible) {
  outline: 2px solid var(--mint);
  outline-offset: -2px;
  border-radius: 4px;
}

.quota-detail-open {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-raised);
  border: 0;
  border-radius: 9px;
  font: inherit;
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
  cursor: pointer;
}

.quota-detail-open:hover { background: var(--surface-hover); }
.quota-detail-open:focus-visible { outline: 2px solid var(--mint); outline-offset: -2px; }

html.native-content-geometry .profile-toolbar {
  width: calc(100% - 20px - var(--column-content-left) - var(--column-content-right));
  margin-inline: calc(10px + var(--column-content-left)) calc(10px + var(--column-content-right));
}
