:root {
    --bg-color: #ece7dc;
    --surface-color: #fcfaf5;
    --surface-elevated: #f3ede2;
    --text-color: #171717;
    --text-muted: #696255;
    --border-color: #d9cfbe;
    --accent-color: #1f6feb;
    --accent-hover: #175fca;
    --accent-soft: rgba(31, 111, 235, 0.14);
    --user-bg: #1f6feb;
    --user-text: #eef4ff;
    --assistant-bg: #f4eee3;
    --assistant-text: #171717;
    --system-bg: #f5ead2;
    --system-text: #8b5a18;
    --error-bg: #fde8e8;
    --error-text: #991b1b;
    --input-bg: #fffdf9;
    --shadow: 0 24px 48px rgba(54, 43, 21, 0.10);
    --radius: 22px;
    --radius-sm: 14px;
    --font-size-base: 16px;
    --line-height: 1.6;
    --spacing: 16px;
    --app-max-width: 1500px;

    --sidebar-bg: #171715;
    --sidebar-surface: #21211f;
    --sidebar-text: #f6f1e8;
    --sidebar-muted: #9c968a;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-hover: #262623;
    --sidebar-active: #2d2d29;
}

body.dark {
    --bg-color: #121212;
    --surface-color: #171717;
    --surface-elevated: #1d1d1b;
    --text-color: #f4efe7;
    --text-muted: #9f988b;
    --border-color: #2c2c28;
    --accent-color: #2d8cff;
    --accent-hover: #1f6feb;
    --accent-soft: rgba(45, 140, 255, 0.18);
    --user-bg: #2d8cff;
    --user-text: #f7fbff;
    --assistant-bg: #1d1d1b;
    --assistant-text: #f4efe7;
    --system-bg: #332510;
    --system-text: #f0bf68;
    --error-bg: #3a1515;
    --error-text: #ffcccc;
    --input-bg: #1d1d1b;
    --shadow: 0 32px 80px rgba(0, 0, 0, 0.32);

    --sidebar-bg: #171715;
    --sidebar-surface: #21211f;
    --sidebar-text: #f6f1e8;
    --sidebar-muted: #9c968a;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-hover: #262623;
    --sidebar-active: #30302c;
}

body.light {
    --bg-color: #ece7dc;
    --surface-color: #fcfaf5;
    --surface-elevated: #f3ede2;
    --text-color: #171717;
    --text-muted: #696255;
    --border-color: #d9cfbe;
    --accent-color: #1f6feb;
    --accent-hover: #175fca;
    --accent-soft: rgba(31, 111, 235, 0.12);
    --user-bg: #1f6feb;
    --user-text: #eef4ff;
    --assistant-bg: #f4eee3;
    --assistant-text: #171717;
    --system-bg: #f5ead2;
    --system-text: #8b5a18;
    --error-bg: #fde8e8;
    --error-text: #991b1b;
    --input-bg: #fffdf9;
    --shadow: 0 24px 48px rgba(54, 43, 21, 0.10);

    --sidebar-bg: #f5efe4;
    --sidebar-surface: #fbf7f0;
    --sidebar-text: #1f1b16;
    --sidebar-muted: #756c5d;
    --sidebar-border: rgba(121, 103, 72, 0.16);
    --sidebar-hover: #efe7da;
    --sidebar-active: #e8decd;
}

* {
    box-sizing: border-box;
}

html {
    font-size: var(--font-size-base);
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(45, 140, 255, 0.08), transparent 28%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.02)),
        var(--bg-color);
    color: var(--text-color);
    line-height: var(--line-height);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.light {
    background:
        radial-gradient(circle at top left, rgba(31, 111, 235, 0.08), transparent 26%),
        radial-gradient(circle at bottom right, rgba(201, 166, 92, 0.10), transparent 24%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.08)),
        var(--bg-color);
}

:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

button, input, textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

/* App layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
    max-width: var(--app-max-width);
    margin: 0 auto;
    padding: 10px;
    gap: 0;
}

/* Sidebar */
.sidebar {
    width: 264px;
    min-width: 264px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border: 1px solid var(--sidebar-border);
    border-radius: 22px 0 0 22px;
    display: flex;
    flex-direction: column;
    z-index: 50;
    box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.02);
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    padding: 14px;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 14px;
}

.sidebar-section-heading h2 {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--sidebar-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sidebar-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-brand {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at top right, rgba(112, 82, 29, 0.26), transparent 40%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
        #1d1c19;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.06),
        0 14px 28px rgba(0, 0, 0, 0.18);
}

.sidebar-brand::after {
    content: "";
    position: absolute;
    inset: auto -18px -24px auto;
    width: 84px;
    height: 84px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(255, 219, 160, 0.12), transparent 68%);
    pointer-events: none;
}

.sidebar-brand-mark-wrap {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, #fff8ef, #ede2cf);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.54),
        0 10px 24px rgba(0, 0, 0, 0.22);
}

.sidebar-brand-mark {
    width: 30px;
    height: 30px;
    display: block;
}

.sidebar-brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: relative;
    z-index: 1;
}

.sidebar-brand-kicker {
    margin: 0;
    font-size: 0.68rem;
    line-height: 1.2;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(246, 241, 232, 0.62);
}

.sidebar-brand-name {
    display: block;
    font-size: 1.1rem;
    line-height: 1.1;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-bubble-primary {
    fill: #1f1a15;
}

.brand-bubble-secondary {
    fill: #ccbda4;
}

.brand-dot {
    fill: #f7f0e5;
}

.brand-dot-soft {
    fill: #44392d;
}

.sidebar-utility-btn,
#menu-toggle-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--sidebar-border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--sidebar-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-utility-btn:hover,
#menu-toggle-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    border-color: rgba(255, 255, 255, 0.14);
}

#archive-toggle-btn.active {
    background: var(--accent-soft);
    color: var(--accent-color);
    border-color: transparent;
}

.sidebar-primary-btn {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--sidebar-border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--sidebar-text);
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    font-weight: 600;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.sidebar-primary-btn span:last-child {
    min-width: 0;
    white-space: nowrap;
}

.sidebar-primary-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.14);
}

.sidebar-primary-btn:active {
    transform: translateY(1px);
}

.sidebar-primary-btn-icon {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}

.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 10px 24px;
    border-radius: 14px;
    cursor: pointer;
    margin-bottom: 6px;
    transition: background 0.12s, border-color 0.12s;
    gap: 10px;
    min-height: 46px;
    color: var(--sidebar-text);
    border: 1px solid transparent;
    position: relative;
}

.conversation-item::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.conversation-item:hover {
    background: var(--sidebar-hover);
    border-color: rgba(255, 255, 255, 0.06);
}

.conversation-item.active {
    background: var(--sidebar-active);
    border-color: rgba(255, 255, 255, 0.08);
}

.conversation-item.active::before {
    background: var(--accent-color);
}

.conversation-item.active .conversation-title {
    color: var(--sidebar-text);
    font-weight: 600;
}

.conversation-title {
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    color: var(--sidebar-text);
}

.conversation-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.12s;
    margin-left: auto;
}

.conversation-item:hover .conversation-actions,
.conversation-item.active .conversation-actions,
.conversation-item:focus-within .conversation-actions {
    opacity: 1;
}

.icon-btn {
    border: none;
    background: transparent;
    color: var(--sidebar-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    min-width: 32px;
    min-height: 32px;
    transition: background 0.12s, color 0.12s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--sidebar-text);
}

.icon-btn.delete-conv:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.15);
}

.icon-btn.rename-conv:hover {
    color: var(--accent-color);
}

.icon-btn.archive-conv:hover,
.icon-btn.unarchive-conv:hover {
    color: #fbbf24;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
}

.user-bar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 36px;
    align-items: center;
    column-gap: 12px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.02)),
        var(--sidebar-surface);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 10px 12px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.04),
        0 10px 24px rgba(0, 0, 0, 0.18);
}

.user-initials {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff8ef, #ece3d4);
    color: #121212;
    font-size: 0.9rem;
    font-weight: 800;
    flex-shrink: 0;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        0 6px 16px rgba(0, 0, 0, 0.14);
}

.user-meta {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#logout-btn {
    width: 36px;
    height: 36px;
    justify-self: end;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--sidebar-muted);
}

#logout-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
}

.lang-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    flex-wrap: wrap;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.18);
    color: var(--sidebar-muted);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.05s, color 0.12s, box-shadow 0.12s;
    padding: 0 10px;
}

.lang-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
}

.lang-btn.active {
    border-color: var(--accent-color);
    background: rgba(31, 111, 235, 0.18);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.lang-btn:active {
    transform: scale(0.95);
}

/* Chat container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    flex: 1;
    background: var(--bg-color);
    overflow: hidden;
    padding-left: 0;
}

.chat-frame {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-left: -1px;
    border: 1px solid var(--border-color);
    border-radius: 0 22px 22px 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0.005)), var(--surface-color);
    box-shadow: var(--shadow);
    overflow: hidden;
}

body.light .chat-frame {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(249, 244, 235, 0.92)),
        var(--surface-color);
    box-shadow:
        0 22px 46px rgba(80, 66, 37, 0.10),
        inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

body.light .sidebar {
    box-shadow:
        inset -1px 0 0 rgba(121, 103, 72, 0.05),
        0 18px 36px rgba(80, 66, 37, 0.06);
}

body.light .sidebar-brand-mark-wrap,
body.light .user-initials {
    background: linear-gradient(180deg, #2a241d, #171411);
    color: #f7f0e5;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 8px 18px rgba(80, 66, 37, 0.12);
}

body.light .sidebar-brand {
    background:
        radial-gradient(circle at top right, rgba(201, 166, 92, 0.24), transparent 42%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 236, 220, 0.94));
    border-color: rgba(121, 103, 72, 0.14);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.72),
        0 14px 30px rgba(80, 66, 37, 0.10);
}

body.light .sidebar-brand-kicker {
    color: rgba(81, 68, 54, 0.62);
}

body.light .sidebar-brand-name {
    color: #201b15;
}

body.light .brand-bubble-primary {
    fill: #1f1b16;
}

body.light .brand-bubble-secondary {
    fill: #ccbda4;
}

body.light .brand-dot {
    fill: #f7f0e5;
}

body.light .brand-dot-soft {
    fill: #514436;
}

body.light .sidebar-utility-btn,
body.light #menu-toggle-btn {
    background: rgba(121, 103, 72, 0.04);
    color: var(--sidebar-muted);
    border-color: rgba(121, 103, 72, 0.12);
}

body.light .sidebar-utility-btn:hover,
body.light #menu-toggle-btn:hover {
    background: #efe7da;
    color: var(--sidebar-text);
    border-color: rgba(121, 103, 72, 0.18);
}

body.light .sidebar-primary-btn {
    background: rgba(255, 255, 255, 0.68);
    border-color: rgba(121, 103, 72, 0.12);
}

body.light .sidebar-primary-btn:hover {
    background: #fffaf2;
    border-color: rgba(121, 103, 72, 0.18);
}

body.light .sidebar-primary-btn-icon {
    background: rgba(121, 103, 72, 0.08);
}

body.light .conversation-item::before {
    background: rgba(121, 103, 72, 0.28);
}

body.light .icon-btn:hover {
    background: rgba(121, 103, 72, 0.08);
    color: var(--sidebar-text);
}

body.light .user-bar {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 239, 228, 0.92)),
        var(--sidebar-surface);
    border-color: rgba(121, 103, 72, 0.12);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.82),
        0 10px 20px rgba(80, 66, 37, 0.06);
}

body.light #logout-btn {
    background: rgba(121, 103, 72, 0.04);
    border-color: rgba(121, 103, 72, 0.10);
}

body.light #logout-btn:hover {
    background: rgba(121, 103, 72, 0.10);
}

body.light .lang-btn {
    background: rgba(121, 103, 72, 0.06);
    color: var(--sidebar-muted);
    border-color: rgba(121, 103, 72, 0.08);
}

body.light .lang-btn:hover {
    background: rgba(121, 103, 72, 0.12);
    color: var(--sidebar-text);
}

body.light .lang-btn.active {
    background: rgba(31, 111, 235, 0.10);
    color: var(--accent-color);
    border-color: rgba(31, 111, 235, 0.55);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 28px 18px;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    min-height: 92px;
}

body.light .chat-header {
    border-bottom-color: rgba(185, 169, 140, 0.52);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.chat-title-block {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.chat-kicker {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-header h1 {
    margin: 0;
    font-size: 1.85rem;
    line-height: 1.1;
    font-weight: 500;
    font-family: Georgia, "Times New Roman", serif;
    word-break: break-word;
}

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

.active-conversation-title {
    max-width: min(34vw, 420px);
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 0.82rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.light .active-conversation-title {
    background: rgba(255, 255, 255, 0.72);
}

#model-display,
#system-badge,
#theme-toggle {
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    font-weight: 500;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
}

#model-display {
    cursor: default;
}

#system-badge {
    display: none;
    background: var(--system-bg);
    border-color: var(--system-text);
    color: var(--system-text);
}

#system-badge.active {
    display: inline-flex;
}

#theme-toggle {
    font-size: 1rem;
    width: 34px;
    padding: 0;
    justify-content: center;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 26px 28px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: transparent;
}

body.light .messages {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 24%);
}

.message {
    max-width: min(860px, 88%);
    padding: 16px 18px;
    border-radius: 20px;
    line-height: var(--line-height);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.98rem;
    box-shadow: none;
}

.message.new {
    animation: fadeIn 0.15s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: 8px;
}

.message.user.editable-message {
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.14s ease, outline-color 0.14s ease;
}

.message.user.editable-message:hover {
    transform: translateY(-1px);
}

.message.user.edit-target {
    outline: 2px solid rgba(255, 255, 255, 0.34);
    outline-offset: 3px;
}

body.light .message.user.edit-target {
    outline-color: rgba(105, 77, 29, 0.34);
}

.message.assistant {
    align-self: flex-start;
    background: var(--assistant-bg);
    color: var(--assistant-text);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 8px;
}

body.light .message.assistant {
    box-shadow: 0 10px 24px rgba(66, 54, 30, 0.05);
}

.message.system-info {
    align-self: center;
    background: var(--system-bg);
    color: var(--system-text);
    font-size: 0.9rem;
    padding: 10px 18px;
    border-radius: 20px;
    box-shadow: none;
}

.message.error {
    align-self: center;
    background: var(--error-bg);
    color: var(--error-text);
    border-radius: 12px;
}

.thinking {
    color: var(--text-muted);
    font-style: italic;
}

/* Markdown v assistant sporočilih */
.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin: 16px 0 10px;
    font-size: 1.1em;
    color: var(--text-color);
}

.message.assistant p {
    margin: 0 0 12px;
}

.message.assistant p:last-child {
    margin-bottom: 0;
}

.message.assistant ul,
.message.assistant ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message.assistant li {
    margin-bottom: 6px;
}

.message.assistant code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    background: rgba(0, 0, 0, 0.06);
    padding: 3px 6px;
    border-radius: 6px;
    font-size: 0.92em;
}

body.dark .message.assistant code {
    background: rgba(255, 255, 255, 0.1);
}

.message.assistant pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 12px 0;
}

body.dark .message.assistant pre {
    background: rgba(255, 255, 255, 0.1);
}

.message.assistant pre code {
    background: transparent;
    padding: 0;
}

.message.assistant blockquote {
    margin: 12px 0;
    padding-left: 16px;
    border-left: 4px solid var(--border-color);
    color: var(--text-muted);
}

.message.assistant a {
    color: var(--accent-color);
    text-decoration: underline;
    font-weight: 500;
}

.message.assistant table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
    font-size: 0.95rem;
}

.message.assistant th,
.message.assistant td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message.assistant th {
    background: var(--bg-color);
    font-weight: 600;
}

/* Input area */
.input-area {
    padding: 12px 28px 14px;
    background: transparent;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 22px;
    padding: 12px 14px 12px 16px;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

body.light .input-wrapper {
    border-color: #d6c8b1;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        0 8px 20px rgba(66, 54, 30, 0.04);
}

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

#message-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-color);
    font-size: 1rem;
    line-height: var(--line-height);
    resize: none;
    min-height: 28px;
    max-height: 160px;
    overflow-y: auto;
    font-family: inherit;
    padding: 6px 4px;
}

#send-btn {
    border: none;
    background: var(--accent-color);
    color: #fff;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}

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

#send-btn:active {
    transform: scale(0.95);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hint {
    text-align: left;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 10px;
    margin-bottom: 0;
    padding-left: 8px;
}

body.light .hint,
body.light .status-bar {
    color: #736a5c;
}

/* Status bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 28px 22px;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: transparent;
    min-height: 36px;
}

.status-bar .left,
.status-bar .right {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

#token-count,
#cost-count {
    font-weight: 500;
}

#clear-chat {
    background: var(--surface-elevated);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 6px 10px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

#clear-chat:hover {
    color: var(--accent-color);
    background: var(--accent-soft);
}

body.light #clear-chat {
    background: rgba(243, 237, 226, 0.75);
}

.empty-state {
    align-self: center;
    color: var(--text-muted);
    margin-top: auto;
    margin-bottom: auto;
    text-align: center;
    padding: 36px 24px;
    max-width: 560px;
}

.empty-state-title {
    margin: 0 0 8px;
    font-size: 2rem;
    line-height: 1.1;
    color: var(--text-color);
    font-family: Georgia, "Times New Roman", serif;
}

.empty-state p {
    margin: 0 0 10px;
    font-size: 1rem;
}

.empty-state-help {
    font-size: 0.82rem;
}

body.light .empty-state-title {
    color: #2e261b;
}

/* Mobile menu toggle */
#menu-toggle-btn {
    display: none;
}

/* Responsive */
@media (max-width: 800px) {
    .app-layout {
        padding: 0;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        width: 85vw;
        max-width: 300px;
        min-width: auto;
        border-radius: 0 22px 22px 0;
    }

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

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
    }

    .sidebar.open + .sidebar-overlay,
    .sidebar-overlay.active {
        display: block;
    }

    #menu-toggle-btn {
        display: flex;
    }

    .chat-container {
        max-width: 100%;
        padding-left: 0;
    }

    .chat-frame {
        border-radius: 0;
        margin-left: 0;
    }

    .sidebar-brand {
        padding-right: 10px;
    }

    .chat-header {
        padding: 12px 16px;
        min-height: 72px;
    }

    .chat-header h1 {
        font-size: 1.35rem;
    }

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

    .message {
        max-width: 92%;
        padding: 14px 16px;
        font-size: 1rem;
    }

    .input-area {
        padding: 12px 14px 16px;
    }

    .status-bar {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
        padding: 10px 14px;
    }
}

@media (max-width: 500px) {
    html {
        font-size: 18px;
    }

    .header-actions {
        gap: 6px;
    }

    .active-conversation-title {
        max-width: 44vw;
        padding: 4px 10px;
        font-size: 0.75rem;
    }

    #model-display,
    #system-badge,
    #theme-toggle {
        padding: 4px 8px;
        font-size: 0.75rem;
        min-height: 30px;
    }

    #model-display {
        display: none;
    }

    #send-btn {
        width: 44px;
        height: 44px;
    }

    .icon-btn {
        min-width: 36px;
        min-height: 36px;
    }

    .conversation-actions {
        opacity: 1;
    }

    .lang-btn {
        min-width: 30px;
        height: 28px;
    }

    .sidebar-brand {
        gap: 10px;
        padding: 9px 10px;
    }

    .sidebar-brand-mark-wrap {
        width: 42px;
        height: 42px;
        flex-basis: 42px;
    }

    .sidebar-brand-name {
        font-size: 1rem;
    }

    .sidebar-brand-kicker {
        font-size: 0.64rem;
    }
}

/* Accessibility: prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast focus for accessibility */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Custom modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    backdrop-filter: blur(2px);
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.modal-title {
    margin: 0 0 10px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-color);
}

.modal-message {
    margin: 0 0 18px;
    color: var(--text-muted);
    line-height: 1.5;
}

.modal-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
    margin-bottom: 18px;
    min-height: 48px;
}

.modal-input.hidden {
    display: none;
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    min-height: 44px;
    transition: background 0.15s, transform 0.1s;
}

.modal-btn:hover {
    transform: translateY(-1px);
}

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

.modal-btn-primary:hover {
    background: var(--accent-hover);
}

.modal-btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border-color: var(--border-color);
}

.modal-btn-secondary:hover {
    background: var(--border-color);
}

.modal-btn-danger {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error-text);
}

.modal-btn-danger:hover {
    background: var(--error-text);
    color: #fff;
}

@media (max-width: 500px) {
    .modal-box {
        padding: 22px;
    }
    .modal-actions {
        flex-direction: column;
    }
    .modal-btn {
        width: 100%;
    }
}
