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

:root {
    --bg-primary: #0e1621;
    --bg-secondary: #17212b;
    --bg-chat: #0e1621;
    --bg-input: #242f3d;
    --bg-bubble-bot: #182533;
    --bg-bubble-user: #2b5278;
    --text-primary: #f5f5f5;
    --text-secondary: #8b9bab;
    --text-link: #6ab2f2;
    --accent: #5288c1;
    --accent-hover: #6ba0d6;
    --border: #1c2a38;
    --header-bg: #17212b;
    --keyboard-bg: #17212b;
    --keyboard-btn: #2b5278;
    --keyboard-btn-hover: #3a6a9b;
    --danger: #e25656;
    --success: #4caf50;
    --shadow: rgba(0,0,0,0.3);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ==================== SCREENS ==================== */
.screen {
    display: none;
    width: 100%;
    height: 100%;
}
.screen.active { display: flex; }

/* ==================== LOGIN ==================== */
#login-screen {
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.login-container {
    width: 100%;
    max-width: 380px;
    padding: 24px;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

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

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

.input-group input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.input-group {
    position: relative;
}

.input-group input:focus {
    border-color: var(--accent);
}

.pwd-toggle {
    position: absolute;
    right: 10px;
    top: 32px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    opacity: 0.6;
}

.pwd-toggle:hover { opacity: 1; }

.input-group input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.turnstile-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

#login-btn {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

#login-btn:hover { background: var(--accent-hover); }
#login-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
    color: var(--danger);
    text-align: center;
    margin-top: 12px;
    font-size: 13px;
}

.login-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 20px;
}

/* ==================== CHAT ==================== */
#chat-screen {
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    min-height: 56px;
    flex-shrink: 0;
    z-index: 10;
}

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

.bot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.header-info {
    display: flex;
    flex-direction: column;
}

.bot-name {
    font-size: 15px;
    font-weight: 600;
}

.bot-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.bot-status.online { color: var(--success); }

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

.user-balance {
    font-size: 14px;
    font-weight: 600;
    color: var(--success);
    background: rgba(76, 175, 80, 0.15);
    padding: 4px 10px;
    border-radius: 12px;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.1);
    color: var(--danger);
}

/* ==================== MESSAGES ==================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-chat);
    scroll-behavior: smooth;
}

.chat-date-divider {
    text-align: center;
    padding: 8px 0;
}

.chat-date-divider span {
    background: rgba(0,0,0,0.3);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 12px;
}

.message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    position: relative;
    animation: fadeIn 0.15s ease;
}

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

.message.bot {
    align-self: flex-start;
    background: var(--bg-bubble-bot);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message.user {
    align-self: flex-end;
    background: var(--bg-bubble-user);
    border-bottom-right-radius: 4px;
    color: #fff;
}

.message .time {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 4px;
    opacity: 0.7;
}

.message.user .time { color: rgba(255,255,255,0.5); }

.message a {
    color: var(--text-link);
    text-decoration: underline;
    word-break: break-all;
}

.message.user a { color: #aad4ff; }

/* Inline keyboards inside messages */
.inline-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.inline-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--text-link);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s;
}

.inline-btn:hover { background: rgba(82, 136, 193, 0.15); }

/* ==================== REPLY KEYBOARD ==================== */
.reply-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 12px;
    background: var(--keyboard-bg);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    max-height: 200px;
    overflow-y: auto;
}

.reply-keyboard:empty {
    display: none;
    padding: 0;
    border: none;
}

.kb-row {
    display: flex;
    gap: 6px;
}

.kb-btn {
    flex: 1;
    padding: 10px 8px;
    background: var(--keyboard-btn);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kb-btn:hover { background: var(--keyboard-btn-hover); }
.kb-btn:active { transform: scale(0.97); }

/* ==================== INPUT ==================== */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-input);
    border: none;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
}

#chat-input::placeholder { color: var(--text-secondary); opacity: 0.5; }

.send-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.send-button:hover { background: var(--accent-hover); }

/* ==================== OVERLAY ==================== */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: 16px;
    text-align: center;
    max-width: 340px;
    width: 90%;
}

.overlay-icon { font-size: 48px; margin-bottom: 16px; }
.overlay-content h2 { margin-bottom: 8px; }
.overlay-content p { color: var(--text-secondary); margin-bottom: 20px; font-size: 14px; }

.overlay-btn {
    padding: 12px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 600;
}

.overlay-btn:hover { background: var(--accent-hover); }

/* ==================== TYPING INDICATOR ==================== */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--bg-bubble-bot);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.2s infinite;
}

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

@keyframes typing {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* ==================== SCROLLBAR ==================== */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

/* ==================== MOBILE ==================== */
@media (max-width: 480px) {
    .message { max-width: 92%; font-size: 14px; }
    .chat-header { padding: 8px 12px; }
    .bot-avatar { width: 36px; height: 36px; font-size: 18px; }
    .user-balance { font-size: 12px; padding: 3px 8px; }
    .kb-btn { padding: 10px 6px; font-size: 13px; }
    #chat-input { font-size: 16px; padding: 10px 14px; }
    .login-container { padding: 20px 16px; }
}

@media (max-height: 500px) {
    .reply-keyboard { max-height: 120px; }
}
