/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #212121;
    --bg-secondary: #2f2f2f;
    --bg-sidebar: #171717;
    --bg-input: #2f2f2f;
    --bg-hover: #3a3a3a;
    --bg-active: #424242;
    --bg-modal: #2f2f2f;
    --text-primary: #ececec;
    --text-secondary: #8e8ea0;
    --text-muted: #6b6b7b;
    --accent: #10a37f;
    --accent-hover: #0d8f6f;
    --accent-light: rgba(16, 163, 127, 0.15);
    --border: rgba(255,255,255,0.08);
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --sidebar-width: 260px;
    --input-max-width: 48rem;
}

html { height: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

#app { height: 100vh; display: flex; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

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

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font);
    transition: background 0.15s;
    white-space: nowrap;
}

.new-chat-btn:hover { background: var(--bg-hover); }
.new-chat-btn svg { flex-shrink: 0; }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 14px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-sessions {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-sessions::-webkit-scrollbar { width: 4px; }
.sidebar-sessions::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.session-group-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 8px 8px 4px;
}

.session-item {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
}

.session-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.session-item.active { background: var(--bg-active); color: var(--text-primary); }

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

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.user-info:hover { background: var(--bg-hover); }

.user-avatar {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.user-email {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.user-sub-badge {
    font-size: 10px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 600;
    flex-shrink: 0;
}

/* ===== MAIN CONTENT ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
    min-width: 0;
}

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-logo {
    width: 72px;
    height: 72px;
    background: var(--accent);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    box-shadow: 0 0 40px rgba(16, 163, 127, 0.3);
}

.welcome-title {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.welcome-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 440px;
    margin-bottom: 32px;
}

.welcome-examples {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 540px;
    width: 100%;
}

.example-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    text-align: left;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font);
}

.example-card:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.example-card strong {
    display: block;
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 4px;
}

/* ===== CHAT AREA ===== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.chat-area::-webkit-scrollbar { width: 6px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.messages-list {
    padding: 24px 0 0;
    display: flex;
    flex-direction: column;
}

.message {
    display: flex;
    gap: 16px;
    padding: 16px 24px;
    max-width: 100%;
    animation: fadeUp 0.2s ease;
}

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

.message.assistant { background: var(--bg-secondary); }
.message.user { background: transparent; justify-content: flex-end; }

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.message.user .message-avatar { background: #5a5a8a; order: 2; }
.message.assistant .message-avatar { background: var(--accent); }

.message-content {
    flex: 1;
    max-width: var(--input-max-width);
    min-width: 0;
}

.message.user .message-content {
    background: var(--bg-secondary);
    border-radius: 18px 18px 4px 18px;
    padding: 12px 16px;
    max-width: 75%;
    flex: none;
}

.message-text {
    line-height: 1.7;
    color: var(--text-primary);
    font-size: 15px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Markdown-подобное форматирование */
.message-text strong, .message-text b { font-weight: 600; }
.message-text em, .message-text i { font-style: italic; }
.message-text code {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Menlo', 'Monaco', monospace;
    font-size: 13px;
}
.message-text pre {
    background: #1a1a2e;
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--border);
}
.message-text pre code { background: none; padding: 0; }
.message-text ul, .message-text ol { padding-left: 24px; margin: 8px 0; }
.message-text li { margin: 4px 0; }
.message-text p { margin: 0 0 8px; }
.message-text p:last-child { margin-bottom: 0; }
.message-text h1, .message-text h2, .message-text h3 { margin: 12px 0 6px; font-weight: 600; }

/* Курсор при стриминге */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--text-primary);
    margin-left: 2px;
    animation: blink 0.8s steps(1) infinite;
    vertical-align: text-bottom;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ===== INPUT AREA ===== */
.input-area {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
}

.input-wrapper {
    max-width: var(--input-max-width);
    margin: 0 auto;
    position: relative;
}

.input-box {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 56px 14px 18px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
    resize: none;
    min-height: 52px;
    max-height: 200px;
    overflow-y: auto;
    transition: border-color 0.15s;
    line-height: 1.6;
}

.input-box:focus { border-color: var(--accent); }
.input-box::placeholder { color: var(--text-muted); }
.input-box::-webkit-scrollbar { width: 4px; }
.input-box::-webkit-scrollbar-thumb { background: var(--border); }

.send-btn {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
    flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-footer {
    text-align: center;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.free-counter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-light);
    border: 1px solid rgba(16, 163, 127, 0.3);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    margin-bottom: 8px;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

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

.modal {
    background: var(--bg-modal);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
    line-height: 1.5;
}

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    color: var(--text-primary);
    font-size: 15px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 4px;
    display: none;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: background 0.15s, opacity 0.15s;
    margin-top: 8px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font);
    font-size: 14px;
    transition: all 0.15s;
}

.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}
.modal-switch a:hover { text-decoration: underline; }

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ===== PAYMENT MODAL ===== */
.payment-modal { max-width: 520px; }

.plan-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 20px 0;
}

.plan-card {
    background: var(--bg-primary);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    position: relative;
}

.plan-card:hover { border-color: var(--accent); background: var(--accent-light); }
.plan-card.selected { border-color: var(--accent); background: var(--accent-light); }

.plan-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 10px;
    white-space: nowrap;
}

.plan-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.plan-price {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
}

.plan-price span { font-size: 14px; font-weight: 400; color: var(--text-secondary); }
.plan-per { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.plan-single {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    padding: 12px 16px;
}

.single-info { text-align: left; }

/* ===== TOAST ===== */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    animation: toastIn 0.2s ease;
    max-width: 360px;
}

.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== TOP BAR (mobile) ===== */
.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.hamburger {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
}

/* ===== LOADING ===== */
.typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 0;
}
.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ===== VERIFY NOTICE ===== */
.verify-notice {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 13px;
    color: var(--warning);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 24px 0;
}

.verify-notice a {
    color: var(--warning);
    text-decoration: underline;
    cursor: pointer;
    white-space: nowrap;
}

/* ===== USER MENU ===== */
.user-menu {
    position: absolute;
    bottom: 70px;
    left: 8px;
    right: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    z-index: 50;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: background 0.15s;
    border: none;
    width: 100%;
    background: transparent;
    font-family: var(--font);
    text-align: left;
}

.user-menu-item:hover { background: var(--bg-hover); }
.user-menu-item.danger { color: var(--danger); }

.divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .topbar { display: flex; }
    
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
    }
    
    .sidebar.open { transform: translateX(0); }
    
    .welcome-examples { grid-template-columns: 1fr; }
    
    .plan-grid { grid-template-columns: 1fr; }
    .plan-single { grid-column: 1; }
    
    .message { padding: 12px 16px; }
    .input-area { padding: 12px 16px 20px; }
    
    .modal { padding: 24px 20px; margin: 0; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Кнопка генерации изображений */
.img-gen-btn {
    position: absolute;
    right: 52px;
    bottom: 10px;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.img-gen-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* Зона загрузки изображения */
#upload-zone:hover { border-color: var(--accent) !important; }


/* Панель режима изображений */
#image-mode-bar { transition: all 0.2s ease; }

/* Кнопка генерации изображений */
.img-gen-btn {
    position: absolute;
    right: 52px;
    bottom: 10px;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s;
    flex-shrink: 0;
}

.img-gen-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-color: var(--accent);
}

.img-gen-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Превью загруженного изображения */
#img-upload-preview-bar {
    display: none;
    align-items: center;
    gap: 8px;
}


/* Кнопка закрытия сайдбара */
.sidebar-close-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.15s;
    flex-shrink: 0;
}

.sidebar-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

@media (max-width: 768px) {
    .sidebar-close-btn { display: flex; }
}

/* Кнопка удаления сессии */
.session-item { position: relative; padding-right: 28px !important; }
.session-delete-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0;
    transition: all 0.15s;
    font-family: var(--font);
}
.session-item:hover .session-delete-btn { display: flex; }
.session-delete-btn:hover { background: rgba(239,68,68,0.15); color: var(--danger); }

/* Кнопки экспорта ответа */
.export-btns {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
}

.export-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent);
}
