/* ─── Variables (same as landing) ─── */
html { color-scheme: dark; }

: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: calc(14px + env(safe-area-inset-top)) 16px 14px;
    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; overflow: hidden;
}

.character-placeholder {
    position: relative;
    overflow: hidden;
    color: transparent;
    background: linear-gradient(110deg, rgba(255,255,255,.06) 25%, rgba(255,255,255,.14) 38%, rgba(255,255,255,.06) 55%);
    background-size: 220% 100%;
    animation: characterPlaceholder 1.2s ease-in-out infinite;
}

@keyframes characterPlaceholder {
    to { background-position: -120% 0; }
}

.chat-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    object-position: center 20%;
    border-radius: 50%;
}

.chat-avatar img[src*="asya-card.webp"] {
    transform: scale(1.45);
    object-position: center 18%;
}

.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-characters-btn,
.chat-memory-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 28px;
    padding: 6px 9px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font: inherit;
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
    flex-shrink: 0;
}

.chat-characters-btn:hover,
.chat-memory-btn:hover {
    border-color: var(--accent2);
    background: rgba(168, 85, 247, 0.1);
    color: var(--text);
}

.chat-characters-btn svg,
.chat-memory-btn svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
}

.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: color 0.2s, border-color 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: color 0.2s, border-color 0.2s, background-color 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: color 0.2s, background-color 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: color 0.2s, border-color 0.2s, background-color 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: color 0.25s, border-color 0.25s, background-color 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: color 0.2s, border-color 0.2s, background-color 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);
    overflow: hidden;
}

.token-balance {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    line-height: 1;
}

.token-icon {
    width: 16px;
    height: 16px;
    display: inline-block;
    flex: 0 0 16px;
    vertical-align: -3px;
}

.token-popover .token-icon {
    width: 15px;
    height: 15px;
    flex-basis: 15px;
}

.welcome-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    object-position: center 20%;
    border-radius: 50%;
}

.welcome-avatar img[src*="asya-card.webp"] {
    transform: scale(1.45);
    object-position: center 18%;
}

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

.chat-quick-replies {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 8px;
    padding: 9px 12px 3px;
    overflow: hidden;
    scrollbar-width: none;
}

.chat-quick-replies[hidden] { display: none !important; }
.chat-quick-replies::-webkit-scrollbar { display: none; width: 0; height: 0; }

.chat-quick-replies:not([hidden]) + .chat-input-bar {
    border-top-color: transparent !important;
}

.chat-quick-replies button {
    min-height: 34px;
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(255, 255, 255, .09), rgba(168, 85, 247, .1));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 6px 18px rgba(0, 0, 0, .1);
    color: rgba(244, 239, 255, .9);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    white-space: nowrap;
    backdrop-filter: blur(14px) saturate(120%);
    -webkit-backdrop-filter: blur(14px) saturate(120%);
    transition: border-color .18s, background .18s, transform .18s;
}

.chat-quick-replies button:hover {
    border-color: rgba(196, 165, 255, .52);
    background: linear-gradient(135deg, rgba(255, 255, 255, .13), rgba(168, 85, 247, .18));
    transform: translateY(-1px);
}

.chat-quick-replies button:disabled { opacity: .48; cursor: wait; transform: none; }

/* Спайсер — толкает контент к центру; при переполнении сжимается в 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-content { display: block; }

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    margin-top: 4px;
    color: rgba(232, 228, 244, .52);
    font-size: 10px;
    line-height: 1;
    white-space: nowrap;
}

.msg-cost {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: rgba(255, 236, 157, .72);
}

.msg-cost img {
    width: 11px;
    height: 11px;
    object-fit: contain;
    opacity: .78;
}

.msg--them {
    align-self: flex-start;
    border: 1px solid rgba(255, 255, 255, .13);
    background: linear-gradient(145deg, rgba(255, 255, 255, .085), rgba(255, 255, 255, .025)), rgba(22, 20, 34, .28);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .14), inset 0 1px 0 rgba(255, 255, 255, .09);
    backdrop-filter: blur(18px) saturate(130%);
    -webkit-backdrop-filter: blur(18px) saturate(130%);
    border-bottom-left-radius: 6px;
    color: #d4d4e0;
}

.msg--me {
    align-self: flex-end;
    border: 1px solid rgba(255, 255, 255, .2);
    background: linear-gradient(135deg, rgba(139, 92, 246, .62), rgba(168, 85, 247, .48)), rgba(75, 38, 132, .22);
    box-shadow: 0 10px 28px rgba(74, 39, 137, .2), inset 0 1px 0 rgba(255, 255, 255, .18);
    backdrop-filter: blur(18px) saturate(135%);
    -webkit-backdrop-filter: blur(18px) saturate(135%);
    border-bottom-right-radius: 6px;
    color: #fff;
}

/* ─── Photo messages ─── */
.msg--photo {
    align-self: flex-start;
    background: transparent !important;
    padding: 0 !important;
    max-width: min(92%, 360px);
    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;
    width: 100%;
    max-width: 360px;
    max-height: 520px;
    height: auto;
    object-fit: cover;
    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;
}

.msg--photo .msg-meta {
    padding: 0 4px;
}

/* ─── 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 {
    display: block;
    width: auto;
    height: auto;
    max-width: 92vw;
    max-height: 92vh;
    object-fit: contain;
    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); }
}

.voice-recording-indicator {
    align-items: center;
    gap: 10px;
    color: var(--text2);
    font-size: 13px;
}

.voice-recording-bars {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 22px;
}

.voice-recording-bars i {
    display: block;
    width: 3px;
    height: 8px;
    border-radius: 99px;
    background: var(--accent);
    animation: voiceRecordingBar .85s ease-in-out infinite alternate;
}

.voice-recording-bars i:nth-child(2) { height: 16px; animation-delay: .14s; }
.voice-recording-bars i:nth-child(3) { height: 11px; animation-delay: .28s; }
.voice-recording-bars i:nth-child(4) { height: 19px; animation-delay: .08s; }
.voice-recording-bars i:nth-child(5) { height: 10px; animation-delay: .22s; }

@keyframes voiceRecordingBar {
    from { transform: scaleY(.45); opacity: .55; }
    to { transform: scaleY(1); opacity: 1; }
}

/* ─── 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: color 0.2s, background-color 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: box-shadow 0.25s, transform 0.25s, opacity 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;
    }

    .msg--photo { max-width: 84%; }
    .msg-photo-img img { max-width: 100%; max-height: 460px; }

    .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;
    }
}

/* --- Compact chat layout for narrow phones --- */
@media (max-width: 480px) {
    .chat-header {
        gap: 6px;
        padding: calc(10px + env(safe-area-inset-top)) 8px 10px;
    }

    .chat-back-btn {
        width: 28px;
        height: 28px;
        margin-right: 0;
    }

    .chat-back-btn svg,
    .chat-close-btn svg,
    .chat-clear-btn svg {
        width: 15px;
        height: 15px;
    }

    .chat-avatar {
        width: 36px;
        height: 36px;
        font-size: 17px;
    }

    .chat-user-info {
        min-width: 0;
        flex: 1 1 auto;
        overflow: hidden;
    }

    .chat-user-info .chat-name,
    .chat-user-info .chat-status {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-user-info .chat-name {
        font-size: 14px;
    }

    .chat-user-info .chat-status {
        font-size: 11px;
    }

    .chat-balance {
        margin-left: 0;
        padding: 4px 7px;
        font-size: 11px;
    }

    .chat-token-info-btn {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .chat-characters-btn,
    .chat-memory-btn {
        width: 34px;
        height: 34px;
        min-height: 34px;
        padding: 0;
        border-radius: 50%;
        font-size: 0;
    }

    .chat-characters-btn span,
    .chat-memory-btn span {
        display: none;
    }

    .chat-characters-btn svg,
    .chat-memory-btn svg {
        width: 15px;
        height: 15px;
    }

    .chat-close-btn,
    .chat-clear-btn {
        width: 28px;
        height: 28px;
        margin-left: 0;
    }

    .chat-input-bar {
        gap: 6px;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    }

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

    .chat-input {
        min-width: 0;
        padding: 0 12px;
    }

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

@media (max-width: 360px) {
    .chat-header {
        gap: 4px;
        padding-right: 6px;
        padding-left: 6px;
    }

    .chat-balance {
        padding-right: 5px;
        padding-left: 5px;
    }

    .chat-body {
        padding-right: 10px;
        padding-left: 10px;
    }
}

/* --- Character memory controls used by the standalone /chat page --- */
.memory-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(5, 4, 12, .76);
    backdrop-filter: blur(8px);
}

.memory-overlay[hidden] { display: none; }

.memory-panel {
    position: relative;
    width: min(560px, 100%);
    max-height: min(760px, 92vh);
    overflow: auto;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg-card);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .45);
}

.memory-panel__close {
    position: absolute;
    top: 12px;
    right: 16px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 28px;
    cursor: pointer;
}

.memory-panel__eyebrow {
    color: var(--accent2);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.memory-panel h2 {
    margin: 7px 34px 8px 0;
    font-size: 24px;
}

.memory-panel__hint,
.memory-panel__note {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.memory-panel__note {
    margin: 12px 0 0;
    text-align: center;
}

.memory-overview {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 12px;
}

.memory-overview strong {
    color: var(--text);
    font-size: 15px;
}

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: min(52vh, 520px);
    overflow: auto;
    margin: 20px 0;
    padding-right: 3px;
}

.memory-list__empty {
    padding: 28px 18px;
    border: 1px dashed var(--border);
    border-radius: 14px;
    color: var(--text-muted);
    text-align: center;
}

.memory-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-group__heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px;
}

.memory-group__heading h3 {
    margin: 0;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.memory-group__heading > span {
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(168, 85, 247, .12);
    color: var(--accent2);
    font-size: 11px;
    text-align: center;
}

.memory-group__items {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.memory-fact {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, .03);
}

.memory-fact__body {
    flex: 1;
    min-width: 0;
}

.memory-fact__text {
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

.memory-fact__meta {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 10px;
    line-height: 1.35;
}

.memory-fact button {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.memory-fact button:hover { color: #ff7f8d; }

.memory-panel__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.memory-action {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.memory-action--secondary {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, .03);
    color: var(--text);
}

.memory-action--danger {
    border: 1px solid rgba(255, 92, 112, .45);
    background: rgba(255, 92, 112, .1);
    color: #ff9aa6;
}

.chat-memory-suggestion {
    width: min(430px, 88%);
    margin: 10px auto;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: rgba(255, 255, 255, .03);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.4;
}

.chat-memory-suggestion > div {
    display: flex;
    gap: 8px;
    margin-top: 9px;
}

.chat-memory-suggestion button {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.chat-memory-suggestion button:first-child {
    border-color: var(--accent);
    background: rgba(124, 92, 231, .14);
}

.chat-system-note {
    width: fit-content;
    max-width: 90%;
    margin: 10px auto;
    color: rgba(220, 214, 235, .58);
    font-size: 12px;
    font-style: italic;
    text-align: center;
}

.msg--voice {
    align-self: flex-start;
    width: min(100%, 350px);
    max-width: 88%;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.voice-message {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px 11px 11px;
    border: 1px solid rgba(161, 134, 255, .3);
    border-radius: 18px 18px 18px 7px;
    background: linear-gradient(135deg, rgba(112, 78, 217, .31), rgba(73, 50, 130, .24));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 8px 20px rgba(36, 21, 77, .13);
}

.voice-play-button {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #a28bff, #785ce5);
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 5px 12px rgba(62, 38, 149, .32);
    transition: transform .18s ease, filter .18s ease;
}

.voice-play-button:hover {
    transform: scale(1.05);
    filter: brightness(1.08);
}

.voice-message-main {
    min-width: 0;
    flex: 1;
}

.voice-wave {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 31px;
    overflow: hidden;
    cursor: pointer;
    touch-action: none;
    outline: none;
}

.voice-wave:focus-visible {
    border-radius: 8px;
    box-shadow: 0 0 0 2px rgba(216, 206, 255, .45);
}

.voice-wave.is-seeking {
    cursor: grabbing;
}

.voice-wave-bar {
    display: block;
    width: 3px;
    height: var(--wave-height);
    min-height: 5px;
    border-radius: 99px;
    background: rgba(235, 229, 255, .4);
    transform-origin: center;
    transition: background .16s ease, transform .16s ease;
}

.voice-wave-bar.is-played {
    background: #d8ceff;
}

.voice-message--playing .voice-wave-bar {
    animation: voiceWaveBreath .95s ease-in-out infinite alternate;
}

.voice-message--playing .voice-wave-bar:nth-child(3n) { animation-delay: .18s; }
.voice-message--playing .voice-wave-bar:nth-child(4n) { animation-delay: .32s; }

@keyframes voiceWaveBreath {
    from { transform: scaleY(.72); }
    to { transform: scaleY(1.08); }
}

.voice-message-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    color: rgba(235, 229, 255, .64);
    font-size: 11px;
}

.voice-transcript-toggle {
    margin-left: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: rgba(232, 224, 255, .78);
    font: inherit;
    cursor: pointer;
}

.voice-transcript-toggle:hover { color: #fff; }

.voice-message-audio { display: none; }

.voice-transcript {
    margin: 7px 4px 0;
    padding: 8px 10px;
    border-left: 2px solid rgba(154, 126, 244, .62);
    color: var(--text2);
    font-size: 12px;
    line-height: 1.42;
    white-space: pre-wrap;
}

.voice-transcript[hidden] {
    display: none !important;
}

@media (max-width: 700px) {
    .memory-panel { padding: 24px 16px; border-radius: 20px; }
    .memory-panel__actions { grid-template-columns: 1fr; }
    .memory-list { max-height: 38vh; }
}

@media (max-width: 480px) {
    .chat-characters-btn,
    .chat-memory-btn {
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}


/* --- 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;
}
