/* Shared modal chrome — head/title/close/foot/spacer/cancel/save.
   Originally the project editor modal's CSS, now used by every
   command-palette modal (storage / cheatsheet / prompt templates)
   after the project feature was removed. */
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ui-border-default);
}
.modal-title {
  font-size: var(--ui-font-size-base-medium);
  font-weight: var(--ui-font-weight-semibold);
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--ui-border-default);
  background: var(--ui-bg-page);
}
.modal-spacer {
  flex: 1;
}

/* P5.6 — shortcut cheatsheet modal */
.cheatsheet {
  max-height: 75vh;
  width: min(520px, 92vw);
  display: flex;
  flex-direction: column;
}

/* P2.3 — Storage modal */
.storage-modal {
  width: min(560px, 92vw);
  max-height: 75vh;
  display: flex;
  flex-direction: column;
}

.storage-modal-body {
  padding: 14px 18px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.storage-modal-desc {
  font-size: var(--ui-font-size-xxs);
  color: var(--ui-text-secondary);
  line-height: 1.5;
}
.storage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.storage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-bg-raised);
}
.storage-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.storage-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.storage-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.storage-btn-restore,
.storage-btn-delete {
  padding: 4px 10px;
  border-radius: var(--ui-radius-xs);
  font-size: var(--ui-font-size-xxs);
  cursor: pointer;
  border: 0.5px solid transparent;
  font-weight: var(--ui-font-weight-medium);
  font-family: inherit;
}
.storage-btn-restore {
  background: var(--ui-ink);
  color: hsl(var(--always-white));
}
.storage-btn-restore:hover {
  filter: brightness(1.1);
}
.storage-btn-delete {
  background: transparent;
  color: var(--ui-danger);
  border-color: color-mix(in srgb, var(--ui-danger) 35%, transparent);
}
.storage-btn-delete:hover {
  background: color-mix(in srgb, var(--ui-danger) 14%, transparent);
  color: var(--ui-danger);
}
.storage-empty {
  text-align: center;
  padding: 32px 12px;
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-base-small);
}
.cheatsheet-body {
  padding: 0 6px 12px;
  overflow-y: auto;
}
.cheatsheet-section {
  padding: 8px 12px;
}
.cheatsheet-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.cheatsheet-kbd {
  font-family: var(--font-mono);
  font-size: var(--ui-font-size-caption);
  padding: 2px 6px;
  min-width: 18px;
  text-align: center;
  border: 0.5px solid color-mix(in srgb, var(--ui-border-default) 40%, transparent);
  border-radius: var(--ui-radius-xs);
  background: var(--ui-bg-page);
  color: var(--ui-text-secondary);
}
.cheatsheet-desc {
  margin-left: 8px;
  font-size: var(--ui-font-size-base-small);
  color: var(--ui-text-secondary);
}

/* Display / reading preferences (font size + content width) */
.display-prefs-popover {
  position: fixed;
  min-width: 240px;
  max-width: 280px;
  padding: 10px 12px;
  z-index: var(--ui-z-backdrop);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.display-prefs-popover.hidden {
  display: none;
}

.display-prefs-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.display-prefs-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: calc(var(--ui-font-size-label) * var(--app-font-scale, 1));
  font-weight: var(--ui-font-weight-medium);
  color: var(--ui-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.display-prefs-label .value {
  color: var(--ui-text-secondary);
  font-weight: var(--ui-font-weight-semibold);
  text-transform: none;
  letter-spacing: 0;
}
/* Text-size & content-width segmented controls inside the display
   prefs popover. Both have N buttons (font: 4, width: 4) and share
   the same .display-prefs-segs chrome. The active segment is
   highlighted by a single sliding ::before indicator; JS sets
   --seg-x / --seg-w on the wrapper after measuring the .on button
   so the indicator tracks layout changes (gap, padding) without
   needing fragile calc()-based math here. */
.display-prefs-segs {
  position: relative;
  display: flex;
  gap: 2px;
  background: var(--ui-bg-control);
  border-radius: var(--ui-radius-xs);
  padding: 2px;
  isolation: isolate;
}
.display-prefs-segs::before {
  content: '';
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: var(--seg-x, 0px);
  width: var(--seg-w, 0px);
  border-radius: var(--ui-radius-xs);
  background: var(--ui-bg-segment-active);
  box-shadow: var(--ui-elevation-ring);
  transition:
    left 0.26s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.26s cubic-bezier(0.4, 0, 0.2, 1),
    background-color 0.26s ease;
  pointer-events: none;
  z-index: -1;
}
.display-prefs-seg {
  flex: 1 1 0;
  min-width: 0;
  padding: 4px 6px;
  border-radius: var(--ui-radius-xs);
  border: 0;
  background: transparent;
  color: var(--ui-text-secondary);
  font-size: calc(var(--ui-font-size-label) * var(--app-font-scale, 1));
  cursor: pointer;
  transition:
    color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.12s ease;
  font-family: inherit;
  white-space: nowrap;
  text-align: center;
  position: relative;
  z-index: 1;
}
.display-prefs-seg:hover {
  color: var(--ui-text-secondary);
}

.display-prefs-seg.on {
  color: var(--ui-text-primary);
}
/* The theme selector has three options and uses a compact active fill;
   React renders its checked state, so it does not need the measured
   sliding indicator used by the font and width sliders. */
.display-theme-segs::before {
  display: none;
}
.display-theme-segs .display-prefs-seg.on {
  background: var(--ui-bg-segment-active);
  box-shadow: var(--ui-elevation-ring);
}

.shared-banner.hidden {
  display: none;
}

/* P1.3 — Custom Instructions textareas inside the profile modal */
.profile-instructions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.profile-instructions-label {
  font-size: var(--ui-font-size-xxs);
  color: var(--ui-text-tertiary);
  font-weight: var(--ui-font-weight-medium);
  letter-spacing: 0.01em;
}
.profile-instructions-foot {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
}
.profile-instructions-state {
  font-size: var(--ui-font-size-label);
  color: var(--ui-text-tertiary);
  font-style: italic;
}
.profile-instructions-state.saved {
  color: var(--ui-ink);
}
.profile-instructions-state.pending {
  color: var(--ui-text-tertiary);
}
/* The dim and the blur both come from tokens now (features/surfaces.css sets
   the backdrop, polish/overlays.css clears the blur). The legacy literals
   55% + blur(4px) could still win on desktop because the polish owner rides
   a lazy chunk — so they are removed here rather than overridden there. */
.cmd-k-overlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--ui-z-sheet) - 3);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(18vh, 140px);
}
.cmd-k-overlay.hidden {
  display: none;
}

/* Radix portals SDK menus without a stacking rung; the settings sheet and
   other fixed surfaces otherwise paint over the option list. Radix writes an
   inline z-index: auto on the wrapper, so lift the portal span instead. */
body > span:has(> [data-radix-popper-content-wrapper]) {
  position: relative;
  z-index: var(--ui-z-popover);
}

[data-radix-popper-content-wrapper] {
  z-index: var(--ui-z-popover);
}

.cmd-k-modal {
  width: min(640px, 92vw);
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* The confirm scrim used to be a 65% literal — the darkest of every dialog.
   Converged on the shared token so all dialogs dim by the same amount. */
.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: var(--ui-z-popover);
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-dialog.hidden {
  display: none;
}
.confirm-box {
  width: 90%;
  max-width: 340px;
  padding: 24px 20px 18px;
}
.confirm-title {
  font-size: calc(var(--ui-font-size-base-medium) * var(--app-font-scale, 1));
  font-weight: var(--ui-font-weight-semibold);
  color: var(--ui-text-primary);
  margin-bottom: 8px;
  text-align: center;
}
.confirm-msg {
  font-size: calc(var(--ui-font-size-base-small) * var(--app-font-scale, 1));
  color: var(--ui-text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
  text-align: center;
}
.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
/* Usage modal — heatmap */
.usage-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--ui-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
}
.usage-overlay.hidden {
  display: none;
}
.usage-modal {
  width: min(720px, 94vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}
.usage-body {
  padding: 18px 22px 22px;
  overflow-y: auto;
  flex: 1;
}
.usage-summary {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.usage-stat {
  background: var(--ui-bg-raised);
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-xl);
  padding: 12px 16px;
  flex: 1;
  min-width: 100px;
}
.usage-stat-val {
  font-size: calc(var(--ui-font-size-xl-raw) * var(--app-font-scale, 1));
  font-weight: var(--ui-font-weight-bold);
  color: var(--ui-text-primary);
}
.usage-stat-lbl {
  font-size: calc(var(--ui-font-size-label) * var(--app-font-scale, 1));
  color: var(--ui-text-tertiary);
  margin-top: 2px;
}
.usage-section-title {
  font-size: calc(var(--ui-font-size-xxs-raw) * var(--app-font-scale, 1));
  font-weight: var(--ui-font-weight-semibold);
  color: var(--ui-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}
.usage-period-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}
.usage-calendar-wrap {
  overflow-x: auto;
  padding: 4px 0 8px;
}
.usage-calendar {
  display: grid;
  grid-template-columns: auto repeat(53, 1fr);
  gap: 2px;
  font-size: calc(var(--ui-font-size-caption) * var(--app-font-scale, 1));
  min-width: 560px;
}

.usage-cal-day {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--ui-radius-xs);
  min-width: 10px;
  min-height: 10px;
  position: relative;
}
.usage-cal-day:hover {
  outline: 2px solid var(--ui-ink);
  outline-offset: -1px;
  z-index: 1;
}
.usage-cal-day-lbl {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: calc(var(--ui-font-size-micro) * var(--app-font-scale, 1));
  color: var(--ui-text-tertiary);
  padding-right: 4px;
}
.usage-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 6px;
  font-size: calc(var(--ui-font-size-caption) * var(--app-font-scale, 1));
  color: var(--ui-text-tertiary);
}
.usage-legend-cell {
  width: 12px;
  height: 12px;
  border-radius: var(--ui-radius-xs);
}
.usage-tooltip {
  position: fixed;
  background: var(--ui-bg-surface);
  border: 1px solid var(--ui-border-default);
  border-radius: var(--ui-radius-md);
  padding: 6px 10px;
  font-size: calc(var(--ui-font-size-label) * var(--app-font-scale, 1));
  color: var(--ui-text-primary);
  pointer-events: none;
  z-index: var(--ui-z-popover);
  white-space: nowrap;
  box-shadow: var(--ui-shadow-popover);
  display: none;
}
.usage-breakdown {
  margin-top: 18px;
  border-top: 0.5px solid color-mix(in srgb, var(--ui-border-default) 8%, transparent);
  padding-top: 14px;
}
.usage-breakdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: calc(var(--ui-font-size-xxs-raw) * var(--app-font-scale, 1));
}
.usage-breakdown th {
  border-bottom: 0.5px solid color-mix(in srgb, var(--ui-border-default) 10%, transparent);
  padding: 5px 8px;
  text-align: left;
  font-weight: var(--ui-font-weight-semibold);
  color: var(--ui-text-secondary);
  font-size: calc(var(--ui-font-size-caption) * var(--app-font-scale, 1));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.usage-breakdown td {
  padding: 5px 8px;
  border-bottom: 0.5px solid color-mix(in srgb, var(--ui-border-default) 5%, transparent);
  color: var(--ui-text-secondary);
}
.usage-breakdown td:last-child {
  text-align: right;
  font-weight: var(--ui-font-weight-medium);
}
.usage-breakdown tr:hover td {
  background: var(--ui-bg-sidebar);
}
.usage-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--ui-text-secondary);
  font-size: calc(var(--ui-font-size-base-small) * var(--app-font-scale, 1));
  gap: 8px;
}

/* Share modal */
.share-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--ui-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
}
.share-overlay.hidden {
  display: none;
}
.share-link-area {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.share-link-input {
  flex: 1;
  min-width: 0;
}
.share-link-input input {
  font-family: var(--font-mono);
}
.share-copy-btn {
  flex: none;
}
/* .share-btn is defined in the top-bar section above */
.share-error {
  font-size: var(--ui-font-size-sm);
  color: var(--ui-danger);
  margin-top: 8px;
  text-align: center;
}
.share-status {
  font-size: var(--ui-font-size-sm);
  color: var(--ui-text-secondary);
  margin-top: 8px;
  text-align: center;
}
/* Shared read-only banner */
.shared-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--ui-bg-hover);
  border-bottom: 1px solid var(--ui-border-default);
  font-size: var(--ui-font-size-sm);
  color: var(--ui-text-primary);
  flex-shrink: 0;
}
.shared-banner svg {
  flex-shrink: 0;
}

/*
 * polish/overlays.css — one contract for every floating surface:
 * hairline border, shared popover/dialog radii, two-layer shadows,
 * and crisp compositor-only motion.
 */

/* ── Menus & popovers ── */
.sidebar-more-popover,
.display-prefs-popover,
.tag-editor-popover {
  font-family: var(--font-sans);
  font-size: var(--ui-text-ui);
  line-height: var(--ui-text-ui-line);
}
/* Shared menu row radius. The model picker owns its rows in components/menu.css. */
.sidebar-more-popover .sidebar-more-item {
  border-radius: var(--ui-radius-row);
}

/* Display-prefs segmented control + toggles. */
.display-prefs-popover .display-prefs-segs {
  background: var(--ui-bg-segment);
  border-radius: var(--ui-segment-radius);
}
.display-prefs-popover .display-prefs-seg {
  border-radius: var(--ui-segment-radius);
  color: var(--ui-text-secondary);
}
.display-prefs-popover .display-prefs-seg.active,
.display-prefs-popover .display-prefs-seg[aria-checked='true'] {
  background: var(--ui-bg-segment-active);
  color: var(--ui-text-primary);
}

/* ── Backdrops: one flat dim ──
   The dim comes from --ui-backdrop (40% light / 50% dark). The legacy
   overlays hard-coded 55–65% black, which turned a light page into a muddy
   grey slab behind every dialog. No blur: chatgpt.com uses a flat scrim
   (docs/ref/chatgpt-parity.md, P1 #9), and a full-viewport backdrop-filter
   re-rasterises the whole page on every frame of the open fade. */
/* Deferred polish links can precede the bundled legacy CSS in production.
   The body scope keeps modal layers authoritative in either loading order. */
body :is(.cmd-k-overlay, .share-overlay, .usage-overlay, .admin-modal-overlay, .confirm-dialog) {
  z-index: var(--ui-z-modal);
}
.app-shell .cmd-k-overlay,
.cmd-k-overlay,
.share-overlay,
.usage-overlay,
.admin-modal-overlay,
.confirm-dialog {
  background: var(--ui-backdrop);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Review flashcards: a centred dialog on desktop and a full-width bottom
   sheet below 640px. The shared component owns the content; this file owns
   the placement so it does not need a viewport read. */
.review-session-panel {
  position: absolute;
  top: 12%;
  align-self: center;
  width: min(560px, calc(100% - 48px));
  max-height: 76%;
  border-radius: var(--ui-radius-card);
}
.review-session-grabber {
  display: none;
}
@media (max-width: 640px) {
  .review-session-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 90%;
    border-radius: var(--ui-radius-card) var(--ui-radius-card) 0 0;
  }
  .review-session-grabber {
    display: block;
  }
}

/* ── Motion: one entrance for dialogs, menus and popovers ──
   Menus and dialogs share a short fade + scale
   ease-out (tokens.css --ui-duration-overlay / --ui-overlay-enter-scale).
   Before this every surface had its own entrance: dialogs slid 12px over
   200ms (confirm 150ms), and the command palette plus the sidebar "more" /
   display popovers had none and popped in. The sidebar More menu now shares
   the anchored-menu primitive with the React menus (sidebar account, session
   rows), message overflow and library row/new/filter menus. The composer
   "+" menu keeps its anchored lift. The generation-config menu enters with
   opacity only so model rows hold their coordinates. */
@keyframes ui-overlay-in {
  from {
    opacity: 0;
    transform: translateY(var(--ui-overlay-enter-y, 0px)) scale(var(--ui-overlay-enter-scale));
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ui-scrim-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes ui-scrim-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.confirm-box,
.anchored-menu,
.msg-action-menu {
  animation: ui-overlay-in var(--ui-duration-overlay) var(--ui-ease-out) both;
}

/* ── Dismissal for the class-hidden panels ────────────────────────────────
   These six panels stay in the DOM and are dismissed by adding `.hidden`, so
   their exit can be a real transition instead of a cut: `allow-discrete`
   keeps the box painted for the fade and flips `display` at the end, and
   `@starting-style` supplies the first frame of the next open. One surface,
   one animation — these selectors were removed from `ui-overlay-in` above.
   Browsers without discrete transitions keep the old instant toggle. */
.cmd-k-modal,
.usage-modal,
.share-modal,
.display-prefs-popover {
  opacity: 1;
  transform: none;
  transform-origin: center;
  transition:
    opacity var(--ui-duration-fast) var(--ui-ease-out),
    transform var(--ui-duration-fast) var(--ui-ease-out),
    display var(--ui-duration-fast) allow-discrete;
}
.cmd-k-modal.hidden,
.usage-modal.hidden,
.share-modal.hidden,
.display-prefs-popover.hidden {
  opacity: 0;
  transform: scale(var(--ui-overlay-enter-scale));
}
@starting-style {
  .cmd-k-modal:not(.hidden),
  .usage-modal:not(.hidden),
  .share-modal:not(.hidden),
  .display-prefs-popover:not(.hidden) {
    opacity: 0;
    transform: scale(var(--ui-overlay-enter-scale));
  }
}
.display-prefs-popover {
  transform-origin: top left;
}

/* Their scrims share the clock: the dim holds while the card leaves, then
   both flip to `display: none` together. */
.cmd-k-overlay,
.usage-overlay,
.share-overlay {
  opacity: 1;
  transition:
    opacity var(--ui-duration-fast) var(--ui-ease-out),
    display var(--ui-duration-fast) allow-discrete;
}
.cmd-k-overlay.hidden,
.usage-overlay.hidden,
.share-overlay.hidden {
  opacity: 0;
}
@starting-style {
  .cmd-k-overlay:not(.hidden),
  .usage-overlay:not(.hidden),
  .share-overlay:not(.hidden) {
    opacity: 0;
  }
}

/* Anchored surfaces grow from the edge that touches their trigger, so the
   entrance reads as the menu unfolding from the button instead of a card
   fading in at its centre. The menu adapter reports its placement/alignment;
   the library menus are positioned by their own right/left anchors. */
.anchored-menu {
  transform-origin: top right;
}
.anchored-menu[data-placement='above'] {
  transform-origin: bottom right;
}
.anchored-menu[data-align='start'] {
  transform-origin: top left;
}
.anchored-menu[data-align='start'][data-placement='above'] {
  transform-origin: bottom left;
}

/* The scrim fades with its card. `.cmd-k-overlay` was the one scrim with no
   entrance at all; the rest carried their own 120–150ms fadeIn. One token
   keeps the dim and the card on the same clock. The four scrims that share
   the dismissal transition above are no longer in this list. */
.admin-modal-overlay,
.confirm-dialog {
  animation: ui-scrim-in var(--ui-duration-overlay) var(--ui-ease-out) both;
}

.confirm-box[data-state='closing'],
.cmd-k-modal[data-state='closing'],
.usage-modal[data-state='closing'],
.share-modal[data-state='closing'],
.display-prefs-popover[data-state='closing'],
.anchored-menu[data-state='closing'],
[data-state='closing'].sidebar-account-menu,
.confirm-dialog[data-state='closing'],
.usage-overlay[data-state='closing'],
.share-overlay[data-state='closing'],
.cmd-k-overlay[data-state='closing'] {
  animation: ui-scrim-out var(--ui-duration-exit) var(--ui-ease-out) forwards;
}

/* Global search: one owner for structure, typography and interactive paint. */
.cmd-k-input-row {
  display: flex;
  align-items: center;
  gap: var(--ui-space-sm);
  padding: var(--ui-space-lg) var(--ui-space-lg);
  border-bottom: 1px solid var(--ui-border-default);
}
.cmd-k-input-row .cmd-k-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--ui-text-tertiary);
}
.cmd-k-input-row input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: none;
  font: inherit;
  color: var(--ui-text-primary);
  font-size: var(--ui-font-size-md);
}
.cmd-k-input-row input::placeholder {
  color: var(--ui-text-placeholder);
}
/* The row owns the focus treatment, the way `.sidebar-search` does.
   The field is auto-focused on open and is the dialog's only focusable
   control, so the shared 2px ring fired on every Cmd-K — a blue capsule
   floating mid-row over a field that has no fill or border of its own,
   reading as an error state rather than as focus. OpenAI's, Linear's and
   Raycast's palettes carry no ring here either: the caret is the cue.
   The row's hairline strengthens instead, which is the same signal the
   sidebar search uses (border colour + fill, no ring). The input keeps the
   contract's transparent outline, so forced-colours users still get the
   system Highlight ring, where the cue actually matters. */
.cmd-k-input-row:focus-within {
  border-bottom-color: var(--ui-border-strong);
}
.cmd-k-input-row input:focus-visible {
  box-shadow: none;
}
/* Geist kbd chip: the control fill with a hairline edge, in Geist Mono at
   the small step. The legacy chip was a bare outline on the card colour,
   which vanished against the raised surface. The edge takes the *strong*
   border, because the chip's own fill is only one step off the card. */
.cmd-k-kbd {
  padding: 2px 6px;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-xs);
  background: var(--ui-bg-control);
  color: var(--ui-text-tertiary);
  font-family: var(--font-mono);
  font-size: var(--ui-font-size-xxs);
  line-height: var(--ui-text-ui-line);
}
.cmd-k-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
/* Section label — the quiet uppercase group heading of the Geist scale. */
.cmd-k-section-label {
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: var(--ui-space-sm) var(--ui-space-md) var(--ui-space-xxs);
  color: var(--ui-text-tertiary);
  font-size: var(--ui-font-size-xxs);
}
/* Result rows: 6px radius (Geist row radius) on the raised surface, a
   ghost wash on hover and the selected fill on the keyboard selection.
   The selected fill is a named scale step rather than --ui-bg-selected:
   the card already sits on the elevated rung, and the control fill would
   land within a hair of it — the hover wash and the selection would read
   as the same tone. */
.cmd-k-row {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.1s;
  padding: var(--ui-space-sm) var(--ui-space-md);
  border-radius: var(--ui-radius-sm);
}
.cmd-k-row:hover {
  background: var(--ui-bg-hover);
}
.cmd-k-row.selected {
  background: var(--ui-bg-hover);
  box-shadow: inset 0 0 0 1px var(--ui-border-default);
}
.cmd-k-row-title {
  font-weight: var(--ui-font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ui-text-primary);
  font-size: var(--ui-font-size-sm);
}
.cmd-k-row-snippet {
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-xs);
}
.cmd-k-row-meta {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
  color: var(--ui-text-tertiary);
  font-size: var(--ui-font-size-xxs);
}
.cmd-k-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--ui-text-tertiary);
  font-size: var(--ui-font-size-xs);
}
.cmd-k-empty kbd {
  margin: 0 2px;
  padding: 1px 5px;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-xs);
  background: var(--ui-bg-control);
  font-family: var(--font-mono);
  font-size: var(--ui-font-size-xxs);
}
.cmd-k-foot {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-sm) var(--ui-space-lg);
  padding: 8px 16px;
  border-top: 1px solid var(--ui-border-default);
  color: var(--ui-text-tertiary);
  font-size: var(--ui-font-size-xxs);
}
.cmd-k-foot kbd {
  padding: 1px 5px;
  margin-right: 4px;
  border: 1px solid var(--ui-border-strong);
  border-radius: var(--ui-radius-xs);
  background: var(--ui-bg-control);
  font-family: var(--font-mono);
  font-size: var(--ui-font-size-xxs);
}

/* Account destinations share the main pane and leave the app sidebar available. */
.account-page {
  width: 100%;
  overflow: hidden;
}
.account-page-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: var(--ui-page-width);
  margin-inline: auto;
  padding-inline: clamp(16px, 3vw, 40px);
  color: var(--ui-text-primary);
}
.account-page-header {
  display: flex;
  align-items: center;
  gap: var(--ui-space-sm);
  padding-block: 20px;
  border-bottom: 1px solid var(--ui-border-subtle);
}
.account-page-title {
  flex: 1;
  min-width: 0;
  margin: 0;
}
.account-page-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--ui-space-sm);
}
.account-page-title h1 {
  margin: 0;
  color: var(--ui-text-primary);
  font-size: var(--ui-text-page);
  font-weight: var(--ui-font-weight-semibold);
  line-height: 1.5;
  letter-spacing: -0.02em;
}
.profile-page {
  max-width: var(--ui-page-reading-width);
}
.profile-page .profile-section {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.profile-page .profile-section + .profile-section {
  padding-top: var(--ui-space-lg);
  border-top: 1px solid var(--ui-border-subtle);
}
.profile-page .profile-section .ui-section-card-header {
  align-items: center;
  margin-bottom: var(--ui-space-sm);
}
.profile-page .profile-section .ui-section-card-title {
  font-size: var(--ui-font-size-md);
  font-weight: var(--ui-font-weight-semibold);
}
.profile-page .profile-section .ui-section-card-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.profile-page .account-page-header {
  flex: 0 0 auto;
  min-height: var(--ui-desktop-header);
  padding-block: 0;
}
.profile-page-body {
  display: flex;
  flex-direction: column;
  gap: var(--ui-space-xl);
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--ui-space-lg) var(--ui-space-xs)
    max(var(--ui-space-xxl), env(safe-area-inset-bottom, 0px));
  scrollbar-gutter: stable;
}
.profile-header,
.profile-section {
  min-width: 0;
}
.profile-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 16rem);
  align-items: center;
  gap: var(--ui-space-lg);
  padding-block-end: var(--ui-space-lg);
  border-bottom: 1px solid var(--ui-border-subtle);
}
.profile-identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--ui-space-md);
}
.profile-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: calc(var(--ui-control-sm) + var(--ui-space-lg));
  aspect-ratio: 1;
  border-radius: var(--ui-radius-pill);
  background: var(--ui-bg-control);
  color: var(--ui-text-primary);
  font-weight: var(--ui-font-weight-semibold);
}
.profile-identity-copy {
  display: grid;
  gap: var(--ui-space-xxs);
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: var(--ui-font-size-sm);
  color: var(--ui-text-secondary);
}
.profile-identity-copy strong {
  color: var(--ui-text-primary);
  font-size: var(--ui-font-size-md);
  font-weight: var(--ui-font-weight-semibold);
}
.profile-display-name {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--ui-space-xs);
  font-size: var(--ui-font-size-sm);
  color: var(--ui-text-secondary);
}
.profile-row,
.profile-action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-md);
  min-width: 0;
  padding-block: var(--ui-space-sm);
  font-size: var(--ui-font-size-sm);
}
.profile-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}
.profile-action-row > button {
  max-width: 100%;
  white-space: normal;
}
.profile-row > * {
  min-width: 0;
}
.profile-web-search-switch {
  flex: none;
}
.profile-row + .profile-row,
.profile-action-row + .profile-action-row,
.profile-section .profile-instructions {
  border-top: 1px solid var(--ui-border-subtle);
}
.profile-row-value {
  min-width: 0;
  color: var(--ui-text-secondary);
  text-align: end;
  overflow-wrap: anywhere;
}
.profile-plan-actions {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0 var(--ui-space-sm);
}
.profile-plan-actions > a {
  max-width: 100%;
  white-space: normal;
}
.profile-id-text {
  font-family: var(--font-mono);
  font-size: var(--ui-font-size-xs);
}
.profile-action-desc,
.profile-toggle-desc {
  margin-top: var(--ui-space-xxs);
  color: var(--ui-text-secondary);
  font-size: var(--ui-font-size-xs);
}
.profile-section .profile-instructions {
  margin-top: 0;
  padding-top: var(--ui-space-md);
}
.profile-instructions-area + .profile-instructions-label {
  margin-top: var(--ui-space-sm);
}
@media (max-width: 768px) {
  html[data-main-view='profilePage'] .app-shell .account-page {
    width: 100%;
    padding: env(safe-area-inset-top, 0px) 0 0;
    overflow: hidden;
  }
  .profile-page .account-page-header {
    display: grid;
    grid-template-columns: var(--ui-control-touch) minmax(0, 1fr) var(--ui-control-touch);
    min-height: var(--ui-mobile-header);
  }
  .profile-page .account-page-title {
    text-align: center;
    overflow-wrap: anywhere;
  }
  .profile-page :is(.account-page-header > button, .profile-settings-action) {
    width: var(--ui-control-touch);
    height: var(--ui-control-touch);
    padding: 0;
    border-radius: var(--ui-radius-pill);
  }
  .profile-page .profile-settings-label {
    display: none;
  }
  .profile-page {
    padding-inline: var(--ui-mobile-page-gutter);
  }
  .profile-header {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--ui-space-md);
  }
  .profile-page-body {
    padding-inline: 0;
    scrollbar-gutter: auto;
  }
  .profile-page-body :is(input, textarea) {
    font-size: max(1rem, var(--ui-font-size-md));
  }
  .profile-row .ui-page-tabs {
    width: auto;
  }
  .profile-plan-actions > a,
  .profile-action-row > button {
    min-height: var(--ui-control-touch);
  }
}

.admin-login-title {
  margin: 0;
  color: var(--ui-text-primary);
  font-size: var(--ui-text-page);
  font-weight: var(--ui-font-weight-semibold);
  line-height: 1.5;
  letter-spacing: -0.02em;
}

/* The footer popover is a quick theme switcher; typography, width, grid and
   background colours have one canonical home in Settings → Display. */
.display-prefs-all {
  width: 100%;
  justify-content: center;
  margin-top: var(--ui-space-xs);
}

/* Empty palette: three quick actions instead of a blank 204px box. */
.cmd-k-quick {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ui-space-xs);
  margin-top: var(--ui-space-sm);
}

/* Cookie consent shares the dialog palette and remains independently accessible. */
.socrates-cookie-consent {
  position: fixed;
  inset: auto max(20px, env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px)) auto;
  margin: 0;
  z-index: var(--ui-z-sheet);
  box-sizing: border-box;
  width: min(25rem, calc(100vw - 40px));
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  font-size: var(--ui-font-size-sm);
  line-height: 1.5;
  pointer-events: auto;
}
.socrates-cookie-consent-title {
  font-size: var(--ui-font-size-sm);
  font-weight: var(--ui-font-weight-medium);
  color: var(--ui-text-primary);
}
.socrates-cookie-consent-message {
  margin: 0;
  color: var(--ui-text-secondary);
}
.socrates-cookie-consent-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.socrates-cookie-consent-link {
  align-self: flex-start;
  font-size: var(--ui-font-size-xs);
  color: var(--ui-text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.socrates-cookie-consent-link:hover {
  color: var(--ui-text-secondary);
}
@media (max-width: 768px) {
  .socrates-cookie-consent {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    inset-inline: 0;
    margin-inline: auto;
    width: min(25rem, calc(100vw - 16px));
    gap: 8px;
    padding: 12px 14px;
  }
  .socrates-cookie-consent-title {
    padding-right: 80px;
    font-size: var(--ui-font-size-sm);
  }
  .socrates-cookie-consent-message {
    font-size: var(--ui-font-size-sm);
    line-height: 1.45;
  }
  .socrates-cookie-consent-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .socrates-cookie-consent-btn {
    width: 100%;
    min-height: var(--ui-control-touch);
  }
  .socrates-cookie-consent-link {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: var(--ui-font-size-xs);
  }
}

/* Do not blur mobile scrims. Keep the underlying page inexpensive to composite. */
@media (max-width: 768px) {
  body
    :is(
      .cmd-k-overlay,
      .usage-overlay,
      .share-overlay,
      .workspace-dialog,
      .tutor-explore-overlay,
      .viz-modal-backdrop
    ) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
