@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #040510;
    --card: rgba(6, 9, 25, 0.75);
    --panel: rgba(13, 17, 37, 0.65);
    --accent: #7ae6ff;
    --accent-strong: #9b6df7;
    --text: #ffffff;
    --muted: #b5bad8;
    --border: rgba(255, 255, 255, 0.15);
    --glass: rgba(255, 255, 255, 0.08);
    --gradient: linear-gradient(120deg, #2f4ab3 0%, #1f9ee3 35%, #9b6df7 65%, #f582c6 100%);
    --page-padding: clamp(12px, 2vw, 24px);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    padding: var(--page-padding);
    position: relative;
    overflow-x: hidden;
    color-scheme: dark;
}

.neon-grid {
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 25% 25%, rgba(102, 214, 255, 0.12), transparent 45%),
        radial-gradient(circle at 75% 0%, rgba(244, 114, 182, 0.15), transparent 40%),
        linear-gradient(120deg, rgba(139, 92, 246, 0.08), transparent);
    z-index: 0;
    pointer-events: none;
    animation: pulse-bg 12s ease-in-out infinite;
}

@keyframes pulse-bg {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

.page {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    width: min(1200px, calc(100% - 2 * var(--page-padding)));
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: clamp(18px, 2vw, 28px);
    overflow: visible;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    backdrop-filter: blur(20px);
    box-shadow: 0 25px 60px rgba(5, 8, 24, 0.6);
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--gradient);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(102, 214, 255, 0.4);
}

.brand-icon .pulse {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    opacity: 0.8;
    animation: orb 2.2s ease-in-out infinite;
}

@keyframes orb {
    0%, 100% { transform: scale(0.85); opacity: 0.5; }
    50% { transform: scale(1); opacity: 1; }
}

.brand-label {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.brand-tagline {
    font-size: 13px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.cta {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 12px 22px;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 14px;
}

.cta:hover {
    border-color: rgba(255, 255, 255, 0.4);
    color: var(--accent);
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    gap: clamp(16px, 2vw, 24px);
    min-height: 0;
    width: 100%;
    overflow: visible;
    position: relative;
}

.insight-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    backdrop-filter: blur(20px);
    box-shadow: 0 30px 80px rgba(5, 8, 24, 0.6);
    min-height: 0;
    overflow: visible !important;
    position: relative;
    z-index: 5;
    contain: none;
    clip-path: none;
}

.model-selector {
    contain: none;
    position: relative;
    z-index: 20;
}

.badge {
    display: inline-flex;
    padding: 6px 16px;
    border-radius: 999px;
    border: 1px solid rgba(122, 230, 255, 0.4);
    font-size: 12px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--accent);
}

.insight-panel h1 {
    font-size: clamp(22px, 2.5vw, 32px);
    line-height: 1.2;
}

.intro {
    color: var(--muted);
    line-height: 1.6;
    font-size: 16px;
}

.pill-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.pill-list li {
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--glass);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
    text-shadow: 0 0 8px rgba(122, 230, 255, 0.2);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
}

.stat-card {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-card span {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
}

.stat-card p {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.model-selector {
    margin-top: 8px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(9, 12, 30, 0.8);
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    z-index: 20;
    overflow: visible;
}

.selector-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--muted);
}

.tag {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(102, 214, 255, 0.15);
    color: var(--accent);
}

.select-wrapper {
    position: relative;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    overflow: visible;
    /* Улучшение для Chromium браузеров */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.select-wrapper:hover {
    border-color: rgba(122, 230, 255, 0.4);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 12px rgba(122, 230, 255, 0.1);
}

.select-wrapper.custom-dropdown.open {
    border-color: rgba(122, 230, 255, 0.5);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 4px 16px rgba(122, 230, 255, 0.15);
}

.select-wrapper.custom-dropdown.open .custom-select-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: all;
    /* Важно: убеждаемся что dropdown поверх всех элементов */
    position: absolute !important;
}

/* Изменяем направление анимации chevron - стрелка указывает вниз когда открыт (на ПК открывается вверх) */
.select-wrapper.custom-dropdown.open .custom-select-trigger .chevron {
    transform: translateY(-50%) rotate(0deg);
    transform-origin: center center;
}

/* Кастомный триггер */
.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    padding-right: 44px;
    cursor: pointer;
    user-select: none;
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    border-radius: 14px;
    transition: all 0.2s ease;
    min-height: 48px;
    box-sizing: border-box;
    position: relative;
}

.custom-select-trigger:hover {
    background: rgba(255, 255, 255, 0.02);
}

.custom-select-value {
    flex: 1;
}

.custom-select-trigger .chevron {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    transform-origin: center center;
    pointer-events: none;
}

/* Кастомный выпадающий список - открывается вверх */
.custom-select-dropdown {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(6, 9, 25, 0.98);
    border: 1px solid rgba(122, 230, 255, 0.3);
    border-radius: 14px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(122, 230, 255, 0.1);
    overflow: hidden;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    max-height: 400px;
    overflow-y: auto;
    /* Важно: создаем новый контекст стекирования */
    isolation: isolate;
}

/* Скроллбар для кастомного dropdown */
.custom-select-dropdown::-webkit-scrollbar {
    width: 8px;
}

.custom-select-dropdown::-webkit-scrollbar-track {
    background: rgba(6, 9, 25, 0.5);
    border-radius: 4px;
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
    background: rgba(122, 230, 255, 0.3);
    border-radius: 4px;
}

.custom-select-dropdown::-webkit-scrollbar-thumb:hover {
    background: rgba(122, 230, 255, 0.5);
}

/* Опции в кастомном dropdown */
.custom-select-option {
    padding: 12px 16px;
    cursor: pointer;
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}

.custom-select-option:last-child {
    border-bottom: none;
}

.custom-select-option:hover:not(.selected) {
    background: rgba(122, 230, 255, 0.15) !important;
    color: var(--accent) !important;
    padding-left: 20px;
}

.custom-select-option.selected {
    background: linear-gradient(120deg, rgba(122, 230, 255, 0.25) 0%, rgba(139, 92, 246, 0.25) 100%) !important;
    color: var(--accent) !important;
    font-weight: 600;
    border-left: 3px solid var(--accent);
    padding-left: 16px !important;
}

.custom-select-option.selected:hover {
    background: linear-gradient(120deg, rgba(122, 230, 255, 0.35) 0%, rgba(139, 92, 246, 0.35) 100%) !important;
    padding-left: 16px !important;
}

/* Auth overlay */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 5, 16, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    padding: 16px;
    transition: opacity 0.3s ease;
}

.auth-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.auth-modal {
    width: min(420px, 100%);
    background: rgba(9, 12, 30, 0.95);
    border: 1px solid rgba(122, 230, 255, 0.25);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 18px;
    color: var(--text);
}

.auth-title {
    font-size: 20px;
    margin: 0;
}

.auth-subtitle {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: var(--muted);
    margin: 0;
}

.auth-description {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
    font-size: 14px;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-field label {
    font-size: 13px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

.auth-field input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
}

.auth-field input:focus {
    outline: none;
    border-color: rgba(122, 230, 255, 0.5);
}

.auth-submit {
    border: none;
    border-radius: 14px;
    padding: 14px;
    background: var(--gradient);
    color: #040510;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.auth-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(139, 92, 246, 0.35);
}

.auth-access {
    border: 1px solid rgba(122, 230, 255, 0.4);
    background: transparent;
    color: var(--accent);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    font-weight: 500;
}

.auth-error {
    color: #ff7a7a;
    min-height: 18px;
    font-size: 13px;
    margin: 0;
}

body.auth-locked {
    overflow: hidden;
}

body.auth-locked .page {
    filter: blur(6px);
    pointer-events: none;
    user-select: none;
}

.select-wrapper select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 15px;
    padding: 14px 40px 14px 16px;
    font-family: inherit;
    cursor: pointer;
    font-weight: 500;
    outline: none;
    color-scheme: dark;
    border-radius: 14px;
}

.select-wrapper select:focus {
    outline: none;
}

.select-wrapper select:active {
    outline: none;
}

.select-wrapper select:focus-visible {
    outline: none;
}

/* Стилизация опций в выпадающем списке */
.select-wrapper select option {
    background: rgba(6, 9, 25, 0.98) !important;
    background-color: rgba(6, 9, 25, 0.98) !important;
    color: var(--text) !important;
    padding: 12px 16px;
    border: none;
    font-size: 15px;
    font-weight: 500;
    border-radius: 10px;
    margin: 3px 6px;
}

/* Первая и последняя опции с дополнительным скруглением */
.select-wrapper select option:first-child {
    border-radius: 10px 10px 6px 6px;
}

.select-wrapper select option:last-child {
    border-radius: 6px 6px 10px 10px;
}

/* Выделенная опция при наведении/выборе - всегда должна быть хорошо видна */
.select-wrapper select option:checked,
.select-wrapper select option:checked:hover {
    background: linear-gradient(120deg, rgba(122, 230, 255, 0.4) 0%, rgba(139, 92, 246, 0.4) 100%) !important;
    background-color: rgba(122, 230, 255, 0.35) !important;
    color: var(--accent) !important;
    font-weight: 600;
    opacity: 1 !important;
}

.select-wrapper select option:focus {
    background: linear-gradient(120deg, rgba(122, 230, 255, 0.4) 0%, rgba(139, 92, 246, 0.4) 100%) !important;
    background-color: rgba(122, 230, 255, 0.35) !important;
    color: var(--accent) !important;
    font-weight: 600;
}

/* Обычные опции при наведении */
.select-wrapper select option:hover:not(:checked) {
    background: rgba(122, 230, 255, 0.15) !important;
    background-color: rgba(122, 230, 255, 0.15) !important;
}

/* Дополнительные стили для лучшей поддержки */
.select-wrapper select optgroup {
    background: rgba(6, 9, 25, 0.98);
    color: var(--text);
}

/* Для Firefox */
@-moz-document url-prefix() {
    .select-wrapper select option {
        background-color: rgba(6, 9, 25, 0.98);
    }
    
    .select-wrapper select option:checked,
    .select-wrapper select option:checked:hover {
        background-color: rgba(122, 230, 255, 0.4) !important;
        color: var(--accent) !important;
        opacity: 1 !important;
        font-weight: 600;
    }
}

/* Для WebKit (Chrome, Safari, Edge) - улучшенная стилизация */
@supports (-webkit-appearance: none) {
    .select-wrapper select {
        -webkit-appearance: none;
        appearance: none;
        background-image: none;
    }
    
    .select-wrapper select::-webkit-scrollbar {
        width: 8px;
    }

    .select-wrapper select::-webkit-scrollbar-track {
        background: rgba(6, 9, 25, 0.5);
        border-radius: 4px;
    }

    .select-wrapper select::-webkit-scrollbar-thumb {
        background: rgba(122, 230, 255, 0.3);
        border-radius: 4px;
    }

    .select-wrapper select::-webkit-scrollbar-thumb:hover {
        background: rgba(122, 230, 255, 0.5);
    }
    
    /* Дополнительные стили для опций в Chromium */
    .select-wrapper select option {
        background-color: rgba(6, 9, 25, 0.98) !important;
        color: var(--text) !important;
        padding: 12px 16px;
        font-size: 15px;
        font-weight: 500;
    }
    
    /* Выделенная опция в Chromium */
    .select-wrapper select option:checked {
        background-color: rgba(122, 230, 255, 0.4) !important;
        background: linear-gradient(120deg, rgba(122, 230, 255, 0.4) 0%, rgba(139, 92, 246, 0.4) 100%) !important;
        color: var(--accent) !important;
        font-weight: 600;
    }
    
    /* Стили для самого dropdown меню в Chromium */
    .select-wrapper select {
        background-color: rgba(255, 255, 255, 0.04);
    }
    
    .select-wrapper select:focus {
        background-color: rgba(255, 255, 255, 0.06);
    }
}

/* Дополнительные стили для Chromium браузеров */
.select-wrapper select {
    background-color: rgba(255, 255, 255, 0.04);
    -webkit-background-clip: padding-box;
    background-clip: padding-box;
}

/* Улучшение внешнего вида для Chromium */
@supports selector(:has(*)) {
    .select-wrapper:has(select:focus) {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(122, 230, 255, 0.5);
    }
}

.select-wrapper .chevron {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%) rotate(180deg);
    pointer-events: none;
    color: var(--accent);
    opacity: 0.8;
    transition: transform 0.3s ease;
}

.select-wrapper.select-open .chevron {
    transform: translateY(-50%) rotate(0deg);
}

.helper {
    font-size: 13px;
    color: var(--muted);
}

.chat-panel {
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(18px);
    padding: 20px;
    display: flex;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    flex: 1;
    overflow: visible;
    position: relative;
    z-index: 1;
}

.chat-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 16px;
    height: clamp(500px, 70vh, 720px);
    max-height: clamp(500px, 70vh, 720px);
    flex: none;
}

.chat-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.clear-chat-btn {
    border: 1px solid rgba(122, 230, 255, 0.3);
    background: rgba(122, 230, 255, 0.1);
    color: var(--accent);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    line-height: 1;
}

.clear-chat-btn:hover {
    background: rgba(122, 230, 255, 0.2);
    border-color: rgba(122, 230, 255, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(122, 230, 255, 0.2);
}

.clear-chat-btn:active {
    transform: translateY(0);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.3em;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.chat-header h2 {
    font-size: 20px;
}

.model-chip {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid rgba(122, 230, 255, 0.3);
    background: rgba(122, 230, 255, 0.1);
    font-size: 13px;
    color: var(--accent);
    text-shadow: 0 0 8px rgba(122, 230, 255, 0.3);
}

.chat-feed {
    flex: 1;
    min-height: 0;
    background: rgba(4, 6, 18, 0.85);
    border-radius: 24px;
    border: 1px solid var(--border);
    padding: 28px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* Firefox scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(122, 230, 255, 0.5) rgba(4, 6, 18, 0.5);
}

/* Chromium/Safari scrollbar */
.chat-feed::-webkit-scrollbar {
    width: 10px;
}

.chat-feed::-webkit-scrollbar-track {
    background: rgba(4, 6, 18, 0.5);
    border-radius: 10px;
}

.chat-feed::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    border-radius: 10px;
    border: 2px solid rgba(4, 6, 18, 0.85);
}

.chat-feed::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(122, 230, 255, 1), rgba(155, 109, 247, 1));
}

.chat-feed::-webkit-scrollbar-corner {
    background: transparent;
}

.welcome-card {
    padding: 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.welcome-card h3 {
    font-size: 18px;
}

.welcome-card p {
    color: var(--muted);
    line-height: 1.5;
}

.prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.prompts button {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    transition: border-color 0.2s ease;
}

.prompts button:hover {
    border-color: rgba(255, 255, 255, 0.4);
}

.input-bar {
    display: flex;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    resize: none;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    max-height: 180px;
}

#messageInput::placeholder {
    color: rgba(255, 255, 255, 0.45);
}

#messageInput:focus {
    outline: none;
}

#sendButton {
    border: none;
    border-radius: 16px;
    background: var(--gradient);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0a0d1f;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#sendButton:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 12px 25px rgba(139, 92, 246, 0.35);
}

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

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-content {
    max-width: 75%;
    padding: 16px 20px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.15);
    text-shadow: 0 0 4px rgba(122, 230, 255, 0.1);
}

.message.user .message-content {
    background: var(--gradient);
    color: #0a0d1f;
    border-color: transparent;
}

.message.assistant .message-content {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text);
}

.message-content pre {
    background: #0d0f1f;
    border-radius: 14px;
    margin: 16px 0;
}

.message-content pre code {
    display: block;
    padding: 18px;
    overflow-x: auto;
}

.message-content :not(pre) > code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 13px;
}

.code-block {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    overflow: hidden;
    margin: 16px 0;
    background: #050711;
}

.code-header {
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.code-language {
    color: var(--accent);
    font-size: 13px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.copy-button {
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
}

.copy-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.copy-button.copied {
    background: rgba(20, 184, 166, 0.35);
}

.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 14px 20px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

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

body::-webkit-scrollbar {
    width: 8px;
}

body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999px;
}

/* Планшеты и небольшие экраны */
@media (max-width: 1080px) {
    body {
        padding: 20px;
    }
    
    .page {
        max-width: 100%;
        gap: 20px;
    }
    
    .layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .insight-panel {
        padding: 24px;
    }
    
    .chat-shell {
        height: clamp(400px, 65vh, 600px);
        max-height: clamp(400px, 65vh, 600px);
        flex: none;
    }

    .chat-feed {
        min-height: 0;
        padding: 20px;
    }
    
    .stat-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

/* Мобильные устройства */
@media (max-width: 768px) {
    body {
        padding: 12px;
    }
    
    .page {
        gap: 16px;
        width: 100%;
        max-width: 100%;
    }
    
    .layout {
        width: 100%;
        max-width: 100%;
    }
    
    .top-bar {
        padding: 12px 16px;
        flex-direction: row;
        align-items: center;
        gap: 12px;
    }
    
    .brand-icon {
        width: 40px;
        height: 40px;
    }
    
    .brand-label {
        font-size: 16px;
    }
    
    .brand-tagline {
        font-size: 11px;
    }
    
    .cta {
        padding: 10px 18px;
        font-size: 13px;
        white-space: nowrap;
    }
    
    .insight-panel {
        padding: 20px;
        gap: 16px;
        overflow: visible !important;
        z-index: 5 !important;
    }
    
    .insight-panel h1 {
        font-size: clamp(20px, 5vw, 26px);
    }
    
    .intro {
        font-size: 14px;
    }
    
    .stat-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .stat-card {
        padding: 14px;
    }
    
    .stat-card span {
        font-size: 22px;
    }
    
    .model-selector {
        padding: 14px;
    }
    
    .select-wrapper {
        border-radius: 12px;
    }
    
    .custom-select-trigger {
        padding: 12px 14px;
        padding-right: 38px;
        font-size: 14px;
        min-height: 40px;
    }
    
    .custom-select-dropdown {
        max-height: 300px;
        border-radius: 12px;
        /* Открывается вниз на мобильных */
        bottom: auto;
        top: calc(100% + 8px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(122, 230, 255, 0.1);
        transform: translateY(-10px);
        position: absolute !important;
        z-index: 99999 !important;
    }
    
    .select-wrapper.custom-dropdown.open .custom-select-dropdown {
        transform: translateY(0);
        position: absolute !important;
        z-index: 99999 !important;
    }
    
    .model-selector {
        overflow: visible !important;
        z-index: 30 !important;
    }
    
    .insight-panel {
        overflow: visible !important;
    }
    
    /* Chevron указывает вниз на мобильных */
    .custom-select-trigger .chevron {
        position: absolute;
        right: 14px;
        top: 50%;
        transform: translateY(-50%) rotate(0deg);
    }
    
    .select-wrapper.custom-dropdown.open .custom-select-trigger .chevron {
        transform: translateY(-50%) rotate(180deg);
    }
    
    .custom-select-option {
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .chat-panel {
        padding: 16px;
        border-radius: 20px;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .chat-shell {
        height: clamp(350px, 60vh, 500px);
        max-height: clamp(350px, 60vh, 500px);
        flex: none;
        gap: 12px;
    }
    
    .chat-header {
        gap: 6px;
        width: 100%;
    }
    
    .chat-header-main {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
    }
    
    .chat-header h2 {
        font-size: 18px;
        margin: 0;
        flex: 1;
        min-width: 0;
    }
    
    .chat-header-actions {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }
    
    .model-chip {
        padding: 6px 12px;
        font-size: 12px;
        white-space: nowrap;
    }
    
    .clear-chat-btn {
        padding: 6px 10px;
        flex-shrink: 0;
    }
    
    .chat-feed {
        padding: 16px;
        border-radius: 18px;
        gap: 16px;
    }
    
    .welcome-card {
        padding: 16px;
    }
    
    .welcome-card h3 {
        font-size: 16px;
    }
    
    .prompts {
        gap: 8px;
    }
    
    .prompts button {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .input-bar {
        padding: 12px 14px;
        gap: 10px;
        border-radius: 16px;
    }
    
    #messageInput {
        font-size: 14px;
        max-height: 120px;
    }
    
    #sendButton {
        padding: 12px 16px;
        border-radius: 12px;
    }
    
    .message-content {
        max-width: 85%;
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* Маленькие мобильные устройства */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }
    
    .page {
        gap: 12px;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .insight-panel,
    .chat-panel {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .top-bar {
        padding: 10px 12px;
        border-radius: 14px;
    }
    
    .brand {
        gap: 10px;
    }
    
    .brand-icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }
    
    .brand-label {
        font-size: 15px;
    }
    
    .brand-tagline {
        font-size: 10px;
    }
    
    .cta {
        padding: 8px 14px;
        font-size: 12px;
    }
    
    .insight-panel {
        padding: 16px;
        border-radius: 18px;
        gap: 12px;
    }
    
    .insight-panel h1 {
        font-size: 20px;
        line-height: 1.3;
    }
    
    .badge {
        padding: 5px 12px;
        font-size: 11px;
    }
    
    .intro {
        font-size: 13px;
        line-height: 1.5;
    }
    
    .pill-list {
        gap: 8px;
    }
    
    .pill-list li {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-card span {
        font-size: 20px;
    }
    
    .stat-card p {
        font-size: 12px;
    }
    
    .model-selector {
        padding: 12px;
        border-radius: 14px;
    }
    
    .selector-head {
        font-size: 11px;
    }
    
    .tag {
        padding: 3px 8px;
        font-size: 10px;
    }
    
    .select-wrapper {
        border-radius: 10px;
    }
    
    .custom-select-trigger {
        padding: 10px 12px;
        padding-right: 36px;
        font-size: 13px;
        min-height: 40px;
    }
    
    .custom-select-trigger .chevron {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%) rotate(0deg);
        margin-left: 0;
    }
    
    .select-wrapper.custom-dropdown.open .custom-select-trigger .chevron {
        transform: translateY(-50%) rotate(180deg);
    }
    
    .custom-select-dropdown {
        max-height: 250px;
        border-radius: 10px;
        /* Открывается вниз на маленьких мобильных */
        bottom: auto;
        top: calc(100% + 6px);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(122, 230, 255, 0.1);
        transform: translateY(-10px);
        position: absolute !important;
        z-index: 99999 !important;
    }
    
    .select-wrapper.custom-dropdown.open .custom-select-dropdown {
        transform: translateY(0);
        position: absolute !important;
        z-index: 99999 !important;
    }
    
    .model-selector {
        overflow: visible !important;
        z-index: 30 !important;
    }
    
    .insight-panel {
        overflow: visible !important;
    }
    
    /* Chevron указывает вниз на маленьких мобильных */
    .custom-select-trigger .chevron {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%) rotate(0deg);
    }
    
    .select-wrapper.custom-dropdown.open .custom-select-trigger .chevron {
        transform: translateY(-50%) rotate(180deg);
    }
    
    .custom-select-option {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .helper {
        font-size: 12px;
    }
    
    .page {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    
    .layout {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .insight-panel {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .chat-panel {
        padding: 12px;
        border-radius: 18px;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    
    .chat-shell {
        height: clamp(300px, 55vh, 450px);
        max-height: clamp(300px, 55vh, 450px);
        flex: none;
        gap: 10px;
    }
    
    .chat-header {
        gap: 4px;
    }
    
    .chat-header-main {
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }
    
    .eyebrow {
        font-size: 11px;
        margin-bottom: 2px;
    }
    
    .chat-header h2 {
        font-size: 16px;
        margin: 0;
        flex: 1;
        min-width: 0;
    }
    
    .chat-header-actions {
        gap: 6px;
        flex-wrap: wrap;
    }
    
    .model-chip {
        padding: 5px 10px;
        font-size: 11px;
        white-space: nowrap;
    }
    
    .clear-chat-btn {
        padding: 5px 8px;
        flex-shrink: 0;
    }
    
    .clear-chat-btn svg {
        width: 16px;
        height: 16px;
    }
    
    .chat-feed {
        padding: 12px;
        border-radius: 14px;
        gap: 12px;
    }
    
    .welcome-card {
        padding: 14px;
        border-radius: 14px;
    }
    
    .welcome-card h3 {
        font-size: 15px;
    }
    
    .welcome-card p {
        font-size: 13px;
    }
    
    .prompts {
        gap: 6px;
        flex-direction: column;
    }
    
    .prompts button {
        width: 100%;
        padding: 10px 12px;
        font-size: 12px;
        text-align: center;
    }
    
    .input-bar {
        padding: 10px 12px;
        gap: 8px;
        border-radius: 14px;
        flex-direction: row;
    }
    
    #messageInput {
        font-size: 13px;
        max-height: 100px;
    }
    
    #sendButton {
        padding: 10px 14px;
        border-radius: 10px;
        flex-shrink: 0;
    }
    
    #sendButton svg {
        width: 20px;
        height: 20px;
    }
    
    .message {
        gap: 8px;
    }
    
    .message-content {
        max-width: 90%;
        padding: 10px 14px;
        font-size: 13px;
        border-radius: 14px;
    }
    
    .message-content pre {
        border-radius: 10px;
        margin: 12px 0;
    }
    
    .message-content pre code {
        padding: 12px;
        font-size: 12px;
    }
    
    .code-block {
        border-radius: 12px;
        margin: 12px 0;
    }
    
    .code-header {
        padding: 8px 12px;
    }
    
    .code-language {
        font-size: 11px;
    }
    
    .copy-button {
        padding: 5px 10px;
        font-size: 11px;
    }
    
    .typing-indicator {
        padding: 10px 14px;
    }
}

/* ============ Header Actions ============ */

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}

.token-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(122, 230, 255, 0.1);
    border: 1px solid rgba(122, 230, 255, 0.2);
    border-radius: 999px;
    font-size: 12px;
    color: var(--accent);
}

.token-badge svg {
    opacity: 0.7;
}

.admin-btn,
.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
}

.admin-btn:hover {
    border-color: var(--accent-strong);
    color: var(--accent-strong);
    background: rgba(139, 92, 246, 0.1);
}

.logout-btn:hover {
    border-color: #ff7a7a;
    color: #ff7a7a;
    background: rgba(255, 122, 122, 0.1);
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ============ Quota Modal ============ */

.quota-modal {
    text-align: center;
}

.pulse-warning {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b6b, #ff4757);
    opacity: 0.9;
    animation: pulse-warning 1.5s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% { transform: scale(0.9); opacity: 0.7; }
    50% { transform: scale(1.1); opacity: 1; }
}

.quota-info {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    margin: 16px 0;
}

.quota-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.quota-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}

.quota-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
}

.quota-contact {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 10px;
    background: rgba(0, 136, 204, 0.15);
    border-color: rgba(0, 136, 204, 0.4);
    color: #00aaff;
}

.quota-contact:hover {
    background: rgba(0, 136, 204, 0.25);
}

/* ============ Service Modal (503) ============ */

.service-modal {
    text-align: center;
}

.pulse-service {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    opacity: 0.9;
    animation: pulse-service 2s ease-in-out infinite;
}

@keyframes pulse-service {
    0%, 100% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 1; }
}

.service-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 16px;
    margin: 20px 0;
}

.service-icon {
    color: #f59e0b;
    opacity: 0.9;
}

.service-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.service-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
}

.service-time {
    font-size: 24px;
    font-weight: 600;
    color: #f59e0b;
}

/* ============ Responsive Header ============ */

@media (max-width: 768px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px 16px;
    }

    .top-bar .brand {
        justify-content: center;
    }

    .header-actions {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .user-info {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 12px;
        width: 100%;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        border: 1px solid var(--border);
    }

    .user-name {
        font-size: 14px;
        color: var(--text);
        font-weight: 500;
    }

    .token-badge {
        padding: 6px 14px;
        font-size: 14px;
        background: rgba(122, 230, 255, 0.15);
    }

    .header-buttons {
        display: flex;
        gap: 10px;
        width: 100%;
    }

    .header-buttons .admin-btn,
    .header-buttons .logout-btn {
        flex: 1;
        justify-content: center;
        padding: 12px 14px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .top-bar {
        padding: 12px;
        border-radius: 14px;
    }

    .brand-icon {
        width: 36px;
        height: 36px;
    }

    .brand-label {
        font-size: 15px;
    }

    .brand-tagline {
        font-size: 10px;
    }

    .header-actions {
        gap: 8px;
    }

    .user-info {
        flex-direction: row;
        gap: 10px;
        padding: 10px 14px;
    }

    .user-name {
        font-size: 13px;
    }

    .token-badge {
        padding: 6px 12px;
        font-size: 13px;
    }

    .header-buttons {
        gap: 8px;
    }

    .header-buttons .admin-btn,
    .header-buttons .logout-btn {
        padding: 10px 12px;
        font-size: 12px;
    }

    .quota-info {
        flex-direction: column;
        gap: 16px;
    }
}