/* Nexus controls. Tokens and primitives live here; screen files own layout only. */
:root {
  --ctl-r6: 6px; --ctl-r8: 8px; --ctl-r10: 10px; --ctl-r14: 14px; --ctl-pill: 999px;
  --ctl-h28: 28px; --ctl-h32: 32px; --ctl-h36: 36px; --ctl-h44: 44px;
  --ctl-s4: 4px; --ctl-s8: 8px; --ctl-s12: 12px; --ctl-s16: 16px; --ctl-s24: 24px;
  --hairline: rgba(29,29,31,.10); --ctl-line-strong: rgba(29,29,31,.16);
  --ctl-contact: 0 1px 0 rgba(29,29,31,.04), 0 1px 2px rgba(29,29,31,.06);
  --ctl-raised: 0 1px 1px rgba(29,29,31,.04), 0 4px 12px rgba(29,29,31,.08);
  --ctl-overlay: 0 12px 32px rgba(29,29,31,.14), 0 2px 6px rgba(29,29,31,.06);
  --ctl-ease: cubic-bezier(.2,.8,.2,1); --ctl-state: 120ms; --ctl-enter: 160ms; --ctl-leave: 90ms;
  --ctl-neutral: #ecebe6; --ctl-hover: rgba(29,29,31,.05); --ctl-pressed: rgba(29,29,31,.08);
  --ctl-key-fill: #f1efea; --ctl-disabled: #f3f1ec; --ctl-ring: 0 0 0 3px rgba(29,29,31,.08);
  /* Text and meaning-bearing glyphs are opaque; hairlines are decorative. */
  --tertiary: #6a6662; --attention: #885700; --verified: #236b35; --destructive: #b42332;
  --radius: var(--ctl-r14); --radius-small: var(--ctl-r8); --radius-control: var(--ctl-r10); --radius-panel: var(--ctl-r14);
}
/* Interpolated gradient stops keep primary state changes continuous. */
@property --ctl-top { syntax: '<color>'; inherits: false; initial-value: #2a2a2d; }
@property --ctl-bottom { syntax: '<color>'; inherits: false; initial-value: #1d1d1f; }
:where(.ctl-button, .ctl-row, .ctl-marker, .ctl-chip, .ctl-field, .ctl-native, .ctl-overlay) {
  transition: background-color var(--ctl-state) var(--ctl-ease), border-color var(--ctl-state) var(--ctl-ease), color var(--ctl-state) var(--ctl-ease), box-shadow var(--ctl-state) var(--ctl-ease), opacity var(--ctl-state) var(--ctl-ease), transform var(--ctl-state) var(--ctl-ease);
}
:is(.ctl-button, .ctl-row, .ctl-marker, .ctl-native, .ctl-segment):focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.ctl-button.ctl-button {
  --ctl-height: var(--ctl-h32); position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  height: var(--ctl-height); min-height: var(--ctl-height); gap: 6px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--ctl-r8); background: transparent; color: var(--ink);
  font: 550 13px/1 var(--font); text-decoration: none; white-space: nowrap; cursor: pointer; vertical-align: middle;
}
.ctl-button.ctl-compact { --ctl-height: var(--ctl-h28); padding-inline: 12px; }
.ctl-button.ctl-large { --ctl-height: var(--ctl-h36); padding-inline: 16px; }
.ctl-button.ctl-touch { --ctl-height: var(--ctl-h44); padding-inline: 16px; }
.ctl-button.ctl-icon { width: var(--ctl-height); padding: 0; }
.ctl-button.ctl-inline { height: auto; min-height: 0; padding: 4px 6px; font: inherit; white-space: inherit; }
:is(.ctl-button, .ctl-row, .ctl-chip) > svg { flex: none; width: 16px; height: 16px; }
.ctl-button.ctl-button.ctl-primary {
  color: white; background: linear-gradient(var(--ctl-top), var(--ctl-bottom));
  transition: --ctl-top var(--ctl-state) var(--ctl-ease), --ctl-bottom var(--ctl-state) var(--ctl-ease), box-shadow var(--ctl-state) var(--ctl-ease), transform var(--ctl-state) var(--ctl-ease), opacity var(--ctl-state) var(--ctl-ease);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), var(--ctl-contact);
}
.ctl-button.ctl-button.ctl-secondary { background: white; border-color: var(--hairline); box-shadow: var(--ctl-contact); }
.ctl-button.ctl-destructive { color: var(--destructive); border-color: var(--destructive); background: transparent; box-shadow: none; }
.ctl-button.ctl-quiet { border-color: transparent; background: transparent; box-shadow: none; }
@media (hover: hover) {
  .ctl-button.ctl-primary:is(:hover, [data-state=hover]):not(:disabled) { --ctl-top: #2e2e31; --ctl-bottom: #222224; }
  .ctl-button.ctl-secondary:is(:hover, [data-state=hover]):not(:disabled) { border-color: var(--ctl-line-strong); background: #fbfaf8; box-shadow: var(--ctl-contact); }
  .ctl-button.ctl-quiet:is(:hover, [data-state=hover]):not(:disabled), .ctl-row:hover:not(:disabled) { background: var(--ctl-hover); color: var(--ink); }
  .ctl-button.ctl-destructive:is(:hover, [data-state=hover]):not(:disabled) { background: color-mix(in srgb, var(--destructive) 6%, transparent); }
}
.ctl-button.ctl-button:is(:active, [data-state=pressed]):not(:disabled) { transform: translateY(.5px); box-shadow: none; opacity: 1; }
.ctl-button.ctl-primary:is(:active, [data-state=pressed]):not(:disabled) { --ctl-top: #1d1d1f; --ctl-bottom: #2a2a2d; }
.ctl-button.ctl-secondary:is(:active, [data-state=pressed]):not(:disabled) { background: #f1efea; }
.ctl-button.ctl-quiet:is(:active, [data-state=pressed]):not(:disabled), .ctl-row:active:not(:disabled) { background: var(--ctl-pressed); }
.ctl-button.ctl-button:disabled, .ctl-button.ctl-button[aria-disabled=true] { opacity: .4; cursor: default; box-shadow: none; transform: none; }
.ctl-button.ctl-button[aria-busy=true] { opacity: 1; cursor: progress; }
.ctl-busy-label { display: contents; visibility: hidden; }
.ctl-busy-dots { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 4px; }
.ctl-busy-dots i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; animation: ctl-pulse 900ms var(--ctl-ease) infinite alternate; }
.ctl-busy-dots i:nth-child(2) { animation-delay: 120ms; } .ctl-busy-dots i:nth-child(3) { animation-delay: 240ms; }
@keyframes ctl-pulse { from { opacity: .35; transform: translateY(1px); } to { opacity: 1; transform: translateY(-1px); } }
.ctl-button.ctl-icon[aria-pressed=true] { color: var(--ink); background: var(--ctl-neutral); border-color: var(--ink); }
.ctl-button[data-state=focus] { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Fields. Wrappers own adornments; the input remains the event/focus target. */
.ctl-label { gap: var(--ctl-s4); color: var(--secondary); font-size: 12px; }
.ctl-field.ctl-field {
  width: 100%; min-width: 0; height: var(--ctl-h36); padding: 0 12px; border: 1px solid var(--hairline); border-radius: var(--ctl-r10);
  background: white; color: var(--ink); font: 400 13px/1.5 var(--font); outline: none;
}
textarea.ctl-field.ctl-field { height: auto; min-height: var(--ctl-h36); padding-block: 8px; }
.ctl-field.ctl-field::placeholder { color: var(--tertiary); opacity: 1; }
.ctl-field.ctl-field:hover:not(:disabled):not(:focus):not([aria-invalid=true]):not([data-state=focus]) { border-color: var(--ctl-line-strong); }
.ctl-field.ctl-field:is(:focus, [data-state=focus]) { border-color: var(--ink); box-shadow: var(--ctl-ring); outline: none !important; background: white; }
.ctl-field.ctl-field[aria-invalid=true] { border-color: var(--destructive); }
.ctl-field.ctl-field:disabled { background: var(--ctl-disabled); color: var(--tertiary); cursor: default; }
.ctl-field-error { margin: 4px 0 0; color: var(--destructive); font-size: 12px; }
.ctl-native { accent-color: var(--ink); }
.ctl-native:is([type=checkbox], [type=radio]) { width: 16px; height: 16px; vertical-align: middle; margin: 0; }
.ctl-search { position: relative; display: grid; gap: 4px; min-width: 0; flex: 1; }
.ctl-search-slot { position: relative; display: flex; align-items: center; min-width: 0; }
.ctl-search-slot > svg { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--tertiary); pointer-events: none; z-index: 1; }
.ctl-search-slot > .ctl-field.ctl-field { padding-left: 34px; padding-right: 42px; }
.ctl-search-tail { position: absolute; right: 6px; display: flex; align-items: center; }
.ctl-search-tail .ctl-icon { --ctl-height: var(--ctl-h28); }
.ctl-search .ctl-key { pointer-events: none; }
.ctl-search input::-webkit-search-cancel-button { display: none; }
.ctl-key.ctl-key { display: inline-flex; align-items: center; justify-content: center; flex: none; height: 18px; min-width: 18px; padding: 0 4px; border: 1px solid var(--hairline); border-bottom-color: #ccc8c2; border-radius: 5px; background: #f1efea; color: var(--secondary); font: 500 11px/1 var(--font); white-space: nowrap; }

/* One moving pseudo-element is the thumb; options never paint their own thumb. */
.ctl-segments.ctl-segments { position: relative; isolation: isolate; display: inline-flex; flex: none; padding: 2px; gap: 0; border: 0; border-radius: var(--ctl-r10); background: #ecebe6; }
.ctl-segments::before { content: ''; position: absolute; top: 0; left: 0; width: var(--ctl-indicator-w, 0px); height: var(--ctl-indicator-h, 0px); transform: translate(var(--ctl-indicator-x, 2px), var(--ctl-indicator-y, 2px)); border-radius: var(--ctl-r8); background: white; box-shadow: var(--ctl-contact); opacity: var(--ctl-indicator-opacity, 0); transition: transform var(--ctl-enter) var(--ctl-ease), width var(--ctl-enter) var(--ctl-ease), opacity var(--ctl-state) var(--ctl-ease); pointer-events: none; }
.ctl-segments.ctl-segments .ctl-segment { position: relative; height: 28px; min-height: 28px; padding: 0 12px; border: 0; background: transparent; box-shadow: none; color: var(--secondary); font-size: 13px; font-weight: 400; transform: none; }
.ctl-segments.ctl-segments .ctl-segment:is([aria-pressed=true], [aria-selected=true], [aria-current]) { background: transparent; color: var(--ink); font-weight: 550; box-shadow: none; }
.ctl-segments.ctl-segments .ctl-segment:hover:not(:disabled) { background: var(--ctl-hover); }
.ctl-segments.ctl-segments .ctl-segment:disabled { opacity: .4; }
.ctl-chip.ctl-chip, .ctl-counter.ctl-counter { display: inline-flex; flex: none; align-items: center; justify-content: center; gap: 4px; height: 22px; min-height: 22px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--ctl-pill); background: var(--ctl-neutral); color: var(--secondary); font: 500 12px/1 var(--font); white-space: nowrap; }
.ctl-counter.ctl-counter { min-width: 22px; font-variant-numeric: tabular-nums; }
.ctl-chip.ctl-outlined { background: transparent; border-color: var(--ctl-line-strong); }
.ctl-chip:is(.ok, .passed, [data-tone=ok]) { color: var(--verified); }
.ctl-chip:is(.bad, .failed, [data-tone=bad]) { color: var(--destructive); }
.ctl-chip:is(.warn, [data-tone=warn]) { color: var(--attention); }
.ctl-chip:is(.ok, .passed):not(:has(svg, [aria-hidden]))::before { content: '✓'; }
.ctl-chip:is(.bad, .failed):not(:has(svg, [aria-hidden]))::before { content: '×'; }
.ctl-chip.warn:not(:has(svg, [aria-hidden]))::before { content: '!'; }

/* Rows keep multi-line screen geometry; ordinary menu rows use the 32px rhythm. */
.ctl-row.ctl-row { position: relative; border: 0; border-radius: var(--ctl-r8); background: transparent; color: var(--ink); cursor: pointer; font-size: 13px; }
.ctl-row.ctl-row:is(:hover, [aria-current]:not([aria-current=false]), [aria-selected=true], .selected, .active) { background: var(--ctl-hover); }
.ctl-row:is([aria-current]:not([aria-current=false]), [aria-selected=true], .selected, .active)::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--ink); pointer-events: none; }
:is(.work-menu-item, .work-pop-action, .rv-menu > button, .rv-menu > a).ctl-row { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 8px; border: 0; background: transparent; font: 400 13px/1.4 var(--font); }
:is(.work-menu-item, .work-pop-action, .rv-menu > button, .rv-menu > a).ctl-row:hover { background: var(--ctl-hover); }
.ctl-row.ctl-destructive { color: var(--destructive); }
.ctl-row[aria-disabled=true], .ctl-row:disabled { opacity: .4; cursor: default; }
.ctl-navigation { position: relative; }
.ctl-navigation::before { content: ''; position: absolute; left: 0; top: 0; width: 2px; height: max(0px, calc(var(--ctl-indicator-h, 0px) - 16px)); background: var(--ink); border-radius: 2px; transform: translate(var(--ctl-indicator-x, 0px), calc(var(--ctl-indicator-y, 0px) + 8px)); opacity: var(--ctl-indicator-opacity, 0); transition: transform var(--ctl-enter) var(--ctl-ease), height var(--ctl-enter) var(--ctl-ease); z-index: 1; pointer-events: none; }
.ctl-navigation .ctl-row::before { display: none; }
:is(.work-menu-heading, .command-results h2) { font-size: 11px; letter-spacing: .04em; color: var(--tertiary); }
.ctl-card.ctl-card { border: 1px solid var(--hairline); border-radius: var(--ctl-r14); background: white; box-shadow: none; }
.ctl-card:is(button, a, [tabindex]):not([tabindex='-1']) { box-shadow: var(--ctl-contact); }
.ctl-overlay.ctl-overlay { border: 1px solid var(--hairline); border-radius: var(--ctl-r14); background: white; box-shadow: var(--ctl-overlay); }
dialog:is(.ctl-overlay, .ctl-modal)::backdrop { background: rgba(29,29,31,.18); backdrop-filter: none; -webkit-backdrop-filter: none; }
.ctl-overlay:not(dialog) { animation: ctl-overlay-in var(--ctl-enter) var(--ctl-ease); }
@keyframes ctl-overlay-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: scale(1); } }
.ctl-tooltip { position: fixed; z-index: 10000; display: flex; align-items: center; gap: 6px; max-width: min(320px, calc(100vw - 16px)); padding: 6px 8px; border-radius: var(--ctl-r6); color: white; background: var(--ink); font: 400 12px/1.4 var(--font); pointer-events: none; animation: ctl-overlay-in var(--ctl-state) var(--ctl-ease); }
.ctl-tooltip .ctl-key { background: #3b3b3e; border-color: #626266; color: white; }
@media (pointer: coarse) { .ctl-tooltip { display: none; } }
.ctl-copy-icon, .ctl-copy-check { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity var(--ctl-state) var(--ctl-ease); }
.copy-btn.ctl-button { display: inline-grid; }
.ctl-copy-check { opacity: 0; }
[data-copied=true] > .ctl-copy-icon { opacity: 0; }
[data-copied=true] > .ctl-copy-check { opacity: 1; }
.ctl-composer.ctl-composer { border: 1px solid var(--hairline); border-radius: var(--ctl-r14); background: white; box-shadow: var(--ctl-raised); transition: border-color var(--ctl-state) var(--ctl-ease), box-shadow var(--ctl-state) var(--ctl-ease); }
.ctl-composer.ctl-composer:focus-within { border-color: var(--ink); box-shadow: var(--ctl-raised), var(--ctl-ring); }
.ctl-composer textarea.ctl-field.ctl-field { border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: none !important; }
.send-btn.ctl-button { --ctl-height: var(--ctl-h32); transform: scale(1); }
.send-btn.ctl-button:disabled { transform: scale(.9); }

/* Integration geometry: retain existing row/header measurements and specialised content. */
.ctl-button.work-title { display: block; padding: 0 6px; font: inherit; min-height: 26px; }
.ctl-button.work-switcher, .ctl-button.work-new-session, .ctl-button.palette-trigger { justify-content: flex-start; width: 100%; }
.ctl-button.work-search-all { justify-content: flex-start; width: 100%; font-size: 11px; padding-inline: 0; }
.ctl-field.work-session-rename { height: 26px; min-height: 26px; padding: 0 6px; }
.ctl-field.work-title-input { height: 28px; min-height: 28px; padding: 0 5px; font: inherit; }
.ctl-field.work-side-filter { height: 32px; }
.ctl-field.persona { min-height: 220px; }
.ctl-field:is(.work-new-project, .work-settings-project) { width: auto; max-width: 220px; }
.ctl-button.rv-notes-toggle, .ctl-button.work-split-toggle { display: none; }
@container review (max-width: 719px) { .ctl-button.rv-notes-toggle { display: inline-flex; } }
@container (min-width: 1180px) { .ctl-button.work-split-toggle { display: inline-flex; } }
.work-session .work-header > .ctl-icon { display: none; }
@media (max-width: 719px) { .work-session .work-header > .ctl-icon { display: inline-flex; } .ctl-button.work-expand-toggle { display: none; } }
@media (pointer: coarse) {
  .ctl-button.ctl-button, .ctl-segments.ctl-segments .ctl-segment { --ctl-height: var(--ctl-h44); min-height: 44px; height: 44px; }
  .ctl-field.ctl-field { min-height: 44px; }
  .ctl-row:is(button, a), .ctl-marker { min-height: 44px; }
  .ctl-button.ctl-icon { min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
.ctl-field-label { color: var(--secondary); font: 400 12px/1.4 var(--font); }
.ctl-search [hidden], .ctl-button[hidden], .ctl-row[hidden] { display: none !important; }
.work-pop-search:has(.ctl-search) { height: auto; padding: 8px 12px; }
.column > .ctl-search { margin-bottom: 12px; }

.key-hint::after { content: attr(data-keys); }
.key-hint { margin-left: auto; }
.ctl-button.work-side-more { --ctl-height: var(--ctl-h32); }
/* These two existing header slots are fixed by the Work browser contract. */
.ctl-button.work-switcher { height: 40px; min-height: 40px; }
.ctl-button.work-new-session { height: 34px; min-height: 34px; }
@media (pointer: coarse) { .ctl-button:is(.work-switcher, .work-new-session) { height: 44px; min-height: 44px; } }

/* Explicit inverse control on an ink chat bubble. */
.msg.user .ctl-button.paste-chip { color: white; background: rgba(255,255,255,.14); }
.msg.user .ctl-button.paste-chip:hover { background: rgba(255,255,255,.22); }
.ctl-field[data-state=hover] { border-color: var(--ctl-line-strong); }
.ctl-row.ctl-row.ctl-destructive { color: var(--destructive); }
.ctl-row.ctl-row[aria-disabled=true] { color: var(--secondary); }
.ctl-composer .ctl-field.ctl-field { border: 0; }
.ctl-row:active:not(:disabled) { opacity: 1; }
.ctl-busy-label > svg { flex: none; width: 16px; height: 16px; }
.ctl-button[aria-busy=true]::after { visibility: hidden; }
.ctl-button.ctl-button:not(.ctl-segment)[aria-pressed=true] { border-color: var(--ink); }
.ctl-marker { transition: background-color var(--ctl-state) var(--ctl-ease), opacity var(--ctl-state) var(--ctl-ease), transform var(--ctl-state) var(--ctl-ease); }
.ctl-marker:disabled { opacity: .4; cursor: default; }
.ctl-marker:active:not(:disabled) { transform: translateY(.5px); }

:is(.work-menu, .rv-menu, .menu-sheet).ctl-overlay { transform-origin: top right; }
.work-popover.ctl-overlay { transform-origin: top left; }

@media (pointer: coarse) { .ctl-search-slot > .ctl-field.ctl-field { padding-right: 54px; } }

:is(.rv-send, .rv-notes-toggle)[data-count]::after { min-width: 22px; height: 22px; border-radius: var(--ctl-pill); font-size: 12px; font-weight: 500; }
@media (pointer: coarse) { .key-hint { display: none; } }

/* Inverse quiet controls live on the existing dark media viewer. */
.ctl-button.ctl-inverse { color: white; background: rgba(255,255,255,.12); }
.ctl-button.ctl-inverse:hover:not(:disabled) { background: rgba(255,255,255,.18); }
.ctl-button.ctl-inverse:active:not(:disabled) { background: rgba(255,255,255,.24); }
.ctl-button.ctl-inverse:focus-visible { outline-color: white !important; }

/* Screen geometry takes precedence over the button primitive. */
.ctl-button.work-session-menu { position: absolute; top: 50%; right: 6px; width: 24px; height: 24px; min-height: 24px; transform: translateY(-50%); }
.ctl-button.work-session-menu:active:not(:disabled) { transform: translateY(-50%); }
.ctl-button.rv-round { height: 24px; min-height: 24px; padding: 0 6px 0 9px; font-size: 12.5px; }
.ctl-button.diff-split { display: none; }
@media (min-width: 1100px) { .ctl-button.diff-split { display: inline-flex; } }
/* Opening a dialog fades only: its dimensions and hit targets are final immediately. */
dialog.ctl-overlay { transform: none; transition: opacity var(--ctl-leave) var(--ctl-ease); }
dialog.ctl-overlay[open] { animation: ctl-dialog-in var(--ctl-enter) var(--ctl-ease); transform: none; }
@keyframes ctl-dialog-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 719px) {
  dialog.ctl-overlay:is(.work-sheet, .work-settings, .work-repos) { width: 100%; max-width: 100%; border: 0; border-radius: 0; }
  .ctl-button.work-session-menu { width: 36px; height: 36px; min-height: 36px; right: 2px; }
}
@media (prefers-reduced-motion: reduce) { dialog.ctl-overlay[open] { animation: none; } }

.reminders-entry.ctl-row.ctl-row { font: 400 13.5px/20px var(--font); }
.ctl-button.work-search-all { height: auto; min-height: 32px; white-space: normal; }

/* Shared conversation overlay: preserve its placement and pill above control defaults. */
.jump-latest.ctl-button.ctl-button:not(:disabled) {
  position: absolute; --ctl-height: 28px; padding: 0 12px; border: 1px solid var(--hairline);
  border-radius: var(--ctl-pill); background: white; box-shadow: var(--ctl-raised);
  color: var(--secondary); font-size: 12px; font-weight: 500; transform: translateX(-50%);
}
.jump-latest.ctl-button[hidden] { display: none; }
