:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #222222;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;

    /* Собственные переменные для юридического стиля */
    --legal-primary: var(--tg-theme-button-color, #1A365D); /* Строгий тёмно-синий/голубой */
    --legal-surface: var(--tg-theme-secondary-bg-color, #F7FAFC);
    --bot-bubble-bg: var(--tg-theme-secondary-bg-color, #E2E8F0);
    --bot-bubble-text: var(--tg-theme-text-color, #2D3748);
    --user-bubble-bg: var(--tg-theme-button-color, #3182CE);
    --user-bubble-text: var(--tg-theme-button-text-color, #FFFFFF);
    --error-color: #E53E3E;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    height: 100vh;
    height: 100dvh; /* Для мобильных экранов (dynamic viewport height) */
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--tg-theme-bg-color);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    z-index: 10;
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}

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

.bot-avatar {
    font-size: 24px;
    background: var(--legal-surface);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.bot-details h1 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

.status-indicator.online { background-color: #48BB78; }
.status-indicator.offline { background-color: #A0AEC0; }

.status-text {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--tg-theme-hint-color);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: var(--legal-surface);
    color: var(--tg-theme-text-color);
}

/* Messages Area */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

.bot-message { align-self: flex-start; }
.user-message { align-self: flex-end; }
.error-message { align-self: center; text-align: center; max-width: 100%; width: 100%;}

.bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

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

.user-message .bubble {
    background-color: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-bottom-right-radius: 4px;
}

.error-message .bubble {
    background-color: rgba(229, 62, 62, 0.1);
    color: var(--error-color);
    border: 1px solid rgba(229, 62, 62, 0.2);
    border-radius: 12px;
    font-size: 13px;
    display: inline-block;
}

/* Markdown styling inside bubbles */
.bot-message .bubble p { margin-bottom: 8px; }
.bot-message .bubble p:last-child { margin-bottom: 0; }
.bot-message .bubble strong { font-weight: 600; color: inherit; }
.bot-message .bubble ul, .bot-message .bubble ol { margin-left: 20px; margin-bottom: 8px; }
.bot-message .bubble li { margin-bottom: 4px; }
.bot-message .bubble code { 
    background: rgba(0,0,0,0.05); 
    padding: 2px 4px; 
    border-radius: 4px; 
    font-family: monospace; 
    font-size: 13px;
}

/* === Expert Loader Card === */
.loader-card {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    padding: 24px 20px;
    width: 100%;
    max-width: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transition: all 0.3s ease;
    align-self: flex-start;
}

.loader-card.hidden {
    display: none !important;
}

/* Radar/Scanner */
.scanner-container {
    position: relative;
    width: 70px;
    height: 70px;
    margin: 0 auto 16px auto;
}
.scanner-circle {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #1e293b;
    border: 2px solid rgba(59, 130, 246, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    z-index: 10;
    transition: opacity 0.3s;
}
.scanner-sweep {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 70%, rgba(59, 130, 246, 0.8) 100%);
    animation: spin 1.5s linear infinite;
    filter: blur(4px);
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Loader Status Text */
.loader-card .status-text {
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    min-height: 40px;
    color: #e2e8f0;
    transition: opacity 0.4s ease, transform 0.4s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Skeleton Shimmer */
.skeleton-container {
    margin-top: 14px;
    opacity: 0.7;
}
.skeleton-line {
    height: 10px;
    background: linear-gradient(90deg, #1e293b 0%, #334155 50%, #1e293b 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite linear;
    border-radius: 5px;
    margin-bottom: 8px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* Progress Bar */
.progress-bg {
    width: 100%;
    height: 5px;
    background: #1e293b;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 16px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899);
    background-size: 200% 200%;
    width: 0%;
    transition: width 0.2s linear;
    position: relative;
    animation: gradient-shift 3s ease infinite;
}
@keyframes gradient-shift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }

.progress-bar::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    transform: translateX(-100%);
    animation: shine 1.5s infinite;
}
@keyframes shine { 100% { transform: translateX(100%); } }

.queue-status {
    font-size: 13px;
    color: var(--tg-theme-hint-color);
}

/* Input Area */
.input-area {
    padding: 12px 16px;
    background-color: var(--tg-theme-bg-color);
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background-color: var(--legal-surface);
    border-radius: 20px;
    padding: 8px 12px;
    border: 1px solid rgba(0,0,0,0.05);
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--tg-theme-button-color);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--tg-theme-text-color);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    max-height: 120px;
    padding: 8px 0;
    outline: none;
    line-height: 1.4;
}

#message-input::placeholder {
    color: var(--tg-theme-hint-color);
}

.send-btn {
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2px;
    flex-shrink: 0;
}

.send-btn svg {
    width: 18px;
    height: 18px;
    margin-right: -2px; /* slight visual center tweak */
    margin-bottom: -2px;
}

.send-btn:disabled {
    background-color: var(--tg-theme-hint-color);
    opacity: 0.5;
    cursor: not-allowed;
}

.send-btn:not(:disabled):active {
    transform: scale(0.95);
}

/* Scrollbar styling */
.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
}

/* Темная тема (Telegram Dark Mode Overrides) */
@media (prefers-color-scheme: dark) {
    body.theme-dark {
        --tg-theme-bg-color: #1c1c1d;
        --tg-theme-text-color: #ffffff;
        --tg-theme-secondary-bg-color: #2c2c2e;
    }
}
