:root {
    color-scheme: light;
    --page: #f7f8fb;
    --surface: #ffffff;
    --soft: #f1f3f8;
    --line: #e4e7ee;
    --text: #252936;
    --muted: #7d8493;
    --accent: #7768df;
    --accent-soft: #eeebff;
    --danger: #bf4960;
    --success: #3f8062;
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body { width: 100%; min-height: 100%; margin: 0; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    background: radial-gradient(circle at 50% -18%, rgba(119, 104, 223, .075), transparent 35%), var(--page);
    color: var(--text);
}

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

button,
a { color: inherit; }

button:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible,
input:focus-visible { outline: 2px solid #8a7bea; outline-offset: 3px; }

[hidden] { display: none !important; }

.app-shell { display: grid; width: 100%; height: 100vh; height: 100dvh; }

.chat-app {
    position: relative;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto auto auto;
    width: min(980px, 100%);
    height: 100%;
    margin: auto;
    overflow: hidden;
}

.floating-actions {
    position: absolute;
    z-index: 6;
    top: 18px;
    right: 22px;
    display: flex;
    gap: 8px;
}

.round-button {
    display: grid;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(255, 255, 255, .88);
    box-shadow: 0 5px 18px rgba(42, 48, 69, .06);
    color: #747985;
    text-decoration: none;
    place-items: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: 150ms ease;
}

.round-button:hover { border-color: #d4d0f4; background: #fff; color: var(--accent); }
.new-chat { font-size: 22px; font-weight: 300; }

.conversation {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 72px clamp(20px, 7vw, 82px) 28px;
    scroll-behavior: smooth;
    scrollbar-color: #d9dce5 transparent;
    scrollbar-width: thin;
}

.conversation::-webkit-scrollbar { width: 5px; }
.conversation::-webkit-scrollbar-thumb { border-radius: 10px; background: #d9dce5; }

.welcome {
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: center;
    min-height: 100%;
    padding: 20px 0 78px;
    text-align: center;
}

.welcome-mark { display: grid; width: 52px; height: 52px; margin-bottom: 17px; place-items: center; }
.gemini-mark {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 34px;
    border-radius: 58% 42% 58% 42%;
    background: linear-gradient(145deg, #5eb9ed 6%, #8574ef 50%, #c273d8 94%);
    box-shadow: 0 8px 24px rgba(116, 100, 220, .18);
    transform: rotate(45deg) scale(.72);
}

.gemini-mark::after {
    position: absolute;
    inset: 9px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .42);
    filter: blur(4px);
    content: "";
}

.welcome h1 { margin: 0; color: #323641; font-size: clamp(27px, 4vw, 38px); font-weight: 570; letter-spacing: -.045em; }

.handoff-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: min(760px, 100%);
    margin: 0 auto 22px;
    padding: 12px 14px;
    border: 1px solid #ead8ae;
    border-radius: 14px;
    background: #fffaf0;
    color: #6f5927;
    font-size: 12px;
}

.handoff-banner div { display: flex; flex-direction: column; gap: 3px; }
.handoff-banner strong { font-size: 13px; }
.handoff-banner button { flex: 0 0 auto; border: 0; background: transparent; color: #78601f; font-size: 11px; font-weight: 650; cursor: pointer; }

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: min(760px, 100%);
    margin: 0 auto 25px;
    animation: message-in 180ms ease-out both;
}

.message.user { flex-direction: row-reverse; }
.avatar {
    position: relative;
    display: grid;
    width: 29px;
    height: 29px;
    flex: 0 0 auto;
    margin-top: 2px;
    border-radius: 9px;
    background: var(--surface);
    box-shadow: 0 2px 9px rgba(45, 50, 70, .08);
    place-items: center;
}

.message.model .avatar::before {
    width: 14px;
    height: 14px;
    border-radius: 58% 42% 58% 42%;
    background: linear-gradient(145deg, #5ab9ee, #8874ec 55%, #ca75d7);
    content: "";
    transform: rotate(45deg) scale(.72);
}

.message.user .avatar { background: #8980d8; }
.message.user .avatar::before { color: white; content: "Я"; font-size: 10px; font-weight: 650; }
.message-column { min-width: 0; max-width: calc(100% - 41px); }
.message.user .message-column { display: flex; align-items: flex-end; flex-direction: column; }

.bubble {
    padding: 6px 9px;
    color: #353a46;
    font-size: 15px;
    line-height: 1.68;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.message.user .bubble { padding: 11px 15px; border-radius: 16px 5px 16px 16px; background: var(--accent-soft); color: #3f3a65; }
.message-attachments { display: grid; grid-template-columns: repeat(2, minmax(0, 220px)); gap: 7px; margin-bottom: 7px; }
.message.user .message-attachments { justify-content: end; }
.message-attachments img { display: block; width: 100%; max-height: 260px; border: 1px solid var(--line); border-radius: 13px; object-fit: cover; background: var(--soft); }
.message-attachments audio { width: min(330px, 72vw); height: 38px; }
.message-state { margin: 5px 8px 0; color: var(--danger); font-size: 10px; }
.message-state:empty { display: none; }
.message-state button { padding: 0; border: 0; background: transparent; color: var(--danger); font-size: inherit; font-weight: 650; cursor: pointer; }

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    width: min(760px, calc(100% - 40px));
    min-height: 22px;
    margin: 0 auto 3px;
}

.typing-indicator span { width: 5px; height: 5px; border-radius: 50%; background: #9488e4; animation: typing 1.15s infinite ease-in-out; }
.typing-indicator span:nth-child(2) { animation-delay: .14s; }
.typing-indicator span:nth-child(3) { animation-delay: .28s; }

.error-banner {
    width: min(790px, calc(100% - 32px));
    margin: 0 auto 9px;
    padding: 9px 12px;
    border: 1px solid #f2d4da;
    border-radius: 10px;
    background: #fff5f7;
    color: var(--danger);
    font-size: 12px;
    line-height: 1.45;
}

.debug-panel { position: absolute; z-index: 5; left: 20px; bottom: 116px; max-width: min(330px, calc(100% - 40px)); }
.debug-panel > summary {
    width: 34px;
    padding: 6px 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, .9);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    list-style: none;
    cursor: pointer;
    box-shadow: 0 5px 16px rgba(42, 48, 69, .05);
}

.debug-panel > summary::-webkit-details-marker { display: none; }
.debug-panel[open] > summary { margin-bottom: 6px; color: var(--accent); }
.debug-content { padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 255, 255, .97); box-shadow: 0 10px 30px rgba(42, 48, 69, .12); font-size: 11px; }
.ai-switch { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; }
.debug-content dl { display: grid; gap: 6px; margin: 0; }
.debug-content dl div { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 8px; }
.debug-content dt { color: var(--muted); }
.debug-content dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.composer-wrap { padding: 10px clamp(14px, 6vw, 64px) max(18px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--page) 78%, rgba(247, 248, 251, 0)); }
.composer,
.attachments-preview { width: min(820px, 100%); margin: 0 auto; }
.attachments-preview { display: flex; gap: 7px; margin-bottom: 8px; overflow-x: auto; padding: 1px; }
.attachment-preview { display: flex; align-items: center; gap: 8px; min-width: 190px; max-width: 245px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, .95); }
.attachment-thumb { display: grid; width: 34px; height: 34px; flex: 0 0 auto; border-radius: 8px; background: #efedf9 center/cover; place-items: center; }
.attachment-thumb.audio::before { width: 9px; height: 14px; border: 1.5px solid #8478d8; border-radius: 7px; content: ""; }
.attachment-info { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 2px; }
.attachment-info strong,
.attachment-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-info strong { font-size: 11px; font-weight: 620; }
.attachment-info span { color: var(--muted); font-size: 9px; }
.attachment-preview > button { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 17px; cursor: pointer; }
.attachment-preview > button:hover { background: var(--soft); color: var(--text); }

.composer { padding: 12px 12px 9px; border: 1px solid #dfe2ea; border-radius: 19px; background: rgba(255, 255, 255, .97); box-shadow: 0 10px 34px rgba(43, 49, 68, .08); transition: 150ms ease; }
.composer:focus-within { border-color: #c7c0ef; box-shadow: 0 12px 38px rgba(65, 57, 124, .1), 0 0 0 3px rgba(120, 104, 232, .055); }
.composer textarea { display: block; width: 100%; max-height: 150px; min-height: 31px; resize: none; overflow-y: auto; padding: 4px 5px 9px; border: 0; outline: none; background: transparent; color: var(--text); font-size: 15px; line-height: 1.5; }
.composer textarea::placeholder { color: #9da3b0; }
.composer-actions,
.media-actions { display: flex; align-items: center; }
.composer-actions { justify-content: space-between; gap: 10px; }
.media-actions { min-width: 0; gap: 4px; }
.action-button { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #858b98; cursor: pointer; transition: 140ms ease; }
.action-button:hover { background: var(--soft); color: #6054b7; }
.action-button.recording { width: auto; padding: 0 10px; background: #fff0f3; color: #c75469; }
.photo-icon { position: relative; width: 16px; height: 13px; border: 1.5px solid currentColor; border-radius: 4px; }
.photo-icon::before { position: absolute; top: 2px; right: 2px; width: 3px; height: 3px; border-radius: 50%; background: currentColor; content: ""; }
.photo-icon::after { position: absolute; right: 2px; bottom: 2px; left: 2px; height: 5px; border-top: 1.4px solid currentColor; content: ""; transform: skewY(-25deg); }
.mic-icon { position: relative; width: 10px; height: 15px; border: 1.5px solid currentColor; border-radius: 8px; }
.mic-icon::before { position: absolute; right: -4px; bottom: -4px; left: -4px; height: 8px; border: 1.5px solid currentColor; border-top: 0; border-radius: 0 0 9px 9px; content: ""; }
.record-time { margin-left: 8px; font-size: 11px; font-variant-numeric: tabular-nums; }
.model-control { min-width: 0; }
.model-control select { width: min(190px, 28vw); padding: 7px 25px 7px 9px; border: 0; border-radius: 9px; outline: 0; background: var(--soft); color: #666d7c; font-size: 11px; text-overflow: ellipsis; cursor: pointer; }
.send-button { display: grid; width: 35px; height: 35px; flex: 0 0 auto; border: 0; border-radius: 11px; background: #7f70dc; box-shadow: 0 6px 16px rgba(93, 78, 186, .2); color: white; place-items: center; cursor: pointer; transition: 140ms ease; }
.send-button span { font-size: 19px; line-height: 1; transform: translateY(-1px); }
.send-button:hover:not(:disabled) { background: #7161d2; transform: translateY(-1px); }
.send-button:disabled { background: #e8e9ee; box-shadow: none; color: #a8acb7; cursor: not-allowed; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Settings */
.settings-page { overflow: auto; }
.settings-shell { width: min(820px, calc(100% - 32px)); margin: 0 auto; padding: 42px 0 70px; }
.back-link { display: inline-block; margin-bottom: 34px; color: var(--muted); font-size: 13px; text-decoration: none; }
.back-link:hover { color: var(--accent); }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.settings-heading h1 { margin: 0 0 8px; font-size: clamp(28px, 5vw, 40px); font-weight: 620; letter-spacing: -.04em; }
.settings-heading p { max-width: 560px; margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.secondary-button,
.primary-button { border-radius: 11px; font-weight: 620; cursor: pointer; }
.secondary-button { padding: 9px 12px; border: 1px solid var(--line); background: var(--surface); color: #656b79; font-size: 12px; }
.primary-button { margin-top: 20px; padding: 11px 18px; border: 0; background: var(--accent); color: white; font-size: 13px; }
.settings-notice { margin-bottom: 16px; padding: 11px 13px; border-radius: 11px; font-size: 12px; }
.settings-notice.success { border: 1px solid #cce4d7; background: #f1faf5; color: var(--success); }
.settings-notice.error { border: 1px solid #f0d2d8; background: #fff5f7; color: var(--danger); }
.models-list { display: grid; gap: 10px; }
.model-card { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 17px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255, 255, 255, .88); }
.model-enabled { display: flex; align-items: flex-start; min-width: 0; flex: 1; gap: 12px; cursor: pointer; }
.model-enabled > input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-mark { position: relative; width: 34px; height: 20px; flex: 0 0 auto; margin-top: 1px; border-radius: 20px; background: #dfe2e9; transition: 150ms ease; }
.toggle-mark::after { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgba(0, 0, 0, .14); content: ""; transition: 150ms ease; }
.model-enabled input:checked + .toggle-mark { background: #8375df; }
.model-enabled input:checked + .toggle-mark::after { transform: translateX(14px); }
.model-copy { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.model-copy strong { font-size: 15px; }
.model-copy small { max-width: 560px; margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.model-capabilities { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.capability { display: inline-flex; align-items: center; gap: 5px; padding: 4px 7px 4px 5px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; color: #69707e; font-size: 10px; font-weight: 590; }
.capability-icon { display: grid; min-width: 19px; height: 19px; padding: 0 3px; border-radius: 6px; background: #ece9ff; color: #6556bd; font-size: 9px; font-weight: 750; place-items: center; }
.capability-state { color: var(--success); font-weight: 800; }
.capability.unsupported { background: #f7f7f8; color: #969ba6; }
.capability.unsupported .capability-icon { background: #eceef1; color: #9499a3; }
.capability.unsupported .capability-state { color: #a8adb6; }
.model-pricing { display: flex; max-width: 620px; flex-direction: column; gap: 5px; margin-top: 9px; padding: 10px 11px; border-radius: 11px; background: #f5f6f9; color: #656c7a; font-size: 10px; line-height: 1.45; }
.pricing-title { color: #7a808c; font-size: 9px; font-weight: 700; letter-spacing: .045em; text-transform: uppercase; }
.pricing-row { display: flex; flex-wrap: wrap; gap: 7px 15px; color: #5c6371; }
.pricing-row b { color: #343945; font-size: 11px; }
.price-example { display: flex; flex-direction: column; gap: 2px; color: #554a92; font-weight: 650; }
.example-details { color: #777184; font-size: 9px; font-weight: 500; font-variant-numeric: tabular-nums; }
.pricing-note { color: #8b7380; font-size: 9px; line-height: 1.4; }
.default-choice { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; color: #777d8b; font-size: 11px; cursor: pointer; }
.default-choice input { accent-color: var(--accent); }

@keyframes message-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes typing { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 700px) {
    .floating-actions { top: 14px; right: 14px; }
    .conversation { padding: 62px 13px 18px; }
    .welcome { padding-bottom: 48px; }
    .message { gap: 8px; margin-bottom: 20px; }
    .avatar { width: 27px; height: 27px; }
    .message-column { max-width: calc(100% - 35px); }
    .bubble { padding: 5px 7px; font-size: 14px; }
    .message.user .bubble { padding: 10px 13px; }
    .composer-wrap { padding: 8px 9px max(10px, env(safe-area-inset-bottom)); }
    .composer { padding: 10px 9px 7px; border-radius: 16px; }
    .model-control select { width: min(154px, 39vw); }
    .debug-panel { left: 9px; bottom: 104px; }
    .message-attachments { grid-template-columns: repeat(2, minmax(0, 150px)); }
    .settings-shell { padding-top: 24px; }
    .settings-heading { flex-direction: column; }
    .model-card { align-items: flex-start; flex-direction: column; }
    .default-choice { margin-left: 46px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
