/* V25 functional repairs. Reuse the four editions' existing finish tokens. */
body[data-edition] { --repair-danger: #ecaaa1; }
body[data-edition="ivory"] { --repair-danger: #9b3b32; }

/* Flex children must be allowed to shrink before long titles reach controls. */
body[data-edition] .main-area,
body[data-edition] .chat-surface,
body[data-edition] .chat-feed { min-width: 0; }
body[data-edition] .topbar {
  height: auto; min-height: 66px; flex: 0 0 auto;
  gap: 14px; padding-block: 12px;
}
body[data-edition] .topbar-left { flex: 1 1 140px; min-width: 0; }
body[data-edition] .topbar-left > button { flex-shrink: 0; }
body[data-edition] .topbar-context { flex: 1; min-width: 0; max-width: 100%; }
body[data-edition] .topbar-title {
  display: block; min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.5;
}
body[data-edition] .topbar-right {
  flex: 0 1 auto; min-width: 0; max-width: 72%;
  flex-wrap: wrap; justify-content: flex-end; gap: 7px;
}
body[data-edition] .topbar-right > :is(button, .live-indicator) { flex-shrink: 0; white-space: nowrap; }
body[data-edition] .composer-controls { gap: 10px; align-items: flex-end; }
body[data-edition] .composer-left { min-width: 0; flex: 1; flex-wrap: wrap; justify-content: flex-start; gap: 8px; }
body[data-edition] .composer-left > :is(button, label, span) { min-width: 0; }
body[data-edition] :is(.attach-button, .model-picker, .mode-picker, .model-cost, .char-count) { white-space: nowrap; }
body[data-edition] .model-picker { max-width: min(250px, 100%); }
body[data-edition] .model-picker > .ui-icon { flex-shrink: 0; }
body[data-edition] .model-picker #model-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
body[data-edition] .mode-picker { max-width: 100%; }
body[data-edition] .mode-picker select { min-width: 0; max-width: 150px; }
body[data-edition] .send-button { flex: 0 0 auto; }

/* Assistant content: real semantic blocks, isolated table/code scrolling. */
.rich-text { min-width: 0; max-width: 100%; white-space: normal; overflow-wrap: anywhere; line-height: 1.85; }
.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text p { margin: .75em 0; }
.rich-text :is(h1, h2, h3, h4, h5, h6) { margin: 1.4em 0 .6em; font-weight: 650; line-height: 1.45; letter-spacing: -.015em; color: inherit; }
.rich-text h1 { font-size: 1.65em; }
.rich-text h2 { font-size: 1.4em; }
.rich-text h3 { font-size: 1.2em; }
.rich-text :is(h4, h5, h6) { font-size: 1.05em; }
.rich-text strong { font-weight: 650; }
.rich-text :is(ul, ol) { margin: .8em 0; padding-inline-start: 1.8em; }
.rich-text li { margin: .3em 0; padding-inline-start: .18em; }
.rich-text li > p { margin: .25em 0; }
.rich-text li > :is(ul, ol) { margin: .3em 0 .5em; }
.rich-text blockquote { margin: 1em 0; padding: .3em 1em; border-inline-start: 2px solid var(--finish-icon, #bcb4a4); color: var(--finish-muted, #aaa); background: var(--finish-highlight, #ffffff08); border-radius: 0 8px 8px 0; }
.rich-text blockquote > :first-child { margin-top: .2em; }
.rich-text blockquote > :last-child { margin-bottom: .2em; }
.rich-text a { color: var(--finish-icon, #d7c4a4); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .22em; overflow-wrap: anywhere; }
.rich-text a:hover { text-decoration-thickness: 2px; }
.rich-text hr { margin: 1.5em 0; border: 0; border-top: 1px solid var(--finish-edge, #ffffff25); }
.rich-text code { font-family: ui-monospace, 'Cascadia Code', 'SFMono-Regular', Consolas, monospace; font-variant-ligatures: none; }
.rich-text .rt-inline-code { padding: .13em .35em; border: 1px solid var(--finish-edge, #ffffff25); border-radius: 5px; font-size: .9em; background: var(--finish-highlight, #ffffff08); overflow-wrap: anywhere; }
.rich-text .rt-code-block { margin: 1em 0; max-width: 100%; overflow: hidden; border: 1px solid var(--finish-edge, #ffffff25); border-radius: 11px; background: var(--finish-surface, #191a19); }
.rich-text .rt-code-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px; border-bottom: 1px solid var(--finish-edge, #ffffff25); background: var(--finish-highlight, #ffffff08); }
.rich-text .rt-code-language { color: var(--finish-muted, #aaa); font-size: 11px; letter-spacing: .03em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rich-text .rt-code-copy { flex: none; padding: 4px 8px; min-height: 28px; color: var(--finish-label, #ddd); border: 1px solid var(--finish-edge, #ffffff25); border-radius: 6px; background: transparent; font: inherit; font-size: 11px; cursor: pointer; white-space: nowrap; }
.rich-text .rt-code-copy:hover { background: var(--finish-highlight, #ffffff08); border-color: var(--finish-icon, #bcb4a4); }
.rich-text pre { margin: 0; padding: 15px; max-width: 100%; overflow-x: auto; white-space: pre; overflow-wrap: normal; tab-size: 2; line-height: 1.7; color: var(--finish-label, #ddd); }
.rich-text pre code { display: block; padding: 0; border: 0; background: none; font-size: 12px; white-space: inherit; }
.rich-text .rt-table-scroll { margin: 1em 0; max-width: 100%; overflow-x: auto; border: 1px solid var(--finish-edge, #ffffff25); border-radius: 10px; }
.rich-text table { width: 100%; min-width: 350px; border-collapse: collapse; font-size: .93em; }
.rich-text :is(th, td) { padding: 10px 13px; border-bottom: 1px solid var(--finish-edge, #ffffff25); border-inline-end: 1px solid var(--finish-edge, #ffffff25); text-align: left; vertical-align: top; min-width: 80px; }
.rich-text th { background: var(--finish-highlight, #ffffff08); font-weight: 600; }
.rich-text :is(th, td):last-child { border-inline-end: 0; }
.rich-text tbody tr:last-child td { border-bottom: 0; }
.rich-text .rt-align-center { text-align: center; }
.rich-text .rt-align-right { text-align: right; }
.rich-text .rt-plain { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Native page dialogs replace browser prompt/confirm without changing materials. */
body[data-edition] .dialog-backdrop:has(.chat-action-dialog) { z-index: 90; }
.dialog-backdrop[hidden] { display: none; }
body[data-edition] .chat-action-dialog {
  width: min(100%, 460px); max-height: calc(100dvh - 40px); min-width: 0;
  overflow: auto; overscroll-behavior: contain; padding: 26px;
  border: 1px solid var(--finish-edge); border-radius: 18px;
  color: var(--finish-label); background: var(--finish-composer);
  box-shadow: inset 0 1px var(--finish-highlight), 0 25px 80px #0006;
}
.chat-action-dialog form { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.chat-action-dialog h2 { margin: 0; font-size: 21px; font-weight: 550; line-height: 1.45; letter-spacing: -.025em; }
.chat-action-description { margin: 0; font-size: 13px; line-height: 1.8; overflow-wrap: anywhere; color: var(--finish-muted); white-space: pre-line; }
.chat-action-dialog label { display: block; font-size: 12px; line-height: 1.7; color: var(--finish-label); }
body[data-edition] .chat-action-input {
  display: block; width: 100%; min-width: 0; margin-top: 7px; padding: 11px 12px;
  font: inherit; font-size: 14px; border: 1px solid var(--finish-edge); border-radius: 8px;
  color: var(--finish-label); background: var(--finish-surface);
}
.chat-action-error { margin: 0; min-height: 0; color: var(--repair-danger); font-size: 12px; line-height: 1.65; overflow-wrap: anywhere; }
.chat-action-error:empty { display: none; }
.chat-action-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 9px; padding-top: 6px; }
body[data-edition] :is(.chat-action-actions button, .conversation-load-more, .history-load-more, .device-toolbar button, .device-revoke) {
  min-height: 36px; padding: 8px 13px; border: 1px solid var(--finish-edge); border-radius: 8px;
  color: var(--finish-label); background: var(--finish-surface); box-shadow: inset 0 1px var(--finish-highlight);
  font: inherit; font-size: 12px; line-height: 1.5; cursor: pointer; text-align: center;
}
body[data-edition] :is(.chat-action-actions button, .conversation-load-more, .history-load-more, .device-toolbar button, .device-revoke):hover:not(:disabled) { border-color: var(--finish-icon); background: var(--finish-raised); }
body[data-edition] .chat-action-actions button[type="submit"] { color: var(--finish-icon); border-color: var(--finish-icon); }
body[data-edition] .chat-action-actions button.is-danger,
body[data-edition] .device-revoke { color: var(--repair-danger); }
body[data-edition] :is(.chat-action-actions button, .conversation-load-more, .history-load-more, .device-toolbar button, .device-revoke, .rt-code-copy):disabled { opacity: .55; cursor: not-allowed; }
body[data-edition] [aria-busy="true"] :is(.chat-action-actions button, .history-load-more),
body[data-edition] :is(.conversation-load-more, .history-load-more, .device-revoke, .rt-code-copy)[aria-busy="true"] { cursor: wait; }
body[data-edition] :is(.rich-text a, .rt-code-copy, .rich-text pre, .rt-table-scroll, .chat-action-input, .chat-action-actions button, .conversation-load-more, .history-load-more, .device-toolbar button, .device-revoke):focus-visible { outline: 2px solid var(--finish-icon); outline-offset: 3px; }

/* Pagination and account details remain readable without dominating the sidebar. */
.conversation-load-more { display: block; width: calc(100% - 8px); margin: 10px 4px; }
.history-pagination { display: flex; justify-content: center; margin: 10px 0 25px; }
.history-load-more { max-width: 100%; }
.access-details { margin-top: 19px; padding-top: 16px; border-top: 1px solid var(--finish-edge); }
.access-expiry, .access-limit-summary { margin: 7px 0; color: var(--finish-muted); font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; white-space: pre-line; }
.access-expiry strong, .access-limit-summary strong { color: var(--finish-label); font-weight: 550; }
.device-management { margin-top: 19px; padding-top: 16px; border-top: 1px solid var(--finish-edge); min-width: 0; }
.device-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; color: var(--finish-label); font-size: 13px; }
.device-toolbar :is(h3, p) { margin: 0; font: inherit; }
.device-list { display: grid; gap: 8px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 0; padding: 12px; border: 1px solid var(--finish-edge); border-radius: 10px; background: var(--finish-highlight); }
.device-copy { min-width: 0; flex: 1; }
.device-copy strong { display: block; font-size: 12px; font-weight: 550; color: var(--finish-label); overflow-wrap: anywhere; line-height: 1.6; }
.device-copy small { display: block; margin-top: 4px; color: var(--finish-muted); font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.device-revoke { flex: none; white-space: nowrap; }
.device-empty { margin: 10px 0; color: var(--finish-muted); font-size: 12px; line-height: 1.75; }

@media (min-width: 761px) and (max-width: 1280px) {
  body[data-edition] .topbar { padding-inline: 20px; gap: 10px; }
  body[data-edition] .topbar-right { gap: 6px; }
  body[data-edition] .topbar-overline { display: none; }
  body[data-edition] .edition-trigger .edition-current-name { display: none; }
}
@media (max-width: 760px) {
  body[data-edition] .topbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; padding: 9px 12px; }
  body[data-edition] .topbar-left { width: 100%; gap: 10px; }
  body[data-edition] .topbar-context { display: flex; }
  body[data-edition] .topbar-title { font-size: 13px; margin: 0; }
  body[data-edition] .topbar-right { width: 100%; max-width: 100%; justify-content: flex-start; gap: 6px; }
  body[data-edition] .topbar-right :is(.edition-trigger, .immersive-trigger, .ambience-trigger) { width: 38px; min-height: 38px; height: 38px; }
  body[data-edition] .topbar-right .top-access { min-height: 38px; margin-left: 0; padding-inline: 10px; }
  body[data-edition] .live-indicator { margin-inline-start: auto; }
  body[data-edition] .composer-left { gap: 7px; }
  body[data-edition] .model-picker { max-width: min(210px, 100%); }
  body[data-edition] :is(.model-picker, .mode-picker, .attach-button) { min-height: 35px; }
  body[data-edition] .model-cost { flex-basis: auto; }
  body[data-edition] .chat-action-dialog { max-height: calc(100dvh - 28px); padding: 22px 19px; border-radius: 15px; }
  body[data-edition] .chat-action-input { font-size: 16px; }
  .chat-action-actions > button { flex: 1; min-height: 42px; }
  .device-row { padding: 11px; gap: 10px; }
  body[data-edition] .device-revoke { padding-inline: 10px; min-height: 40px; }
  .rich-text .rt-code-toolbar { padding: 7px 10px; }
  .rich-text pre { padding: 12px; }
  .rich-text .rt-code-copy { min-height: 32px; }
  .rich-text :is(th, td) { padding: 9px 11px; }
}
