/* ==============================================================
   ZUB Pilgrim Chat — Стили
   ==============================================================
   Минималистичный тёмный интерфейс в стиле Jarvis / HUD
   ============================================================== */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2332;
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.3);
    --accent-light: #60a5fa;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border: #1f2937;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --user-bg: #1e3a5f;
    --assistant-bg: #1a2332;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ─── Layout ──────────────────────────────────────────────── */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 900px;
    margin: 0 auto;
    overflow: hidden;
}

/* ─── Header ──────────────────────────────────────────────── */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

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

.pilgrim-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 12px var(--accent-glow);
    overflow: hidden;
    padding: 0;
}

.pilgrim-avatar svg {
    width: 100%;
    height: 100%;
}

.header-info h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-status {
    font-size: 12px;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

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

/* ─── Messages area ──────────────────────────────────────── */

.messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ─── Сообщение ──────────────────────────────────────────── */

.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: msg-appear 0.3s ease-out;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

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

.message.user .msg-avatar {
    background: var(--user-bg);
}

.message.assistant .msg-avatar {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    box-shadow: 0 0 8px var(--accent-glow);
}

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-content {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.user .msg-content {
    background: var(--user-bg);
    border-bottom-right-radius: 4px;
}

.message.assistant .msg-content {
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
}

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

.msg-type-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

/* Ссылки в сообщениях */
.msg-content a {
    color: var(--accent-light);
    text-decoration: none;
}

.msg-content a:hover {
    text-decoration: underline;
}

/* Обнаруженные ссылки */
.detected-links {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 8px;
    font-size: 13px;
}

.detected-links .link-label {
    color: var(--accent-light);
    font-weight: 500;
    margin-bottom: 4px;
}

.detected-links .link-item {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 2px 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Индикатор набора */
.typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-left: 42px;
}

.typing-indicator.visible {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* ─── Input area ─────────────────────────────────────────── */

.input-container {
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-wrapper textarea {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 24px;
}

.input-wrapper textarea::placeholder {
    color: var(--text-muted);
}

.input-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn {
    background: var(--accent);
    color: white;
}

.send-btn:hover {
    background: var(--accent-light);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

.voice-btn {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

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

.voice-btn.recording {
    background: var(--error);
    color: white;
    border-color: var(--error);
    animation: pulse-record 1s infinite;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ─── Voice mode overlay ─────────────────────────────────── */

.voice-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 23, 0.95);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.voice-overlay.active {
    display: flex;
}

.voice-visualizer {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    animation: voice-pulse 1.5s infinite;
    box-shadow: 0 0 40px var(--accent-glow);
}

@keyframes voice-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 40px var(--accent-glow); }
    50% { transform: scale(1.08); box-shadow: 0 0 60px var(--accent-glow); }
}

.voice-status {
    font-size: 18px;
    color: var(--text-primary);
}

.voice-recognized {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 400px;
    text-align: center;
    min-height: 20px;
}

.voice-cancel-btn {
    padding: 10px 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
}

.voice-cancel-btn:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* ─── Welcome screen ─────────────────────────────────────── */

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px;
    text-align: center;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px var(--accent-glow);
    overflow: hidden;
    padding: 0;
    flex-shrink: 0;
}

.welcome-logo svg {
    width: 100%;
    height: 100%;
}

.welcome-title {
    font-size: 20px;
    font-weight: 600;
}

.welcome-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 400px;
    line-height: 1.6;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.quick-action {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-action:hover {
    background: var(--border);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ─── Connection status ──────────────────────────────────── */

.connection-bar {
    display: none;
    padding: 6px 16px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
}

.connection-bar.disconnected {
    display: block;
    background: var(--error);
    color: white;
}

.connection-bar.reconnecting {
    display: block;
    background: var(--warning);
    color: #000;
}

/* ─── Audio player for TTS ───────────────────────────────── */

.tts-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(139, 92, 246, 0.15);
    border-radius: 6px;
    font-size: 12px;
    color: #a78bfa;
    cursor: pointer;
}

.tts-indicator.playing {
    display: inline-flex;
}

.tts-wave {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    height: 14px;
}

.tts-wave span {
    width: 2px;
    background: #a78bfa;
    border-radius: 1px;
    animation: tts-bar 0.8s infinite;
}

.tts-wave span:nth-child(1) { height: 4px; animation-delay: 0s; }
.tts-wave span:nth-child(2) { height: 8px; animation-delay: 0.15s; }
.tts-wave span:nth-child(3) { height: 12px; animation-delay: 0.3s; }
.tts-wave span:nth-child(4) { height: 6px; animation-delay: 0.45s; }

@keyframes tts-bar {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.4); }
}

/* ─── Responsive ─────────────────────────────────────────── */

@media (max-width: 640px) {
    .chat-header {
        padding: 8px 12px;
    }

    .messages-container {
        padding: 8px 12px;
    }

    .input-container {
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .message {
        max-width: 92%;
    }

    .header-btn span {
        display: none;
    }

    .welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px;
    text-align: center;
}

    .welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px var(--accent-glow);
    overflow: hidden;
    padding: 0;
    flex-shrink: 0;
}

    .welcome-title {
    font-size: 20px;
    font-weight: 600;
}

    .welcome-subtitle {
        font-size: 13px;
    }

    .quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

    .quick-action {
        padding: 6px 12px;
        font-size: 12px;
    }
}

/* ZUB mascot image avatars */
.bot-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.pilgrim-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.welcome-logo img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
