:root {
    color-scheme: light dark;
    --bg: #f5f6f2;
    --surface: #fff;
    --field: #eef0eb;
    --line: #d6ddd4;
    --text: #1d1d1f;
    --secondary: #535e55;
    --accent: #216243;
    --on-accent: #fff;
    --tint: #dfece4;
    --control: #e7ece5;
    --danger: #a12c32;
    --focus: var(--accent);
    font: 100%/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #141815;
        --surface: #1f2520;
        --field: #29312a;
        --line: #424e44;
        --text: #f5f5f7;
        --secondary: #acb9ae;
        --accent: #a9e8bc;
        --on-accent: #183825;
        --tint: #263d30;
        --control: #2a342c;
        --danger: #ff9a9f;
    }
}
@media (prefers-contrast: more) {
    :root { --line: #747984; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
main { width: 100%; max-width: 795px; min-width: 0; margin-inline: auto; padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.bar {
    position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
    padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
    background: var(--bg); background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(16px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; font-size: 1.0625rem; line-height: 1.3; letter-spacing: -.025em; }
.brand strong { font-weight: 650; }
.brand img { border-radius: 10px; }
.brand, .brand > div { min-width: 0; }
.brand strong, #device { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#device { color: var(--secondary); font-size: .75rem; }
#device:empty { display: none; }
h1, h2 { margin: 0 0 8px; line-height: 1.22; letter-spacing: -.025em; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.0625rem; }
button, a { color: inherit; }
button {
    min-height: 44px; min-width: 44px; border: 0; border-radius: 999px; padding: 8px 15px;
    background: var(--control); color: var(--text); font: inherit; font-size: .875rem;
    font-weight: 600; line-height: 1.25; cursor: pointer;
    touch-action: manipulation;
    transition: opacity 140ms cubic-bezier(.2, .8, .2, 1);
    -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: .48; cursor: default; }
button:not(:disabled):active { opacity: .72; }
button[aria-pressed="true"] { color: var(--accent); background: var(--tint); }
.primary { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) {
    button:not(:disabled):hover { filter: brightness(.94); }
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
label { display: block; min-width: 0; overflow-wrap: anywhere; color: var(--secondary); font-size: .875rem; }
input, select, textarea {
    width: 100%; min-width: 0; padding: 9px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 12px;
    background: var(--field); color: var(--text); font: inherit; font-size: 1rem;
}
input[type="checkbox"] { width: 19px; height: 19px; min-height: 0; margin: 0; accent-color: var(--accent); flex: 0 0 19px; }
input[type="checkbox"]:disabled { opacity: .65; }
form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.welcome { max-width: 410px; margin: 6vh auto 0; padding: 24px; border-radius: 24px; background: var(--surface); }
.welcome p, .muted { color: var(--secondary); font-size: .875rem; }
.muted { margin: 0 0 12px; }
nav, .invitations, .composer-actions, .thread-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
nav { margin-bottom: 16px; }
#new-chat { margin-left: auto; }
.chat-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 3px; }
.chat-list:empty { display: none; }
.chat-row { display: flex; align-items: center; min-width: 0; gap: 4px; }
.chat-list .chat-item { flex: 1; min-width: 0; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; background: transparent; border-radius: 12px; }
.chat-delete { flex: none; padding: 0; background: transparent; color: var(--secondary); font-size: 1.25rem; }
.chat-delete:hover { background: var(--control); }
.chat-list button[aria-pressed="true"] { background: var(--tint); }
#archive-chat { margin: 12px 0 0; }
.session-actions { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.chat-list + .muted { padding-inline: 8px; }
.thread-head { justify-content: flex-end; }
.thread-head:has(a[hidden]) { display: none; }
.thread-head a { display: inline-flex; min-height: 44px; align-items: center; padding-inline: 8px; color: var(--accent); font-size: .8125rem; text-underline-offset: 3px; }
.messages { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 16px; margin: 12px 0; }
.messages:empty { display: none; }
.message { white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { justify-self: end; max-width: 86%; padding: 10px 15px; border-radius: 20px 20px 7px 20px; background: var(--tint); }
.message.assistant { padding: 2px 3px; font-size: 1.0625rem; line-height: 1.55; }
.reasoning { color: var(--secondary); margin-block: 4px 8px; }
.reasoning summary { width: fit-content; padding-inline: 3px 12px; font-size: .875rem; }
.reasoning-text { border-inline-start: 2px solid var(--line); padding-inline: 12px 4px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9375rem; }
#live-reasoning + #live-answer { margin-block-start: 4px; }
.attachments, .attachment-options { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; padding: 2px 6px; }
.attachment-name, .attachment-pill { max-width: 100%; overflow-wrap: anywhere; font-size: .8125rem; }
.attachment-name { background: var(--control); border-radius: 12px; padding: 5px 10px; }
.attachment-pill { text-align: start; }
#attach { margin-inline-end: auto; }
.message.activity { justify-self: start; padding: 4px 10px; border-radius: 8px; background: var(--control); color: var(--secondary); font-size: .8125rem; }
.message a { color: var(--accent); }
.image-message { display: block; width: min(100%, 400px); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; background: var(--field); }
.image-message img { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.image-message .edited-photo { aspect-ratio: auto; }
.code-block { margin: 12px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; }
.code-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; padding-inline: 12px; color: var(--secondary); font-size: .8125rem; }
.code-bar span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.code-bar button { flex: none; min-height: 44px; margin-inline-end: -8px; background: transparent; color: var(--accent); }
.code-block pre { margin: 0; padding: 10px 12px 14px; overflow-x: auto; border-top: 1px solid var(--line); white-space: pre; font-size: .875rem; }
.code-block pre, .file-proposal pre { max-width: 100%; overscroll-behavior-inline: contain; }
#composer {
    flex: none; gap: 3px; padding: 5px 7px 7px;
    border: 1px solid var(--line); border-radius: 24px; background: var(--surface);
    box-shadow: 0 3px 14px rgb(23 34 25 / .08);
}
#composer:focus-within { border-color: color-mix(in srgb, var(--accent) 54%, var(--line)); }
.composer-actions { justify-content: flex-end; gap: 4px; }
.composer-note { margin: 0 10px 3px; color: var(--secondary); font-size: .8125rem; overflow-wrap: anywhere; }
#local-project { margin-inline-end: auto; }
textarea { resize: none; min-height: 44px; max-height: min(32dvh, 180px); border-color: transparent; background: transparent; }
textarea:focus-visible { outline-offset: -2px; }
@supports (field-sizing: content) {
    textarea { field-sizing: content; }
}
.composer-actions button, .header-icon {
    display: inline-grid; place-items: center; padding: 0; font-size: 1.5rem; font-weight: 400;
}
.composer-actions svg, .header-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#mic:not([aria-pressed="true"]) { background: var(--control); }
#chat-status, #notice { color: var(--secondary); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .875rem; }
#chat-status:empty, #notice:empty { display: none; }
#chat-status { flex: none; margin: 4px 10px 6px; max-block-size: 4.5em; overflow-y: auto; font-variant-numeric: tabular-nums; }
.chat-view #notice { flex: none; max-block-size: min(7em, 20%); margin-block: 4px 0; overflow: auto; }
#approval, .card { padding: 16px; margin: 12px 0; border-radius: 20px; background: var(--surface); }
#approval pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8125rem; }
.card .settings { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 8px; }
.card fieldset { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 14px; }
.permissions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 8px; }
.permissions label, .card label:has(input[type="checkbox"]), .invitations label { display: flex; gap: 8px; align-items: center; min-height: 44px; }
.card button { justify-self: start; }
.admin-nav { margin-block: 4px 20px; }
.admin-nav button { flex: 0 1 auto; }
.section-head, .row-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.section-head { justify-content: space-between; }
.section-head :is(h1, h2) { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.key-card { border: 1px solid var(--line); }
.key-state { color: var(--secondary); font-size: .8125rem; }
.key-meta { margin-block: 6px 2px; }
.key-share label input { margin-top: 4px; }
.key-share .row-actions { margin-top: 8px; }
.danger { color: var(--danger); background: transparent; }
.file-proposal { margin-block: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; white-space: normal; }
.file-proposal pre { max-height: 18rem; overflow: auto; padding: 8px; background: var(--field); border-radius: 8px; font-size: .8125rem; }
.file-proposal summary { overflow-wrap: anywhere; }
#local-project-dialog {
    width: min(520px, calc(100% - 32px)); max-height: min(calc(var(--app-height, 100dvh) - 24px), 640px); min-width: 0; overflow: auto;
    border: 1px solid var(--line); border-radius: 24px; padding: 16px; background: var(--surface); color: var(--text);
}
#local-project-dialog::backdrop { background: rgb(0 0 0 / .42); }
#local-project-dialog .muted { margin-top: 8px; }
#project-files label { display: flex; min-height: 44px; align-items: center; gap: 8px; overflow-wrap: anywhere; }
#invite-result { margin: 12px 0; }
#invite-result input { margin: 4px 0 8px; }
summary { min-height: 44px; cursor: pointer; padding-block: 7px; }
dl { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin: 8px 0; }
dd { margin: 0; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.signed-in .bar { gap: 12px; border-bottom-color: transparent; }
.signed-in .brand { flex: 1; }
.signed-in .brand img { width: 32px; height: 32px; }
.signed-in main { padding-top: 0; }
/* Let the browser scroll admin forms to their focused field. Only chat needs a pinned composer. */
html:has(body.chat-view) { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; }
.chat-view {
    position: fixed; inset: var(--viewport-top, 0px) 0 auto;
    display: flex; flex-direction: column; height: min(var(--app-height, 100dvh), 100dvh);
    overflow: hidden; overscroll-behavior: none;
}
.chat-view .bar { position: static; flex: none; }
.chat-view main, .chat-view #app, #chats, #thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; flex: 1; width: 100%; }
.chat-view main { padding-bottom: max(10px, var(--chat-safe-bottom, env(safe-area-inset-bottom))); }
.conversation-scroll { min-width: 0; min-height: 0; flex: 1; overflow: hidden auto; overscroll-behavior: none; }
.conversation-scroll > * { min-width: 0; }
#admin { width: 100%; }
#admin :is(input, select) { scroll-margin-block: 12px 24px; }
.signed-in:has(#admin :is(input:not([type="checkbox"]), select):focus) .bar { position: relative; }
#draft { max-height: min(32dvh, calc(var(--app-height, 100dvh) * .32), 180px); }
.conversation-scroll:has(.empty:not([hidden])) { display: grid; place-items: center; }
.empty { display: grid; justify-items: center; gap: 12px; text-align: center; }
.empty h1 { margin: 0; font-size: clamp(1.5rem, 5vw, 1.875rem); }
#sidebar {
    margin: 0; inset: var(--viewport-top, 0px) auto auto 0; width: min(350px, calc(100vw - 30px)); max-width: none;
    height: min(var(--app-height, 100dvh), 100dvh); max-height: none; border: 0; border-inline-end: 1px solid var(--line);
    padding: calc(12px + env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    color: var(--text); background: var(--surface);
    overflow: hidden auto; overscroll-behavior: contain; touch-action: pan-y pinch-zoom;
}
#sidebar::backdrop { background: rgb(0 0 0 / .42); }
#sidebar[open] { animation: sidebar-in 140ms cubic-bezier(.2, .8, .2, 1); }
@keyframes sidebar-in { from { opacity: .82; } }
#portrait-notice {
    display: none; position: fixed; inset: 0; z-index: 20;
    padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
    background: var(--bg); color: var(--text); text-align: center;
}
#portrait-notice img { display: block; margin: 0 auto 12px; }
#portrait-notice p { margin: 0; color: var(--secondary); }
@media (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-height: 600px) {
    #portrait-notice { display: grid; place-items: center; }
    body > :not(#portrait-notice), body dialog, dialog::backdrop { visibility: hidden; }
}
.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.side-head h1 { min-width: 0; margin: 0; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) {
    button { transition: none; }
    #sidebar[open] { animation: none; }
}
@media (max-width: 365px) {
    .card .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .permissions { grid-template-columns: minmax(0, 1fr); }
    .welcome { padding: 18px; }
}
