/* Shared interaction finish, loaded after page-specific styles. */
:root {
  --radius-control: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

::selection {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--color-accent) 25%, var(--surface-primary));
}

/* Do not paint a page-sized focus box when selecting text inside main. */
.web-main:focus:not(:focus-visible) { outline: none; }
:where(button, a, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}
:where(button, .btn, [role="tab"], .agent-topbar nav, .nav-links, .mobile-nav-toggle) {
  -webkit-user-select: none;
  user-select: none;
}
:where(input, textarea, [contenteditable="true"]) {
  -webkit-user-select: text;
  user-select: text;
}
:where(.panel, .settings-section, .agent-settings-section) {
  overflow-wrap: anywhere;
}
:where(input, select, textarea) { scroll-margin-block: 6rem; }

/* The empty thread/row space is chrome; the actual message stays selectable. */
:where(.agent-thread, .message-stack) {
  -webkit-user-select: none;
  user-select: none;
  scrollbar-gutter: stable;
}
:where(.agent-turn > div, .message, .chat-empty, .agent-chat-cards,
  .agent-thread form, .agent-thread h2, .agent-thread > p) {
  -webkit-user-select: text;
  user-select: text;
}
.agent-thread .agent-turn {
  line-height: 1.65;
  font-size: clamp(1rem, .95rem + .2vw, 1.2rem);
  overflow-wrap: anywhere;
}
.agent-thread .agent-turn:not([data-speaker="user"]) > div {
  max-width: min(100%, 66ch);
  border-left: 0;
  padding: .25rem .5rem;
}
.agent-thread .agent-turn[data-speaker="user"] > div {
  max-width: min(88%, 56ch);
  background: var(--selection-default);
  border-color: var(--border-subtle);
  box-shadow: none;
}
.agent-composer {
  background: var(--surface-primary);
  border-color: var(--border-strong);
  box-shadow: 0 4px 18px rgb(var(--rgb-ink) / .06);
}
.agent-composer:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent) 12%, transparent);
}
.agent-composer textarea::placeholder { color: var(--color-muted); }
.agent-composer .agent-send-button { min-width: 44px; min-height: 44px; }
/* One native page scrollbar, including the composer. The thread is content,
   not a second viewport whose height changes when the input receives focus. */
html:has(.agent-conversation) {
  height: auto;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior-y: auto;
}
body:has(.agent-conversation) {
  position: static;
  height: auto;
  overflow: visible;
  overscroll-behavior-y: auto;
}
body:has(.agent-conversation) .web-main { overflow: visible; }
body:has(#agent-composer) .web-shell { height: auto; min-height: 100svh; }
.agent-shell:has(#agent-composer) {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  height: auto;
  min-height: 100svh;
  overflow: visible;
  grid-template-rows: auto 1fr;
}
.agent-shell:has(.agent-conversation) .agent-app,
.agent-conversation { height: auto; }
.agent-shell:has(.agent-conversation) .agent-topbar,
.agent-shell-data .agent-topbar,
.agent-public-shell .agent-public-header {
  position: sticky;
  top: 0;
  align-self: start;
  background: var(--color-page) !important;
}
/* Keep navigation in the viewport while the page owns scrolling. */
html:has(.agent-shell-data), html:has(.agent-public-shell) {
  height: auto;
  overflow-x: clip;
  overflow-y: auto;
}
body:has(.agent-shell-data), body:has(.agent-public-shell) {
  position: static;
  height: auto;
  overflow: visible;
}
body:has(.agent-shell-data) .web-main,
body:has(.agent-public-shell) .web-main { overflow: visible; padding-bottom: 0; }
.agent-shell-data, .agent-public-shell {
  height: auto;
  min-height: 100svh;
  overflow: visible;
  grid-template-rows: auto 1fr;
}
.agent-shell-data .agent-settings-layout { overflow: visible; }
.agent-public-thread { overflow: visible; }
.agent-public-chat { overflow: visible; }
.agent-public-composer-dock { position: sticky; bottom: 0; padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
.agent-conversation { grid-template-rows: 1fr auto; }
.agent-conversation .agent-thread {
  overflow: visible;
  max-height: none;
  scrollbar-gutter: auto;
  overscroll-behavior: auto;
}
.agent-conversation .agent-composer-dock {
  position: sticky;
  bottom: 0;
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
}
.agent-conversation .agent-composer textarea { scroll-margin: 0; }

.chat-window {
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  height: min(800px, calc(100dvh - 130px));
}
.chat-window .chat-message-stack {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.chat-message-stack {
  gap: 16px;
  background: var(--surface-secondary);
}
.chat-message-stack .message {
  width: fit-content;
  min-width: 0;
  max-width: min(85%, 62ch);
  justify-self: start;
  border-color: var(--border-subtle);
  border-radius: 16px 16px 16px 5px;
  padding: 12px 16px;
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: none;
  overflow-wrap: anywhere;
}
.chat-message-stack .message.out {
  justify-self: end;
  border-radius: 16px 16px 5px 16px;
  border-color: var(--border-subtle);
  background: var(--selection-default);
  color: var(--text-primary);
}
.chat-message-stack .message > div { white-space: pre-wrap; line-height: 1.6; }
.chat-message-stack .message.out :is(small, time) { color: var(--text-secondary); }
.chat-compose {
  padding: 14px;
  background: var(--surface-primary);
}
.chat-compose label { min-width: 0; }
.chat-compose textarea { min-height: 64px; resize: vertical; }
.chat-compose button { min-height: 44px; }
.chat-empty { transform: none; }

.message-copy {
  display: block;
  width: fit-content;
  min-height: 28px;
  margin-top: 5px;
  padding: 3px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.message-copy:hover { background: var(--selection-default); color: var(--text-primary); }
.message-copy:disabled { cursor: default; }
.message-actions { display: flex; gap: 6px; }
.message-quotation {
  display: block;
  padding-inline: 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--color-accent);
  color: var(--text-secondary);
  font-size: .9em;
}
.chat-reply-preview {
  grid-column: 1 / -1;
  position: relative;
  width: min(100%, var(--agent-chat-width, 58rem));
  margin: 0 auto 8px;
  padding: 10px 48px 10px 14px;
  border-left: 3px solid var(--color-accent);
  border-radius: 8px;
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: 13px;
}
.chat-reply-preview p {
  margin: 4px 0 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
  color: var(--text-secondary);
}
.chat-reply-preview button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
}
.chat-reply-preview[hidden] { display: none; }
.chat-latest-button {
  display: block;
  margin: 0 auto 8px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-subtle);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.chat-latest-button[hidden] { display: none; }
@media (pointer: coarse) { .message-copy { min-height: 44px; } }
@media (max-width: 640px) {
  .agent-conversation .agent-composer textarea { font-size: 16px; }
  .chat-window { height: min(760px, 80dvh); }
  .chat-message-stack { padding: 16px 12px; }
  .chat-message-stack .message { max-width: 92%; padding: 10px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .agent-typing i { animation: none; opacity: .65; }
  .agent-composer, .message-copy { transition: none; }
}

/* Messaging-app controls stay out of the transcript until requested. */
.message-with-menu { position: relative; touch-action: pan-y; translate: var(--reply-swipe, 0) 0; }
.message-menu-trigger {
  position: static; width: 36px; height: 36px; min-height: 0;
  display: inline-grid; place-items: center; padding: 0;
  margin: 0 0 0 4px; vertical-align: middle;
  border: 0; border-radius: 6px; box-shadow: none;
  background: transparent; color: var(--text-secondary);
  cursor: pointer; opacity: 0;
}
.message-menu-trigger svg { width: 18px; height: 18px; fill: currentColor; }
.message-menu-trigger:hover, .message-menu-trigger[aria-expanded="true"] { background: var(--selection-default); color: var(--text-primary); }
.message-menu-trigger:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.message-with-menu:hover .message-menu-trigger,
.message-with-menu:focus-within .message-menu-trigger { opacity: 1; }
.message-actions[popover] {
  position: fixed; inset: auto; margin: 0; padding: 3px; width: max-content;
  max-width: calc(100vw - 16px); border: 1px solid var(--border-subtle);
  border-radius: 8px; background: var(--surface-primary); color: var(--text-primary);
  box-shadow: 0 4px 16px rgb(0 0 0 / .1);
}
.message-actions[popover]:not(:popover-open) { display: none; }
.message-actions[popover]:popover-open { display: flex; gap: 2px; }
.message-actions .message-copy { width: auto; min-height: 36px; margin: 0; padding: 6px 10px; border-radius: 5px; text-align: start; font-size: 13px; white-space: nowrap; }
@media (pointer: coarse) {
  .message-menu-trigger { opacity: .65; width: 44px; height: 44px; }
  .message-actions .message-copy { min-height: 44px; }
  .message-with-menu { -webkit-touch-callout: default; }
  .message-with-menu > p, .message-with-menu.message > div:not(.message-actions) { -webkit-user-select: text; user-select: text; }
}

@media (pointer: coarse) {
 .message-menu-trigger { border: 0; background: transparent; }
}

button[aria-busy="true"] { cursor: progress; }

.message-feedback {
 position: fixed; z-index: 2100; bottom: 110px; left: 50%; transform: translateX(-50%);
 padding: 8px 16px; border: 1px solid var(--border-subtle); border-radius: 999px;
 background: var(--surface-primary); color: var(--text-primary); box-shadow: 0 4px 16px rgb(0 0 0 / .12);
 font-size: 14px; pointer-events: none;
}
.message-feedback[hidden] { display: none; }

/* Compact consent notice with two equally weighted choices. */
.analytics-consent-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.analytics-consent-actions form { margin: 0; }
.analytics-consent-banner .analytics-consent-actions form { display: flex; }
.analytics-consent-banner {
  position: fixed;
  z-index: 1000;
  inset: auto auto max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgb(10 40 52 / .10);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
}
.analytics-consent-banner h2 { margin: 0 0 6px; font-size: 15px; line-height: 1.3; font-weight: 600; }
.analytics-consent-banner p { margin: 0; color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
.analytics-consent-banner .analytics-consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.analytics-consent-banner form { margin: 0; }
.analytics-consent-banner button { width: 100%; min-height: 44px; padding: 8px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-primary); color: var(--text-primary); font: inherit; font-weight: 500; cursor: pointer; box-shadow: none; }
.analytics-consent-banner button:hover { background: var(--selection-default); border-color: var(--text-secondary); }
.analytics-consent-banner button:disabled { opacity: .65; cursor: progress; }
.analytics-consent-customize { margin-top: 2px; }
.analytics-consent-customize > summary { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; color: var(--text-secondary); font-size: 12px; cursor: pointer; list-style: none; }
.analytics-consent-customize > summary::-webkit-details-marker { display: none; }
.analytics-consent-customize > summary:hover { color: var(--text-primary); }
.analytics-consent-customize summary svg { width: 16px; height: 16px; transition: transform 150ms ease; }
.analytics-consent-customize[open] summary svg { transform: rotate(180deg); }
.cookie-consent-details { display: grid; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
.cookie-consent-details a { color: var(--text-secondary); text-underline-offset: 3px; }
.analytics-consent-banner .cookie-consent-error { margin-top: 8px; color: var(--text-primary); font-size: 13px; }
@media (max-width: 520px) {
  .analytics-consent-banner { left: 50%; transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom)); max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  .analytics-consent-banner button { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .analytics-consent-customize summary svg { transition: none; }
}
