/* ===== Таски · тёмная тема в стиле MAX (web.max.ru, [data-color-scheme=dark]) =====
   Токены взяты из реального CSS MAX (темы "space"/"simple"): тёмные поверхности,
   iOS-синий #007aff, плоские элементы без градиентов, Roboto. */
:root {
  --surface: #0f0f12;
  --primary: #17181c;
  --secondary: #25262d;
  --tertiary: rgba(255, 255, 255, 0.09);
  --text: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.8);
  --text-tertiary: rgba(255, 255, 255, 0.64);
  --text-mute: rgba(255, 255, 255, 0.4);
  --accent: #007aff;
  --accent-pressed: #0066d6;
  --positive: #2bc644;
  --negative: #ce4257;
  --divider: rgba(255, 255, 255, 0.12);
  --divider-soft: rgba(255, 255, 255, 0.06);
  --btn-secondary: #434455;
  --radius: 16px;
  --radius-sm: 12px;
}

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

html, body {
  height: 100%;
  height: 100dvh; /* iOS PWA: только dvh совпадает с видимым экраном, 100vh даёт чёрную полосу под нижней панелью */
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; }

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none !important; }

/* --- login --- */
#login-view { align-items: center; justify-content: center; padding: 24px; }
.login-box {
  width: 100%; max-width: 360px;
  background: var(--primary);
  border: 1px solid var(--divider);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.login-box h1 { font-size: 28px; margin-bottom: 4px; letter-spacing: 0.3px; }
.subtitle { color: var(--text-secondary); margin-bottom: 24px; font-size: 14px; }
.login-box input, .login-box button { width: 100%; margin-top: 12px; }

input {
  background: var(--secondary);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
}
input::placeholder { color: var(--text-mute); }
input:focus { border-color: var(--accent); }

button {
  background: var(--secondary);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 14px 16px;
  font-size: 16px;
  cursor: pointer;
}
button:active { opacity: 0.85; }
button.primary { background: var(--accent); border: none; color: #fff; font-weight: 600; }
button.primary:active { background: var(--accent-pressed); opacity: 1; }

.icon-btn { background: none; border: none; color: var(--text-tertiary); padding: 8px 10px; font-size: 20px; line-height: 1; }
.icon-btn:active { opacity: 0.7; }

.error { color: var(--negative); margin-top: 12px; font-size: 14px; }

/* --- главный экран: шапка и таб-бар закреплены, скроллится только середина --- */
#main-view { overflow: hidden; }
.main-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + constant(safe-area-inset-top));
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--primary);
  border-bottom: 1px solid var(--divider);
  flex: none;
}
.main-title { flex: 1; font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }

.tabs-content { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: calc(72px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.tab-panel { padding: 0 16px; }
.section-label {
  color: var(--text-mute);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 14px 4px 6px;
}

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--divider-soft);
  border-radius: 0;
  padding: 12px 4px;
  color: var(--text);
}
.list-row:active { background: var(--tertiary); opacity: 1; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-size: 16px; font-weight: 500; }
.row-sub { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-time { font-size: 12px; color: var(--text-mute); align-self: flex-start; margin-top: 4px; flex: none; }
.status-inline { display: flex; align-items: center; gap: 5px; color: var(--text-tertiary); }

/* аватар-заглушка (у Таски нет картинки — нейтральный серый круг с силуэтом) */
.avatar-stub {
  width: 44px; height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--tertiary);
  color: var(--text-tertiary);
  display: flex; align-items: center; justify-content: center;
}
.avatar-stub svg { width: 22px; height: 22px; }

/* --- нижняя панель вкладок ---
   Жёстко прижата к нижней кромке экрана (position: fixed; bottom: 0) и имеет явную
   высоту с учётом безопасной зоны — так она никогда не «всплывает» над чёрной
   полосой на iPhone (тот же приём, что победил эту проблему в старом taskie). */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--primary);
  border-top: 1px solid var(--divider);
  height: calc(52px + constant(safe-area-inset-bottom));
  height: calc(52px + env(safe-area-inset-bottom, 0px));
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
  z-index: 40;
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background: none; border: none;
  padding: 4px;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
  border-radius: 0;
  height: 100%;
}
.tab-btn:active { opacity: 0.7; }
.tab-btn.active { color: var(--accent); }
.tab-icon { width: 24px; height: 24px; flex: none; }

/* --- настройки (заглушка) --- */
.settings-stub {
  margin-top: 8px;
  background: var(--primary);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 24px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
  text-align: center;
}

/* --- настройки: уведомления --- */
.settings-card {
  margin-top: 8px;
  background: var(--primary);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 20px 16px;
}
.settings-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.settings-desc { color: var(--text-tertiary); font-size: 13px; line-height: 1.45; margin-bottom: 14px; }
.settings-btn { width: 100%; margin-top: 10px; }
button.ghost { background: none; color: var(--accent); border: 1px solid var(--divider); }
.push-status {
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-secondary);
}
.push-status.ok { color: var(--positive, #34c759); }

/* --- профиль агента --- */
.subpage-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 12px;
  padding-top: calc(12px + constant(safe-area-inset-top));
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--primary);
  border-bottom: 1px solid var(--divider);
  flex: none;
}
.subpage-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subpage-side { width: 36px; height: 36px; flex: none; }

.profile-content {
  flex: 1; overflow-y: auto; min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 24px;
}
.profile-card {
  width: 100%;
  max-width: 380px;
  background: var(--primary);
  border: 1px solid var(--divider);
  border-radius: 24px;
  padding: 28px 20px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.profile-avatar {
  width: 96px; height: 96px;
  background: var(--tertiary);
}
.profile-avatar svg { width: 48px; height: 48px; }
.profile-name { font-size: 22px; font-weight: 700; letter-spacing: 0.2px; }
.profile-role { color: var(--text-tertiary); font-size: 13px; }
.profile-status { font-size: 13px; }
.profile-desc {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin-top: 4px;
}
.profile-btn {
  width: 100%;
  max-width: 380px;
  padding: 16px;
  font-size: 16px;
}

/* --- чат --- */
#chat-view header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px;
  padding-top: calc(12px + constant(safe-area-inset-top));
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--primary);
  border-bottom: 1px solid var(--divider);
  flex: none;
}
.chat-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
#chat-view .avatar-stub { width: 36px; height: 36px; }
#chat-view .avatar-stub svg { width: 18px; height: 18px; }
.title { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 16px; }
.status { color: var(--text-tertiary); font-size: 12px; }
.status .dot, .status-inline .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--positive); margin-right: 5px;
}

#messages {
  flex: 1; overflow-y: auto; min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.bubble {
  max-width: 84%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: var(--secondary); border: 1px solid var(--divider); border-bottom-left-radius: 6px; }
.bubble.system { align-self: center; background: transparent; color: var(--text-mute); font-size: 12px; padding: 4px 8px; }
.bubble.divider { align-self: center; background: transparent; color: var(--text-mute); font-size: 12px; padding: 6px 12px; border: none; }
.bubble.typing { color: var(--text-mute); font-style: italic; }
.bubble-img {
  max-width: 100%; max-height: 220px;
  border-radius: 10px;
  display: block;
  margin-bottom: 6px;
}
.bubble-img:last-child { margin-bottom: 0; }

footer {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 16px;
  padding-bottom: calc(12px + constant(safe-area-inset-bottom));
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--divider-soft);
  flex: none;
}
.input-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; min-width: 0; }
textarea#input {
  flex: 1; min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 4px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.35;
  outline: none;
  resize: none;
  max-height: 148px;
  min-height: 40px;
  overflow-y: auto;
}
textarea#input::placeholder { color: var(--text-mute); }
textarea#input:focus { border: none; }
.attach-btn {
  flex: none;
  width: 40px; height: 40px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.attach-btn svg { width: 22px; height: 22px; }
.attach-btn:active { color: var(--text); transform: scale(0.94); }
.attachment-preview { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-preview.hidden { display: none; }
.thumb { position: relative; width: 56px; height: 56px; border-radius: 12px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-remove {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: rgba(0, 0, 0, 0.7); color: #fff;
  font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.send-btn {
  background: var(--accent); border: none;
  border-radius: 50%;
  width: 48px; height: 48px;
  padding: 0;
  color: #fff;
  font-size: 20px;
  flex: none;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:active { background: var(--accent-pressed); opacity: 1; }

#scroll-down-btn {
  position: fixed;
  right: 16px;
  bottom: 84px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#scroll-down-btn:active { background: var(--accent-pressed); opacity: 1; }

/* --- аватарки (фото профиля) --- */
.avatar-img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  background: var(--tertiary);
}
.profile-avatar { position: relative; cursor: pointer; }
.avatar-edit-badge {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 2px solid var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  z-index: 2;
}
.avatar-edit-badge svg { width: 16px; height: 16px; }
.avatar-edit-badge:active { transform: scale(0.94); background: rgba(0, 0, 0, 0.7); }

/* --- время у сообщений --- */
.msg-time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1;
  text-align: right;
  color: var(--text-mute);
  opacity: 0.85;
}
.bubble.user .msg-time { color: rgba(255, 255, 255, 0.75); }
.bubble.typing .msg-time { display: none; }

/* --- подсветка непрочитанных при входе в чат --- */
.bubble-unread { animation: unreadFade 2.2s ease-out forwards; }
@keyframes unreadFade {
  0% { box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(0, 122, 255, 0); }
}

/* --- бейджи непрочитанных в списке чатов --- */
.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.badge {
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-unread { font-weight: 600; color: var(--text); }

/* --- бейдж на вкладке «Чаты» --- */
.tab-btn { position: relative; }
.tab-badge {
  position: absolute;
  top: 2px;
  left: calc(50% + 8px);
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
