:root {
    color-scheme: light;
    --page: #ffffff;
    --surface: #ffffff;
    --sidebar: #f9f9f9;
    --hover: #ececec;
    --text: #0d0d0d;
    --muted: #676767;
    --line: #e5e5e5;
    --accent: #212121;
    --user: #f4f4f4;
    --danger: #c23b2a;
    --app-height: 100dvh;
    --viewport-top: 0px;
    --composer-height: 88px;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    position: fixed;
    top: var(--viewport-top);
    right: 0;
    left: 0;
    height: var(--app-height);
    margin: 0;
    overflow: hidden;
    background: var(--page);
    color: var(--text);
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
}

.auth-pending .sidebar,
.auth-pending .sidebar-backdrop,
.auth-pending .topbar,
.auth-pending .composer-wrap,
.anonymous .sidebar,
.anonymous .sidebar-backdrop,
.anonymous .topbar,
.anonymous .composer-wrap {
    display: none;
}

.auth-pending .chat {
    visibility: hidden;
}

.anonymous .chat {
    margin-left: 0;
    padding: 0 24px;
}

.anonymous .login {
    min-height: var(--app-height);
}

.sidebar {
    position: absolute;
    z-index: 4;
    top: 0;
    height: var(--app-height);
    left: 0;
    width: 260px;
    display: flex;
    flex-direction: column;
    padding: 10px 8px;
    border-right: 0;
    background: var(--sidebar);
}

.sidebar-backdrop {
    display: none;
}

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 4px 8px 10px;
}

.sidebar-heading strong {
    font-size: 14px;
    font-weight: 600;
}

.conversation-list {
    display: grid;
    align-content: start;
    flex: 1;
    gap: 2px;
    overflow-y: auto;
    min-height: 0;
}

.conversation-item {
    width: 100%;
    min-height: 36px;
    padding: 8px 10px;
    overflow: hidden;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.conversation-item:hover,
.conversation-item.active {
    background: var(--hover);
}

button,
textarea {
    font: inherit;
}

.topbar {
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    left: 260px;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    height: 56px;
    padding: 0 18px;
    border-bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
}

.icon-button,
.send {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

.icon-button {
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 22px;
    font-weight: 400;
}

.icon-button:hover {
    background: var(--hover);
}

.conversation-title {
    justify-self: center;
    max-width: min(60vw, 640px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
}

.status {
    color: var(--muted);
    font-size: 10px;
}

.status {
    min-width: 54px;
    text-align: right;
}

.account-button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: none;
    padding: 8px;
    overflow: hidden;
    border: 0;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

.account-button:hover {
    background: var(--hover);
}

.account-button img {
    flex: 0 0 auto;
    border-radius: 50%;
}

.account-button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.chat {
    height: var(--app-height);
    overflow-y: auto;
    margin-left: 260px;
    padding: 84px max(24px, calc((100% - 1028px) / 2)) calc(var(--composer-height) + 28px);
    overscroll-behavior: contain;
    scroll-padding-top: 80px;
    scroll-padding-bottom: calc(var(--composer-height) + 16px);
    scroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
}

.empty {
    display: grid;
    place-items: center;
    align-content: center;
    min-height: calc(var(--app-height) - var(--composer-height) - 84px);
    text-align: center;
}

.login {
    display: grid;
    place-items: center;
    align-content: center;
    min-height: calc(var(--app-height) - 170px);
    text-align: center;
}

.login h1 {
    margin: 18px 0 6px;
    font-size: 28px;
}

.login p {
    margin: 0 0 24px;
    color: var(--muted);
}

.google-login {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 0 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.google-login:hover {
    background: var(--hover);
}

[hidden] {
    display: none !important;
}

.empty[hidden] {
    display: none;
}

.mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin-bottom: 16px;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 18px;
}

h1 {
    margin: 0;
    font-size: clamp(24px, 5vw, 30px);
    font-weight: 600;
    letter-spacing: 0;
}

.message {
    display: flex;
    flex-direction: column;
    width: min(100%, 768px);
    margin: 0 auto 28px;
    animation: appear 180ms ease-out both;
}

.message.user {
    align-items: flex-end;
}

.message-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 0;
    margin-bottom: 7px;
}

.message-tools:empty {
    display: none;
}

.tool-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 26px;
    padding: 3px 8px;
    border: 0;
    border-radius: 8px;
    background: var(--sidebar);
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
    line-height: 1;
}

.tool-badge-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.tool-badge-count {
    color: var(--text);
    font-size: 10px;
}

.tool-badge.running .tool-badge-icon {
    animation: blink 800ms steps(1) infinite;
}

.message-content {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.65;
}

.user .message-content {
    max-width: min(85%, 620px);
    padding: 10px 16px;
    border-radius: 18px;
    background: var(--user);
    white-space: pre-wrap;
}

.assistant .message-content {
    width: 100%;
}

.assistant .message-content > :first-child {
    margin-top: 0;
}

.assistant .message-content > :last-child {
    margin-bottom: 0;
}

.assistant .message-content p,
.assistant .message-content ul,
.assistant .message-content ol,
.assistant .message-content blockquote,
.assistant .message-content pre {
    margin: 0 0 12px;
}

.assistant .message-content h1,
.assistant .message-content h2,
.assistant .message-content h3 {
    margin: 20px 0 8px;
    color: var(--text);
    font-size: 19px;
    font-weight: 500;
    line-height: 1.35;
}

.assistant .message-content h2 {
    font-size: 17px;
}

.assistant .message-content h3 {
    font-size: 15px;
}

.assistant .message-content strong,
.assistant .message-content b {
    font-weight: 500;
}

.assistant .message-content em {
    color: color-mix(in srgb, var(--text) 82%, var(--muted));
}

.assistant .message-content ul,
.assistant .message-content ol {
    padding-left: 22px;
}

.assistant .message-content li + li {
    margin-top: 3px;
}

.assistant .message-content li::marker {
    color: var(--muted);
}

.assistant .message-content code {
    padding: 2px 5px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--surface);
    font-family: "Consolas", monospace;
    font-size: 0.88em;
}

.assistant .message-content pre {
    overflow-x: auto;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f6f6f4;
    color: var(--text);
    white-space: pre;
}

.assistant .message-content pre code {
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 13px;
    line-height: 1.55;
}

.assistant .message-content blockquote {
    padding: 2px 0 2px 12px;
    border-left: 2px solid #c8c8c3;
    color: var(--muted);
}

.assistant .markdown-table {
    max-width: 100%;
    margin: 0 0 14px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.assistant .markdown-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 14px;
}

.assistant .markdown-table th,
.assistant .markdown-table td {
    min-width: 90px;
    padding: 9px 11px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.assistant .markdown-table th:last-child,
.assistant .markdown-table td:last-child {
    border-right: 0;
}

.assistant .markdown-table tbody tr:last-child td {
    border-bottom: 0;
}

.assistant .markdown-table th {
    background: var(--sidebar);
    font-weight: 500;
}

.assistant .message-content .source-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 180px;
    min-height: 18px;
    margin: 0 2px;
    padding: 1px 6px;
    border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface) 88%, var(--page));
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
    line-height: 1.35;
    text-decoration: none;
    vertical-align: middle;
    white-space: nowrap;
}

.assistant .message-content .source-pill-icon {
    display: block;
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    object-fit: contain;
}

.assistant .message-content .source-pill-link-icon,
.assistant .message-content .source-pill .lucide-link {
    display: grid;
    place-items: center;
    width: 11px;
    height: 11px;
    flex: 0 0 11px;
    color: currentColor;
    font-size: 9px;
    stroke-width: 2;
}

.assistant .message-content .source-pill {
    overflow: hidden;
    text-overflow: ellipsis;
}

.assistant .message-content .source-pill:hover,
.assistant .message-content .source-pill:focus-visible {
    border-color: #aaa9a3;
    background: #ededeb;
    color: var(--text);
    text-decoration: none;
}

.assistant .message-content a:not(.source-pill) {
    color: #2458a6;
    font-weight: 500;
    text-decoration: none;
}

.assistant .message-content a:not(.source-pill):hover,
.assistant .message-content a:not(.source-pill):focus-visible {
    color: #173f7c;
    text-decoration: none;
}

.assistant.pending .message-content::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 3px;
    background: currentColor;
    vertical-align: -2px;
    animation: blink 800ms steps(1) infinite;
}

.message.error .message-content {
    color: var(--danger);
}

.composer-wrap {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 260px;
    padding: 22px 20px 12px;
    background: linear-gradient(transparent, var(--page) 38%);
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: min(100%, 768px);
    margin: 0 auto;
    padding: 9px 10px 9px 18px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: #f7f7f7;
    box-shadow: none;
}

textarea {
    display: block;
    flex: 1;
    max-height: 180px;
    padding: 8px 0;
    resize: none;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    line-height: 1.45;
}

textarea::placeholder {
    color: #989790;
}

.send {
    flex: 0 0 auto;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-size: 20px;
}

.send:disabled {
    cursor: default;
    opacity: 0.35;
}

.send.stop span {
    width: 11px;
    height: 11px;
    background: white;
    color: transparent;
}

.composer-wrap p {
    margin: 9px 0 0;
    color: #8a8a8a;
    font-size: 10px;
    text-align: center;
}

@keyframes appear {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes blink {
    50% { opacity: 0; }
}

@media (max-width: 600px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    .ui-ready .sidebar {
        transition: transform 180ms ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: absolute;
        z-index: 3;
        inset: 0;
        display: block;
        padding: 0;
        border: 0;
        background: rgba(0, 0, 0, 0.08);
        cursor: default;
        opacity: 0;
        pointer-events: none;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .topbar {
        left: 0;
        padding: 0 14px;
    }

    .chat {
        margin-left: 0;
        padding: 86px 16px calc(var(--composer-height) + 16px);
    }

    .message {
        margin-bottom: 24px;
    }

    .user .message-content {
        max-width: 90%;
    }

    .composer-wrap {
        left: 0;
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    textarea {
        font-size: 16px;
    }

    .send {
        display: none;
    }
}

.sidebar-account {
    position: relative;
    flex: 0 0 auto;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.account-copy {
    display: grid;
    flex: 1;
    min-width: 0;
    text-align: left;
}

.account-copy strong,
.account-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-copy strong {
    font-size: 13px;
}

.account-copy small {
    color: var(--muted);
    font-size: 10px;
}

.account-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    left: 0;
    z-index: 6;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.account-menu button {
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.account-menu button:hover {
    background: var(--hover);
}

.settings-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: min(680px, calc(100dvh - 32px));
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
}

.settings-dialog::backdrop {
    background: rgba(0, 0, 0, 0.22);
}

.settings-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.settings-heading h2,
.settings-section h3 {
    margin: 0;
}

.settings-heading h2 {
    font-size: 17px;
}

.settings-section {
    padding: 18px 16px;
    overflow-y: auto;
}

.settings-section h3 {
    margin-bottom: 14px;
    font-size: 14px;
}

.allowed-user-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.allowed-user-form input {
    min-width: 0;
    height: 40px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    outline: none;
    font: inherit;
}

.allowed-user-form input:focus {
    border-color: #888;
}

.allowed-user-form button,
.allowed-user button {
    padding: 0 13px;
    border: 0;
    border-radius: 7px;
    background: var(--accent);
    color: white;
    cursor: pointer;
}

.settings-error {
    margin: 10px 0 0;
    color: var(--danger);
    font-size: 12px;
}

.allowed-users-list {
    display: grid;
    margin-top: 14px;
    border-top: 1px solid var(--line);
}

.allowed-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    border-bottom: 1px solid var(--line);
}

.allowed-user > span {
    display: grid;
    min-width: 0;
}

.allowed-user strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.allowed-user small {
    color: var(--muted);
    font-size: 10px;
}

.allowed-user button {
    min-height: 32px;
    background: transparent;
    color: var(--danger);
}