:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --page-bg: #ffffff;
  --text: #1f2328;
  --border: #d0d7de;
  --border-subtle: #d8dee4;
  --button-bg: #f6f8fa;
  --button-hover: #eaeef2;
  --sidebar-bg: #f6f8fa;
  --thread-active: #eaeef2;
  --muted: #656d76;
  --muted-strong: #57606a;
  --input-text: #424a53;
  --panel-bg: #f6f8fa;
  --control-bg: #ffffff;
  --notice-text: #633c01;
  --notice-bg: #fff8c5;
  --notice-border: #d4a72c;
  --jump-border: #8c959f;
  --jump-bg: #ffffff;
  --jump-hover: #f3f4f6;
  --focus: #0969da;
  --empty: #6e7781;
  --link: #0969da;
  --link-hover: #0550ae;
  --quote-border: #8c959f;
  --quote-text: #57606a;
  --code-bg: #f6f8fa;
  --pre-text: #24292f;
  --user-bg: #f0f2f4;
  --activity-bg: #f6f8fa;
  --activity-text: #424a53;
  --activity-output: #57606a;
  --request-border: #bf8700;
  --request-bg: #fff8c5;
  --request-output: #633c01;
  --request-control-border: #afb8c1;
  --drop-bg: #eef8f1;
  --attachment-text: #424a53;
  --composer-bg: #ffffff;
  --success: #1f883d;
  --success-text: #1a7f37;
  --match-bg: #fff1a8;
  --match-outline: #bf8700;
  --shadow: rgb(31 35 40 / 20%);
  --floating-shadow: rgb(31 35 40 / 25%);
  --scrim: rgb(31 35 40 / 45%);
  --sidebar-width: 260px;
  --sidebar-rail-width: 64px;
  background: var(--page-bg);
  color: var(--text);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #101112;
  --text: #ecebea;
  --border: #3b3d40;
  --border-subtle: #2b2d30;
  --button-bg: #242628;
  --button-hover: #303336;
  --sidebar-bg: #171819;
  --thread-active: #27292b;
  --muted: #8f9397;
  --muted-strong: #9da1a5;
  --input-text: #bfc2c5;
  --panel-bg: #151718;
  --control-bg: #202224;
  --notice-text: #ffdca0;
  --notice-bg: #332a1b;
  --notice-border: #5c4827;
  --jump-border: #596168;
  --jump-bg: #303438;
  --jump-hover: #3a4045;
  --focus: #78b7e8;
  --empty: #74787c;
  --link: #78b7e8;
  --link-hover: #a6d5f8;
  --quote-border: #555b60;
  --quote-text: #b4b8bc;
  --code-bg: #1b1d1f;
  --pre-text: #d7dadd;
  --user-bg: #24272a;
  --activity-bg: #151617;
  --activity-text: #c4c7ca;
  --activity-output: #aeb2b6;
  --request-border: #725d31;
  --request-bg: #2a2419;
  --request-output: #d7d1c3;
  --request-control-border: #4c4e51;
  --drop-bg: #20272b;
  --attachment-text: #cfd2d5;
  --composer-bg: #121314;
  --success: #57c785;
  --success-text: #80c99b;
  --match-bg: #493d1d;
  --match-outline: #d4a72c;
  --shadow: rgb(0 0 0 / 35%);
  --floating-shadow: rgb(0 0 0 / 45%);
  --scrim: rgb(0 0 0 / 55%);
}

* { box-sizing: border-box; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

html, body { height: 100%; margin: 0; overflow: hidden; }

button, input, select, textarea { font: inherit; }

button {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--button-bg);
  color: inherit;
  padding: .48rem .72rem;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover:not(:disabled) { background: var(--button-hover); }
button:disabled { cursor: default; opacity: .45; }

.shell { position: relative; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-width: 0; min-height: 0; height: 100vh; height: 100dvh; overflow: hidden; }

.menu-button { display: none; }
.close-sidebar, .sidebar-scrim, .sidebar-swipe-edge { display: none; }

.sidebar {
  grid-column: 1;
  min-width: 0;
  padding: 14px;
  border-right: 1px solid var(--border-subtle);
  background: var(--sidebar-bg);
  overflow: auto;
}

.chat { grid-column: 2; }

.sidebar-resizer {
  position: absolute;
  z-index: 20;
  top: 0;
  bottom: 0;
  left: calc(var(--sidebar-width) - 6px);
  width: 12px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: col-resize;
  touch-action: none;
}
.sidebar-resizer::after { content: ""; position: absolute; inset: 0 auto 0 5px; width: 1px; background: var(--border-subtle); }
.sidebar-resizer:hover::after,
.sidebar-resizer:focus-visible::after { left: 4px; width: 3px; background: var(--focus); }
.sidebar-resizer:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.sidebar-resizer[hidden] { display: none; }
.shell.sidebar-resizing,
.shell.sidebar-resizing * { cursor: col-resize !important; user-select: none; }

@media (min-width: 761px) {
  .shell.sidebar-collapsed { grid-template-columns: var(--sidebar-rail-width) minmax(0, 1fr); }
  .shell.sidebar-collapsed .sidebar { padding: 14px; overflow: visible; }
  .shell.sidebar-collapsed .sidebar-resizer,
  .shell.sidebar-collapsed .brand-home { display: none; }
  .shell.sidebar-collapsed .brand { display: grid; justify-content: center; justify-items: center; gap: 10px; margin: 0; }
  .shell.sidebar-collapsed .sidebar-toggle-icon { transform: rotate(180deg); }
}

.brand, .topbar { display: flex; align-items: center; gap: 10px; }
.brand { justify-content: space-between; margin-bottom: 14px; }
.brand-home { margin-right: auto; color: inherit; text-decoration: none; }
.brand-home:hover { color: var(--link-hover); }
.wide { width: 100%; margin-bottom: 12px; text-align: left; }
.sidebar-content[hidden] { display: none; }
.sidebar-action { display: flex; align-items: center; gap: 8px; }
.sidebar-action[aria-pressed="true"] { border-color: var(--focus); background: var(--thread-active); }
.settings-cog,
.sidebar-toggle { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; line-height: 1; }
.settings-cog { font-size: 1.15rem; }
.sidebar-toggle-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 140ms ease; }

.preferences-dialog {
  width: min(470px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--page-bg);
  color: var(--text);
  box-shadow: 0 18px 55px var(--shadow);
}
.preferences-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.preferences-header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); }
.preferences-header h2 { flex: 1; margin: 0; font-size: 1.05rem; }
.preferences-close { display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0; font-size: 1.3rem; line-height: 1; }
.preferences-body { padding: 18px 16px 16px; }
.preferences-body h3 { margin: 0 0 10px; font-size: .9rem; }
.theme-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.theme-option { min-width: 0; min-height: 66px; display: grid; align-content: center; gap: 3px; padding-inline: .55rem; text-align: left; }
.theme-option strong, .theme-option small { overflow: hidden; text-overflow: ellipsis; }
.theme-option small { color: var(--muted); font-size: .68rem; }
.theme-option[aria-pressed="true"] { border-color: var(--focus); background: var(--thread-active); box-shadow: inset 0 0 0 1px var(--focus); }
.preferences-note { min-height: 1.4em; margin: 12px 0 0; color: var(--muted); font-size: .78rem; }

#threads { display: grid; gap: 4px; }
.thread-row { display: grid; grid-template-columns: minmax(0, 1fr) 32px; align-items: center; border-radius: 7px; }
.thread-row:hover, .thread-row:has(.thread.active) { background: var(--thread-active); }
.thread {
  display: block;
  width: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: .48rem .72rem;
  border: 1px solid transparent;
  border-radius: 7px;
  border-color: transparent;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
}
.thread:hover, .thread.active { background: var(--thread-active); }
.thread.running { border-left-color: var(--success); }
.thread.running small { color: var(--success-text); }
.thread strong, .thread small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread small { margin-top: 3px; color: var(--muted); }
.thread-pin { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; background: transparent; color: var(--muted); }
.thread-pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.thread-pin[aria-pressed="true"] { color: var(--focus); }
.thread-pin[aria-pressed="true"] svg path:first-child { fill: currentColor; }
.thread-pin:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

@media (hover: hover) and (pointer: fine) {
  .thread-pin[aria-pressed="false"] { opacity: 0; pointer-events: none; }
  .thread-row:hover .thread-pin, .thread-row:has(:focus-visible) .thread-pin { opacity: 1; pointer-events: auto; }
}

.chat { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto auto; height: 100%; overflow: hidden; }
.chat.search-active { grid-template-rows: minmax(0, 1fr); }
.chat.search-active > :not(.search-view) { display: none; }

.topbar { grid-row: 1; min-width: 0; min-height: 58px; padding: 10px 18px; border-bottom: 1px solid var(--border-subtle); }
.topbar > strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.settings-dialog { width: min(620px, calc(100vw - 32px)); }
.model-catalog-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.model-catalog-controls button { flex-shrink: 0; }
.model-catalog-controls p { flex: 1 1 200px; margin: 0; color: var(--muted); font-size: .78rem; }
.settings-grid { min-width: 0; margin: 0; padding: 0; border: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.setting { min-width: 0; display: grid; gap: 4px; color: var(--muted-strong); font-size: .72rem; }
.setting select, .setting input { min-width: 0; width: 100%; height: 34px; border: 1px solid var(--border); border-radius: 6px; background: var(--control-bg); color: var(--text); padding: 4px 7px; }
.working-folder { grid-column: 1 / -1; }
.working-folder small { color: var(--muted); font-size: .75rem; line-height: 1.45; }
.setting select:disabled { opacity: .5; }
.settings-note { margin: 16px 0 0; color: var(--muted); font-size: .78rem; }

.notice { grid-row: 2; min-width: 0; padding: 8px 18px; color: var(--notice-text); background: var(--notice-bg); border-bottom: 1px solid var(--notice-border); font-size: .85rem; }

.messages-region { grid-row: 3; position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.messages { min-width: 0; min-height: 0; width: 100%; height: 100%; overflow: auto; padding: 24px max(20px, calc((100% - 850px) / 2)); }
.jump-present {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  border-color: var(--jump-border);
  background: var(--jump-bg);
  box-shadow: 0 4px 18px var(--floating-shadow);
  font-size: .82rem;
  white-space: nowrap;
}
.jump-present:hover { background: var(--jump-hover); }
.jump-present:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.jump-present[hidden] { display: none; }
.history-control {
  display: block;
  margin: 0 auto 16px;
  min-height: 44px;
  padding: 8px 16px;
  cursor: pointer;
}

.empty { color: var(--empty); text-align: center; margin-top: 20vh; }
.thinking-indicator {
  display: flex;
  align-items: center;
  width: fit-content;
  gap: 8px;
  margin: 2px 0 18px;
  color: var(--muted-strong);
  font-size: .82rem;
}
.thinking-indicator[hidden] { display: none; }
.thinking-dots { display: inline-flex; align-items: center; gap: 3px; }
.thinking-indicator.waiting .thinking-dots { display: none; }
.thinking-dots > span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: thinking-pulse 1.2s infinite ease-in-out;
}
.thinking-dots > span:nth-child(2) { animation-delay: .15s; }
.thinking-dots > span:nth-child(3) { animation-delay: .3s; }

@keyframes thinking-pulse {
  0%, 70%, 100% { opacity: .25; }
  35% { opacity: 1; }
}

.message { margin: 0 0 18px; line-height: 1.48; }
.message-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 5px; }
.message .role { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
.message-timestamp { color: var(--muted); font-size: .72rem; font-weight: 400; overflow-wrap: anywhere; }
.activity .message-timestamp { display: inline-block; margin-left: 10px; }
.message-timestamp[hidden] { display: none; }
.message-toolbar { display: flex; align-items: center; gap: 4px; min-height: 30px; margin-top: 7px; }
.message-toolbar[hidden] { display: none; }
.message-action {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 3px 7px 3px 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted-strong);
  font-size: .75rem;
  line-height: 1;
}
.message-action::after { content: ""; position: absolute; inset: -6px; }
.message-action svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message-action:hover:not(:disabled) { background: var(--button-hover); color: var(--text); }
.message-action:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.message .body { min-width: 0; overflow-wrap: anywhere; }
.message .body.plain-text { white-space: pre-wrap; }
.message .body > :first-child { margin-top: 0; }
.message .body > :last-child { margin-bottom: 0; }
.message .body p { margin: .65em 0; }
.message .body h1, .message .body h2, .message .body h3,
.message .body h4, .message .body h5, .message .body h6 {
  margin: 1.05em 0 .45em;
  line-height: 1.25;
}
.message .body h1 { font-size: 1.42rem; }
.message .body h2 { font-size: 1.25rem; }
.message .body h3 { font-size: 1.1rem; }
.message .body ul, .message .body ol { margin: .6em 0; padding-left: 1.55rem; }
.message .body li { margin: .2em 0; }
.message .body li > p { margin: .25em 0; }
.message .body a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.message .body a:hover { color: var(--link-hover); }
.message .body blockquote {
  margin: .75em 0;
  padding: .15em 0 .15em .9em;
  border-left: 3px solid var(--quote-border);
  color: var(--quote-text);
}
.message .body code, .message .body pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
.message .body :not(pre) > code {
  padding: .12em .34em;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--code-bg);
  font-size: .9em;
}
.message .body pre {
  max-width: 100%;
  margin: .8em 0;
  padding: 12px 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  line-height: 1.42;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}
.message .body pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--pre-text);
  font-size: .87em;
  overflow-wrap: normal;
}
.code-block { position: relative; max-width: 100%; margin: .8em 0; }
.message .body .code-block pre { margin: 0; padding-right: 54px; }
.copy-code {
  position: absolute;
  z-index: 1;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  background: var(--control-bg);
  color: var(--muted-strong);
}
.copy-code::after { content: ""; position: absolute; inset: -6px; }
.copy-code-icon { width: 16px; height: 16px; pointer-events: none; }
.copy-code.copying .copy-code-icon { opacity: .55; }
.copy-code.copied { border-color: var(--success); background: var(--drop-bg); color: var(--success-text); }
.copy-code.copy-failed { border-color: var(--notice-border); background: var(--notice-bg); color: var(--notice-text); }
.clipboard-buffer { position: fixed; top: -1000px; left: -1000px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.message .body hr { margin: 1.1em 0; border: 0; border-top: 1px solid var(--border-subtle); }
.message .body table {
  display: block;
  max-width: 100%;
  margin: .8em 0;
  overflow-x: auto;
  border-collapse: collapse;
  -webkit-overflow-scrolling: touch;
}
.message .body th, .message .body td { padding: 6px 9px; border: 1px solid var(--border); text-align: left; }
.message .body th { background: var(--panel-bg); }
.message .body .embedded-image-link:focus-visible { border-radius: 7px; outline: 2px solid var(--focus); outline-offset: 2px; }
.message .body img { max-width: 100%; height: auto; border-radius: 7px; }
.message .body input[type="checkbox"] { margin-right: .4em; }
.message .body .katex { font-size: 1.04em; }
.message .body .katex-display {
  max-width: 100%;
  margin: .8em 0;
  padding: .25em 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.message-attachments { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; margin-top: 10px; }
.message-attachments[hidden] { display: none; }
.message-attachment { text-decoration: none; }
.message-attachment .attachment-label { display: flex; align-items: center; gap: 6px; min-width: 0; }
.message-attachment.image-attachment { flex-direction: column; align-items: stretch; width: min(360px, 100%); padding: 0; overflow: hidden; }
.message-attachment.image-attachment .attachment-label { padding: 6px 8px; }
.attachment-preview { display: block; width: 100%; max-height: 320px; object-fit: contain; background: var(--panel-bg); }
.message-attachment:hover { border-color: var(--jump-border); background: var(--button-hover); }
.message-attachment:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.message-attachment .attachment-download { color: var(--muted-strong); font-size: .9rem; line-height: 1; }
.message.user { margin-left: 13%; padding: 12px 14px; border-radius: 10px; background: var(--user-bg); }
.message.agent { margin-right: 6%; }

.activity { min-width: 0; max-width: 100%; margin: 10px 0 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--activity-bg); color: var(--activity-text); }
.activity summary { padding: 8px 10px; cursor: pointer; overflow-wrap: anywhere; }
.activity pre { max-width: 100%; max-height: 320px; margin: 0; padding: 10px; overflow: auto; overflow-wrap: anywhere; border-top: 1px solid var(--border); color: var(--activity-output); white-space: pre-wrap; }

.requests { grid-row: 4; min-width: 0; max-height: 40vh; overflow: auto; padding: 0 max(20px, calc((100% - 850px) / 2)); }
.request { margin: 8px 0; padding: 12px; border: 1px solid var(--request-border); border-radius: 9px; background: var(--request-bg); }
.request[hidden] { display: none; }
.request strong, .request p, .request pre { display: block; margin: 0 0 9px; }
.request pre { max-height: 220px; overflow: auto; white-space: pre-wrap; color: var(--request-output); }
.request .actions { display: flex; flex-wrap: wrap; gap: 7px; }
.request .request-error { margin: 10px 0 0; color: var(--request-output); }
.request .request-connection { margin: 10px 0 0; }
.request .request-connection[hidden] { display: none; }

.pending-questions { grid-row: 5; min-width: 0; padding: 0 max(20px, calc((100% - 850px) / 2)); border-top: 1px solid var(--border-subtle); background: var(--panel-bg); }
.pending-questions[hidden], .pending-questions-content[hidden] { display: none; }
.pending-questions-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 10px 0; border: 0; border-radius: 0; background: transparent; text-align: left; font-size: .85rem; font-weight: 600; }
.pending-questions-toggle:hover:not(:disabled) { background: transparent; color: var(--link); }
.pending-questions-toggle svg { flex: 0 0 18px; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pending-questions-toggle[aria-expanded="false"] svg { transform: rotate(180deg); }
.pending-questions-toggle:focus-visible, .pending-questions-list:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.pending-questions-list { max-height: min(30dvh, 300px); margin: 0; padding: 0 6px 0 24px; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.pending-question { padding-left: 3px; }
.pending-question::marker { color: var(--muted-strong); font-size: .85rem; }
.pending-question + .pending-question { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-subtle); }
.pending-question .message { margin: 0; font-size: .9rem; }
.pending-questions-hint { margin: 8px 0 10px; color: var(--muted-strong); font-size: .78rem; line-height: 1.4; }

.composer { grid-row: 6; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "attachments attachments" "prompt tools"; gap: 10px; padding: 14px max(20px, calc((100% - 850px) / 2)) 18px; border-top: 1px solid var(--border-subtle); }
.composer.drop-target { background: var(--drop-bg); box-shadow: inset 0 2px var(--success); }
.composer-tools { grid-area: tools; align-self: end; justify-self: end; display: grid; gap: 6px; }
.composer-tools > .composer-settings, .composer-tools > .file-picker { width: 100%; }
.composer-settings { display: inline-grid; place-items: center; width: 38px; min-height: 38px; padding: 0; }
.composer-settings svg, .file-picker svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.attachments { grid-area: attachments; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.attachments[hidden] { display: none; }
.attachment { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; padding: 5px 7px; border: 1px solid var(--border); border-radius: 7px; background: var(--control-bg); color: var(--attachment-text); font-size: .78rem; }
.attachment .attachment-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .attachment-kind { color: var(--success-text); text-transform: uppercase; font-size: .64rem; letter-spacing: .06em; }
.attachment button { border: 0; padding: 0 2px; background: transparent; color: var(--muted-strong); }
.file-picker { display: inline-grid; place-items: center; width: 38px; min-height: 38px; padding: 0; border: 1px solid var(--border); border-radius: 7px; background: var(--button-bg); cursor: pointer; }
.file-picker:hover, .file-picker:focus-within { background: var(--button-hover); }
.file-picker:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.file-picker:has(input:disabled) { cursor: default; opacity: .45; }
.file-picker input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.composer textarea { grid-area: prompt; min-width: 0; resize: vertical; max-height: 40vh; border: 1px solid var(--border); border-radius: 9px; background: var(--control-bg); color: inherit; padding: 11px; outline: none; }
.composer textarea:focus { border-color: var(--jump-border); }
.composer button { align-self: end; }
#send { min-width: 5rem; min-height: 38px; }

.search-view {
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: var(--page-bg);
}
.search-view[hidden] { display: none; }
.search-topbar { min-width: 0; min-height: 72px; display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-bottom: 1px solid var(--border-subtle); }
.search-heading { min-width: 0; flex: 1; }
.search-heading h1 { margin: 0; font-size: 1.12rem; line-height: 1.3; }
.search-heading p { margin: 3px 0 0; color: var(--muted); font-size: .78rem; }
.search-content { min-width: 0; min-height: 0; overflow: auto; padding: 28px max(20px, calc((100% - 850px) / 2)) 40px; }
.search-form, .search-status, .search-results { width: min(100%, 850px); margin-inline: auto; }
.search-form { display: grid; gap: 12px; }
.search-query-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.search-query-row input,
.search-filters input,
.search-filters select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--control-bg);
  color: var(--text);
  padding: .58rem .65rem;
}
.search-query-row input { min-height: 42px; }
.search-submit { min-width: 7.25rem; min-height: 44px; padding-inline: 1.15rem; font-weight: 600; }
.search-query-row input:focus,
.search-filters input:focus,
.search-filters select:focus { border-color: var(--focus); outline: 2px solid color-mix(in srgb, var(--focus) 25%, transparent); outline-offset: 1px; }
.search-filters { min-width: 0; margin: 0; padding: 0; border: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 9px; }
.search-filters label { min-width: 0; display: grid; gap: 4px; color: var(--muted-strong); font-size: .72rem; }
.search-filters input[type="date"] { display: block; min-inline-size: 0; max-width: 100%; inline-size: 100%; }
.search-filters input[aria-invalid="true"] { border-color: var(--notice-border); }
.search-clear { justify-self: start; width: auto; min-width: 0; min-height: 39px; padding-inline: .65rem; }
.search-status { min-height: 1.5em; margin-top: 22px; margin-bottom: 12px; color: var(--muted); font-size: .82rem; }
.search-status.loading::before { content: ""; display: inline-block; width: .72rem; height: .72rem; margin-right: 7px; border: 2px solid var(--border); border-top-color: var(--focus); border-radius: 50%; vertical-align: -.08rem; animation: search-spin .8s linear infinite; }
.search-status.error { color: var(--notice-text); }
.search-status.empty { color: var(--empty); }
.search-results { margin-top: 0; margin-bottom: 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.search-result { min-width: 0; }
.search-result-button { width: 100%; min-width: 0; display: grid; gap: 8px; padding: 13px 14px; border: 1px solid var(--border-subtle); border-radius: 7px; background: var(--control-bg); color: inherit; cursor: pointer; text-decoration: none; touch-action: manipulation; text-align: left; }
.search-result-button:hover { background: var(--button-hover); }
.search-result-button[aria-disabled="true"] { cursor: default; opacity: .45; }
.search-result-heading { min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.search-result-title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-snippet { margin: 0; overflow: hidden; color: var(--text); font-size: .9rem; line-height: 1.45; overflow-wrap: anywhere; white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.search-result-snippet mark { padding: 0 .08em; border-radius: 2px; background: var(--match-bg); color: inherit; }
.search-result-meta { color: var(--muted); font-size: .72rem; }
.search-result-fallback { font-style: italic; }
.message.search-match { border-radius: 8px; outline: 3px solid var(--match-outline); outline-offset: 4px; animation: search-match-pulse 1.2s ease-out 2; }

@keyframes search-spin { to { transform: rotate(360deg); } }
@keyframes search-match-pulse { 50% { background-color: var(--match-bg); } }

@media (max-width: 760px) {
  .sidebar-toggle { display: none; }
  .shell { display: block; position: relative; }
  .chat { height: 100vh; height: 100dvh; }
  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    max-width: 100%;
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    border-right: 1px solid var(--border);
    transform: translateX(-105%);
    transition: transform 160ms ease-out;
    box-shadow: 12px 0 32px var(--shadow);
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.sidebar-swiping {
    transform: translateX(var(--sidebar-swipe-translate));
    transition: none;
  }
  .sidebar-resizer { display: none; }
  .sidebar-scrim {
    position: fixed;
    z-index: 29;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--scrim);
    opacity: 1;
    transition: opacity 160ms ease-out;
  }
  .sidebar-scrim:hover:not(:disabled) { background: var(--scrim); }
  .sidebar-scrim[hidden] { display: none; }
  .sidebar-scrim.sidebar-swiping {
    opacity: var(--sidebar-swipe-opacity);
    transition: none;
  }
  .sidebar-swipe-edge {
    position: fixed;
    z-index: 28;
    inset: 0 auto 0 0;
    display: block;
    width: max(24px, env(safe-area-inset-left));
    touch-action: pan-y;
    overscroll-behavior-x: contain;
  }
  .sidebar-swipe-edge[hidden] { display: none; }
  .menu-button, .close-sidebar { display: inline-flex; align-items: center; justify-content: center; }
  .topbar button { min-height: 44px; }
  .close-sidebar { width: 44px; height: 44px; margin-left: 0; padding: 0; font-size: 1.35rem; }
  .brand { justify-content: flex-start; margin-bottom: 12px; }
  .wide, .settings-cog, .thread { min-height: 44px; }
  .thread-row { grid-template-columns: minmax(0, 1fr) 44px; }
  .thread-pin { width: 44px; height: 44px; }
  #threads { display: grid; }
  .topbar { min-height: calc(54px + env(safe-area-inset-top)); padding: calc(6px + env(safe-area-inset-top)) 10px 6px; }
  .setting select, .setting input { min-height: 44px; font-size: 16px; }
  .messages { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 14px 12px; }
  .jump-present { bottom: 10px; min-height: 44px; }
  .requests { padding: 0 10px; }
  .pending-questions { padding: 0 12px; }
  .pending-questions-list { max-height: min(26dvh, 240px); }
  .composer {
    gap: 8px;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
    background: var(--composer-bg);
  }
  .attachments { max-height: 74px; overflow: auto; }
  .attachment { flex: 1 1 180px; }
  .file-picker, .composer-settings, #send { min-height: 44px; justify-content: center; }
  .composer-settings, .file-picker { width: 44px; }
  .composer textarea { min-height: 68px; max-height: 30dvh; resize: none; font-size: 16px; }
  .message { margin-bottom: 14px; }
  .message.user { margin-left: 4%; padding: 10px 12px; }
  .message.agent { margin-right: 0; }
  .activity { margin: 8px 0 12px; }
  .request .actions button { min-height: 44px; }
  .preferences-dialog { width: min(470px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); }
  .preferences-close, .theme-option { min-height: 44px; }
  .search-topbar { min-height: calc(60px + env(safe-area-inset-top)); padding: calc(8px + env(safe-area-inset-top)) 10px 8px; gap: 9px; }
  .search-heading h1 { font-size: 1rem; }
  .search-heading p { display: none; }
  .search-topbar > button { min-height: 44px; }
  .search-content { padding: 18px 12px calc(30px + env(safe-area-inset-bottom)); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .search-query-row input, .search-filters input, .search-filters select { min-height: 44px; font-size: 16px; }
  .search-submit { min-width: 7rem; min-height: 48px; }
  .search-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-clear { min-height: 44px; }
  .search-result-button { min-height: 44px; padding: 12px; }
}

@media (max-width: 480px) {
  .search-filters { grid-template-columns: minmax(0, 1fr) auto; }
  .search-date-filter { grid-column: 1 / -1; }
}

@media (max-height: 520px) {
  .pending-questions-list { max-height: 18dvh; }
}

@media (max-width: 360px) {
  .menu-button { padding-inline: .55rem; }
  .topbar { gap: 7px; }
  .messages { padding-inline: 9px; }
  .composer { padding-inline: 8px; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .search-topbar { gap: 6px; padding-inline: 8px; }
  .search-topbar > button { padding-inline: .55rem; }
  .search-content { padding-inline: 9px; }
  .search-filters { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar-scrim { transition: none; }
  .sidebar-toggle-icon { transition: none; }
  .thinking-dots > span { animation: none; opacity: .7; }
  .search-status.loading::before, .message.search-match { animation: none; }
}
