/* ==========================================================================
   Wchat — стили
   Палитра: насыщенная мята (#00d9a0 / #05c98f) + насыщенный лиловый (#8b5cf6 / #7c3aed)
   ========================================================================== */

:root {
  --mint: #00d9a0;
  --mint-dark: #00b988;
  --mint-light: #4be3b8;
  --lilac: #8b5cf6;
  --lilac-dark: #7c3aed;
  --lilac-light: #b18cfa;

  --bg-grad: linear-gradient(160deg, #e4fbf3 0%, #eef1fd 45%, #f1eafe 100%);
  --bg-solid: #f2f3fb;

  --surface: #ffffff;
  --surface-soft: #f7f6fd;
  --border: #e6e3f5;

  --text: #221b3a;
  --text-soft: #6b6485;
  --text-faint: #a29cc0;

  --danger: #ef4a6b;

  --shadow-sm: 0 2px 8px rgba(124, 58, 237, 0.08);
  --shadow-md: 0 8px 24px rgba(124, 58, 237, 0.12), 0 2px 6px rgba(0, 217, 160, 0.08);
  --shadow-lg: 0 20px 48px rgba(80, 40, 180, 0.16);
  --shadow-glow-mint: 0 6px 20px rgba(0, 217, 160, 0.35);
  --shadow-glow-lilac: 0 6px 20px rgba(139, 92, 246, 0.35);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --gradient-brand: linear-gradient(135deg, var(--mint) 0%, var(--lilac) 100%);
}

* { box-sizing: border-box; }

/* Атрибут hidden обязан побеждать любые .class { display: ... } правила —
   без этого элементы вроде .chat-window остаются видимыми, даже когда
   помечены как hidden (именно из-за этого "прилипала" шапка чата). */
[hidden] { display: none !important; }


html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-grad);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Экран приложения (не auth-страница) — жёстко прибиваем к вьюпорту,
   чтобы страницу нельзя было "оттянуть" свайпом на телефоне */
body.app-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

button, input, textarea {
  font-family: inherit;
}

a { color: inherit; text-decoration: none; }

/* ---------------- Scrollbars ---------------- */
* { scrollbar-width: thin; scrollbar-color: var(--lilac-light) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: var(--lilac-light); border-radius: 10px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }

.btn-primary {
  color: #fff;
  background: var(--gradient-brand);
  box-shadow: var(--shadow-glow-lilac);
}
.btn-primary:hover { box-shadow: 0 10px 28px rgba(139, 92, 246, 0.45); }

.btn-ghost {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #eeeafd; }
.btn-danger-text { color: var(--danger); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface-soft);
  color: var(--text-soft);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: #eeeafd; transform: translateY(-1px); }

/* ---------------- Fields ---------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
}
.field input, .field textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  background: var(--surface-soft);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  resize: none;
}
.field input:focus, .field textarea:focus {
  border-color: var(--lilac);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.14);
  background: #fff;
}
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  margin-bottom: 18px;
}
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--lilac); }

/* ==========================================================================
   AUTH PAGE
   ========================================================================== */
.auth-body {
  overflow: auto;
  min-height: 100vh;
}
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 6px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-logo img { border-radius: 10px; }
.auth-subtitle {
  color: var(--text-faint);
  font-size: 14px;
  margin: 0 0 28px;
}
.auth-error {
  background: rgba(239, 74, 107, 0.1);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 18px;
}
.auth-form { margin-top: 4px; }

/* ==========================================================================
   APP LAYOUT
   ========================================================================== */
.app {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.sidebar {
  width: 340px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
}
.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
#btnNotify {
  font-size: 17px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; box-shadow: var(--shadow-sm); }
.brand-name {
  font-size: 20px;
  font-weight: 800;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sidebar-search { padding: 0 18px 12px; }
.sidebar-search input {
  width: 100%;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sidebar-search input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 4px rgba(0, 217, 160, 0.14);
}

.user-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 10px;
}
.empty-hint {
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  padding: 30px 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
  margin-bottom: 2px;
}
.user-row:hover { background: var(--surface-soft); }
.user-row.active { background: linear-gradient(135deg, rgba(0,217,160,0.12), rgba(139,92,246,0.12)); }
.user-row-info { flex: 1; min-width: 0; }
.user-row-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-row-username {
  font-size: 13px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-row-admin-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--lilac-dark);
  background: rgba(139, 92, 246, 0.12);
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
}
.unread-badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--gradient-brand);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow-mint);
}

.sidebar-footer {
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--border);
}

/* ---------------- Avatars ---------------- */
.avatar {
  border-radius: 50%;
  background: var(--gradient-brand);
  background-size: cover;
  background-position: center;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}
.avatar-sm { width: 40px; height: 40px; font-size: 16px; }
.avatar-lg { width: 84px; height: 84px; font-size: 32px; }

.avatar-upload {
  position: relative;
  cursor: pointer;
  overflow: hidden;
}
.avatar-upload-overlay {
  position: absolute;
  inset: 0;
  background: rgba(34, 27, 58, 0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.avatar-upload:hover .avatar-upload-overlay { opacity: 1; }

/* ---------------- Chat area ---------------- */
.chat-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-solid);
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  text-align: center;
  gap: 12px;
  padding: 20px;
}
.placeholder-cloud {
  font-size: 64px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 16px rgba(139, 92, 246, 0.25));
}

.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-shrink: 0;
}
.chat-header-info { min-width: 0; }
.chat-header-name { font-size: 16px; font-weight: 700; }
.chat-header-username { font-size: 13px; color: var(--text-faint); }
.only-mobile { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  margin-bottom: 6px;
}
.msg-row.mine { justify-content: flex-end; }
.msg-bubble {
  max-width: min(70%, 480px);
  padding: 11px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg-row.theirs .msg-bubble {
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-row.mine .msg-bubble {
  background: var(--gradient-brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 10px;
  opacity: 0.65;
  margin-top: 4px;
  display: block;
  text-align: right;
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.composer input {
  flex: 1;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer input:focus {
  border-color: var(--lilac);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.14);
}
.btn-send {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  flex-shrink: 0;
}

/* ---------------- Modals ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(34, 27, 58, 0.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 8px;
}
.modal-header h3 { margin: 0; font-size: 18px; font-weight: 800; }
.modal-body { padding: 16px 24px 26px; }
.modal-error {
  background: rgba(239, 74, 107, 0.1);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}
.profile-username { color: var(--text-faint); font-weight: 600; }
.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 22px 0 18px;
}
.modal-subheading {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-soft);
}
.modal-success {
  background: rgba(0, 217, 160, 0.12);
  color: var(--mint-dark);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ==========================================================================
   RESPONSIVE — телефоны
   ========================================================================== */
@media (max-width: 780px) {
  .sidebar {
    width: 100%;
    border-right: none;
  }
  .chat-area { display: none; }

  .app.view-chat .sidebar { display: none; }
  .app.view-chat .chat-area { display: flex; }

  .only-mobile { display: inline-flex; }
  .messages { padding: 16px; }
  .composer { padding: 12px 14px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .chat-header { padding: 12px 14px; padding-top: max(12px, env(safe-area-inset-top)); }
  .msg-bubble { max-width: 82%; }
}

@media (min-width: 781px) {
  .chat-area { display: flex !important; }
}
