:root {
    --bg: #0f1012;
    --panel: #17181b;
    --panel-2: #202126;
    --line: #2c2e34;
    --line-soft: #24262b;
    --text: #f2f3f5;
    --muted: #a4a8b3;
    --faint: #747984;
    --accent: #19c37d;
    --accent-strong: #23d18b;
    --accent-soft: rgba(25, 195, 125, 0.13);
    --user: #2f6f5f;
    --agent: #1a1b1f;
    --warning-bg: #2d2413;
    --warning-text: #f0c66b;
    --danger: #ff6b5f;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
    --sidebar-width: 304px;
    --app-height: 100dvh;
    --keyboard-offset: 0px;
    --composer-shift: 0px;
    --composer-height: 74px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    min-width: 0;
    overscroll-behavior: none;
}

body {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    letter-spacing: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
}

html.standalone-pwa,
html.standalone-pwa body {
    background: rgba(23, 24, 27, 0.96);
}

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

button,
select {
    cursor: pointer;
}

/* Login */
.login-container {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    background: #0f1012;
}

.login-box {
    width: min(380px, 100%);
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.login-box h1 {
    margin-bottom: 22px;
    color: var(--text);
    font-size: 22px;
    font-weight: 700;
    text-align: left;
}

.login-box input {
    width: 100%;
    height: 44px;
    margin-bottom: 10px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #101114;
    color: var(--text);
    outline: none;
}

.login-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-box button {
    width: 100%;
    height: 44px;
    margin-top: 6px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #07100c;
    font-weight: 650;
}

.login-box button:hover {
    background: var(--accent-strong);
}

.error {
    min-height: 18px;
    margin-top: 12px;
    color: var(--danger);
    font-size: 13px;
}

/* App Layout */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 5px minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
    height: var(--app-height);
    overflow: hidden;
}

.sidebar-resize {
    position: relative;
    z-index: 10;
    border-right: 1px solid var(--line);
    background: #101114;
    cursor: col-resize;
}

.sidebar-resize::after {
    content: "";
    position: absolute;
    inset: 0 1px;
    background: transparent;
    transition: background 120ms ease;
}

.sidebar-resize:hover::after,
body.resizing-sidebar .sidebar-resize::after {
    background: var(--accent);
}

body.resizing-sidebar {
    cursor: col-resize;
    user-select: none;
}

/* Sidebar */
.sidebar {
    display: flex;
    min-height: 0;
    border-right: 1px solid var(--line);
    background: #131417;
    flex-direction: column;
}

.sidebar-header {
    position: relative;
    padding: 18px;
    border-bottom: 1px solid var(--line-soft);
}

/* shown only on mobile (see media query) — closes the chats menu */
.sidebar-close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101114;
    color: var(--text);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    z-index: 1;
}

.user-info {
    overflow: hidden;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-new {
    width: 100%;
    height: 38px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--text);
    color: #101114;
    font-size: 14px;
    font-weight: 650;
}

.btn-new:hover {
    background: #ffffff;
}

.chat-list {
    min-height: 0;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    min-height: 38px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--muted);
    font-size: 14px;
}

.chat-item span:first-child {
    overflow: hidden;
    min-width: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item:hover {
    background: var(--panel-2);
    color: var(--text);
}

.chat-item.active {
    border-color: rgba(25, 195, 125, 0.32);
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 650;
}

.chat-actions {
    display: flex;
    gap: 2px;
    flex: 0 0 auto;
    opacity: 0;
}

.chat-item:hover .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--faint);
    font-size: 15px;
    line-height: 1;
}

.chat-action-btn:hover {
    background: rgba(255, 107, 95, 0.12);
    color: var(--danger);
}

.restore-btn:hover {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.sidebar-section {
    border-top: 1px solid var(--line-soft);
    padding: 14px 10px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 8px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.toggle-arrow {
    font-size: 10px;
}

.hidden {
    display: none;
}

.notes-list {
    display: grid;
    gap: 2px;
}

.note-item {
    overflow: hidden;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.note-item:hover {
    background: var(--panel-2);
    color: var(--text);
}

.note-item.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 650;
}

.active-note {
    min-height: 18px;
    margin: 8px 8px 0;
    color: var(--faint);
    font-size: 12px;
}

.btn-logout {
    height: 36px;
    margin: auto 18px 18px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.btn-logout:hover {
    border-color: rgba(255, 107, 95, 0.42);
    background: rgba(255, 107, 95, 0.10);
    color: var(--danger);
}

/* Main */
.main {
    display: grid;
    position: relative;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--bg);
}

.top-bar {
    display: flex;
    min-height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(23, 24, 27, 0.96);
    padding: 12px 22px;
    backdrop-filter: blur(16px);
}

.top-title {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.chat-title {
    overflow: hidden;
    min-width: 160px;
    color: var(--text);
    font-size: 16px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-menu-btn {
    display: none;
    height: 34px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101114;
    color: var(--muted);
    padding: 0 12px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.top-actions {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.mobile-overlay {
    display: none;
}

.token-usage {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--faint);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.token-bar {
    display: inline-block;
    width: 60px;
    height: 6px;
    border-radius: 3px;
    background: var(--line);
    overflow: hidden;
}

.token-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease, background-color 0.4s ease;
}

.controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.controls label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 7px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #101114;
    padding: 10px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.controls select {
    width: 100%;
    height: 30px;
    min-width: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    padding: 0;
    outline: none;
    font-size: 13px;
    font-weight: 650;
    text-transform: none;
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 10px) 13px,
        calc(100% - 5px) 13px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.controls select:hover {
    color: var(--text);
}

.controls select:focus {
    box-shadow: none;
}

/* Messages */
.messages {
    display: flex;
    min-height: 0;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding: 24px clamp(16px, 4vw, 56px);
}

.messages:empty::before {
    content: "Выберите или создайте чат, затем отправьте сообщение.";
    margin: auto;
    color: var(--faint);
    font-size: 14px;
}

.msg {
    max-width: min(780px, 82%);
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.msg.client {
    align-self: flex-end;
    background: var(--user);
    color: #f5fffb;
}

.msg.agent {
    align-self: flex-start;
    border: 1px solid var(--line-soft);
    background: var(--agent);
    box-shadow: 0 8px 22px rgba(56, 49, 40, 0.06);
    position: relative;
}

.msg.agent.with-kb {
    border-left: 3px solid #5b8a72;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.source-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 0;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.5;
    cursor: pointer;
}

.kb-badge {
    background: rgba(91, 138, 114, 0.2);
    color: #7cb899;
}

.web-badge {
    background: rgba(67, 136, 204, 0.2);
    color: #83bfff;
}

.source-badge:hover {
    filter: brightness(1.16);
}

.voice-explain-btn {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    color: var(--text-soft, #9aa);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}

.voice-explain-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.voice-explain-audio {
    display: block;
    width: 100%;
    margin-top: 10px;
    height: 34px;
}

.msg.agent p,
.msg.agent ul,
.msg.agent ol {
    margin-bottom: 10px;
}

.msg.agent p:last-child,
.msg.agent ul:last-child,
.msg.agent ol:last-child {
    margin-bottom: 0;
}

.msg.agent ul,
.msg.agent ol {
    padding-left: 20px;
}

.source-popover {
    position: fixed;
    z-index: 50;
    width: min(360px, calc(100vw - 32px));
    max-height: min(430px, calc(100vh - 96px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.source-popover.hidden {
    display: none;
}

.source-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 42px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
    color: var(--text);
    font-size: 13px;
    font-weight: 750;
}

.source-popover-header button {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
}

.source-popover-header button:hover {
    background: var(--panel-2);
    color: var(--text);
}

.source-popover-body {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    padding: 10px;
}

.source-item {
    display: block;
    padding: 9px 10px;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: #101114;
    color: var(--text);
    text-decoration: none;
}

.source-item:hover {
    border-color: var(--line);
    background: var(--panel-2);
}

.source-title {
    margin-bottom: 3px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.35;
}

.source-meta,
.source-empty {
    color: var(--faint);
    font-size: 12px;
    line-height: 1.35;
}

.source-queries {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding-bottom: 2px;
}

.source-queries span {
    padding: 3px 7px;
    border-radius: 999px;
    background: rgba(67, 136, 204, 0.13);
    color: #83bfff;
    font-size: 11px;
}

.msg.agent li + li {
    margin-top: 4px;
}

.msg.agent a {
    color: var(--accent);
}

.msg.agent code {
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    background: #111215;
    padding: 1px 5px;
    font-size: 0.92em;
}

.msg.agent pre {
    overflow-x: auto;
    margin: 10px 0;
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: 6px;
    background: #0d0e10;
    color: #f3f4f6;
}

.msg.agent pre code {
    border: 0;
    background: transparent;
    padding: 0;
}

.msg.warning {
    align-self: center;
    max-width: min(680px, 90%);
    border: 1px solid #edd59a;
    background: var(--warning-bg);
    color: var(--warning-text);
    font-size: 13px;
    padding: 8px 12px;
}

/* Input */
.input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--line);
    background: rgba(23, 24, 27, 0.96);
    padding: 14px 22px 18px;
}

.input-area textarea {
    min-height: 44px;
    max-height: 140px;
    min-width: 0;
    flex: 1;
    resize: none;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101114;
    color: var(--text);
    outline: none;
    padding: 11px 13px;
    line-height: 1.45;
}

.input-area textarea::placeholder {
    color: var(--faint);
}

.input-area textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-send,
.btn-voice {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 18px;
}

.btn-send {
    border-color: transparent;
    background: var(--accent);
    color: #07100c;
}

.btn-send:hover {
    background: var(--accent-strong);
}

.btn-voice {
    background: #101114;
    color: var(--muted);
}

.btn-voice:hover {
    border-color: #3a3d45;
    background: var(--panel-2);
    color: var(--text);
}

.btn-voice.recording {
    border-color: transparent;
    background: var(--danger);
    color: #fff;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.68; }
}

/* While waiting (no text yet) the bubble would collapse to 0 width, making the
   100%-wide progress bar invisible. Give it a concrete width during thinking. */
.msg.agent.thinking {
    width: min(240px, 70%);
}

.thinking-bar {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    overflow: hidden;
}

.thinking-bar-fill {
    width: 0%;
    height: 100%;
    border-radius: 2px;
    background: var(--accent);
    /* Animation is started once from JS with the real avg duration (no CSS autostart,
       otherwise it would run at the default rate and restart → visible double-load). */
}

@keyframes thinking-fill {
    0% { width: 0%; }
    100% { width: 100%; }
}

/* Settings panel */
.model-settings-btn {
    display: inline-flex;
    height: 34px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101114;
    color: var(--muted);
    cursor: pointer;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    transition: color 120ms, border-color 120ms, background 120ms;
}

.model-settings-btn:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.settings-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(380px, 100%);
    height: auto;
    background: var(--panel);
    border-left: 1px solid var(--line);
    z-index: 30;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.3);
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    transition: transform 180ms ease, opacity 180ms ease, visibility 180ms ease;
}

.settings-panel.hidden {
    display: flex;
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    pointer-events: none;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 64px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    font-weight: 750;
    color: var(--text);
    font-size: 0.96rem;
}

.settings-close {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0;
    border-radius: 8px;
}

.settings-close:hover {
    border-color: var(--line);
    color: var(--text);
    background: var(--panel-2);
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-section {
    display: grid;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line-soft);
}

.settings-section:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.settings-section-title {
    color: var(--faint);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.settings-body label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.settings-body select {
    width: 100%;
    min-width: 0;
    height: 40px;
    background: #101114;
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: 8px;
    padding: 0 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.settings-body select:focus {
    outline: none;
    border-color: var(--accent);
}

.settings-body .controls label {
    gap: 7px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #101114;
    padding: 10px;
    color: var(--faint);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.settings-body .controls select {
    height: 30px;
    border: 0;
    border-radius: 6px;
    background-color: transparent;
    padding: 0 16px 0 0;
    font-size: 13px;
    text-transform: none;
}

.settings-cost {
    padding: 14px 18px 18px;
    border-top: 1px solid var(--line);
    color: var(--text);
    font-size: 0.85rem;
}

.cost-total {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.cost-total span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

.cost-total strong {
    color: var(--accent-strong);
    font-size: 18px;
}

.cost-breakdown {
    color: var(--faint);
    font-size: 12px;
    line-height: 1.45;
}

/* Scrollbars */
* {
    scrollbar-color: #3a3d45 transparent;
    scrollbar-width: thin;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background-clip: padding-box;
    background-color: #3a3d45;
}

/* Responsive */
@media (max-width: 860px) {
    body {
        overflow: hidden;
        min-height: var(--app-height);
        height: var(--app-height);
    }

    .app {
        height: var(--app-height);
        min-height: var(--app-height);
        grid-template-columns: 1fr;
        overflow: hidden;
    }

    .sidebar-resize {
        display: none;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 40;
        width: min(86vw, 340px);
        height: var(--app-height);
        max-height: none;
        border-right: 1px solid var(--line);
        border-bottom: 0;
        box-shadow: 24px 0 60px rgba(0, 0, 0, 0.42);
        transform: translateX(-105%);
        transition: transform 180ms ease;
        /* keep content out from under the Dynamic Island / home indicator */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
    }

    .chat-actions {
        opacity: 1;
    }

    .chat-action-btn {
        width: 30px;
        height: 30px;
        border: 1px solid var(--line-soft);
        background: #101114;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 30;
        background: rgba(0, 0, 0, 0.54);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    .mobile-overlay.show {
        opacity: 1;
        pointer-events: auto;
    }

    .main {
        height: var(--app-height);
        grid-template-rows: auto minmax(0, 1fr);
        min-height: 0;
    }

    .top-bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr);
        min-height: auto;
        position: relative;
        align-items: center;
        gap: 8px;
        padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
    }

    .top-actions {
        grid-column: 3;
        justify-self: end;
        min-width: 0;
        gap: 6px;
    }

    .top-title {
        display: contents;
    }

    .mobile-menu-btn {
        display: grid;
        grid-column: 1;
        justify-self: start;
        height: 34px;
        flex-basis: auto;
        min-width: 58px;
        border-radius: 8px;
    }

    .chat-title {
        grid-column: 2;
        justify-self: center;
        max-width: min(52vw, 260px);
        min-width: 0;
        text-align: center;
        font-size: 15px;
    }

    .token-usage {
        display: none;
    }

    .model-settings-btn {
        height: 34px;
        padding: 0 12px;
        font-size: 13px;
    }

    .controls {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
    }

    .settings-body .controls label {
        padding: 9px;
        font-size: 9px;
    }

    .settings-body .controls select {
        height: 26px;
        font-size: 13px;
    }

    .messages {
        padding: 14px max(10px, env(safe-area-inset-right)) calc(var(--composer-height) + var(--keyboard-offset) + 14px) max(10px, env(safe-area-inset-left));
        gap: 10px;
    }

    .msg {
        max-width: 94%;
        padding: 11px 12px;
        border-radius: 10px;
        font-size: 14px;
    }

    .input-area {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 25;
        gap: 8px;
        padding: 10px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left));
        transform: translate3d(0, var(--composer-shift), 0);
    }

    .input-area::after {
        content: "";
        position: absolute;
        right: 0;
        bottom: -56px;
        left: 0;
        height: 56px;
        background: rgba(23, 24, 27, 0.96);
        pointer-events: none;
    }

    html.standalone-pwa .input-area::after {
        height: 72px;
        bottom: -72px;
    }

    .input-area textarea {
        min-height: 42px;
        border-radius: 10px;
        padding: 10px 12px;
        font-size: 16px;
    }

    .settings-panel {
        width: min(390px, 100vw);
        border-left: 1px solid var(--line);
        box-shadow: -16px 0 48px rgba(0, 0, 0, 0.42);
    }

    /* close (×) was hidden under the Dynamic Island — push the header below it */
    .settings-header {
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .settings-close {
        width: 40px;
        height: 40px;
        border-color: var(--line);
    }

    /* explicit close button for the chats menu (sidebar) on mobile */
    .sidebar-close {
        display: grid;
    }
}

@media (max-width: 520px) {
    .sidebar-header {
        padding: 14px;
    }

    .input-area {
        gap: 8px;
    }

    .model-settings-btn {
        height: 34px;
        padding: 0 10px;
        font-size: 12px;
    }

    .btn-send,
    .btn-voice {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }
}
