:root {
    color-scheme: light;
    --bg: #f4efe6;
    --panel: rgba(255, 250, 242, 0.92);
    --panel-strong: rgba(255, 248, 236, 0.98);
    --sidebar-surface: rgba(252, 246, 237, 0.84);
    --main-surface: rgba(249, 242, 233, 0.48);
    --rail-surface: rgba(245, 237, 226, 0.68);
    --border: rgba(102, 74, 43, 0.18);
    --text: #22170c;
    --muted: #69533b;
    --code-bg: #0d1117;
    --code-text: #c9d1d9;
    --accent: #b9502a;
    --accent-dark: #7b2d16;
    --accent-soft: #f2d5bd;
    --shadow: 0 24px 80px rgba(79, 49, 21, 0.12);
    --radius: 24px;
}

html {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

/* =================================================================
   認証ゲート
   ================================================================= */

#auth-gate {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--text);
}

#auth-panel {
    width: min(420px, calc(100vw - 32px));
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg, var(--panel, var(--bg)));
    box-shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

#auth-panel h1 {
    margin-bottom: 10px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0;
}

#auth-panel p {
    margin-bottom: 18px;
    color: var(--text-muted, var(--muted, #888));
    line-height: 1.6;
}

#auth-panel p.error {
    color: #ff8a8a;
}

#auth-form {
    display: flex;
    gap: 10px;
}

#auth-password-input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

#auth-password-input:focus {
    outline: none;
    border-color: var(--accent);
}

#auth-submit {
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

#auth-submit:disabled {
    cursor: wait;
    opacity: .72;
}

body.auth-locked #auth-gate {
    display: flex;
}

body.auth-locked #sidebar,
body.auth-locked #main,
body.auth-locked #sidebar-backdrop,
body.auth-locked .shell {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    height: 100vh;
    height: 100dvh;
    display: flex;
    overflow: hidden;
    font-family: "Segoe UI Variable Text", "Yu Gothic UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(227, 173, 111, 0.32), transparent 32%),
        radial-gradient(circle at bottom right, rgba(185, 80, 42, 0.22), transparent 30%),
        linear-gradient(135deg, #f8f2e9 0%, #efe2d1 45%, #f4ece2 100%);
}

button,
input,
select,
textarea {
    font: inherit;
}

.shell {
    display: grid;
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
    gap: 0;
    flex: 1;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.panel {
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(255, 249, 242, 0.98);
    box-shadow: 0 24px 72px rgba(79, 49, 21, 0.14);
}

.sidebar,
.main-column,
.conversation-panel,
.side-panel {
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 18px 16px;
    background: var(--sidebar-surface);
    border-right: 1px solid rgba(102, 74, 43, 0.12);
    overflow: hidden;
}

.main-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--main-surface);
    overflow: hidden;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.conversation-panel,
.side-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    background: transparent;
}

.conversation-panel {
    padding: 0;
}

.side-panel {
    padding: 18px 20px;
    border-left: 1px solid rgba(102, 74, 43, 0.12);
    background: var(--rail-surface);
}

.sidebar .panel-header,
.conversation-panel .panel-header {
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(102, 74, 43, 0.12);
}

.conversation-panel .panel-header {
    padding: 16px 22px;
    background: rgba(255, 249, 242, 0.95);
}

.sidebar .panel-header {
    padding-top: max(6px, env(safe-area-inset-top));
}

.sidebar>.subtle-link,
.sidebar>.stack {
    width: 100%;
}

.conversation-view {
    padding: 20px 22px 0;
}

.generation-status {
    margin: 0 22px;
}

.composer {
    margin-top: 0;
    padding: 16px 22px 22px;
    background: rgba(255, 249, 242, 0.58);
}

.voice-progress {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    min-height: 18px;
    margin-top: 6px;
    padding-right: 2px;
    font-size: 0.68rem;
    line-height: 1.25;
    color: var(--muted);
    text-align: right;
}

.voice-progress-step {
    font-weight: 600;
    color: var(--accent-dark);
}

.voice-progress-detail {
    max-width: min(460px, 70vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 0 8px;
}

.image-preview-item {
    position: relative;
    display: inline-block;
}

.image-preview-thumb {
    display: block;
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border, #ddd);
}

.image-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: var(--accent-dark, #c0392b);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.image-preview-remove:hover {
    opacity: 0.85;
}

h1,
h2 {
    font-family: inherit;
    font-weight: 600;
}

.sidebar h1 {
    font-size: 1.25rem;
}

#threadTitle {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
}

.panel-header,
.section-heading,
.row {
    display: flex;
    align-items: center;
}

.panel-header,
.section-heading {
    justify-content: space-between;
    gap: 16px;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.new-thread-button {
    padding: 6px 12px;
    border-radius: 8px;
    background: var(--accent);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.panel-title-group {
    min-width: 0;
    flex: 1;
}

.drawer-toggle-button,
.drawer-close-button {
    display: none;
}

.drawer-toggle-button {
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 1px solid rgba(123, 45, 22, 0.16);
    border-radius: 14px;
    background: rgba(255, 248, 240, 0.9);
    color: var(--text);
    cursor: pointer;
}

.drawer-toggle-lines {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

.drawer-toggle-lines span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.thread-drawer-backdrop {
    display: none;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(28, 19, 10, 0.4);
    backdrop-filter: blur(8px);
}

.directory-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 90;
    width: min(720px, calc(100vw - 32px));
    max-height: min(80vh, 860px);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transform: translate(-50%, -50%);
    overflow: hidden;
}

.directory-dialog .eyebrow {
    font-size: 0.68rem;
}

.directory-dialog h2 {
    font-size: 0.94rem;
    line-height: 1.3;
}

.directory-dialog .panel-header,
.directory-dialog-current-path,
.directory-breadcrumbs,
.directory-dialog-toolbar,
.directory-dialog .panel-note,
.directory-dialog .row.end {
    flex: 0 0 auto;
}

.directory-dialog-current-path {
    padding: 12px 14px;
    border: 1px solid rgba(123, 45, 22, 0.12);
    border-radius: 16px;
    background: rgba(255, 248, 240, 0.88);
    color: var(--text);
    font-size: 0.82rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.directory-breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.directory-breadcrumb-button,
.directory-list-button {
    border: 1px solid rgba(123, 45, 22, 0.12);
    background: rgba(255, 248, 240, 0.88);
    color: var(--text);
    cursor: pointer;
}

.directory-breadcrumb-button {
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 0.74rem;
    line-height: 1.15;
}

.directory-breadcrumb-separator {
    color: var(--muted);
    font-size: 0.78rem;
}

.directory-dialog-toolbar {
    align-items: center;
}

.directory-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 44vh;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.directory-list-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 18px;
    text-align: left;
}

.directory-list-button:hover,
.directory-breadcrumb-button:hover {
    transform: translateY(-1px);
}

.directory-list-name {
    font-size: 0.84rem;
    font-weight: 600;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.directory-list-path {
    font-size: 0.68rem;
    color: var(--muted);
    flex-shrink: 0;
}

.directory-list-empty {
    min-height: 140px;
}

.directory-dialog .panel-note {
    font-size: 0.78rem;
}

.directory-dialog .ghost-button,
.directory-dialog .primary-button {
    font-size: 11px;
    padding: 8px 12px;
}

.section-heading {
    margin-bottom: 12px;
}

.row.wrap {
    flex-wrap: wrap;
}

.row.end {
    justify-content: flex-end;
}

.row.space-between {
    justify-content: space-between;
}

.gap-sm {
    gap: 10px;
}

.top-gap {
    margin-top: 20px;
}

.stack {
    display: flex;
    flex-direction: column;
}

.grow {
    flex: 1;
    min-height: 0;
}

.flex-grow {
    flex: 1;
}

.eyebrow {
    margin: 0 0 4px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 0.74rem;
    color: var(--muted);
}

h1,
h2 {
    margin: 0;
    font-family: inherit;
    font-weight: 600;
}

#threadTitle {
    display: block;
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.thread-working-directory {
    margin-top: 3px;
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
    color: var(--muted);
    font-size: 0.68rem;
    line-height: 1.2;
    opacity: 0.88;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.label {
    font-size: 0.85rem;
    color: var(--muted);
}

.subtle-link {
    color: var(--accent-dark);
    font-size: 0.92rem;
    text-decoration-color: rgba(123, 45, 22, 0.28);
    text-underline-offset: 0.18em;
}

.subtle-link:hover {
    text-decoration-color: currentColor;
}

.text-input,
.composer-input {
    width: 100%;
    border: 1px solid rgba(123, 45, 22, 0.16);
    border-radius: 16px;
    padding: 12px 14px;
    background: var(--panel-strong);
    color: var(--text);
}

.composer-input {
    resize: vertical;
    min-height: 96px;
}

.primary-button,
.ghost-button,
.mini-button {
    border-radius: 999px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}

.primary-button {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    padding: 11px 18px;
}

.ghost-button {
    background: rgba(255, 248, 240, 0.74);
    border-color: var(--border);
    color: var(--text);
    padding: 10px 16px;
}

.mini-button {
    padding: 8px 12px;
    background: white;
}

.mini-button.accept {
    border-color: rgba(37, 115, 66, 0.24);
}

.mini-button.decline {
    border-color: rgba(140, 44, 44, 0.24);
}

.primary-button:hover,
.ghost-button:hover,
.mini-button:hover,
.thread-item:hover {
    transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled,
.mini-button:disabled {
    opacity: 0.6;
    cursor: default;
    transform: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.8rem;
}

.thread-list,
.approval-list,
.event-list,
.conversation-view {
    overflow: auto;
}

.thread-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 10px;
    min-height: 0;
}

.thread-item {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    width: 100%;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 18px;
    padding: 12px 10px 12px 14px;
    overflow: visible;
    text-align: left;
    background: rgba(255, 252, 247, 0.9);
    color: var(--text);
}

.thread-select-button {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.thread-delete-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0.72;
    transition: opacity 140ms ease, background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.thread-item:hover .thread-delete-button,
.thread-item:focus-within .thread-delete-button {
    opacity: 1;
}

.thread-delete-button:hover,
.thread-delete-button:focus-visible {
    border-color: rgba(140, 44, 44, 0.22);
    background: rgba(140, 44, 44, 0.1);
    color: #8c2c2c;
    outline: none;
}

.thread-delete-button svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

.thread-item.deleting {
    opacity: 0.62;
}

.thread-item.generating::before {
    content: "";
    position: absolute;
    top: 9px;
    bottom: 9px;
    left: 5px;
    width: 3px;
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 0 0 1px rgba(185, 80, 42, 0.12), 0 0 14px rgba(185, 80, 42, 0.34);
    animation: thread-generating-pulse 1.35s ease-in-out infinite;
}

.thread-item-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    min-width: 0;
}

.thread-item.active {
    border-color: rgba(185, 80, 42, 0.34);
    background: linear-gradient(135deg, rgba(255, 237, 220, 0.95), rgba(250, 244, 234, 0.98));
}

@keyframes thread-generating-pulse {

    0%,
    100% {
        opacity: 0.42;
        transform: scaleY(0.72);
    }

    50% {
        opacity: 1;
        transform: scaleY(1);
    }
}

.thread-name {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.35;
    padding-bottom: 1px;
    color: var(--text);
    -webkit-text-fill-color: var(--text);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-meta,
.event-seq {
    font-size: 0.8rem;
    color: var(--muted);
}

.thread-meta {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    font-size: 0.68rem;
    line-height: 1.35;
    padding-bottom: 1px;
    opacity: 0.9;
    color: var(--muted);
    -webkit-text-fill-color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conversation-view {
    flex: 1;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 22px 0;
    scroll-padding-bottom: 16px;
}

.message-bubble,
.approval-card,
.event-card,
.json-box {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 252, 246, 0.95);
}

.message-bubble {
    padding: 14px;
}

.message-bubble.user {
    background: rgba(255, 237, 220, 0.95);
}

.message-bubble.assistant {
    background: rgba(251, 248, 241, 0.96);
}

.message-bubble.system {
    background: rgba(244, 235, 224, 0.92);
}

.message-title {
    margin-bottom: 8px;
    font-size: 0.82rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.message-summary,
.event-summary,
.panel-note {
    color: var(--text);
    line-height: 1.45;
    position: relative;
    z-index: 1;
}

.message-content {
    display: grid;
    gap: 10px;
    line-height: 1.65;
    min-width: 0;
}

.message-content>* {
    min-width: 0;
    max-width: 100%;
}

.message-content h1,
.message-content h2,
.message-content h3 {
    font-size: 0.96rem;
    font-weight: 600;
    line-height: 1.35;
}

.message-content> :first-child {
    margin-top: 0;
}

.message-content> :last-child {
    margin-bottom: 0;
    position: relative;
    z-index: 1;
}

.message-content p,
.message-content ul,
.message-content ol,
.message-content blockquote,
.message-content pre,
.message-content table {
    margin: 0;
}

.message-content ul,
.message-content ol {
    padding-left: 22px;
}

.message-content blockquote {
    padding-left: 14px;
    border-left: 3px solid rgba(185, 80, 42, 0.28);
    color: var(--muted);
}

.message-content a {
    color: var(--accent-dark);
}

.message-content .katex-display {
    margin: 0.6rem 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.inline-code {
    padding: 0.14rem 0.38rem;
    border-radius: 8px;
    background: rgba(123, 45, 22, 0.08);
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9em;
}

.inline-file-link {
    color: inherit;
    text-decoration: none;
}

.inline-file-link .inline-code {
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.12em;
}

.markdown-absolute-file-link {
    cursor: pointer;
    color: var(--accent-dark);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.markdown-absolute-file-link[data-file-link-state="missing"] {
    cursor: default;
    text-decoration: none;
    opacity: 0.6;
}

/* imageView ツールカードのプレビューエリア */
.image-view-card .image-view-preview-area {
    padding: 6px 10px 10px;
}

.image-view-card .image-view-preview-area .inline-file-image-preview {
    margin: 0;
    max-width: 100%;
}

.image-view-card[data-image-view-state="loading"] .image-view-preview-area::after {
    content: "Loading…";
    display: block;
    padding: 4px 0 6px;
    color: var(--muted);
    font-size: 12px;
}

.image-view-card[data-image-view-state="error"] .image-view-preview-area::after {
    content: "Image not found";
    display: block;
    padding: 4px 0 6px;
    color: var(--muted);
    font-size: 12px;
}

.inline-file-image-preview {
    display: block;
    width: fit-content;
    max-width: 300px;
    margin: 8px 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    cursor: zoom-in;
    overflow: hidden;
}

.inline-file-image-preview img {
    display: block;
    max-width: 300px;
    max-height: 250px;
    width: auto;
    height: auto;
    margin: 0;
    border: 0;
    border-radius: 0;
}

.file-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(20, 12, 4, 0.84);
}

.file-image-lightbox.open {
    display: flex;
}

.file-image-lightbox-panel {
    max-width: min(96vw, 1200px);
    max-height: 94vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-strong, var(--panel));
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    overflow: hidden;
}

.file-image-lightbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.file-image-lightbox-title {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: Consolas, "Courier New", monospace;
}

.file-image-lightbox-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.file-image-lightbox-open,
.file-image-lightbox-close {
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    padding: 4px 10px;
    font-size: 12px;
    text-decoration: none;
    cursor: pointer;
    font-family: inherit;
}

.file-image-lightbox-open:hover,
.file-image-lightbox-close:hover {
    border-color: var(--accent);
    color: var(--accent-dark, var(--accent));
}

.file-image-lightbox-img {
    display: block;
    max-width: 96vw;
    max-height: calc(94vh - 46px);
    object-fit: contain;
    background: #1a120a;
}

.code-block {
    border: 1px solid rgba(102, 74, 43, 0.14);
    border-radius: 16px;
    background: rgba(248, 241, 230, 0.92);
    overflow: hidden;
    max-width: 100%;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 2px 10px;
    border-bottom: 1px solid rgba(102, 74, 43, 0.12);
    background: rgba(255, 248, 240, 0.92);
}

.code-language {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.copy-code-button {
    border: 1px solid rgba(123, 45, 22, 0.16);
    border-radius: 999px;
    padding: 3px 7px;
    background: white;
    color: var(--text);
    font-size: 0.48rem;
    line-height: 1;
    letter-spacing: 0.02em;
    cursor: pointer;
}

.copy-code-button:hover {
    transform: translateY(-1px);
}

.code-block pre {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 14px;
    background: var(--code-bg);
    color: var(--code-text) !important;
    max-width: 100%;
    scrollbar-gutter: stable;
    font-size: 0.78rem;
    line-height: 1.5;
}

.code-block code {
    display: block;
    width: max-content;
    min-width: 100%;
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
    font-size: inherit;
    line-height: inherit;
    color: var(--code-text) !important;
}

.code-block code.hljs {
    padding: 0;
    background: transparent;
    color: var(--code-text);
}

.message-summary,
.event-summary {
    margin-bottom: 8px;
}

.panel-note {
    margin: 0 0 12px;
    font-size: 0.84rem;
    color: var(--muted);
}

.card-list {
    margin: 0;
    padding-left: 18px;
    color: var(--text);
}

.card-list li+li {
    margin-top: 6px;
}

pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.88rem;
}

.composer {
    margin-top: 0;
    padding: 16px 22px 22px;
    border-top: 1px solid var(--border);
    background: rgba(255, 249, 242, 0.58);
}

.generation-status {
    margin: 0 22px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border: 1px solid rgba(123, 45, 22, 0.16);
    border-radius: 16px;
    background: rgba(255, 248, 240, 0.82);
}

.generation-indicator {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    color: var(--muted);
}

.generation-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.generation-dots span {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--accent);
    opacity: 0.35;
    animation: generation-pulse 1.1s infinite ease-in-out;
}

.generation-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.generation-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

.stop-button {
    flex-shrink: 0;
}

@keyframes generation-pulse {

    0%,
    80%,
    100% {
        opacity: 0.25;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-1px);
    }
}

.approval-list,
.event-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.approval-list {
    max-height: 28vh;
    min-height: 0;
}

.event-list {
    flex: 1;
    min-height: 0;
}

.approval-card,
.event-card,
.json-box {
    padding: 14px;
}

.message-bubble.tool {
    background: rgba(244, 238, 224, 0.96);
    border-color: rgba(128, 96, 54, 0.22);
}

.message-bubble.error,
.event-card.error {
    background: rgba(255, 237, 234, 0.96);
    border-color: rgba(161, 64, 48, 0.22);
}

.event-card.tool {
    background: rgba(244, 238, 224, 0.96);
}

.event-card.event {
    background: rgba(251, 248, 241, 0.96);
}

.event-details {
    margin-top: 8px;
}

.event-details summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.82rem;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 120px;
    border: 1px dashed var(--border);
    border-radius: 18px;
    color: var(--muted);
}

@media (max-width: 1100px) {
    body {
        height: auto;
        overflow: auto;
    }

    .shell {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }

    .workspace-grid {
        grid-template-columns: 1fr;
        overflow: visible;
    }

    .side-panel {
        border-left: 0;
        border-top: 1px solid rgba(102, 74, 43, 0.12);
    }

    .sidebar,
    .main-column,
    .conversation-panel,
    .side-panel {
        overflow: visible;
    }
}

@media (max-width: 720px) {
    .shell {
        padding: 0;
        gap: 0;
    }

    .sidebar,
    .side-panel {
        padding: 16px;
    }

    .conversation-panel .panel-header,
    .conversation-view,
    .composer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .conversation-panel .panel-header {
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .conversation-view {
        padding-top: 16px;
    }

    .composer {
        padding-top: 14px;
        padding-bottom: 18px;
    }

    .generation-status {
        margin-left: 16px;
        margin-right: 16px;
    }

    .directory-dialog {
        top: 10px;
        right: 10px;
        bottom: 10px;
        left: 10px;
        width: auto;
        max-height: none;
        padding: 18px;
        transform: none;
    }

    .directory-list {
        max-height: none;
    }

    .directory-dialog .panel-note {
        margin-bottom: 0;
    }

    .directory-dialog .top-gap {
        margin-top: 12px;
    }
}

body.ios-safari-mobile {
    height: 100dvh;
    overflow: hidden;
}

body.ios-safari-mobile .directory-dialog {
    top: calc(env(safe-area-inset-top) + 10px);
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom) + 10px);
    left: 10px;
    width: auto;
    max-height: none;
    padding: 18px;
    transform: none;
}

body.ios-safari-mobile .directory-list {
    max-height: none;
    min-height: 0;
}

@media (max-width: 720px) and (max-height: 620px) {
    .directory-dialog {
        gap: 10px;
        padding: 14px;
    }

    .directory-dialog-current-path {
        padding: 10px 12px;
        font-size: 0.78rem;
    }

    .directory-breadcrumbs {
        gap: 4px;
    }

    .directory-dialog-toolbar {
        gap: 8px;
    }

    .directory-list-button {
        padding: 10px 12px;
    }

    .directory-dialog .panel-note {
        display: none;
    }

    .directory-dialog .top-gap {
        margin-top: 8px;
    }
}

@media (max-width: 720px) and (max-height: 620px) {
    body.ios-safari-mobile .directory-dialog {
        padding: 14px;
    }
}

body.ios-safari-mobile .shell {
    grid-template-columns: 1fr;
    width: 100%;
    max-width: 100vw;
    height: 100dvh;
    padding: 0;
    gap: 0;
}

body.ios-safari-mobile .main-column,
body.ios-safari-mobile .workspace-grid,
body.ios-safari-mobile .conversation-panel {
    width: 100%;
    max-width: 100vw;
    min-height: 0;
    height: 100%;
}

body.ios-safari-mobile .workspace-grid {
    grid-template-columns: 1fr;
    gap: 0;
}

body.ios-safari-mobile .main-column,
body.ios-safari-mobile .workspace-grid,
body.ios-safari-mobile .conversation-panel,
body.ios-safari-mobile .panel-header,
body.ios-safari-mobile .panel-title-group,
body.ios-safari-mobile .conversation-view,
body.ios-safari-mobile .conversation-view>*,
body.ios-safari-mobile .message-bubble,
body.ios-safari-mobile .message-content,
body.ios-safari-mobile .message-content>*,
body.ios-safari-mobile .composer,
body.ios-safari-mobile .composer-input,
body.ios-safari-mobile .composer-actions,
body.ios-safari-mobile .generation-status,
body.ios-safari-mobile .code-block,
body.ios-safari-mobile .code-block pre,
body.ios-safari-mobile pre {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

body.ios-safari-mobile .side-panel {
    display: none;
}

body.ios-safari-mobile #runtimeConfigLink,
body.ios-safari-mobile .sidebar .label,
body.ios-safari-mobile .sidebar #modelSelect {
    display: none;
}

body.ios-safari-mobile .drawer-toggle-button,
body.ios-safari-mobile .drawer-close-button {
    display: inline-flex;
}

body.ios-safari-mobile .drawer-close-button {
    align-items: center;
}

body.ios-safari-mobile .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(84vw, 320px);
    max-width: min(84vw, 320px);
    transform: translateX(calc(-100% - 24px));
    transition: transform 180ms ease, box-shadow 180ms ease;
    overflow: hidden;
    gap: 12px;
    padding: max(18px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
    border-right: 1px solid rgba(102, 74, 43, 0.16);
    border-radius: 0 24px 24px 0;
    background: rgba(252, 246, 237, 0.97);
}

body.ios-safari-mobile .sidebar .panel-header {
    align-items: center;
    gap: 10px;
}

body.ios-safari-mobile .sidebar .panel-header>div:first-child {
    min-width: 0;
}

body.ios-safari-mobile .sidebar .eyebrow {
    display: none;
}

body.ios-safari-mobile .sidebar h1,
body.ios-safari-mobile .sidebar h2 {
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.35;
}

body.ios-safari-mobile .sidebar .ghost-button,
body.ios-safari-mobile .sidebar .primary-button {
    padding: 9px 12px;
}

body.ios-safari-mobile .sidebar .new-thread-button {
    padding: 6px 12px;
}

body.ios-safari-mobile .sidebar .stack.gap-sm {
    gap: 0;
}

body.ios-safari-mobile .sidebar .stack.grow {
    gap: 8px;
}

body.ios-safari-mobile .sidebar .section-heading {
    margin-bottom: 0;
}

body.ios-safari-mobile .thread-list {
    min-height: 220px;
    padding-right: 2px;
}

body.ios-safari-mobile .thread-item {
    padding-top: 16px;
    padding-bottom: 16px;
    color: var(--text);
    -webkit-text-fill-color: var(--text);
}

body.ios-safari-mobile .thread-item-content,
body.ios-safari-mobile .thread-name,
body.ios-safari-mobile .thread-meta {
    opacity: 1;
    visibility: visible;
    transform: none;
}

body.ios-safari-mobile.mobile-thread-drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 28px 90px rgba(40, 25, 11, 0.24);
}

body.ios-safari-mobile .thread-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    border: 0;
    background: rgba(34, 23, 12, 0.24);
}

body.ios-safari-mobile.mobile-thread-drawer-open .thread-drawer-backdrop {
    display: block;
}

body.ios-safari-mobile .conversation-panel {
    padding: 0;
    overflow-x: hidden;
}

body.ios-safari-mobile .panel-header {
    align-items: center;
    overflow: hidden;
}

body.ios-safari-mobile .conversation-panel .panel-header {
    padding: max(14px, env(safe-area-inset-top)) 16px 14px;
}

body.ios-safari-mobile #threadTitle {
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

body.ios-safari-mobile .conversation-view {
    min-height: 0;
    overflow-x: hidden;
    padding: 16px 16px 0;
}

body.ios-safari-mobile .generation-status {
    width: auto;
    max-width: calc(100% - 32px);
    align-self: stretch;
    margin: 0 16px;
}

body.ios-safari-mobile .ui-notice-stack {
    align-items: stretch;
    padding: 0 16px 8px;
}

body.ios-safari-mobile .ui-notice {
    width: 100%;
}

body.ios-safari-mobile .composer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 0;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}

body.ios-safari-mobile .composer-input {
    min-height: 44px;
    max-height: 200px;
    padding-top: 12px;
    padding-bottom: 12px;
    resize: none;
}

body.ios-safari-mobile .composer-actions {
    align-self: stretch;
}

body.ios-safari-mobile .composer-actions .primary-button {
    height: 48px;
    padding: 0 14px;
    white-space: nowrap;
}

body.ios-safari-mobile .message-bubble,
body.ios-safari-mobile .message-content,
body.ios-safari-mobile .message-content p,
body.ios-safari-mobile .message-content li,
body.ios-safari-mobile .message-summary,
body.ios-safari-mobile .event-summary,
body.ios-safari-mobile pre {
    overflow-wrap: anywhere;
    word-break: break-word;
}

body.ios-safari-mobile .code-block pre,
body.ios-safari-mobile .code-block code {
    overflow-wrap: normal;
    word-break: normal;
    white-space: pre;
}

/* -----------------------------------------------------------------
   Sibling-style chat layout overrides
   ----------------------------------------------------------------- */

.sidebar-header {
    align-items: flex-start;
}

.sidebar-section {
    padding: 0 2px 4px;
}

.sidebar-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 6px;
    border-top: 1px solid rgba(102, 74, 43, 0.12);
}

.section-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.subtle-chip {
    background: rgba(123, 45, 22, 0.08);
    color: var(--muted);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
}

.chat-header-main {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.header-control {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid rgba(123, 45, 22, 0.14);
    border-radius: 16px;
    background: rgba(255, 248, 240, 0.82);
}

.header-control-label {
    font-size: 0.72rem;
    line-height: 1;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.header-select {
    min-width: 220px;
    border: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid rgba(123, 45, 22, 0.14);
    background: rgba(255, 243, 224, 0.92);
    color: var(--accent-dark);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}

.conversation-view {
    padding: 18px 16px 0;
    gap: 14px;
}

.generation-status {
    margin: 0 16px 12px;
}

.composer {
    padding: 14px 16px 18px;
}

.composer-input {
    min-height: 52px;
    max-height: 220px;
    resize: none;
}

.composer-actions {
    margin-top: 12px;
}

.message-row {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 980px;
}

.message-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-row.assistant,
.message-row.system {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.86rem;
    font-weight: 700;
    color: white;
    background: rgba(123, 45, 22, 0.4);
    box-shadow: 0 10px 24px rgba(79, 49, 21, 0.12);
}

.message-row.user .message-avatar {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
}

.message-row.assistant .message-avatar {
    background: linear-gradient(135deg, #8f6845 0%, #6c4d35 100%);
}

.message-row.assistant .message-avatar.avatar-blue {
    background: linear-gradient(135deg, #001233 0%, #38b6ff 100%);
    box-shadow: 0 4px 14px rgba(56, 182, 255, 0.45);
}

.message-row.assistant .message-avatar.avatar-purple {
    background: linear-gradient(135deg, #18002a 0%, #da00ff 100%);
    box-shadow: 0 4px 14px rgba(218, 0, 255, 0.45);
}

.message-row.assistant .message-avatar.avatar-yellow {
    background: linear-gradient(135deg, #d48806 0%, #fadb14 100%);
    box-shadow: 0 4px 14px rgba(250, 219, 20, 0.45);
    color: #333333;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.message-row.assistant .message-avatar.avatar-crimson {
    background: linear-gradient(135deg, #3d000f 0%, #e74c3c 100%);
    box-shadow: 0 4px 14px rgba(231, 76, 60, 0.45);
}

.message-row.system .message-avatar {
    background: rgba(123, 45, 22, 0.1);
    color: var(--accent-dark);
    border: 1px solid rgba(123, 45, 22, 0.14);
    box-shadow: none;
}

.message-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    max-width: min(860px, calc(100% - 44px));
}

.message-row.user .message-stack {
    align-items: flex-end;
}

.message-row.system .message-stack {
    width: min(860px, calc(100% - 44px));
}

.message-bubble {
    width: fit-content;
    max-width: 100%;
    padding: 12px 14px;
}

.message-row.user .message-bubble {
    background: rgba(255, 237, 220, 0.98);
    border-color: rgba(185, 80, 42, 0.2);
}

.message-row.assistant .message-bubble {
    background: rgba(255, 252, 246, 0.96);
}

.message-row.system .message-bubble {
    background: rgba(244, 235, 224, 0.92);
    width: 100%;
}

.message-bubble.approval {
    background: rgba(255, 244, 227, 0.98);
    border-color: rgba(185, 80, 42, 0.24);
}

.message-bubble.error {
    background: rgba(255, 237, 234, 0.98);
    border-color: rgba(161, 64, 48, 0.24);
}

.message-meta {
    padding: 0 4px;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.3;
}

.message-row.user .message-meta {
    text-align: right;
}

.message-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 4px;
}

.message-actions .mini-button {
    background: rgba(255, 252, 247, 0.96);
}

.message-actions .mini-button.accept {
    background: rgba(231, 244, 236, 0.92);
}

.message-actions .mini-button.decline {
    background: rgba(255, 240, 238, 0.92);
}

.empty-state {
    width: min(720px, 100%);
    align-self: center;
    min-height: 160px;
    background: rgba(255, 252, 247, 0.72);
}

@media (max-width: 980px) {
    .chat-header {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-header-actions {
        justify-content: flex-start;
    }

    .header-control {
        width: 100%;
    }

    .header-select {
        min-width: 0;
        width: 100%;
    }
}

@media (max-width: 720px) {
    .sidebar-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .sidebar-footer {
        justify-content: stretch;
    }

    .sidebar-footer .ghost-button {
        width: 100%;
    }

    .message-row {
        max-width: 100%;
    }

    .message-stack,
    .message-row.system .message-stack {
        max-width: calc(100% - 44px);
        width: calc(100% - 44px);
    }

    .status-chip {
        max-width: 100%;
        white-space: normal;
    }
}

body.ios-safari-mobile .chat-header {
    flex-direction: column;
    align-items: stretch;
}

body.ios-safari-mobile .chat-header-main {
    width: 100%;
}

body.ios-safari-mobile .chat-header-actions {
    width: 100%;
    justify-content: flex-start;
}

body.ios-safari-mobile .header-control {
    width: 100%;
}

body.ios-safari-mobile .header-select {
    min-width: 0;
    width: 100%;
}

body.ios-safari-mobile .message-row {
    max-width: 100%;
}

/* -----------------------------------------------------------------
   Stronger sibling-project visual parity
   ----------------------------------------------------------------- */

:root {
    --bg: #f6efe4;
    --sidebar-bg-flat: #efe4d3;
    --panel-bg-flat: #f8f1e7;
    --main-bg-flat: #fbf7f1;
    --input-bg-flat: #fffaf3;
    --user-bubble-flat: #ead1ba;
    --assistant-bubble-flat: #f8f1e8;
    --system-bubble-flat: #f2e6d8;
    --hover-flat: rgba(123, 45, 22, 0.07);
    --font-size-body-flat: 14px;
    --font-size-logo-flat: 18px;
    --font-size-header-title-flat: 15px;
    --font-size-thread-title-flat: 13px;
    --font-size-input-flat: 12px;
    --font-size-meta-flat: 11px;
}

body {
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", system-ui, sans-serif;
    font-size: var(--font-size-body-flat);
}

.shell {
    display: flex;
}

.sidebar,
.main-column,
.conversation-panel {
    background: transparent;
    backdrop-filter: none;
}

.sidebar {
    width: 280px;
    min-width: 280px;
    gap: 0;
    padding: 0;
    background: var(--sidebar-bg-flat);
    border-right: 1px solid var(--border);
}

#sidebar-header,
.sidebar-header {
    padding: 16px 14px 12px;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-header .eyebrow {
    margin: 0;
    font-size: var(--font-size-logo-flat);
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
    color: var(--accent);
}

.sidebar-header h1 {
    display: none;
}

.sidebar-section {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.label {
    font-size: var(--font-size-meta-flat);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.text-input,
.composer-input,
.header-control,
.ghost-button,
.primary-button,
.mini-button {
    border-radius: 8px;
}

.text-input {
    padding: 8px 10px;
    background: var(--input-bg-flat);
    border: 1px solid var(--border);
    font-size: var(--font-size-input-flat);
}

.subtle-link {
    font-size: var(--font-size-input-flat);
    color: var(--muted);
}

.section-heading {
    padding: 12px 14px 6px;
    margin-bottom: 0;
}

.section-heading h2 {
    font-size: var(--font-size-header-title-flat);
}

.thread-list {
    flex: 1;
    padding: 4px 8px 8px;
    gap: 4px;
}

.thread-item {
    position: relative;
    border-radius: 8px;
    padding: 8px 8px 8px 10px;
    margin: 0;
    background: transparent;
    border: 1px solid transparent;
}

.thread-item:hover {
    background: var(--hover-flat);
    transform: none;
}

.thread-select-button {
    min-height: 34px;
}

.thread-delete-button {
    width: 26px;
    height: 26px;
    border-radius: 6px;
}

.thread-item.active {
    background: var(--panel-bg-flat);
    border-color: rgba(123, 45, 22, 0.16);
}

.thread-name {
    font-size: var(--font-size-thread-title-flat);
    font-weight: 500;
}

.thread-meta {
    margin-top: 2px;
    font-size: var(--font-size-meta-flat);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px 12px;
    border-top: 0;
}

.sidebar-footer .ghost-button {
    width: 100%;
}

.settings-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 90;
    width: min(520px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    transform: translate(-50%, -50%);
}

.settings-dialog .panel-note {
    margin: 0;
}

.settings-dialog .ghost-button {
    min-width: 112px;
}

.whisper-target-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.whisper-target-label {
    color: var(--text-muted-flat);
    font-size: var(--font-size-meta-flat);
    font-weight: 600;
}

.whisper-target-select {
    width: 100%;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg-flat);
    color: var(--text);
    font-size: var(--font-size-body-flat);
}

.whisper-target-unavailable {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.main-column {
    flex: 1;
    background: var(--main-bg-flat);
}

#chat-header,
.chat-header {
    padding: 12px 16px;
    background: var(--sidebar-bg-flat);
    border-bottom: 1px solid var(--border);
}

.chat-header .eyebrow {
    display: none;
}

#threadTitle {
    font-size: var(--font-size-header-title-flat);
    font-weight: 600;
}

.thread-working-directory {
    font-size: var(--font-size-meta-flat);
}

.chat-header-actions {
    gap: 10px;
}

.header-control {
    padding: 5px 8px;
    background: var(--input-bg-flat);
}

.header-control-label {
    display: none;
}

.header-select {
    min-width: 180px;
    font-size: var(--font-size-input-flat);
}

.status-chip {
    min-height: 30px;
    padding: 0 10px;
    font-size: var(--font-size-meta-flat);
    border-radius: 999px;
}

.conversation-view {
    flex: 1;
    padding: 20px 16px;
    gap: 12px;
}

.empty-state {
    border-style: none;
    background: transparent;
    color: var(--muted);
    min-height: 140px;
    font-size: var(--font-size-body-flat);
}

.message-row {
    max-width: 900px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    margin-top: 2px;
    font-size: 14px;
    box-shadow: none;
}

.message-stack {
    gap: 4px;
    max-width: 100%;
}

.message-row.system .message-stack,
.message-row.user .message-stack {
    width: auto;
}

.message-bubble {
    width: fit-content;
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--assistant-bubble-flat);
    border: 1px solid var(--border);
    box-shadow: none;
    font-size: var(--font-size-body-flat);
    line-height: 1.6;
}

.message-row.user .message-bubble {
    background: var(--user-bubble-flat);
    border-color: rgba(123, 45, 22, 0.18);
    width: max-content;
    max-width: min(100%, 720px);
    word-break: break-word;
    white-space: normal;
}

.message-row.user .message-content {
    display: block;
    width: auto;
    max-width: 100%;
    font-size: var(--font-size-body-flat);
    line-height: 1.6;
}

.message-summary,
.message-content {
    font-size: var(--font-size-body-flat);
}

.message-row.assistant .message-content .code-block .code-language,
.message-row.assistant .message-content .code-block .copy-code-button,
.message-row.assistant .message-content .code-block pre,
.message-row.assistant .message-content .code-block code,
.message-row.assistant .message-content .code-block code * {
    font-size: 10px !important;
    line-height: 1.35;
}

.message-row.assistant .message-bubble {
    background: var(--assistant-bubble-flat);
}

.message-row.system .message-bubble {
    width: 100%;
    background: var(--system-bubble-flat);
}

.message-row.tool .message-stack {
    align-items: flex-start;
    width: auto;
    max-width: min(900px, calc(100% - 44px));
    gap: 0;
}

.message-row.tool .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
    background: rgba(123, 45, 22, 0.08);
    color: var(--accent-dark);
}

.tool-inline-card {
    width: fit-content;
    max-width: 100%;
    border: 1px solid rgba(128, 96, 54, 0.2);
    border-left: 2px solid rgba(185, 120, 36, 0.9);
    border-radius: 8px;
    background: rgba(250, 246, 239, 0.96);
    overflow: hidden;
}

.tool-inline-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-size: 11px;
    line-height: 1.35;
}

.tool-inline-summary::-webkit-details-marker {
    display: none;
}

.tool-inline-summary.static {
    cursor: default;
}

.tool-inline-main {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1 1 auto;
}

.tool-inline-label {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-dark);
}

.tool-inline-text {
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
    font-size: 11px;
}

.tool-inline-toggle {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 10px;
    line-height: 1;
}

.tool-inline-toggle::before {
    content: "▸";
}

.tool-inline-card[open] .tool-inline-toggle::before {
    content: "▾";
}

.tool-inline-body {
    display: grid;
    gap: 8px;
    padding: 6px 8px 8px;
    border-top: 1px solid rgba(128, 96, 54, 0.16);
    font-size: 11px;
}

.tool-inline-body .message-content,
.tool-inline-body pre,
.tool-inline-body .card-list,
.tool-inline-meta-block {
    font-size: 11px;
    line-height: 1.45;
}

.tool-inline-body pre {
    white-space: pre-wrap;
}

.tool-inline-body .card-list {
    padding-left: 16px;
}

.tool-inline-body .card-list li+li {
    margin-top: 4px;
}

.tool-inline-meta-block {
    color: var(--muted);
}

.message-title {
    font-size: var(--font-size-meta-flat);
    letter-spacing: 0.05em;
}

.message-meta {
    font-size: var(--font-size-meta-flat);
    line-height: 1.4;
}

.message-actions {
    gap: 6px;
}

.message-meta-copyable {
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-meta-text {
    min-width: 0;
}

.message-time {
    white-space: nowrap;
}

.message-copy-button {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: var(--font-size-meta-flat);
    line-height: 1.2;
    cursor: pointer;
    padding: 1px 5px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity .2s, background-color .2s, color .2s;
}

.message-row.assistant:hover .message-copy-button,
.message-copy-button:focus-visible {
    opacity: 1;
}

.message-copy-button:hover {
    background: rgba(123, 45, 22, 0.1);
    color: var(--text);
}

.generation-status {
    margin: 0 16px 8px;
    padding: 4px 4px 0;
    border: 0;
    background: transparent;
}

.ui-notice-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    padding: 0 16px 8px;
    min-width: 0;
}

.ui-notice {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: min(100%, 420px);
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid rgba(161, 64, 48, 0.22);
    border-radius: 12px;
    background: rgba(255, 244, 240, 0.96);
    box-shadow: 0 10px 24px rgba(97, 53, 31, 0.1);
    color: var(--text);
}

.ui-notice-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 3px 7px;
    border-radius: 999px;
    background: rgba(185, 80, 42, 0.12);
    color: var(--accent-dark);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ui-notice-text {
    min-width: 0;
    flex: 1 1 auto;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.ui-notice-dismiss {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 999px;
    padding: 0;
    background: rgba(123, 45, 22, 0.08);
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
}

.generation-indicator {
    gap: 8px;
    font-size: var(--font-size-meta-flat);
    line-height: 1.3;
}

.generation-dots {
    gap: 3px;
}

.generation-dots span {
    width: 5px;
    height: 5px;
}

.stop-button {
    padding: 5px 10px;
    font-size: var(--font-size-meta-flat);
    line-height: 1.2;
}

.composer {
    padding: 14px 16px;
    background: var(--sidebar-bg-flat);
    border-top: 1px solid var(--border);
}

.whisper-target-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.whisper-target-label {
    flex: 0 0 auto;
    color: var(--text-muted-flat);
    font-size: var(--font-size-meta-flat);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.whisper-target-select {
    min-width: 0;
    max-width: min(100%, 320px);
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg-flat);
    color: var(--text);
    font-size: var(--font-size-meta-flat);
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.composer-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    max-height: 200px;
    padding: 10px 14px;
    background: var(--input-bg-flat);
    border: 1px solid var(--border);
    font-size: var(--font-size-body-flat);
    line-height: 1.5;
}

.composer-actions {
    margin-top: 0;
}

.send-button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 10px;
}

.voice-button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 10px;
    box-shadow: none;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease, opacity .18s ease;
}

.voice-button.recording {
    background: #dc2626;
    border-color: #ef4444;
    color: #fff;
    animation: generation-pulse 1.1s infinite ease-in-out;
}

.voice-button.transcribing {
    background: rgba(105, 83, 59, 0.88);
    border-color: rgba(105, 83, 59, 0.92);
    color: #fff;
}

.voice-button-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    line-height: 1;
}

.voice-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
    display: none;
}

.voice-button .voice-icon-idle {
    display: block;
}

.voice-button.recording .voice-icon-idle,
.voice-button.transcribing .voice-icon-idle {
    display: none;
}

.voice-button.recording .voice-icon-recording {
    display: block;
}

.voice-button.transcribing .voice-icon-transcribing {
    display: block;
}

.send-button svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.quick-prompt-control {
    position: relative;
    display: inline-flex;
    align-items: flex-end;
    flex-shrink: 0;
}

.proceed-button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 10px;
    box-shadow: none;
}

.quick-prompt-icon {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.quick-prompt-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 156px;
    max-width: min(240px, calc(100vw - 24px));
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-strong);
    box-shadow: var(--shadow);
}

.quick-prompt-item {
    width: 100%;
    min-height: 34px;
    padding: 7px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: var(--font-size-meta-flat);
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.quick-prompt-item:hover,
.quick-prompt-item:focus-visible {
    background: var(--accent-soft);
    outline: none;
}

@media (max-width: 980px) {
    .chat-header {
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }
}

@media (max-width: 720px) {
    .whisper-target-controls {
        align-items: stretch;
        flex-direction: column;
    }

    .whisper-target-select {
        max-width: 100%;
        width: 100%;
    }

    .input-row {
        align-items: stretch;
    }
}

/* -----------------------------------------------------------------
   Drawer-first sibling parity
   ----------------------------------------------------------------- */

.shell {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
}

.main-column {
    width: 100%;
    min-width: 0;
    min-height: 100dvh;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
    width: min(84vw, 280px);
    min-width: min(84vw, 280px);
    max-width: min(84vw, 280px);
    transform: translateX(calc(-100% - 24px));
    transition: transform 180ms ease, box-shadow 180ms ease;
    box-shadow: none;
}

.drawer-toggle-button,
.drawer-close-button {
    display: inline-flex;
}

.drawer-close-button {
    align-items: center;
}

.thread-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    border: 0;
    background: rgba(34, 23, 12, 0.24);
    display: none;
}

body.thread-drawer-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 28px 90px rgba(40, 25, 11, 0.24);
}

body.thread-drawer-open .thread-drawer-backdrop {
    display: block;
}

#chat-header,
.chat-header {
    align-items: center;
    justify-content: flex-start;
}

.chat-header-main {
    width: 100%;
}

.chat-header-actions,
.header-control,
.status-chip,
.subtle-chip {
    display: none !important;
}

.sidebar-actions {
    margin-left: auto;
}

.conversation-panel {
    width: 100%;
    min-height: 0;
    height: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conversation-view {
    width: 100%;
    min-height: 0;
    flex: 1;
    overflow-y: auto;
}

body.ios-safari-mobile .sidebar {
    width: min(84vw, 320px);
    min-width: min(84vw, 320px);
    max-width: min(84vw, 320px);
    padding: 0;
    gap: 0;
    border-radius: 0 24px 24px 0;
}

body.ios-safari-mobile .drawer-toggle-button,
body.ios-safari-mobile .drawer-close-button {
    display: inline-flex;
}

body.ios-safari-mobile .main-column,
body.ios-safari-mobile .conversation-panel {
    width: 100%;
}

/* -----------------------------------------------------------------
   Fixed chat shell parity
   ----------------------------------------------------------------- */

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    min-height: 100dvh;
}

.shell,
#main,
.main-column,
.workspace-grid,
.conversation-panel {
    min-height: 0;
}

.shell,
#main,
.main-column {
    height: 100dvh;
    overflow: hidden;
}

#main,
.main-column,
.conversation-panel {
    display: flex;
    flex-direction: column;
}

.conversation-panel {
    flex: 1 1 auto;
    height: 100%;
    overflow: hidden;
}

#chat-header,
.chat-header,
.generation-status,
.composer {
    flex: 0 0 auto;
}

.conversation-view {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 1100px) {

    body,
    .shell,
    #main,
    .main-column,
    .workspace-grid,
    .conversation-panel {
        height: 100dvh;
        overflow: hidden;
    }

    .workspace-grid,
    .main-column,
    .conversation-panel,
    .side-panel {
        min-height: 0;
    }
}

@media (min-width: 981px) {
    .shell {
        display: flex;
    }

    .sidebar {
        position: relative;
        top: auto;
        left: auto;
        bottom: auto;
        z-index: auto;
        width: 280px;
        min-width: 280px;
        max-width: 280px;
        transform: none;
        transition: none;
        box-shadow: none;
    }

    body.thread-drawer-open .sidebar {
        transform: none;
        box-shadow: none;
    }

    .thread-drawer-backdrop,
    body.thread-drawer-open .thread-drawer-backdrop {
        display: none !important;
    }

    .drawer-toggle-button,
    .drawer-close-button {
        display: none !important;
    }
}
