/* GeminiChat — тёмная тема, вёрстка от телефона. */

:root {
    --bg: #0f1115;
    --bg-raised: #171a21;
    --bg-input: #1d212a;
    --border: #262b36;
    --text: #e6e8ee;
    --text-dim: #9aa2b1;
    --accent: #6ea8fe;
    --accent-strong: #4b8ef7;
    --user-bubble: #29405f;
    --danger: #ff7b72;
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.55;
    -webkit-text-size-adjust: 100%;
}

#app, .app-root { height: 100%; }

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

/* --- загрузка до старта WebAssembly ------------------------------------- */
.boot {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
}

.boot-dots, .thinking { display: flex; gap: 6px; }

.boot-dots span, .thinking span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: pulse 1.2s infinite ease-in-out;
}

.boot-dots span:nth-child(2), .thinking span:nth-child(2) { animation-delay: .2s; }
.boot-dots span:nth-child(3), .thinking span:nth-child(3) { animation-delay: .4s; }

@keyframes pulse {
    0%, 80%, 100% { opacity: .25; transform: scale(.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* --- вход ---------------------------------------------------------------- */
.login-screen {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-hint { margin: -.75rem 0 .25rem; color: var(--text-dim); font-size: .9rem; }
.login-card label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--text-dim); }
.login-error { margin: 0; color: var(--danger); font-size: .9rem; }

input, textarea, select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .7rem .85rem;
    outline: none;
}

input:focus, textarea:focus, select:focus { border-color: var(--accent); }

button {
    background: var(--accent-strong);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: .7rem 1rem;
    cursor: pointer;
    min-height: 44px;
}

button:disabled { opacity: .45; cursor: default; }

button.ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

button.ghost:hover { color: var(--text); border-color: var(--accent); }

/* --- каркас чата --------------------------------------------------------- */
.chat { display: flex; height: 100%; }

.sidebar {
    width: 264px;
    flex: 0 0 264px;
    background: var(--bg-raised);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-head, .sidebar-foot { padding: .75rem; }
.sidebar-head button { width: 100%; }

.sidebar-foot {
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding-bottom: calc(.75rem + var(--safe-bottom));
}

.who { color: var(--text-dim); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; }

.conversations { flex: 1; overflow-y: auto; padding: 0 .5rem; }

.conversation {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .65rem;
    border-radius: var(--radius);
    color: var(--text-dim);
    text-decoration: none;
    font-size: .9rem;
}

.conversation:hover { background: var(--bg-input); color: var(--text); }
.conversation.active { background: var(--bg-input); color: var(--text); }

.conversation-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.conversation .delete {
    background: none;
    color: var(--text-dim);
    padding: 0 .3rem;
    min-height: auto;
    opacity: 0;
    font-size: 1.1rem;
}

.conversation:hover .delete, .conversation.active .delete { opacity: 1; }
.conversation .delete:hover { color: var(--danger); }

.conversation-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .6rem .85rem;
    border-bottom: 1px solid var(--border);
}

.burger { display: none; padding: .4rem .7rem; }

.model-picker { flex: 1; max-width: 320px; padding: .45rem .6rem; }

/* --- лента --------------------------------------------------------------- */
.feed {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scroll-behavior: smooth;
}

.empty-state { color: var(--text-dim); text-align: center; margin: 2rem auto; font-size: .95rem; }

.message { max-width: 780px; width: 100%; margin: 0 auto; }
.message-user { display: flex; justify-content: flex-end; }

.message-user .bubble {
    background: var(--user-bubble);
    padding: .65rem .9rem;
    border-radius: 16px 16px 4px 16px;
    max-width: 85%;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.thinking { padding: .5rem 0; }

.message-error { color: var(--danger); font-size: .9rem; }
.usage { color: var(--text-dim); font-size: .75rem; margin: .35rem 0 0; }

.tools { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }

.tool {
    font-size: .75rem;
    padding: .2rem .55rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.tool-running { border-color: var(--accent); color: var(--accent); }
.tool-failed { border-color: var(--danger); color: var(--danger); }

.thoughts { margin-bottom: .6rem; color: var(--text-dim); font-size: .9rem; }
.thoughts summary { cursor: pointer; }

/* --- разметка ответа ----------------------------------------------------- */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: .6rem 0; overflow-wrap: anywhere; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1.2rem 0 .6rem; line-height: 1.3; }
.markdown h1 { font-size: 1.35rem; }
.markdown h2 { font-size: 1.2rem; }
.markdown h3 { font-size: 1.05rem; }
.markdown ul, .markdown ol { padding-left: 1.3rem; }
.markdown li { margin: .25rem 0; }
.markdown a { color: var(--accent); }
.markdown img { max-width: 100%; border-radius: var(--radius); }

.markdown blockquote {
    margin: .8rem 0;
    padding: .3rem 0 .3rem .9rem;
    border-left: 3px solid var(--border);
    color: var(--text-dim);
}

.markdown code {
    background: var(--bg-input);
    padding: .12em .4em;
    border-radius: 5px;
    font-size: .88em;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.markdown pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem;
    overflow-x: auto;
}

.markdown pre code { background: none; padding: 0; font-size: .85rem; line-height: 1.5; }

/* Широкая таблица прокручивается сама, а не растягивает страницу. */
.markdown table {
    display: block;
    overflow-x: auto;
    width: max-content;
    max-width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    margin: .8rem 0;
}

.markdown th, .markdown td {
    border: 1px solid var(--border);
    padding: .45rem .7rem;
    text-align: left;
    vertical-align: top;
}

.markdown th { background: var(--bg-input); }

/* --- поле ввода ---------------------------------------------------------- */
.composer {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    padding: .75rem;
    padding-bottom: calc(.75rem + var(--safe-bottom));
    border-top: 1px solid var(--border);
}

.composer textarea {
    flex: 1;
    resize: none;
    max-height: 30vh;
    min-height: 44px;
    field-sizing: content;
}

.composer button { width: 44px; padding: 0; font-size: 1.1rem; }
.composer button.stop { background: var(--danger); }

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    background: #4a1f1f;
    padding: .8rem 1rem;
    z-index: 100;
}

#blazor-error-ui .dismiss { float: right; cursor: pointer; }

/* --- телефон ------------------------------------------------------------- */
@media (max-width: 720px) {
    .burger { display: block; }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, .5);
    }

    .chat.sidebar-open .sidebar { transform: none; }

    .conversation .delete { opacity: 1; }
    .feed { padding: .85rem; gap: 1rem; }
    .message-user .bubble { max-width: 90%; }
}
