:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-soft: #f0f4f7;
    --text: #17202a;
    --muted: #65717f;
    --line: #dce2e8;
    --primary: #176b87;
    --primary-strong: #0f5067;
    --accent: #d97706;
    --danger: #b42318;
    --shadow: 0 14px 35px rgba(23, 32, 42, 0.08);
    --sidebar-width: 310px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
a.link-button {
    border: 0;
    cursor: pointer;
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

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

.brand-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.brand-row.compact {
    margin: 0;
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #17324d;
    color: #fff;
    font-weight: 800;
}

.auth-panel h1,
.chat-topbar h1,
.admin-header h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0;
}

.auth-panel p,
.chat-topbar p,
.admin-header p,
.muted {
    margin: 4px 0 0;
    color: var(--muted);
}

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    background: var(--panel-soft);
    border-radius: 8px;
    margin-bottom: 18px;
}

.segmented button {
    padding: 10px;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
}

.segmented button.active {
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(23, 32, 42, 0.12);
}

.auth-form,
.settings-panel {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 16px;
    padding: 11px 12px;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.primary,
.secondary,
.ghost,
.google-button,
.tool-button,
.icon-button {
    min-height: 38px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
}

.primary {
    background: var(--primary);
    color: #fff;
}

.primary:hover {
    background: var(--primary-strong);
}

.secondary {
    background: #e8eef2;
    color: var(--text);
}

.secondary.active {
    background: #d8eef6;
    color: var(--primary-strong);
}

.compact-button {
    min-height: 32px;
    justify-self: start;
    padding: 0 10px;
    font-size: 13px;
}

.ghost {
    background: transparent;
    color: var(--muted);
}

.google-button {
    margin-top: 12px;
    border: 1px solid var(--line);
    color: var(--text);
    background: #fff;
    text-decoration: none;
}

.notice,
.form-message {
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff7ed;
    color: #9a3412;
    font-size: 14px;
}

.form-message:empty {
    display: none;
}

.notice.danger {
    background: #fef3f2;
    color: var(--danger);
}

.app-shell {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: var(--sidebar-width) 4px 1fr;
    overflow: hidden;
}

.sidebar-resizer {
    background: transparent;
    cursor: col-resize;
}

.sidebar-resizer:hover {
    background: rgba(23, 107, 135, 0.18);
}

.sidebar {
    min-width: 0;
    min-height: 0;
    background: #101923;
    color: #edf3f8;
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    padding: 18px;
    gap: 14px;
    overflow: hidden auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.sidebar .brand-mark {
    background: #f2f7fb;
    color: #102030;
}

.sidebar-head,
.chat-topbar,
.section-head,
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.speech-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.icon-button {
    width: 38px;
    padding: 0;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
}

.model-card {
    display: grid;
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.conversation-tools {
    display: grid;
    gap: 8px;
    min-height: 0;
    position: relative;
    z-index: 1;
}

.model-card label,
.model-card small {
    color: #b9c6d2;
}

.conversation-list {
    display: grid;
    align-content: start;
    gap: 6px;
    overflow: auto;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 0;
}

.conversation-item {
    text-align: left;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    padding: 10px 12px;
    min-height: 58px;
    overflow: hidden;
    cursor: pointer;
}

.conversation-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.conversation-actions button,
.message-actions button,
.message-actions a {
    min-height: 26px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: inherit;
    padding: 0 8px;
    font-size: 12px;
    text-decoration: none;
}

.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.message-actions button,
.message-actions a {
    background: #e8eef2;
    color: var(--text);
}

.conversation-item span {
    display: -webkit-box;
    min-height: 2.8em;
    line-height: 1.4;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.conversation-item:hover,
.conversation-item.active {
    background: rgba(255, 255, 255, 0.11);
}

.conversation-item small {
    display: block;
    color: #aebccb;
    margin-top: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-foot {
    display: grid;
    gap: 8px;
}

.sidebar-backdrop,
.sidebar-toggle,
.composer-toggle {
    display: none;
}

.text-link {
    color: #dbeafe;
    text-decoration: none;
    padding: 8px 0;
}

.chat-main {
    min-width: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto auto auto;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
}

.chat-topbar {
    min-width: 0;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.84);
}

.chat-heading {
    min-width: 0;
}

.messages {
    overflow: auto;
    overflow-x: hidden;
    min-height: 0;
    min-width: 0;
    padding: 24px;
    display: grid;
    align-content: start;
    gap: 18px;
    overscroll-behavior: contain;
}

.message {
    display: grid;
    gap: 8px;
    width: min(880px, 100%);
    max-width: 100%;
    min-width: 0;
}

.message.user {
    justify-self: end;
}

.message.assistant {
    justify-self: start;
}

.bubble {
    min-width: 0;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 14px 16px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    word-break: normal;
}

.bubble > * {
    max-width: 100%;
}

.bubble p,
.bubble li,
.bubble blockquote,
.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6,
.bubble strong,
.bubble em {
    overflow-wrap: anywhere;
}

.bubble img,
.bubble video,
.bubble audio,
.bubble canvas,
.bubble iframe {
    max-width: 100%;
}

.bubble table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

.bubble code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.user .bubble {
    background: #e6f2f6;
    border-color: #cbe3ec;
}

.message-role {
    font-size: 12px;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
}

.bubble pre {
    position: relative;
    max-width: 100%;
    overflow: auto;
    padding: 12px;
    padding-top: 42px;
    background: #101923;
    color: #edf3f8;
    border-radius: 8px;
}

.bubble pre code {
    white-space: pre-wrap;
}

.copy-code-button {
    position: absolute;
    top: 8px;
    right: 8px;
    min-height: 28px;
    border-radius: 6px;
    background: #223244;
    color: #edf3f8;
    border: 1px solid rgba(255, 255, 255, 0.16);
    padding: 0 10px;
    font-size: 12px;
}

.copy-code-button:hover {
    background: #2f435a;
}

.composer {
    position: relative;
    min-width: 0;
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    gap: 10px;
    align-items: end;
    padding: 16px 24px;
    background: #fff;
    border-top: 1px solid var(--line);
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.composer-main {
    position: relative;
    display: grid;
    gap: 8px;
    min-width: 0;
}

.model-options-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    padding: 10px;
}

.model-options-grid {
    display: grid;
    grid-template-columns: minmax(120px, 180px) minmax(100px, 140px) minmax(220px, 1fr);
    gap: 10px;
    align-items: end;
}

.model-options-grid label {
    min-width: 0;
}

.model-options-grid input,
.model-options-grid select {
    min-height: 36px;
    padding: 8px 10px;
}

.model-options-grid .wide {
    min-width: 0;
    grid-column: span 2;
}

.composer textarea {
    min-height: 44px;
    max-height: 160px;
    resize: none;
}

.composer.dragging .composer-main {
    outline: 2px dashed var(--primary);
    outline-offset: 6px;
    border-radius: 8px;
}

.drop-hint {
    position: absolute;
    inset: -8px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary);
    font-weight: 700;
    pointer-events: none;
}

.attachment-list,
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
}

.generated-image-gallery {
    width: min(820px, 100%);
    max-width: 100%;
    min-width: 0;
    display: grid;
    gap: 12px;
}

.generated-image-gallery.count-1 {
    grid-template-columns: minmax(0, 1fr);
}

.generated-image-gallery.count-2,
.generated-image-gallery.count-3,
.generated-image-gallery.count-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.generated-image-card {
    min-width: 0;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.generated-image-card > a {
    display: block;
    background: #f9fafb;
}

.generated-image-card img {
    width: 100%;
    height: auto;
    max-height: min(72vh, 680px);
    display: block;
    object-fit: contain;
}

.generated-image-gallery:not(.count-1) .generated-image-card img {
    height: clamp(220px, 32vw, 380px);
}

.generated-image-card figcaption {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 13px;
}

.generated-image-card figcaption span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.generated-image-card figcaption a {
    flex: 0 0 auto;
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.generated-video-gallery {
    width: min(820px, 100%);
    max-width: 100%;
    min-width: 0;
    display: grid;
    gap: 12px;
}

.generated-video-card {
    min-width: 0;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.generated-video-card video {
    width: 100%;
    max-height: min(72vh, 680px);
    display: block;
    background: #101923;
}

.generated-video-card figcaption {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    color: var(--muted);
    font-size: 13px;
}

.generated-video-card figcaption span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.generated-video-card figcaption a {
    flex: 0 0 auto;
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.message-audio {
    display: grid;
    gap: 6px;
    width: min(520px, 100%);
    max-width: 100%;
    min-width: 0;
}

.message-audio audio {
    width: 100%;
}

.message-audio a {
    color: var(--primary);
    font-size: 13px;
    text-decoration: none;
}

.generation-metadata {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.generation-metadata span {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--muted);
    font-size: 12px;
    padding: 4px 7px;
}

.message-diagnostic {
    width: min(720px, 100%);
    max-width: 100%;
    min-width: 0;
    border: 1px solid #f4d7a1;
    border-radius: 8px;
    background: #fff7ed;
    color: #8a4b12;
    padding: 8px 10px;
    font-size: 13px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 260px;
    min-width: 0;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 9px;
    background: #f7fafc;
    color: var(--text);
    font-size: 13px;
}

.attachment-chip img {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 6px;
}

.attachment-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip button {
    width: 24px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
}

.attachment-chip a {
    color: inherit;
    text-decoration: none;
}

.tool-button {
    background: #e8eef2;
    color: var(--text);
    align-self: end;
}

.send-button {
    min-width: 92px;
}

.voice-status {
    min-height: 24px;
    margin: 0;
    padding: 0 24px 12px;
    color: var(--accent);
    font-size: 14px;
}

.settings-dialog {
    border: 0;
    border-radius: 8px;
    padding: 0;
    width: min(520px, calc(100vw - 32px));
}

.model-details-dialog {
    width: min(860px, calc(100vw - 32px));
}

.settings-dialog::backdrop {
    background: rgba(16, 25, 35, 0.48);
}

.settings-panel {
    padding: 22px;
}

.settings-panel header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-panel h2,
.admin-section h2 {
    margin: 0;
    font-size: 20px;
}

.model-details-content {
    display: grid;
    gap: 14px;
    color: var(--text);
    max-height: min(72vh, 760px);
    overflow: auto;
    padding-right: 4px;
}

.model-details-content section {
    display: grid;
    gap: 6px;
}

.model-details-content h3 {
    margin: 0;
    font-size: 15px;
}

.model-details-content ul {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
}

.model-details-content code {
    color: var(--text);
    overflow-wrap: anywhere;
}

.model-details-content section[data-kind="examples"] li {
    margin-bottom: 6px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: auto;
}

.settings-actions {
    display: flex;
    gap: 10px;
}

.admin-shell {
    min-height: 100vh;
    padding: 24px;
}

.admin-header {
    margin-bottom: 18px;
}

.admin-index {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0 14px;
    margin-bottom: 4px;
    background: var(--bg);
    scrollbar-width: thin;
}

.admin-index a {
    flex: 0 0 auto;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    background: #fff;
    color: var(--text);
    text-decoration: none;
    box-shadow: 0 1px 4px rgba(23, 32, 42, 0.06);
}

.admin-index a:hover,
.admin-index a:focus-visible {
    border-color: var(--primary);
    color: var(--primary-strong);
}

.admin-grid {
    display: grid;
    gap: 18px;
}

.admin-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    scroll-margin-top: 76px;
}

.admin-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.metric-card {
    display: grid;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfcfd;
}

.metric-card small {
    color: var(--muted);
}

.model-usage-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.model-usage-item {
    display: grid;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}

.model-usage-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-usage-item small {
    color: var(--muted);
}

.table-wrap {
    overflow: auto;
    margin-top: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 10px;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
}

td select {
    min-width: 120px;
}

td input[type="checkbox"] {
    width: auto;
}

.admin-conversation-layout {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
    min-height: 420px;
}

.agent-admin-layout {
    margin-top: 14px;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
}

.agent-form {
    display: grid;
    gap: 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid .wide {
    grid-column: 1 / -1;
}

.agent-source-panel {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.source-list {
    display: grid;
    gap: 8px;
    margin-top: 12px;
}

.source-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #fbfcfd;
}

.source-item small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.admin-list {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    color: var(--text);
}

.admin-list .conversation-item:hover,
.admin-list .conversation-item.active {
    background: var(--panel-soft);
}

.admin-messages {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    overflow: auto;
    background: #fbfcfd;
}

.metadata-preview {
    max-width: 720px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--muted);
    padding: 8px;
    font-size: 12px;
}

@media (max-width: 840px) {
    .app-shell {
        height: 100dvh;
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .sidebar-resizer {
        display: none;
    }

    .sidebar {
        height: auto;
        max-height: 46dvh;
        grid-template-rows: auto auto auto minmax(52px, 1fr) auto;
        padding: 12px;
        gap: 10px;
        overflow: hidden auto;
    }

    .chat-main {
        height: auto;
        min-height: 0;
    }

    .chat-topbar {
        padding: 12px 14px;
        align-items: flex-start;
    }

    .chat-topbar h1 {
        font-size: 20px;
    }

    .chat-topbar p {
        font-size: 13px;
    }

    .conversation-list {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        overflow-y: hidden;
        min-height: 58px;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }

    .conversation-item {
        flex: 0 0 min(260px, 76vw);
        min-width: 0;
    }

    .sidebar-foot {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
        min-height: 38px;
    }

    .sidebar-foot .ghost,
    .sidebar-foot .text-link {
        min-height: 36px;
        padding: 0 10px;
    }

    .messages {
        padding: 14px;
        gap: 14px;
    }

    .message {
        max-width: min(100%, 760px);
    }

    .composer {
        grid-template-columns: auto auto 1fr auto;
        gap: 8px;
        padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    }

    .model-options-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .model-options-grid .wide {
        grid-column: 1 / -1;
    }

    .generated-image-gallery.count-2,
    .generated-image-gallery.count-3,
    .generated-image-gallery.count-4 {
        grid-template-columns: minmax(0, 1fr);
    }

    .generated-image-gallery:not(.count-1) .generated-image-card img {
        height: auto;
        max-height: 70vh;
    }

    .admin-conversation-layout {
        grid-template-columns: 1fr;
    }

    .agent-admin-layout,
    .form-grid,
    .admin-metrics,
    .model-usage-list {
        grid-template-columns: 1fr;
    }

    .source-item {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 560px) {
    .auth-shell,
    .admin-shell {
        padding: 12px;
    }

    .auth-panel,
    .settings-panel,
    .admin-section {
        padding: 16px;
    }

    .admin-index {
        margin-left: -12px;
        margin-right: -12px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .brand-row {
        gap: 10px;
        margin-bottom: 14px;
    }

    .brand-mark {
        width: 38px;
        height: 38px;
    }

    .app-shell {
        grid-template-rows: auto minmax(0, 1fr);
    }

    .sidebar {
        max-height: 48dvh;
    }

    .sidebar-head {
        gap: 10px;
    }

    .model-card {
        grid-template-columns: 1fr 1fr;
        align-items: end;
    }

    .model-card label:nth-of-type(2),
    #model-select,
    .model-card small,
    .model-card button {
        grid-column: 1 / -1;
    }

    .chat-topbar {
        display: grid;
        gap: 10px;
    }

    .speech-actions {
        justify-content: stretch;
    }

    .speech-actions button {
        flex: 1 1 0;
    }

    .bubble {
        padding: 12px;
    }

    .composer {
        grid-template-columns: 44px 44px minmax(0, 1fr) 76px;
        align-items: end;
    }

    .tool-button,
    .icon-button {
        min-width: 44px;
        min-height: 44px;
        padding: 0 10px;
    }

    .send-button {
        min-width: 0;
        padding: 0 10px;
    }

    .model-options-panel,
    .attachment-list {
        grid-column: 1 / -1;
    }

    .model-options-grid {
        grid-template-columns: 1fr;
    }

    .composer-main {
        display: contents;
    }

    .composer textarea {
        grid-column: 1 / -1;
        min-height: 48px;
        max-height: 34dvh;
    }

    .attachment-chip {
        max-width: 100%;
    }

    .generated-image-card figcaption,
    .generated-video-card figcaption {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .settings-dialog,
    .model-details-dialog {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
    }

    .model-details-content {
        max-height: 68dvh;
    }

    th,
    td {
        padding: 8px;
    }
}

@media (max-height: 560px) and (orientation: landscape) {
    .app-shell {
        grid-template-columns: minmax(260px, 34vw) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
        height: 100dvh;
    }

    .sidebar {
        max-height: none;
        height: 100dvh;
        padding: 10px;
        gap: 8px;
        grid-template-rows: auto auto auto minmax(58px, 1fr) auto;
        overflow: hidden auto;
    }

    .brand-row {
        margin-bottom: 0;
    }

    .brand-mark {
        width: 36px;
        height: 36px;
    }

    .model-card {
        gap: 6px;
        padding: 10px;
    }

    .model-card input,
    .model-card select {
        padding: 8px 10px;
        min-height: 38px;
    }

    .conversation-list {
        display: grid;
        overflow: auto;
        min-height: 0;
        padding-bottom: 0;
    }

    .conversation-item {
        flex-basis: auto;
        min-height: 38px;
        padding: 8px 10px;
    }

    .sidebar-foot {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .sidebar-foot .ghost,
    .sidebar-foot .text-link {
        min-height: 34px;
        padding: 0 8px;
    }

    .chat-main {
        height: 100dvh;
        min-height: 0;
    }

    .chat-topbar {
        padding: 8px 14px;
        align-items: center;
    }

    .chat-topbar h1 {
        font-size: 20px;
        line-height: 1.15;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .chat-topbar p {
        font-size: 13px;
    }

    .messages {
        padding: 10px 14px;
        gap: 10px;
    }

    .bubble {
        padding: 10px 12px;
    }

    .composer {
        grid-template-columns: 88px 64px minmax(0, 1fr) auto;
        gap: 8px;
        padding: 8px 14px max(8px, env(safe-area-inset-bottom));
    }

    .model-options-panel {
        max-height: 126px;
        overflow: auto;
    }

    .model-options-grid {
        grid-template-columns: repeat(3, minmax(120px, 1fr));
        gap: 8px;
    }

    .composer textarea {
        min-height: 42px;
        max-height: 96px;
    }

    .voice-status {
        min-height: 0;
        padding: 0 14px 6px;
    }
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr);
        height: 100dvh;
    }

    .sidebar-resizer {
        display: none;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 30;
        width: min(370px, calc(100vw - 28px));
        height: 100dvh;
        max-height: none;
        transform: translateX(-105%);
        transition: transform 180ms ease;
        grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
        overflow: hidden auto;
        box-shadow: 16px 0 36px rgba(16, 25, 35, 0.22);
    }

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

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 20;
        display: block;
        background: rgba(16, 25, 35, 0.34);
    }

    .sidebar-backdrop.hidden {
        display: none;
    }

    .sidebar-toggle {
        display: inline-flex;
        flex: 0 0 auto;
    }

    .composer-toggle {
        display: inline-flex;
        flex: 0 0 auto;
    }

    .conversation-list {
        display: grid;
        overflow: auto;
        min-height: 0;
        padding-bottom: 0;
    }

    .conversation-item {
        flex-basis: auto;
        min-height: 62px;
        overflow: hidden;
    }

    .conversation-item span,
    .conversation-item small {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .conversation-item span {
        display: -webkit-box;
        min-height: 2.8em;
        line-height: 1.4;
        white-space: normal;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .conversation-item small {
        white-space: nowrap;
    }

    .sidebar-foot {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .chat-main {
        height: 100dvh;
        min-height: 0;
    }

    .chat-topbar {
        display: grid;
        grid-template-columns: auto auto minmax(0, 1fr) auto;
        align-items: center;
    }

    .speech-actions {
        min-width: 0;
    }

    .messages {
        min-height: 0;
    }

    .composer {
        max-height: 48dvh;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    body.composer-collapsed .composer,
    body.composer-collapsed .voice-status {
        display: none;
    }

    .model-options-panel {
        max-height: 30dvh;
        overflow: auto;
    }
}

@media (max-width: 560px) {
    .chat-topbar {
        grid-template-columns: auto auto minmax(0, 1fr);
    }

    .speech-actions {
        grid-column: 1 / -1;
    }

    .sidebar {
        width: min(352px, calc(100vw - 16px));
    }

    .composer {
        max-height: 54dvh;
    }

    .model-options-panel {
        max-height: 34dvh;
    }
}

@media (max-width: 1024px) and (max-height: 560px) and (orientation: landscape) {
    .sidebar {
        width: min(360px, 42vw);
    }

    .model-card {
        max-height: 47dvh;
        overflow: auto;
    }

    .composer {
        max-height: 44dvh;
    }

    .model-options-panel {
        max-height: 112px;
    }
}
