:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #f4f4f5;
  --text: #0f0f0f;
  --muted: #707579;
  --line: #e7e8ec;
  --brand: #3390ec;
  --brand-dark: #2b7cd3;
  --brand-soft: #ebf3fb;
  --accent: #4fae4e;
  --bubble-in: #ffffff;
  --bubble-out: #effdde;
  --danger: #e25555;
  --hover: #f4f4f5;
  --shadow: 0 1px 2px rgba(16, 35, 47, 0.12);
  --chat-bg: #d9e3ea;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--panel-soft);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ---------- AUTH ---------- */

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 0%, rgba(51, 144, 236, 0.16), transparent 55%),
    linear-gradient(180deg, #f2f7fc 0%, #eef1f4 100%);
}

.auth-card {
  width: min(400px, 100%);
  padding: 32px 30px 28px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 60px rgba(16, 35, 47, 0.12);
}

.auth-card img {
  width: 86px;
  height: 86px;
  margin-bottom: 14px;
}

.auth-card .eyebrow {
  text-align: center;
}

.auth-card h1 {
  margin-bottom: 22px;
  font-size: 26px;
  font-weight: 600;
}

.auth-card form,
.auth-actions {
  display: grid;
  gap: 10px;
  text-align: left;
}

.auth-card input[type="text"],
.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input:not([type]) {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(51, 144, 236, 0.16);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.check-row input {
  margin-top: 2px;
  accent-color: var(--brand);
}

.auth-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-actions {
  grid-template-columns: 1fr 1fr;
  margin-top: 4px;
}

.auth-error {
  min-height: 22px;
  margin: 2px 0 0;
  color: var(--danger);
  font-weight: 600;
  text-align: center;
}

/* ---------- APP SHELL ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--panel-soft);
}

.sidebar {
  position: relative;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 8px 12px;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand img {
  width: 36px;
  height: 36px;
}

.brand strong {
  font-size: 19px;
  font-weight: 600;
}

/* Двухъярусный логотип: SWIPA + мелкое «light» под ним */
.brand-word {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.brand .brand-word {
  align-items: flex-start;
}

.brand-light {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.32em;
  color: var(--brand);
}

.side-head-actions {
  display: flex;
  gap: 2px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  background: transparent;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--hover);
  color: var(--brand);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

/* search */
.search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 6px;
}

.search svg {
  position: absolute;
  left: 13px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 42px;
  padding: 0 14px 0 40px;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid transparent;
  border-radius: 22px;
  outline: 0;
  transition: background 0.15s, border-color 0.15s;
}

.search input:focus {
  background: #fff;
  border-color: var(--brand);
}

/* nav tabs (folders) */
.nav-tabs {
  display: flex;
  gap: 4px;
  padding: 0 6px 6px;
  border-bottom: 1px solid var(--line);
}

.nav-tabs button {
  position: relative;
  padding: 8px 14px 12px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px 8px 0 0;
}

.nav-tabs button:hover {
  background: var(--hover);
}

.nav-tabs button.active {
  color: var(--brand);
}

.nav-tabs button.active::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--brand);
}

/* thread list */
.thread-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
  padding: 4px 4px 70px;
}

.thread {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 11px;
  padding: 8px 9px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border-radius: 12px;
  transition: background 0.12s;
}

.thread > span:nth-child(2) {
  min-width: 0;
  flex: 1 1 auto;
}

.thread:hover {
  background: var(--hover);
}

.thread.active {
  background: var(--brand);
  color: #fff;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  color: #fff;
  font-weight: 600;
  font-size: 19px;
  background: linear-gradient(135deg, #6bb1f3, var(--brand));
  border-radius: 50%;
  overflow: hidden;
}

/* Telegram-style varied avatar colors */
.thread:nth-child(7n + 1) .avatar { background: linear-gradient(135deg, #ff9a6c, #ff6c8a); }
.thread:nth-child(7n + 2) .avatar { background: linear-gradient(135deg, #6bb1f3, #3390ec); }
.thread:nth-child(7n + 3) .avatar { background: linear-gradient(135deg, #8fd36c, #4fae4e); }
.thread:nth-child(7n + 4) .avatar { background: linear-gradient(135deg, #c08cf0, #8b5cf0); }
.thread:nth-child(7n + 5) .avatar { background: linear-gradient(135deg, #f7c66b, #f0a020); }
.thread:nth-child(7n + 6) .avatar { background: linear-gradient(135deg, #6ad0d6, #18a3ac); }
.thread:nth-child(7n + 7) .avatar { background: linear-gradient(135deg, #f590b6, #e0518a); }

.thread p {
  margin: 0;
  font-weight: 600;
  font-size: 15px;
}

.thread p,
.thread em,
.thread > span:nth-child(2) > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread > span:nth-child(2) > span {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  color: var(--muted);
}

.thread em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13.5px;
  font-style: normal;
}

.thread small {
  align-self: flex-start;
  margin-left: auto;
  margin-top: 3px;
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--muted);
}

.thread.active p,
.thread.active em,
.thread.active small,
.thread.active > span:nth-child(2) > span {
  color: #fff;
}

.thread.active em,
.thread.active small {
  color: rgba(255, 255, 255, 0.82);
}

/* empty states */
.empty-state {
  display: grid;
  gap: 6px;
  margin: 8px;
  padding: 18px;
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 12px;
}

.empty-state strong {
  color: var(--text);
}

.empty-state.center {
  place-items: center;
  margin: auto;
  padding: 14px 22px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.32);
  border-radius: 16px;
  backdrop-filter: blur(2px);
}

.empty-state.center strong {
  color: #fff;
}

/* account footer */
.account {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 6px;
  padding: 10px;
  background: var(--panel-soft);
  border-radius: 12px;
}

.account .avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
}

.account strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.account span {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  color: var(--muted);
}

/* floating action button */
.fab {
  position: absolute;
  right: 18px;
  bottom: 84px;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  color: #fff;
  background: var(--brand);
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(51, 144, 236, 0.45);
  transition: transform 0.15s, background 0.15s;
  z-index: 5;
}

.fab:hover {
  background: var(--brand-dark);
  transform: scale(1.05);
}

.fab svg {
  width: 24px;
  height: 24px;
}

/* ---------- WORKSPACE / CHAT ---------- */

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(255, 255, 255, 0.55) 1px, transparent 1px);
  background-size: 20px 20px;
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 35, 47, 0.04);
  z-index: 2;
}

.conv-peer {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.head-avatar {
  width: 42px;
  height: 42px;
  font-size: 16px;
  background: linear-gradient(135deg, #6bb1f3, var(--brand));
}

.conv-titles {
  min-width: 0;
}

.conversation-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-head p {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.call-buttons {
  display: flex;
  gap: 2px;
  flex: 0 0 auto;
}

.call-buttons button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  background: transparent;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.call-buttons button:hover {
  background: var(--hover);
  color: var(--brand);
}

.call-buttons svg {
  width: 22px;
  height: 22px;
}

/* messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  padding: 18px clamp(14px, 8vw, 90px);
  overflow-y: auto;
}

.message {
  position: relative;
  max-width: min(560px, 75%);
  margin-bottom: 6px;
  padding: 6px 11px 7px;
  background: var(--bubble-in);
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 1px 1.5px rgba(16, 35, 47, 0.16);
  font-size: 15px;
  line-height: 1.4;
}

.message.me {
  align-self: flex-end;
  background: var(--bubble-out);
  border-radius: 12px 12px 4px 12px;
}

/* little bubble tails */
.message::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 9px;
  height: 13px;
}

.message:not(.me)::after {
  left: -6px;
  background: radial-gradient(circle at top left, transparent 9px, var(--bubble-in) 9px);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.message.me::after {
  right: -6px;
  background: radial-gradient(circle at top right, transparent 9px, var(--bubble-out) 9px);
  clip-path: polygon(0 0, 0 100%, 100% 100%);
}

.message strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brand-dark);
}

.message.me strong {
  display: none;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message small {
  display: block;
  margin-top: 2px;
  text-align: right;
  font-size: 11.5px;
  color: var(--muted);
}

.message.me small {
  color: #5aab53;
}

.show-more {
  min-height: 0;
  margin-top: 6px;
  padding: 0;
  color: var(--brand);
  background: transparent;
  font-weight: 600;
}

.message.me .show-more {
  color: var(--brand-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* composer */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 14px;
  background: var(--chat-bg);
}

.composer input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 18px;
  color: var(--text);
  background: #fff;
  border: 0;
  border-radius: 24px;
  outline: 0;
  box-shadow: 0 1px 2px rgba(16, 35, 47, 0.12);
}

.composer button[type="button"] {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  color: var(--muted);
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(16, 35, 47, 0.12);
  transition: color 0.15s;
}

.composer button[type="button"]:hover {
  color: var(--brand);
}

.send-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  color: #fff;
  background: var(--brand);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(51, 144, 236, 0.4);
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover {
  background: var(--brand-dark);
}

.send-btn:active {
  transform: scale(0.94);
}

.composer svg {
  width: 24px;
  height: 24px;
}

/* shared button styles (auth) */
.primary,
.ghost {
  min-height: 48px;
  padding: 0 15px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
}

.primary {
  color: #fff;
  background: var(--brand);
  transition: background 0.15s;
}

.primary:hover {
  background: var(--brand-dark);
}

.ghost {
  color: var(--brand);
  background: #fff;
  border: 1px solid var(--line);
}

.ghost:hover {
  background: var(--brand-soft);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

/* call panel (incoming) */
.details {
  display: none;
}

.call-panel {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.call-panel p {
  margin: 0 0 4px;
  color: rgba(255, 255, 255, 0.78);
}

.call-panel strong {
  display: block;
  font-size: 24px;
  margin-bottom: 16px;
}

.call-panel div {
  display: flex;
  gap: 10px;
}

.call-panel button {
  flex: 1;
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  color: #fff;
}

.call-panel .danger {
  background: var(--danger);
}

.call-panel .accept {
  color: var(--brand-dark);
  background: #fff;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .workspace {
    display: none;
  }

  .sidebar {
    height: 100vh;
  }
}

@media (max-width: 640px) {
  .messages {
    padding: 14px 12px;
  }

  .message {
    max-width: 84%;
  }

  .auth-card {
    padding: 26px 20px;
  }
}
