/* ─── Variables (same as landing) ─── */
:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-chat: #1a1a28;
    --accent: #e854a7;
    --accent2: #a855f7;
    --accent3: #7c3aed;
    --tg-blue: #2aabee;
    --text: #e4e4ec;
    --text-muted: #9090a8;
    --border: #1e1e30;
}

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

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

/* ─── Animated background ─── */
.bg-ambient {
    position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}

.bg-orb {
    position: absolute; border-radius: 50%; filter: blur(120px); opacity: 0.25;
    animation: orbFloat 12s ease-in-out infinite; will-change: transform;
}

.bg-orb--1 {
    width: 600px; height: 600px; background: var(--accent);
    top: -200px; left: -100px;
}
.bg-orb--2 {
    width: 500px; height: 500px; background: var(--accent2);
    bottom: -150px; right: -150px; animation-delay: -6s;
}
.bg-orb--3 {
    width: 350px; height: 350px; background: var(--tg-blue);
    top: 50%; left: 50%; transform: translate(-50%, -50%);
    animation-delay: -3s; opacity: 0.15;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(40px, -30px) scale(1.08); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(-30px, -10px) scale(1.05); }
}

.bg-grid {
    position: fixed; inset: 0; pointer-events: none; z-index: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse 80% 80% at 50% 40%, black 30%, transparent 70%);
}

/* ─── Chat app ─── */
.chat-app {
    position: relative; z-index: 1;
    display: flex; flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px; margin: 0 auto;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 80px -20px rgba(168, 85, 247, 0.15);
}

/* Внутри app-layout чат уже в flex-контейнере */
.app-layout > .chat-app {
    flex: 1;
    height: auto;
    min-height: 0;
}

/* ─── Header ─── */
.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px;
    background: var(--bg-chat);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0; position: relative;
}

.chat-avatar::after {
    content: '';
    position: absolute; bottom: 1px; right: 1px;
    width: 10px; height: 10px; background: #22c55e;
    border-radius: 50%; border: 2px solid var(--bg-chat);
}

.chat-user-info .chat-name {
    font-size: 15px; font-weight: 600; color: var(--text);
}

.chat-user-info .chat-status {
    font-size: 12px; color: #22c55e;
}

.chat-balance {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    white-space: nowrap;
    cursor: default;
    transition: all 0.2s;
}

.chat-balance.low {
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
}

.chat-balance.empty {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

.chat-clear-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: 6px;
}

.chat-clear-btn svg {
    width: 16px;
    height: 16px;
}

.chat-clear-btn:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.25);
    background: rgba(239, 68, 68, 0.08);
}

/* ─── Back button ─── */
.chat-back-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-right: 4px;
}

.chat-back-btn svg {
    width: 18px;
    height: 18px;
}

.chat-back-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

/* ─── Close button (X in header) ─── */
.chat-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-left: 6px;
    text-decoration: none;
}
.chat-close-btn svg {
    width: 16px;
    height: 16px;
}
.chat-close-btn:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.25);
    background: rgba(239, 68, 68, 0.08);
}

/* ─── Home button (bottom) ─── */
.chat-home-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    margin: -8px auto 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.25s;
    max-width: 200px;
    position: relative;
    z-index: 2;
}
.chat-home-btn svg {
    width: 16px;
    height: 16px;
}
.chat-home-btn:hover {
    color: var(--accent2);
    border-color: rgba(168, 85, 247, 0.25);
    background: rgba(168, 85, 247, 0.08);
}

/* ─── Attach button ─── */
.chat-attach-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-attach-btn svg {
    width: 18px;
    height: 18px;
}

.chat-attach-btn:hover {
    color: var(--accent);
    border-color: rgba(168, 85, 247, 0.25);
    background: rgba(168, 85, 247, 0.08);
}

/* ─── Image preview ─── */
.img-preview-wrap {
    position: relative;
    flex-shrink: 0;
    margin-right: 2px;
}

.img-preview-wrap img {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid var(--border);
    display: block;
}

.img-preview-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    border: 2px solid var(--bg-chat);
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    transition: transform 0.15s;
}

.img-preview-remove:hover {
    transform: scale(1.15);
}

/* ─── Messages area ─── */
.chat-body {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    background:
        radial-gradient(ellipse at 50% 30%, rgba(168, 85, 247, 0.04) 0%, transparent 60%);
    -webkit-overflow-scrolling: touch;
}

.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }

/* ─── Welcome ─── */
.chat-welcome {
    display: flex; flex-direction: column; align-items: center;
    gap: 16px; padding: 40px 20px; text-align: center;
}

.welcome-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    font-size: 36px;
    box-shadow: 0 8px 32px rgba(232, 84, 167, 0.3);
}

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

/* Спайсер — толкает контент к центру; при переполнении сжимается в 0 */
.chat-body-spacer {
    flex: 1;
}

/* ─── Messages ─── */
.msg {
    max-width: 82%; padding: 10px 14px; border-radius: 16px;
    font-size: 14px; line-height: 1.55;
    animation: msgIn 0.3s ease-out;
    word-break: break-word;
}

.msg--them {
    align-self: flex-start;
    background: var(--bg-chat);
    border-bottom-left-radius: 6px;
    color: #d4d4e0;
}

.msg--me {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent3), var(--accent2));
    border-bottom-right-radius: 6px;
    color: #fff;
}

/* ─── Photo messages ─── */
.msg--photo {
    align-self: flex-start;
    background: transparent !important;
    padding: 0 !important;
    max-width: 92%;
    width: fit-content;
    border-radius: 16px;
    overflow: visible;
}

.msg-photo-img {
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(160deg, #1a1a2e, #2d1b3d, #16213e, #0f3460);
    line-height: 0;
}

.msg-photo-img img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 16px;
    cursor: zoom-in;
    transition: opacity 0.3s;
}

.msg-photo-img img:hover {
    opacity: 0.92;
}

.msg-photo-caption {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 4px 0;
}

/* ─── Lightbox ─── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    cursor: zoom-out;
    -webkit-tap-highlight-color: transparent;
}

.lightbox.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
    transform: scale(0.9);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    user-select: none;
    -webkit-user-select: none;
}

.lightbox.active img {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.25s;
    z-index: 2;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

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

/* ─── Typing indicator ─── */
.typing-indicator {
    align-self: flex-start;
    display: flex; gap: 4px;
    padding: 12px 16px;
    background: var(--bg-chat);
    border-radius: 16px;
    border-bottom-left-radius: 6px;
}

.typing-dot {
    width: 7px; height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* ─── Photo loading indicator ─── */
.photo-loading {
    align-self: flex-start;
    display: flex; flex-direction: column; gap: 8px;
    padding: 14px 18px;
    background: var(--bg-chat);
    border-radius: 16px;
    border-bottom-left-radius: 6px;
    min-width: 200px;
    max-width: 280px;
}

.photo-loading-header {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-muted);
}

.photo-loading-icon {
    width: 20px; height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: photoSpin 0.8s linear infinite;
}

.photo-loading-percent {
    font-weight: 700; font-size: 13px;
    color: var(--accent);
    margin-left: auto;
    min-width: 38px; text-align: right;
}

.photo-loading-bar-wrap {
    width: 100%; height: 5px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.photo-loading-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #a855f7, #ec4899);
    border-radius: 3px;
    transition: width 0.3s linear;
}

.photo-loading-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
    font-style: italic;
}

@keyframes photoSpin {
    to { transform: rotate(360deg); }
}

/* ─── Token info button (header) ─── */
.chat-token-info-btn {
    display: flex;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}

.chat-token-info-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

/* ─── Token popover (mobile) ─── */
.token-popover {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 150;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    min-width: 210px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    animation: tokenPopIn 0.2s ease;
}

.token-popover-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
    text-align: center;
}

.token-popover-item {
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.token-popover-item:last-child {
    border-bottom: none;
}

.token-popover-item strong {
    color: var(--accent);
}

@keyframes tokenPopIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Low balance banner ─── */
.low-balance-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(135deg, rgba(255,180,0,0.12), rgba(255,140,0,0.06));
    border-top: 1px solid rgba(255,180,0,0.2);
    flex-shrink: 0;
}

.low-balance-text {
    font-size: 13px; color: #ffb400; font-weight: 500;
}

.low-balance-cta {
    font-size: 13px; color: #ffd700; font-weight: 700;
    text-decoration: none; white-space: nowrap;
    transition: opacity 0.2s;
}

.low-balance-cta:hover { opacity: 0.8; }

/* ─── Input bar ─── */
.chat-input-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-chat);
    flex-shrink: 0;
}

.chat-input {
    flex: 1; height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0 16px;
    font-size: 14px; color: var(--text);
    outline: none;
    transition: border-color 0.3s;
    font-family: inherit;
}

.chat-input:focus {
    border-color: var(--accent2);
}

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

.chat-send-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--tg-blue);
    color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: all 0.25s;
    box-shadow: 0 0 12px rgba(42, 171, 238, 0.3);
}

.chat-send-btn:hover {
    box-shadow: 0 0 24px rgba(42, 171, 238, 0.5);
    transform: scale(1.05);
}

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

.chat-send-btn svg {
    width: 18px; height: 18px;
}

.chat-send-btn:disabled {
    opacity: 0.4; cursor: not-allowed; box-shadow: none;
    transform: none;
}

/* ─── Error message ─── */
.chat-error {
    align-self: center;
    font-size: 12px; color: #f87171;
    padding: 8px 14px;
    background: rgba(248, 113, 113, 0.08);
    border-radius: 10px;
    animation: msgIn 0.3s ease-out;
}

/* ─── Mobile ─── */
@media (max-width: 480px) {
    .chat-app {
        max-width: 100%; border: none;
    }

    .msg {
        max-width: 88%;
        font-size: 13.5px;
    }

    .chat-input {
        height: 38px; font-size: 13px;
    }
}

/* ─── Footer ─── */
.site-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 12px;
    margin-top: auto;
    background: rgba(10, 10, 15, 0.55);
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 11px;
    flex-shrink: 0;
}

/* На мобилке в чате футер не нужен */
@media (max-width: 640px) {
    body.hide-footer-mobile .site-footer {
        display: none;
    }
}
.site-footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 16px;
}
.site-footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
}
.site-footer a:hover {
    color: var(--accent2);
}
.site-footer-sep {
    color: rgba(255, 255, 255, 0.1);
    user-select: none;
}
.site-footer-copy {
    color: rgba(255, 255, 255, 0.15);
    font-size: 10px;
    white-space: nowrap;
}
@media (max-width: 480px) {
    .site-footer {
        gap: 1px;
        padding: 8px 8px;
        font-size: 10px;
    }
    .site-footer-links {
        gap: 2px 10px;
    }
    .site-footer-copy {
        font-size: 9px;
    }
}


/* --- CTA-��������� (����� ��� �������) --- */
.msg--cta {
    text-align: center;
    max-width: 320px;
    margin: 12px auto;
    padding: 16px 20px;
    border-radius: 16px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 1px solid #2d2d5e;
    color: #e0e0e0;
    font-size: 0.95rem;
    line-height: 1.5;
}
.msg-cta-link {
    color: #a78bfa;
    font-weight: 600;
    cursor: pointer;
}
.msg-cta-link:hover {
    color: #c4b5fd;
}
.msg-cta-x2 {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255, 165, 0, 0.15);
    border: 1px solid rgba(255, 165, 0, 0.3);
    color: #ffb347;
    font-size: 0.85rem;
    text-align: center;
}
