:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #22263a;
    --accent: #5b8ef0;
    --accent2: #7c5ce8;
    --text: #e8ecf4;
    --text-muted: #7a82a0;
    --bubble-in: #1e2235;
    --border: rgba(255,255,255,0.07);
    --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100dvh; }

body {
    font-family: 'Manrope', sans-serif;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    height: 100dvh; padding: 10px;
}

body::before {
    content: ''; position: fixed; inset: 0;
    background:
        radial-gradient(ellipse 60% 50% at 20% 30%, rgba(91,142,240,0.08) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 70%, rgba(124,92,232,0.07) 0%, transparent 70%);
    pointer-events: none;
}

/* ── Layout ── */
.chat-container {
    width: 100%; max-width: 800px; height: calc(100dvh - 20px);
    background: var(--surface); border-radius: 35px 35px 5px 5px;
    border: 1px solid var(--border); box-shadow: var(--shadow);
    display: flex; flex-direction: column; overflow: hidden;
}

/* ── Header ── */
/* Кликабельная шапка — не ломает верстку */
.header-click-area {
    display: flex;
    align-items: center;
    gap: 20px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity .2s;
    width: 100%;
}
.header-click-area:hover {
    opacity: .85;
}
.header-click-area .header-avatar,
.header-click-area .header-info {
    pointer-events: none;  /* чтобы клик проходил через них */
}
.chat-header {
    display: flex; align-items: center; gap: 1px;
    padding: 20px 20px; background: rgba(26,29,39,0.95);
	background:#224466;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px); flex-shrink: 0;
}
.header-avatar {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.header-info .title { font-size: 1em; font-weight: 700; color: var(--text); }
.header-info .status {
    font-size: .75em; color: #4cd964;
    display: flex; align-items: center; gap: 5px; margin-top: 2px;
}
.status-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #4cd964;
    animation: pulse-green 2s infinite;
}
@keyframes pulse-green { 0%,100%{opacity:1} 50%{opacity:.25} }

/* ── Messages ── */
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px;
    scroll-behavior: smooth; min-height: 0;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 1px; }

.message {
    display: flex; flex-direction: column; margin-bottom: 10px;
    animation: fadeUp .3s ease;
}
@keyframes fadeUp { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:none} }

.message-name {
    font-size: .72em; font-weight: 700; color: var(--accent);
    text-transform: uppercase; letter-spacing: .8px;
    margin-bottom: 5px;
    display: flex; align-items: center; justify-content: space-between;
    width: 100%;
}
.message:has(.bubble-audio) .message-name {
    width: 76px;
}
/* ── Bubble ── */
.message-bubble {
    background: var(--bubble-in); border-radius: 1px 1px 1px 1px;
    padding: 10px 10px 6px 10px; max-width: 100%;
    border: 1px solid var(--border); overflow: hidden;
}
.message-bubble.pending { opacity: .7; }

/* Аудио-пузырь — прозрачный, без рамки */
.message-bubble.bubble-audio {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    overflow: visible;
    max-width: 100px;
}

.message-text {
    font-size: .93em; line-height: 1; color: var(--text);
    white-space: pre-wrap; word-break: break-word;
	padding: 3px 5px 6px 5px;
}

/* ── Media wrap ── */
.message-media-wrap {
    border-radius: 1px; overflow: hidden;
    margin-bottom: 5px; position: relative;
    background: rgba(0,90,120,.75); width: 100%;
}
.message-media-wrap img {
    display: block; width: 100%; height: auto;
    border-radius: 1px; cursor: pointer; transition: opacity .2s;
}
.message-media-wrap img:hover { opacity: .9; }
.message-media-wrap video {
    display: block; width: 100%; height: auto; border-radius: 1px;
}

/* Аудио — убираем фон обёртки */
.message-media-wrap.media-audio {
    background: transparent;
    border-radius: 0;
    overflow: visible;
    margin: 0;
    width: auto;
}

/* ── Спиннер поверх видео ── */
.media-upload-overlay {
    position: absolute; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px; backdrop-filter: blur(2px);
}
.media-spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,.2);
    border-top-color: #fff; border-radius: 50%;
    animation: spin .75s linear infinite;
}
@keyframes spin { to{transform:rotate(360deg)} }

/* ── Прогресс загрузки ── */
.upload-progress-bar {
    height: 3px; background: rgba(255,255,255,.1);
    border-radius: 3px; margin-top: 8px; overflow: hidden;
}

.bubble-audio .upload-progress-bar { margin: -47px 0 0 70px; width: 680px;}

.upload-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 3px; transition: width .2s; width: 0%;
}

/* ── Аудио-плеер: только кнопка с пульсом ── */
.message-audio {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 76px;
    height: 76px;
    padding: 0;
    margin: 8px 0;
    background: transparent;
    border: none;
}

.audio-play-btn {
    -webkit-tap-highlight-color: transparent;
    outline: none;
    width: 40px; height: 40px; min-width: 40px;
    border-radius: 20%;
    background: linear-gradient(135deg, var(--accent2), var(--accent));
    border: none; color: #fff; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    position: relative; overflow: visible; flex-shrink: 0;
    box-shadow: 0 0 20px rgba(124,92,232,0.5);
    transition: transform .15s, box-shadow .15s;
    animation: pulse-glow 2s ease-in-out infinite;
}
.audio-play-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 30px rgba(124,92,232,0.8);
}
.audio-play-btn:active { transform: scale(.95); }

/* Пульсирующий круг вокруг кнопки */
.audio-play-btn::after {
    content: '';
    position: absolute; inset: -6px; border-radius: 50%;
    border: 2px solid rgba(124,92,232,0.4);
    animation: ripple 2s ease-out infinite;
}

@keyframes pulse-glow {
    0%,100% { box-shadow: 0 0 15px rgba(124,92,232,0.5); }
    50%      { box-shadow: 0 0 28px rgba(124,92,232,0.85); }
}
@keyframes ripple {
    0%   { transform: scale(1);   opacity: .6; }
    100% { transform: scale(1.6); opacity: 0;  }
}

.audio-play-btn svg {
    width: 18px; height: 18px; display: block;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
    position: relative; z-index: 1;
}

/* Прогресс и время — скрыты (только кнопка) */
.audio-right   { display: none; }
.audio-time    { display: none; }
.audio-progress { display: none; }

/* ── Время сообщения ── */
.message.pending-upload .message-time {
    display: none;
}

.message-time {
    font-size: .68em;
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

/* ── Input area ── */
.chat-input-area {
    padding: 14px 16px; background: rgba(26,29,39,.98);
    border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-input-area {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
}
/* ── Индикатор записи ── */
.rec-indicator {
    display: none; align-items: center; gap: 8px;
    background: rgba(255,50,50,.1); border: 1px solid rgba(255,50,50,.2);
    border-radius: 12px; padding: 7px 12px;
    margin-bottom: 10px; animation: fadeUp .2s ease;
}
.rec-indicator.visible { display: flex; }
.rec-dot {
    width: 8px; height: 8px; border-radius: 50%; background: #ff3232; flex-shrink: 0;
    animation: pulse-red 1s ease-in-out infinite;
}
@keyframes pulse-red { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.5;transform:scale(.75)} }
.rec-label { font-size: .82em; color: #ff8080; font-weight: 600; flex: 1; }
.rec-time { font-size: .78em; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.rec-cancel {
    background: none; border: none; color: #ff6b6b; cursor: pointer;
    font-size: 12px; font-family: 'Manrope', sans-serif; font-weight: 600;
    padding: 3px 8px; border-radius: 6px; transition: background .2s;
}
.rec-cancel:hover { background: rgba(255,107,107,.2); }

/* ── Превью файла ── */
.file-preview-strip {
    display: none; align-items: center; gap: 10px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 12px; padding: 8px 12px;
    margin-bottom: 10px; animation: fadeUp .2s ease;
}
.file-preview-strip.visible { display: flex; }

.preview-thumb {
    width: 56px; height: 56px; border-radius: 10px;
    object-fit: cover; flex-shrink: 0;
}
.preview-video-wrap {
    position: relative; width: 56px; height: 56px;
    border-radius: 10px; overflow: hidden; background: #000; flex-shrink: 0;
}
.preview-video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-video-play {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    width: 20px; height: 20px; pointer-events: none;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,.7));
}
.preview-icon-box {
    width: 56px; height: 56px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; flex-shrink: 0;
}
.preview-remove {
    background: rgba(255,107,107,.12); border: none; color: #ff6b6b;
    cursor: pointer; padding: 6px 10px; border-radius: 8px;
    font-size: 13px; font-family: 'Manrope', sans-serif; font-weight: 600;
    margin-left: auto; flex-shrink: 0; transition: background .2s;
}
.preview-remove:hover { background: rgba(255,107,107,.25); }

/* ── Input row ── */
.input-row { display: flex; gap: 8px; align-items: center;}
.input-wrap { flex: 1; position: relative; margin: 10px 10px 0px 0px;}

#messageInput {
    width: 100%; padding: 11px 182px 11px 16px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; color: var(--text);
    font-family: 'Manrope', sans-serif; font-size: .93em;
    outline: none; transition: border-color .2s, box-shadow .2s;
}
#messageInput:focus {
    border-color: rgba(91,142,240,.5);
    box-shadow: 0 0 0 3px rgba(91,142,240,.1);
}
#messageInput::placeholder { color: var(--text-muted); }

.input-inner-btns {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    display: flex; align-items: center; gap: 2px;
}
.icon-btn {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 0; border-radius: 8px;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    transition: color .2s, background .15s; flex-shrink: 0; overflow: hidden;
}
.icon-btn:hover { color: var(--accent); background: rgba(91,142,240,.1); }
.icon-btn.active { color: #ff5050; }
.icon-btn svg { width: 24px; height: 24px; pointer-events: none; display: block; flex-shrink: 0; }

#fileInput { display: none; }

	/* ── SEND BUTTON ── */
	.send-btn {
		width: 50px; height: 50px; min-width: 40px; border-radius: 10%; margin-top:5px;
		background: linear-gradient(135deg, var(--accent), var(--accent2));
		border: none; color: white; cursor: pointer;
		display: flex; align-items: center; justify-content: center;
		flex-shrink: 0; transition: transform .15s, box-shadow .2s, opacity .2s;
		box-shadow: 0 4px 16px rgba(91,142,240,.35);
	}

	.send-btn:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 6px 24px rgba(91,142,240,.5); }
	.send-btn:active:not(:disabled) { transform: scale(.95); }
	.send-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
	.send-btn svg { width: 24px; height: 24px; }

.btn-spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: white; border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* ── Toast ── */
.toast {
    position: fixed; bottom: 80px; left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: #e03535; color: #fff;
    padding: 10px 20px; border-radius: 20px;
    font-size: .83em; font-weight: 600;
    opacity: 0; pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 999; white-space: nowrap;
    max-width: calc(100vw - 40px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Lightbox ── */
.lightbox {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.88); z-index: 1000;
    align-items: center; justify-content: center;
    padding: 20px; cursor: zoom-out; backdrop-filter: blur(8px);
}
.lightbox.open { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.lightbox img {
    max-width: 95vw;
    max-height: 92vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.6);
}

@media (max-width: 768px) {
    body { padding: 0; }
    .chat-container { border-radius: 0; height: 100dvh; }
    .message-bubble { max-width: 95%; }
    .message-bot .message-bubble { max-width: 100%; width: 100%; }
}

/* Многострочный ввод */
#messageInput {
    resize: none;
    min-height: 50px;
    max-height: 150px;
    overflow-y: hidden;
    line-height: 1.4;
    padding-top: 12px;
    padding-bottom: 12px;
	border-radius: 10px 10px 10px 10px ;
}

#messageInput:focus {
    border-color: rgba(91,142,240,.5);
    box-shadow: 0 0 0 3px rgba(91,142,240,.1);
}

/* ── Сообщение бота ── */
.message-bot .message-name { color: var(--accent2); }

.bot-text {
    font-size: .93em;
    line-height: 1.55;
    color: var(--text);
}
.bot-text b  { font-weight: 700; }
.bot-text i  { font-style: italic; }
.bot-text code {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: monospace;
    font-size: .92em;
}
.bot-text a {
    color: var(--accent);
    text-decoration: none;
}
.bot-text a:hover { text-decoration: underline; }

/* ── Инлайн кнопки бота ── */
.bot-buttons {
    margin: 10px 0px 7px 0px;
	border-radius:4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.bot-buttons-row {
    display: flex;
    gap: 6px;
}
.bot-btn {
    flex: 1;
    background: rgba(91,142,240,0.12);
    border: 1px solid rgba(91,142,240,0.3);
    color: var(--text);
    border-radius: 4px;
    padding: 8px 10px;
    font-family: 'Manrope', sans-serif;
    font-size: .83em;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
    text-align: center;
    line-height: 1.3;
}
.bot-btn:hover {
    background: rgba(91,142,240,0.25);
    border-color: rgba(91,142,240,0.6);
}
.bot-btn:active {
    transform: scale(.97);
}
.bot-text br { line-height: 1.5; }


/* ── Аудио с обложкой ── */
/* Добавьте в конец styles.css */

.message-audio.has-cover {
    width: 180px;
    height: auto;
    display: block;
    padding: 0;
    background: transparent;
    border: none;
}

.audio-cover-wrap {
    position: relative;
    width: 180px;
    height: 180px;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
}

.audio-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 12px;
    transition: filter .2s;
}

.audio-cover-wrap:hover .audio-cover-img {
    filter: brightness(0.75);
}

/* Кнопка поверх обложки */
.audio-play-over {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    border: 1.5px solid rgba(255,255,255,0.3);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: transform .15s, background .2s;
    animation: none; /* отключаем пульс для этой кнопки */
    box-shadow: none;
}
.audio-play-over:hover { transform: scale(1.1); background: rgba(0,0,0,0.75); }
.audio-play-over:active { transform: scale(.93); }
.audio-play-over.playing { background: rgba(91,142,240,0.7); }
.audio-play-over svg { width: 16px; height: 16px; }

/* Название и автор поверх обложки */
.audio-cover-info {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 10px 10px 30px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    border-radius: 12px 12px 0 0;
}
.audio-cover-title {
    font-size: .82em;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.audio-cover-artist {
    font-size: .72em;
    color: rgba(255,255,255,0.75);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#soundToggle, #modeToggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Manrope', sans-serif;
    font-size: 20px;
    font-weight: 700;
    gap: 2px;
    transition: color .2s, opacity .2s;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}
#soundToggle { margin-right: 4px; width: 30px; flex-shrink: 0; }
#modeToggle  { margin-left: auto; width: 30px; flex-shrink: 0; }

#soundToggle:hover, #modeToggle:hover { color: var(--accent); }
#soundToggle:focus, #modeToggle:focus,
#soundToggle:focus-visible, #modeToggle:focus-visible { outline: none; box-shadow: none; }

#soundToggle.sound-off { opacity: .4; }
#modeToggle.bot-active { color: var(--accent2); }

.header-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius:4px;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    flex-shrink: 0;
    text-decoration: none;
    transition: color .2s;
}
.header-icon-btn:hover { color: var(--accent); }

.message-bot .message-bubble {
    max-width: 100%;
    width: 100%;
}