:root {
 color-scheme: light dark;
 --bg: #fff;
 --side: #f9f9f9;
 --surface: #fff;
 --text: #171717;
 --muted: #626262;
 --line: #e5e5e5;
 --hover: #efefef;
 --active: #eaeaea;
 --bubble: #f4f4f4;
 --action: #171717;
 --action-text: #fff;
 --error: #a92525;
 --shadow: 0 2px 10px #00000012;
 --sidebar-width: 248px;
 --thread-width: 864px;
 --dialog-pad: 16px;
 font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
 :root {
  --bg: #212121; --side: #171717; --surface: #303030; --text: #ececec;
  --muted: #afafaf; --line: #404040; --hover: #272727; --active: #303030;
  --bubble: #303030; --action: #ececec; --action-text: #171717; --error: #ffa3a3;
  --shadow: 0 2px 10px #00000038;
 }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
p, h1, h2 { margin: 0; }
a { color: inherit; }
button, input, textarea, select { color: inherit; font: inherit; }
button {
 display: inline-flex; align-items: center; justify-content: center; gap: 8px;
 min-height: 36px; padding: 6px 12px; border: 0; border-radius: 8px;
 background: transparent; cursor: pointer;
}
button:hover:not(:disabled), summary:hover { background: var(--hover); }
button:disabled { cursor: default; opacity: .48; }
:focus-visible { outline: 2px solid #628bd2; outline-offset: 3px; }
.primary { background: var(--action); color: var(--action-text); border-radius: 999px; }
.primary:hover:not(:disabled) { background: var(--action); opacity: .86; }
.icon-button { width: 40px; height: 40px; padding: 0; font-size: 24px; }
.sr-only {
 position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
 overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.workspace { display: flex; height: 100dvh; overflow: hidden; }
#sidebar {
 display: none; flex: 0 0 var(--sidebar-width); width: var(--sidebar-width);
 flex-direction: column; min-height: 0; padding: 8px; background: var(--side); border-right: 1px solid var(--line);
}
.sidebar-open #sidebar { display: flex; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 5px; }
.brand { display: inline-flex; align-items: center; padding: 6px 8px; text-decoration: none; font-size: 18px; font-weight: 650; }
.brand img { object-fit: cover; border-radius: 50%; }
.nav-action { justify-content: flex-start; width: 100%; padding: 8px; font-size: 14px; }
.nav-action > span { width: 20px; font-size: 20px; }
.panel-icon, .search-icon { display: inline-block; position: relative; flex-shrink: 0; }
.panel-icon { width: 18px; height: 15px; border: 1.5px solid currentColor; border-radius: 4px; }
.panel-icon::after { content: ""; position: absolute; top: 0; bottom: 0; left: 5px; border-left: 1.5px solid currentColor; }
.nav-action .search-icon { width: 15px; height: 15px; margin: 0 4px 0 1px; border: 1.5px solid currentColor; border-radius: 50%; }
.search-icon::after { content: ""; position: absolute; width: 6px; height: 1.5px; background: currentColor; bottom: -2px; right: -4px; transform: rotate(45deg); }
#chat-search { padding: 4px 2px; }
.chat-nav { flex: 1; min-height: 0; overflow-y: auto; padding-top: 14px; scrollbar-width: thin; }
.nav-label { color: var(--muted); font-size: 13px; font-weight: 650; padding: 0 8px 4px; }
#chat-list button {
 display: block; width: 100%; overflow: hidden; padding: 8px;
 text-align: left; white-space: nowrap; text-overflow: ellipsis; font-size: 14px;
}
#chat-list button[aria-current="true"] { background: var(--active); }
.profile { position: relative; flex-shrink: 0; padding-top: 6px; }
.profile summary {
 display: flex; align-items: center; gap: 9px; min-height: 42px;
 padding: 6px 8px; border-radius: 8px; cursor: pointer; list-style: none; font-size: 14px;
}
.profile summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #587399; color: #fff; }
.profile-menu {
 position: absolute; z-index: 2; bottom: calc(100% + 6px); inset-inline: 0;
 padding: 5px; border: 1px solid var(--line); border-radius: 12px;
 background: var(--surface); box-shadow: var(--shadow);
}
.profile-menu button { width: 100%; justify-content: flex-start; font-size: 14px; }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
 display: flex; justify-content: space-between; align-items: center; gap: 10px;
 min-height: 49px; flex-shrink: 0; padding: 4px 12px; border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 7px; min-width: 0; }
.topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 600; }
.topbar .brand { flex-shrink: 0; }
.sidebar-open #sidebar-open { display: none; }
#chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.conversation { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.thread { max-width: var(--thread-width); margin: 0 auto; padding: 20px 20px 24px; }
.messages { display: flex; flex-direction: column; gap: 20px; }
.message { min-width: 0; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
.message.user { align-self: flex-end; max-width: min(84%, 68ch); padding: 10px 14px; border-radius: 18px; background: var(--bubble); }
.message.user .message-body, .message-body.streaming { white-space: pre-wrap; }
.message.assistant:has(.message-body:empty)::before { content: ""; display: block; width: 12px; height: 12px; margin: 8px 0; border-radius: 50%; background: var(--text); }
.message small { color: var(--muted); font-size: 12px; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p + p { margin-top: 1em; }
.message-body pre { overflow: auto; background: var(--bubble); border-radius: 12px; padding: 14px; }
.message-body table { display: block; overflow-x: auto; border-collapse: collapse; }
.message-body th, .message-body td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }
.message-body blockquote { border-left: 2px solid var(--line); margin-left: 0; padding-left: 14px; }
.message-body code { font-size: .88em; }
#older { display: flex; margin: 0 auto 12px; color: var(--muted); font-size: 14px; }
.compose-area { width: min(100%, var(--thread-width)); margin-inline: auto; padding: 0 20px 9px; flex-shrink: 0; }
#chat.empty .conversation { display: none; }
#chat.empty .compose-area { margin-block: clamp(24px, 11vh, 100px) auto; }
.welcome { text-align: center; margin-bottom: 16px; }
.welcome h1 { font-size: clamp(24px, 4vw, 30px); line-height: 1.25; font-weight: 600; letter-spacing: -.55px; }
.welcome p { margin-top: 7px; color: var(--muted); font-size: 14px; }
#notice { min-height: 0; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
#notice:empty, #starter-files:empty, .attached:empty { display: none; }
#compose { gap: 4px; padding: 7px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
#question { min-height: 38px; max-height: min(192px, 31dvh); overflow-y: auto; resize: none; border: 0; background: transparent; padding: 6px 9px; line-height: 24px; outline: 0; }
#question::placeholder { color: var(--muted); opacity: 1; }
.composer-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.material-trigger { border-radius: 9px; font-size: 14px; }
.material-trigger span { font-size: 20px; line-height: 1; }
#chat-model-control { display: flex; justify-content: flex-end; margin-bottom: 6px; }
#chat-model {
 width: auto;
 max-width: 100%;
 min-height: 34px;
 padding: 5px 10px;
 border-color: var(--line);
 color: var(--text);
 font-size: 14px;
 cursor: pointer;
}
#chat-model:disabled { cursor: default; }
.answer-model { display: block; margin-top: 5px; }
.send-button { margin-left: auto; flex: 0 0 34px; width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 50%; background: var(--action); color: var(--action-text); font-size: 23px; }
.send-button:hover:not(:disabled) { background: var(--action); opacity: .82; }
#stop { font-size: 12px; }
.starter-files { margin-top: 6px; padding-inline: 4px; font-size: 13px; overflow-wrap: anywhere; }
.quiet { color: var(--muted); }
form { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-size: 14px; min-width: 0; }
textarea, input, select { width: 100%; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
textarea { resize: vertical; }
.dialog-heading, .actions, .filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dialog-heading { justify-content: space-between; margin-bottom: 6px; }
.dialog-heading h2 { font-size: 20px; }
dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100dvh - 24px); padding: var(--dialog-pad); border: 1px solid var(--line); border-radius: 18px; color: var(--text); background: var(--bg); box-shadow: var(--shadow); }
dialog::backdrop { background: #0007; }
#settings-error, #credentials-error { color: var(--error); }
.filters > * { flex: 1; min-width: 110px; }
.attached, .material-list { list-style: none; padding: 0; }
.attached { display: flex; flex-wrap: wrap; gap: 6px; margin: 1px 2px; }
.attached li { display: flex; gap: 6px; align-items: center; padding-left: 8px; border: 1px solid var(--line); border-radius: 12px; font-size: 13px; overflow-wrap: anywhere; }
.attached button { min-height: 26px; padding: 1px 7px; }
.material-list { display: grid; gap: 7px; }
.material-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.sign-in { width: min(100% - 36px, 380px); margin: clamp(32px, 9vh, 90px) auto 24px; }
.sign-in .brand { padding-left: 0; }
.sign-in h1 { margin: 18px 0 7px; font-size: 30px; }
.sign-in p { margin-bottom: 16px; color: var(--muted); font-size: 14px; }
.sign-in .primary { margin-top: 4px; min-height: 44px; }
#sidebar-backdrop { position: fixed; z-index: 3; inset: 0; width: 100%; height: 100%; border-radius: 0; background: #0007; }
@media (max-width: 700px) {
 #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 4; width: min(var(--sidebar-width), 86vw); }
 .sidebar-open #sidebar-open { display: inline-flex; }
 .topbar { padding-inline: 7px; }
 .thread { padding: 16px 15px 24px; }
 .compose-area { padding-inline: 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
 .message.user { max-width: 88%; }
 #chat.empty .compose-area { transform: none; }
 .welcome { margin-bottom: 18px; }
}
#preset-list button {
 display: block; width: 100%; overflow: hidden; padding: 8px; text-align: left;
 white-space: nowrap; text-overflow: ellipsis; font-size: 14px;
}
#preset-section { margin-bottom: 10px; }
.profile-menu a {
 display: block; padding: 8px 12px; border-radius: 8px; text-decoration: none; font-size: 14px;
}
.profile-menu a:hover, #web-toggle[aria-pressed="true"] { background: var(--hover); }
#web-toggle[aria-pressed="true"] { outline: 1px solid #628bd2; color: var(--text); }
.web-sources { color: var(--muted); font-size: 14px; margin-top: 10px; overflow-wrap: anywhere; }
.web-sources summary { cursor: pointer; }
.web-sources ol { margin: 5px 0; padding-left: 26px; }
.web-sources li { margin-bottom: 5px; }
.message-copy { color: var(--muted); font-size: 13px; margin: 4px 0 0 -8px; min-height: 30px; padding: 4px 8px; }
#empty-chats { flex: 1; display: grid; place-items: center; padding: 20px; }
.message-copy + .message-copy { margin-left: 0; }
#unigma-export-dialog .dialog-content { display: grid; gap: 10px; }
#unigma-export-dialog .export-fields, #unigma-export-dialog [data-parent-fields] {
 display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px;
}
#unigma-export-dialog [data-export-error] { color: var(--error); }
#unigma-export-dialog [data-export-result] { display: grid; gap: 9px; overflow-wrap: anywhere; }
#unigma-export-dialog [data-export-result] code { background: var(--hover); border-radius: 6px; padding: 7px 9px; }
#unigma-export-dialog [data-export-result] .actions { justify-content: flex-start; }
#unigma-export-dialog label { min-width: 0; }
@media (max-width: 480px) {
 #unigma-export-dialog [data-parent-fields] { grid-template-columns: 1fr; }
}


#chat-list button, #preset-list button, .nav-action { padding-block: 6px; min-height: 34px; }
#sidebar .nav-action { gap: 7px; }
#sidebar .profile-menu [aria-pressed="true"] { background: var(--active); }
.topbar .brand { color: var(--muted); font-size: 15px; font-weight: 600; padding: 4px 6px; }
.topbar-title:not(:empty) { border-left: 1px solid var(--line); padding-left: 9px; }
.message-body h2 { font-size: 20px; line-height: 1.3; margin: 1em 0 .4em; }
.message-body h3 { font-size: 18px; line-height: 1.35; margin: .95em 0 .35em; }
.message-body h4 { font-size: 16px; margin: .85em 0 .25em; }
.message-body :is(ul, ol) { padding-inline-start: 22px; }
.message-body th, .message-body td { padding: 5px 10px; font-size: 14px; }
.message-body th { background: var(--bubble); font-weight: 650; }
.message-body a { text-underline-offset: 3px; }
#compose:focus-within { border-color: #628bd2; }
#question { font-size: 16px; }
.composer-actions .material-trigger, #retry-answer { border: 1px solid var(--line); min-height: 34px; }
.composer-actions .material-trigger span { font-size: 17px; }
.attached:not(:empty) { max-height: 4rem; overflow-y: auto; }
.message-copy { font-size: 14px; }
dialog .dialog-heading button { flex: 0 0 36px; padding: 0; font-size: 20px; }
dialog textarea { line-height: 1.5; }
#settings textarea { max-height: 38dvh; }
#settings-prompt { min-height: 112px; }
.prompt-templates { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; }
.prompt-templates summary { cursor: pointer; font-size: 14px; font-weight: 600; }
.prompt-template-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 9px; }
.prompt-template-row label { min-width: 0; }
.prompt-template-row button { min-height: 38px; }
#prompt-template-status { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
#prompt-template-status:empty { display: none; }
#prompt-template-status[data-error] { color: var(--error); }
#settings-instructions { min-height: 72px; }
#credentials-error:empty, #settings-error:empty { display: none; }
#credentials .quiet { font-size: 14px; }
#credentials .actions, #settings .actions, #unigma-export-dialog [data-export-form] > .actions:has(> button:not([hidden])) {
 position: sticky; bottom: calc(0px - var(--dialog-pad)); z-index: 1; justify-content: flex-end;
 padding: 7px 0 var(--dialog-pad); margin-bottom: calc(0px - var(--dialog-pad));
 border-top: 1px solid var(--line); background: var(--bg);
}
#unigma-export-dialog textarea { height: 144px; min-height: 96px; max-height: 36dvh; font-size: 16px; }
#usage { width: min(780px, calc(100% - 24px)); }
#usage > .quiet { font-size: 14px; margin: 2px 0 12px; max-width: 66ch; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.usage-table th, .usage-table td { border-bottom: 1px solid var(--line); text-align: left; padding: 8px 9px; }
.usage-table thead th { background: var(--bubble); font-weight: 650; }
.usage-table th[scope=row] { font-weight: 650; }
.usage-table .metric { text-align: right; }
.usage-table small { display: block; color: var(--muted); font-size: 13px; }
.usage-table .usage-empty { color: var(--muted); }

.workspace[data-density="compact"] .chat-nav { padding-top: 9px; }
.workspace[data-density="compact"] :is(#chat-list button, #preset-list button, .nav-action) { min-height: 30px; padding-block: 4px; }
.workspace[data-density="compact"] .thread { padding-block: 14px 16px; }
.workspace[data-density="compact"] .messages { gap: 14px; }
.workspace[data-density="compact"] .message { line-height: 1.5; }

@media (max-width: 700px) {
 :root { --dialog-pad: 14px; }
 #sidebar { width: min(282px, 86vw); }
 .topbar { min-height: 49px; }
 .topbar .brand { font-size: 14px; }
 .topbar-title { font-size: 14px; }
 .thread { padding: 14px 13px 20px; }
 .messages { gap: 15px; }
 .message { line-height: 1.55; }
 .message.user { max-width: 91%; padding: 8px 12px; }
 .workspace :is(#chat-list button, #preset-list button, .nav-action) { min-height: 38px; }
 .composer-actions { gap: 4px; }
 .composer-actions .material-trigger, #retry-answer { min-height: 36px; padding: 4px 8px; }
 .send-button { min-height: 38px; width: 38px; flex-basis: 38px; }
 dialog .actions .primary { min-height: 40px; }
 #unigma-export-dialog textarea { max-height: 32dvh; }
}
@media (max-width: 560px) {
 .usage-table, .usage-table tbody, .usage-table tr { display: block; }
 .usage-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
 .usage-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-bottom: 1px solid var(--line); padding-block: 5px; }
 .usage-table th, .usage-table td { padding: 4px 6px; border-bottom: 0; }
 .usage-table .metric { text-align: left; }
 .usage-table [data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: 13px; }
 .usage-table th[scope=row], .usage-table td.usage-empty { grid-column: 1 / -1; }
}
