/* =============================================
   Юрист24 — Deep Navy Dark Theme
   Mobile-First / max-width: 768px centered
   ============================================= */

:root {
    /* Фоны */
    --bg-main:       #0B132B;  /* Глубокий чернильно-синий фон */
    --bg-surface:    #141E39;  /* Плашки, карточки, сообщения пользователя */
    --bg-ai-msg:     #0F182E;  /* Сообщения AI */

    /* Акценты */
    --accent-color:  #3A6DF0;  /* Сапфировый акцент */
    --accent-hover:  #2955D9;

    /* Текст */
    --text-primary:  #FFFFFF;  /* White — maximum contrast */
    --text-secondary:#CBD5E1;  /* Второстепенный — lighter for readability */

    /* Границы */
    --border-color:  rgba(255, 255, 255, 0.08);
    --border-ai:     rgba(58, 109, 240, 0.3);  /* Свечение для AI */

    /* Шрифт */
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Радиусы */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

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

html, body {
    height: 100%;
    font-family: var(--font-family);
    background: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* =============================================
   App Shell — Mobile-First, 768px centered
   ============================================= */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* динамическая высота для мобилок */
    max-width: 768px;
    margin: 0 auto;
    background: var(--bg-main);
    position: relative;
    overflow: hidden;
}

/* =============================================
   Header
   ============================================= */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 10;
    position: relative;
}

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

.header__logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent-color);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.header__logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

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

.header__status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.header__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #34D399;
    box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.header__menu-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

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

/* =============================================
   Chat Area — scrollable messages
   ============================================= */
.chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Кастомный скроллбар */
.chat::-webkit-scrollbar {
    width: 4px;
}
.chat::-webkit-scrollbar-track {
    background: transparent;
}
.chat::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* =============================================
   Messages
   ============================================= */
.msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}

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

/* AI-сообщение — слева */
.msg--ai {
    align-self: flex-start;
}

.msg--ai .msg__bubble {
    background: var(--bg-ai-msg);
    border: 1px solid var(--border-ai);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
    box-shadow: 0 0 12px rgba(58, 109, 240, 0.06);
}

/* Пользователь — справа */
.msg--user {
    align-self: flex-end;
}

.msg--user .msg__bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
}

/* Юрист — слева, с другим акцентом */
.msg--lawyer {
    align-self: flex-start;
}

.msg--lawyer .msg__bubble {
    background: #1A2744;
    border: 1px solid rgba(52, 211, 153, 0.3);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

.msg__bubble {
    padding: 12px 16px;
    line-height: 1.55;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msg__sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.msg--ai .msg__sender {
    color: var(--accent-color);
}

.msg--lawyer .msg__sender {
    color: #34D399;
}

.msg__time {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
    opacity: 0.6;
}

.msg--user .msg__time {
    text-align: right;
}

/* =============================================
   Paid indicator
   ============================================= */
.msg__paid {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: #F59E0B;
    margin-top: 4px;
}

/* =============================================
   Input Area — fixed bottom
   ============================================= */
.input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-area__mic {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border: none;
    background: transparent;
    color: #FFFFFF;
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s;
}

.input-area__mic svg {
    stroke: #FFFFFF;
    transition: stroke 0.2s;
}

.input-area__mic:hover {
    color: var(--accent-color);
}

.input-area__mic:hover svg {
    stroke: var(--accent-color);
}

.input-area__field-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s;
}

.input-area__field-wrap:focus-within {
    border-color: var(--accent-color);
}

.input-area__field {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-family);
    resize: none;
    outline: none;
    padding: 8px 0;
    max-height: 120px;
    line-height: 1.4;
}

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

.input-area__send {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    background: var(--accent-color);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.input-area__send:hover {
    background: var(--accent-hover);
}

.input-area__send:active {
    transform: scale(0.95);
}

.input-area__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Кнопка очистки ✖ */
.input-area__clear {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.input-area__clear:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.08);
}

/* =============================================
   Typing indicator
   ============================================= */
.typing {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--bg-ai-msg);
    border: 1px solid var(--border-ai);
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

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

.typing__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-color);
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing__dot:nth-child(2) { animation-delay: 0.15s; }
.typing__dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* =============================================
   Welcome message
   ============================================= */
.welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-secondary);
}

.welcome__icon {
    font-size: 40px;
    margin-bottom: 12px;
}

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

.welcome__text {
    font-size: 13px;
    line-height: 1.5;
    max-width: 400px;
    margin: 0 auto;
}

/* =============================================
   Sidebar (menu)
   ============================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 280px;
    height: 100%;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.sidebar--open {
    left: 0;
}

.sidebar__overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
    pointer-events: none;
}

.sidebar__overlay--visible {
    display: block;
    pointer-events: auto;
}

.sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar__close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.sidebar__section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 16px 0 8px;
}

.sidebar__new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: background 0.2s;
}

.sidebar__new-chat:hover {
    background: var(--accent-hover);
}

.sidebar__chats {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar__chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.sidebar__chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar__chat-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    opacity: 0.7; /* видима всегда, в т.ч. на тач-устройствах без hover */
    transition: opacity 0.15s, color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.sidebar__chat-item:hover .sidebar__chat-delete,
.sidebar__chat-delete:focus-visible {
    opacity: 1;
}

.sidebar__chat-delete:hover {
    color: #EF4444;
    background: rgba(239, 68, 68, 0.1);
}

.sidebar__chat-item:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.sidebar__chat-item--active {
    background: rgba(58, 109, 240, 0.12);
    color: var(--accent-color);
}

.sidebar__footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.sidebar__footer-text {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.5;
}

/* =============================================
   Responsive — Desktop (>768px)
   ============================================= */
@media (min-width: 769px) {
    .app {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }

    .msg {
        max-width: 65%;
    }

    .input-area__field {
        font-size: 15px;
    }
}

/* =============================================
   Responsive — Mobile input area
   ============================================= */
@media (max-width: 480px) {
    .input-area {
        padding: 10px 12px;
        gap: 6px;
    }

    .input-area__mic {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 16px;
    }

    .input-area__send {
        width: 34px;
        height: 34px;
        min-width: 34px;
        font-size: 15px;
    }

    .input-area__field-wrap {
        padding: 3px 3px 3px 12px;
    }

    .input-area__field {
        font-size: 16px; /* prevents iOS zoom */
        padding: 6px 0;
    }
}

/* =============================================
   PWA Install Banner
   ============================================= */
.pwa-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #141E39, #1A2744);
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    flex-shrink: 0;
}

.pwa-banner__text {
    flex: 1;
    color: var(--text-secondary);
}

.pwa-banner__btn {
    padding: 6px 14px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.pwa-banner__btn:hover { background: var(--accent-hover); }

.pwa-banner__close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
}

/* =============================================
   Mic Recording Pulse
   ============================================= */
.input-area__mic--recording {
    color: var(--accent-color) !important;
    animation: mic-pulse 1s ease-in-out infinite;
}

.input-area__mic--recording svg {
    stroke: var(--accent-color);
}

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

/* =============================================
   Legal Disclaimer Bar
   ============================================= */
.legal-disclaimer-bar {
    flex-shrink: 0;
    text-align: center;
    padding: 8px 16px;
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    line-height: 1.4;
    opacity: 0.7;
}

.legal-disclaimer-bar a {
    color: var(--accent-color);
    text-decoration: none;
}

.legal-disclaimer-bar a:hover {
    text-decoration: underline;
}

/* =============================================
   Sidebar Legal Links
   ============================================= */
.sidebar__links {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    color: #FFFFFF;
    text-decoration: none;
    background: transparent;
    transition: background 0.15s, color 0.15s;
}

/* Кнопки в сайдбаре (button.sidebar__link) — убираем дефолтный белый фон браузера */
button.sidebar__link {
    border: none;
    font-family: inherit;
    text-align: left;
    width: 100%;
    cursor: pointer;
}

.sidebar__link:hover {
    background: #1F2C4E;
    color: #FFFFFF;
}

/* =============================================
   Modal Consent Checkbox
   ============================================= */
.modal__consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
    padding: 4px 0;
}

.modal__consent-cb {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    flex-shrink: 0;
    accent-color: var(--accent-color);
    cursor: pointer;
}

.modal__consent a {
    color: var(--accent-color);
    text-decoration: none;
}

.modal__consent a:hover {
    text-decoration: underline;
}

/* Disabled button state */
.modal__btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
