/* Phoenix INVEST — chat page styles */

/* CRITICAL: атрибут hidden має перебивати display: flex/grid у класах нижче */
[hidden] {
    display: none !important;
}

.chat-page {
    /* 100dvh = dynamic viewport (на мобайл враховує URL-bar / клавіатуру) */
    min-height: 100dvh;
    height: 100dvh;
    background: var(--color-bg);
    display: flex;
    align-items: stretch;
    padding: 24px 0;
    box-sizing: border-box;
}

.chat-container {
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ========== WELCOME SCREEN ========== */

.chat-welcome {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 40px 24px;
    overflow-y: auto;
}

.chat-welcome-card {
    text-align: center;
    max-width: 480px;
}

.chat-welcome-avatar {
    /* V5.9.10: квадратний з заокругленими кутами (squircle) +15% розмір */
    width: 101px;
    height: 101px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-bright));
    border-radius: 22px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
    margin: 0 auto 24px;
    box-shadow: var(--shadow-gold);
    animation: bob 3s ease-in-out infinite;
    color: var(--color-bg-deep);
    position: relative;
}
.chat-welcome-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 22px;
}
/* Fallback emoji якщо фото не завантажилось */
.chat-welcome-avatar.avatar-fallback::after {
    content: "🤖";
}

@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.chat-welcome-card h1 {
    font-family: 'Manrope', sans-serif;
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 12px;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.chat-welcome-card p {
    color: var(--color-text-muted);
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 32px;
}

.welcome-form {
    text-align: left;
}

.welcome-form label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.welcome-form input[type="text"] {
    /* V5.9.10: squircle замість pill */
    width: 100%;
    padding: 14px 18px;
    background: var(--color-bg-deep);
    color: var(--color-text);
    border: 1px solid var(--color-border-soft);
    border-radius: 12px;
    font-family: inherit;
    font-size: 16px;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.welcome-form input[type="text"]::placeholder {
    color: var(--color-text-light);
}

.welcome-form input[type="text"]:focus {
    outline: none;
    border-color: var(--color-accent);
}

.chat-welcome-note {
    margin-top: 20px;
    color: var(--color-text-light);
    font-size: 13px;
}

.chat-welcome-note a {
    color: var(--color-accent-hover);
    text-decoration: underline;
}

/* ========== CONSENT MODAL ========== */

.chat-consent {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.chat-consent-card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-lg);
    padding: 36px;
    max-width: 540px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.chat-consent-card h2 {
    font-family: 'Manrope', sans-serif;
    font-size: 22px;
    margin-bottom: 16px;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.chat-consent-card p {
    color: var(--color-text-muted);
    line-height: 1.7;
    font-size: 15px;
    margin-bottom: 24px;
}

.chat-consent-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ========== ACTIVE CHAT ========== */

.chat-active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border-soft);
    background: var(--color-bg-card);
}

.chat-back {
    color: var(--color-text-muted);
    font-size: 14px;
    transition: color 0.2s;
}

.chat-back:hover {
    color: var(--color-text);
}

.chat-peer {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.chat-peer-avatar {
    /* V5.9.10: квадратний з заокругленими кутами (squircle) */
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-bright));
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 23px;
    color: var(--color-bg-deep);
    box-shadow: var(--shadow-gold);
    flex-shrink: 0;
}
.chat-peer-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 12px;
}
.chat-peer-avatar.avatar-fallback::after {
    content: "🤖";
}

.chat-peer-name {
    font-weight: 700;
    font-size: 15px;
}

.chat-peer-role {
    font-size: 12px;
    color: var(--color-success);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-peer-role .dot {
    width: 7px;
    height: 7px;
    background: var(--color-success);
    border-radius: 50%;
    animation: blink 1.4s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* V5.9.24: уніфіковані квадратні іконки в шапці чату */
.chat-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-accent);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    text-decoration: none;
}
.chat-icon-btn svg {
    width: 18px;
    height: 18px;
}
.chat-icon-btn:hover {
    background: var(--color-accent);
    color: var(--color-bg-deep);
    transform: scale(1.05);
}

/* Backwards-compat: старий клас все ще використовується десь? */
.chat-tg-link {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-accent);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.chat-tg-link:hover {
    background: var(--color-accent);
    color: var(--color-bg-deep);
    transform: scale(1.05);
}

/* ========== MESSAGES ========== */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--color-bg-deep);
}

.msg {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    line-height: 1.5;
    font-size: 15px;
    word-wrap: break-word;
    animation: msgIn 0.3s ease-out;
}

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

.msg-user {
    align-self: flex-end;
    background: var(--color-accent);
    color: var(--color-bg-deep);
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.msg-bot {
    align-self: flex-start;
    background: var(--color-bg-card);
    color: var(--color-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--color-border-soft);
}

.msg-bot strong {
    color: var(--color-accent);
}

.msg-bot a {
    color: var(--color-accent);
    text-decoration: underline;
}

.msg-meta {
    font-size: 11px;
    color: var(--color-text-light);
    margin-top: 4px;
    padding: 0 4px;
}

.msg-tools {
    font-size: 11px;
    color: var(--color-text-light);
    margin-top: 6px;
    font-style: italic;
    padding-top: 6px;
    border-top: 1px dashed var(--color-border);
}

.msg-audio {
    width: 100%;
    margin-top: 6px;
    height: 40px;
    border-radius: 8px;
}

.chat-typing {
    padding: 8px 24px;
    color: var(--color-text-muted);
    font-size: 13px;
    background: var(--color-bg-deep);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: typing 1.2s ease-in-out infinite;
}

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

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

/* ========== INPUT ========== */

.chat-input {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--color-border-soft);
    background: var(--color-bg-card);
}

.chat-mic, .chat-send {
    /* V5.9.10: squircle (квадрат з заокругленими кутами) замість кола */
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-mic {
    background: var(--color-bg-deep);
    color: var(--color-accent);
    border: 1px solid var(--color-border-soft);
}

.chat-mic:hover {
    background: var(--color-accent);
    color: var(--color-bg-deep);
}

.chat-mic.recording {
    background: #DC2626;
    color: white;
    animation: pulseRed 1s ease-out infinite;
}

@keyframes pulseRed {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0); }
}

.chat-send {
    background: var(--color-accent);
    color: var(--color-bg-deep);
    font-weight: 700;
    font-size: 22px;
}

.chat-send:hover:not(:disabled) {
    background: var(--color-accent-bright);
    transform: scale(1.05);
    box-shadow: var(--shadow-gold);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#chat-input {
    /* V5.9.10: squircle (12px замість 22px pill) */
    flex: 1;
    background: var(--color-bg-deep);
    color: var(--color-text);
    border: 1px solid var(--color-border-soft);
    border-radius: 12px;
    padding: 11px 18px;
    font-family: inherit;
    font-size: 15px;
    resize: none;
    line-height: 1.4;
    max-height: 140px;
    overflow-y: auto;
}

#chat-input::placeholder {
    color: var(--color-text-light);
}

#chat-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* ========== RECORDING UI ========== */

.chat-recording {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid var(--color-border-soft);
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.18), rgba(220, 38, 38, 0.08));
    color: var(--color-text);
}

.rec-dot {
    width: 10px;
    height: 10px;
    background: #DC2626;
    border-radius: 50%;
    animation: blink 1s ease-in-out infinite;
}

#rec-time {
    flex: 1;
    font-family: ui-monospace, monospace;
    font-weight: 600;
}

.rec-stop, .rec-cancel {
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.rec-stop {
    background: var(--color-accent);
    color: var(--color-bg-deep);
}

.rec-stop:hover {
    background: var(--color-accent-bright);
}

.rec-cancel {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-soft);
}

.rec-cancel:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
}

/* ========== RESPONSIVE ========== */

/* Планшет і середні екрани */
@media (max-width: 900px) {
    .chat-page {
        padding: 12px 0;
    }
}

/* Мобайл — фуллскрін без рамок */
@media (max-width: 768px) {
    .chat-page {
        padding: 0;
        /* iOS Safari fallback на старіших версіях, що не знають 100dvh */
        height: 100vh;
        height: 100dvh;
        min-height: 100vh;
        min-height: 100dvh;
    }
    .chat-container {
        border-radius: 0;
        border: none;
        height: 100%;
        max-width: 100%;
    }
    .chat-welcome {
        padding: 24px 18px;
    }
    .chat-welcome-card h1 {
        font-size: 26px;
    }
    .chat-welcome-card p {
        font-size: 15px;
    }
    .chat-welcome-avatar {
        /* mobile: пропорційно зменшено від 101 до ~83 (з збереженням +15%) */
        width: 83px;
        height: 83px;
        font-size: 42px;
    }
    .chat-header {
        padding: 12px 14px;
        gap: 10px;
    }
    .chat-back {
        font-size: 13px;
    }
    .chat-peer-name {
        font-size: 14px;
    }
    .chat-peer-role {
        font-size: 11px;
    }
    .chat-messages {
        padding: 16px 14px;
        gap: 10px;
    }
    .msg {
        max-width: 90%;
        font-size: 14.5px;
        padding: 11px 14px;
    }
    .chat-input {
        padding: 10px 12px;
        gap: 8px;
        /* iOS: запобігти зум при фокусі на textarea (font-size має бути ≥ 16px) */
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    #chat-input {
        font-size: 16px; /* iOS no-zoom при focus */
        padding: 10px 14px;
    }
    .chat-mic, .chat-send {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }
    .chat-consent-card {
        padding: 22px 18px;
    }
    .chat-consent-card h2 {
        font-size: 19px;
    }
    .chat-consent-actions {
        flex-direction: column-reverse;
    }
    .chat-consent-actions .btn {
        width: 100%;
    }
}

/* Дуже вузькі екрани (iPhone SE 1, старі Android) */
@media (max-width: 360px) {
    .chat-welcome-card h1 {
        font-size: 22px;
    }
    .chat-welcome-card p {
        font-size: 14px;
    }
    .chat-header {
        padding: 10px 12px;
    }
    .chat-tg-link {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }
    .chat-peer-avatar {
        /* very narrow screens: 36 → 41 (+15%) */
        width: 41px;
        height: 41px;
        font-size: 21px;
    }
    .chat-mic, .chat-send {
        width: 40px;
        height: 40px;
    }
    .msg {
        max-width: 95%;
        font-size: 14px;
    }
}

/* Landscape mobile — щоб клавіатура не з'їдала повідомлення */
@media (max-height: 480px) and (orientation: landscape) {
    .chat-welcome {
        padding: 16px;
    }
    .chat-welcome-avatar {
        /* landscape mobile: компактний, але +15% від 56 */
        width: 64px;
        height: 64px;
        font-size: 32px;
        margin-bottom: 12px;
    }
    .chat-welcome-card h1 {
        font-size: 20px;
        margin-bottom: 6px;
    }
    .chat-welcome-card p {
        font-size: 13px;
        margin-bottom: 16px;
    }
    .chat-header {
        padding: 8px 14px;
    }
    .chat-messages {
        padding: 10px 14px;
    }
}
