/* ===== Фирменная тема MAX (точные токены из web.max.ru, тёмная) ===== */
:root {
  --bg: #17181c;
  --bg-secondary: #25262d;
  --bg-elevated: #1e1f25;
  --bg-input: #2c2d35;
  --text: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-tertiary: rgba(255, 255, 255, 0.4);
  --icon: rgba(255, 255, 255, 0.68);
  --accent: #a473ff;                /* фирменный фиолетовый MAX */
  --accent-pressed: #8f5cf0;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #a473ff 100%);
  --separator: rgba(255, 255, 255, 0.08);
  --bubble-in: #25262d;
  --bubble-out: #6c4fb0;
  --danger: #ff5c5c;
  --online: #4bd06a;
  --radius: 14px;
  --header-h: 56px;
  --tabbar-h: 58px;
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  font-size: 16px;
}

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.hidden { display: none !important; }

#screens { flex: 1; position: relative; overflow: hidden; }

/* ---- экран (push-стек) ---- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: slideIn 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.screen.root { animation: fade 0.18s ease; }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* когда таб-бар виден, у корневых экранов резервируем место снизу */
.screens-with-tabbar .screen.root { bottom: var(--tabbar-h); }

/* ---- шапка ---- */
.header {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--separator);
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
}
.header .icon-btn { flex-shrink: 0; }
.header-title { font-size: 17px; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-sub { font-size: 12px; color: var(--text-secondary); font-weight: 400; }
.header-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.25; }
.header-clickable { cursor: pointer; display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.header-action { color: var(--accent); font-weight: 500; font-size: 15px; background: none; border: none; padding: 8px; cursor: pointer; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* ---- строка поиска ---- */
.search-wrap { padding: 8px 12px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-secondary); border-radius: 10px; padding: 0 12px; }
.search-box .search-icon { color: var(--text-tertiary); display: flex; flex-shrink: 0; }
.search-box .search-icon svg { width: 18px; height: 18px; }
.search-input { flex: 1; background: none; border: none; color: var(--text); font-size: 16px; padding: 10px 0; font-family: inherit; }
.search-input:focus { outline: none; }
.search-input::placeholder { color: var(--text-tertiary); }

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--icon); cursor: pointer;
  border-radius: 50%;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---- контент со скроллом ---- */
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ---- аватар ---- */
.avatar {
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent-grad);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 500;
  overflow: hidden;
  position: relative;
}
.avatar-initials { position: relative; z-index: 0; }
.avatar img {
  position: absolute; inset: 0; z-index: 1;
  width: 100%; height: 100%; object-fit: cover;
}
.avatar.sm { width: 48px; height: 48px; font-size: 18px; }
.avatar.lg { width: 96px; height: 96px; font-size: 36px; }
.avatar.xl { width: 112px; height: 112px; font-size: 42px; }
.avatar .online-dot {
  position: absolute; right: 0; bottom: 0;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--online); border: 2.5px solid var(--bg);
}

/* ---- строки списка (чаты/контакты) ---- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; min-height: 68px;
  cursor: pointer;
}
.list-row:active { background: var(--bg-secondary); }
.list-row .row-body { flex: 1; min-width: 0; }
.list-row .row-top { display: flex; align-items: baseline; gap: 8px; }
.list-row .row-name { font-size: 16px; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .row-time { font-size: 12px; color: var(--text-tertiary); flex-shrink: 0; }
.list-row .row-preview { font-size: 14px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.list-row .badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; margin-left: 6px;
}
.row-divider { height: 1px; background: var(--separator); margin-left: 74px; }

/* ---- секции настроек ---- */
.section { margin: 14px 0; background: var(--bg-secondary); border-radius: var(--radius); overflow: hidden; }
.section-title { font-size: 13px; color: var(--text-secondary); padding: 6px 16px; text-transform: none; }
.settings-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; min-height: 52px; cursor: pointer;
  border-bottom: 1px solid var(--separator);
}
.section .settings-row:last-child { border-bottom: none; }
.settings-row:active { background: rgba(255,255,255,0.04); }
.settings-row .sr-icon { color: var(--accent); width: 24px; height: 24px; display: flex; flex-shrink: 0; }
.settings-row .sr-icon svg { width: 22px; height: 22px; }
.settings-row .sr-label { flex: 1; font-size: 16px; }
.settings-row .sr-value { color: var(--text-secondary); font-size: 15px; }
.settings-row .sr-chevron { color: var(--text-tertiary); display: flex; }
.settings-row .sr-chevron svg { width: 20px; height: 20px; }
.settings-row.danger .sr-label, .settings-row.danger .sr-icon { color: var(--danger); }

.pad { padding: 0 16px; }
.muted { color: var(--text-secondary); font-size: 13px; padding: 8px 16px; line-height: 1.4; }

/* ---- toggle ---- */
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 13px;
  background: rgba(255,255,255,0.18); transition: 0.2s;
}
.switch .track::before {
  content: ''; position: absolute; height: 22px; width: 22px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: 0.2s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* ---- сегмент (Все/Контакты/Никто) ---- */
.segment { display: flex; gap: 6px; padding: 6px 16px 14px; }
.segment button {
  flex: 1; padding: 8px; border-radius: 10px; border: 1px solid var(--separator);
  background: transparent; color: var(--text-secondary); font-size: 13px; cursor: pointer;
  font-family: inherit;
}
.segment button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- профиль (шапка) ---- */
.profile-head { display: flex; flex-direction: column; align-items: center; padding: 24px 16px 16px; gap: 12px; }
.avatar.avatar-editable { cursor: pointer; }
.avatar.avatar-editable::after {
  content: ''; position: absolute; right: 0; bottom: 0; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/></svg>') center/18px no-repeat;
  border: 2.5px solid var(--bg);
}
.profile-name { font-size: 22px; font-weight: 500; text-align: center; }
.profile-sub { font-size: 14px; color: var(--text-secondary); text-align: center; }

/* ---- инпуты / формы ---- */
.field { padding: 10px 16px; }
.field label { display: block; font-size: 13px; color: var(--accent); margin-bottom: 6px; }
.input {
  width: 100%; background: var(--bg-input); border: none; border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-size: 16px; font-family: inherit;
}
.input:focus { outline: 1px solid var(--accent); }
textarea.input { resize: none; min-height: 44px; }

.btn {
  display: block; width: calc(100% - 32px); margin: 16px; padding: 14px;
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 500; cursor: pointer; font-family: inherit;
}
.btn:active { background: var(--accent-pressed); }
.btn.secondary { background: var(--bg-secondary); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

/* ---- чат ---- */
#messages-scroll { display: flex; flex-direction: column; gap: 4px; padding: 12px; }
.bubble {
  max-width: 80%; padding: 8px 12px; border-radius: 16px; font-size: 15px;
  line-height: 1.35; word-wrap: break-word; white-space: pre-wrap; position: relative;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-bottom-right-radius: 5px; }
.bubble .b-sender { font-size: 12px; color: var(--accent); font-weight: 500; margin-bottom: 2px; }
.bubble .b-time { font-size: 11px; color: rgba(255,255,255,0.5); text-align: right; margin-top: 2px; }
.bubble img { max-width: 100%; border-radius: 10px; margin-top: 4px; display: block; }
.bubble a.file-link { color: #fff; text-decoration: underline; display: inline-block; margin-top: 4px; }
.bubble video { max-width: 100%; max-height: 320px; border-radius: 10px; margin-top: 4px; display: block; background: #000; }

/* ---- голосовое сообщение (как в MAX): кнопка + waveform + время ---- */
.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 180px; padding: 2px 0; }
.voice-play {
  width: 36px; height: 36px; border-radius: 50%; border: none; flex-shrink: 0;
  background: rgba(255,255,255,0.18); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.bubble.out .voice-play { background: rgba(255,255,255,0.25); }
.voice-play svg { width: 16px; height: 16px; }
.voice-wave-wrap { position: relative; flex: 1; height: 26px; min-width: 90px; }
.voice-wave { position: absolute; inset: 0; }
.voice-wave span {
  position: absolute; bottom: 0; width: 3px; margin-left: -1.5px; border-radius: 1.5px;
  background: rgba(255,255,255,0.35); min-height: 3px;
}
.voice-wave-fg { clip-path: inset(0 100% 0 0); }
.voice-wave-fg span { background: #fff; }
.voice-time { font-size: 11px; color: rgba(255,255,255,0.7); flex-shrink: 0; min-width: 30px; text-align: right; }

.composer {
  position: relative;
  display: flex; align-items: flex-end; gap: 4px; padding: 8px;
  background: var(--bg-elevated); border-top: 1px solid var(--separator);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
/* живое превью камеры при записи видео-кружка — видно, что снимаешь */
.rec-preview {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%) scaleX(-1);
  width: 160px; height: 160px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--accent); box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  background: #000; z-index: 20;
}
.rec-preview.hidden { display: none; }
.composer textarea {
  flex: 1; resize: none; max-height: 120px; border: none; border-radius: 20px;
  padding: 10px 16px; background: var(--bg-input); color: var(--text);
  font-size: 15px; font-family: inherit;
}
.composer textarea:focus { outline: none; }
.composer .send-btn {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.composer .send-btn svg { width: 22px; height: 22px; }
.composer .send-btn:disabled { opacity: 0.5; }
.composer .rec-btn.recording { color: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
.composer .rec-timer { font-size: 12px; color: var(--danger); align-self: center; min-width: 34px; text-align: center; }
.composer .rec-timer.hidden { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---- таб-бар ---- */
#tabbar {
  height: var(--tabbar-h);
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; color: var(--text-tertiary); cursor: pointer; font-family: inherit;
}
.tab.active { color: var(--accent); }
.tab-icon svg { width: 26px; height: 26px; }
.tab-label { font-size: 11px; }

/* ---- прочее ---- */
.empty-hint { color: var(--text-secondary); text-align: center; padding: 40px 24px; font-size: 15px; line-height: 1.5; }
.loading { color: var(--text-tertiary); text-align: center; padding: 30px; font-size: 14px; }
.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 16px); left: 50%; transform: translateX(-50%);
  background: #000; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px;
  z-index: 100; opacity: 0; transition: opacity 0.2s; pointer-events: none; max-width: 80%;
}
.toast.show { opacity: 0.92; }
