:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f3f6f9;
  --text: #18212f;
  --muted: #667085;
  --line: #d8e0e8;
  --accent: #1769e0;
  --accent-strong: #0d4fb3;
  --success: #168a5b;
  --danger: #c0392b;
  --bubble-in: #ffffff;
  --bubble-out: #dcecff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.phone-frame {
  width: min(100%, 1120px);
  height: min(860px, calc(100vh - 48px));
  min-height: 620px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(33, 42, 62, 0.12);
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.topbar,
.chat-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

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

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.title-block {
  min-width: 0;
}

.title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 750;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-status.online {
  color: var(--accent);
}

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-soft);
}

.mobile-only,
.mobile-page-title,
.menu-toggle,
.menu-shade {
  display: none;
}

.auth-wrap {
  width: min(100%, 440px);
  display: grid;
  gap: 18px;
  padding: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 50px rgba(33, 42, 62, 0.1);
}

.auth-wrap .mark {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

.form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 105, 224, 0.12);
}

input:disabled {
  color: var(--text);
  opacity: 1;
  background: transparent;
  border-color: transparent;
  padding-left: 0;
  box-shadow: none;
}

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}

.btn:hover {
  background: var(--accent-strong);
}

.btn.secondary {
  background: #e7edf5;
  color: var(--text);
}

.btn.secondary:hover {
  background: #dbe5ef;
}

.btn.danger {
  background: #f4e5e3;
  color: var(--danger);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: #e8eef6;
  color: var(--text);
  font-size: 18px;
}

.back-btn {
  background: transparent;
  font-size: 36px;
}

.nav {
  display: grid;
  grid-template-rows: repeat(4, auto) 1fr auto;
  gap: 2px;
  padding: calc(18px + env(safe-area-inset-top)) 14px 14px;
  border-bottom: 0;
  min-height: 100%;
}

.nav button {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 16px;
}

.nav button span {
  width: 22px;
  display: inline-grid;
  place-items: center;
  color: #344054;
  font-size: 18px;
}

.nav button.active {
  background: #e8eef6;
}

.nav .logout-btn {
  grid-row: 6;
  color: var(--danger);
}

.nav .logout-btn span {
  color: var(--danger);
}

.list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 0;
  padding: 18px 14px 14px;
  background: transparent;
}

.chat-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 78px;
  padding: 12px 2px;
  border-radius: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.chat-item:hover,
.chat-item.active {
  background: #f6faff;
}

.avatar {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: #dfe8f5;
  color: #244267;
  font-weight: 800;
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.chat-peer-avatar {
  width: 48px;
  height: 48px;
  margin-left: 18px;
}

.chat-main {
  min-width: 0;
}

.chat-name {
  margin: 0;
  color: #000;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticks {
  display: inline-block;
  min-width: 18px;
  margin-right: 3px;
  font-weight: 800;
  letter-spacing: -3px;
}

.ticks.gray {
  color: #98a2b3;
}

.ticks.blue {
  color: #1683ff;
}

.search-wrap {
  padding: 12px 18px;
}

.search-wrap input {
  min-height: 42px;
  border: 0;
  background: #fff;
}

.meta {
  display: grid;
  justify-items: end;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 750;
}

.page {
  position: relative;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.conversation-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--panel-soft);
}

.empty,
.panel {
  margin: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
}

.empty h2,
.panel h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.empty p,
.panel p {
  margin: 0;
  color: var(--muted);
}

.profile-grid {
  display: grid;
  gap: 16px;
  max-width: 520px;
}

.profile-view {
  padding: 18px;
}

.profile-photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 0 24px;
}

.profile-avatar {
  width: 96px;
  height: 96px;
}

.photo-upload input {
  display: none;
}

.photo-upload span {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 8px;
  background: #e7edf5;
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
}

.messages {
  min-height: 0;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}

.bubble {
  max-width: min(72%, 560px);
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bubble-in);
}

.bubble.mine {
  align-self: flex-end;
  background: var(--bubble-out);
}

.date-divider {
  align-self: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: #edf1f4;
  color: #6b7884;
  font-size: 12px;
  pointer-events: none;
}

.scroll-date-wrap {
  position: absolute;
  top: 92px;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.scroll-date {
  min-width: 118px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #edf1f4;
  color: #6b7884;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 180ms ease;
}

.scroll-date.visible {
  opacity: 1;
}

.date-divider ~ .date-divider {
  margin-top: 18px;
}

.bubble p {
  margin: 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.bubble time {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--panel-soft);
}

.composer input {
  min-width: 0;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: #fff;
}

.composer input:focus {
  border: 0;
}

.send-btn {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
}

.send-btn svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notice {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
}

.notice.error {
  color: var(--danger);
}

.notice.success {
  color: var(--success);
}

@media (max-width: 780px) {
  .scroll-date-wrap {
    top: calc(88px + env(safe-area-inset-top));
  }

  .shell {
    padding: 0;
    display: block;
    min-height: 100dvh;
    overflow: visible;
  }

  .phone-frame {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    overflow: visible;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #eef2f6;
  }

  .phone-frame.chat-open {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 1;
    width: 280px;
    border-right: 0;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: 10px 0 30px rgba(25, 35, 52, 0.12);
  }

  .phone-frame.menu-open .sidebar {
    transform: translateX(0);
  }

  .content {
    position: relative;
    z-index: 2;
    min-height: 100dvh;
    overflow: visible;
    transition: transform 180ms ease;
    box-shadow: -10px 0 30px rgba(25, 35, 52, 0.08);
  }

  .phone-frame.chat-open .content,
  .phone-frame.chat-open .page {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .phone-frame.chat-open .conversation-header,
  .phone-frame.chat-open .composer {
    flex: 0 0 auto;
  }

  .phone-frame.chat-open .messages {
    flex: 1 1 auto;
    overflow-y: auto;
  }

  .phone-frame.menu-open .content {
    transform: translateX(280px);
  }

  .menu-shade {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(14, 25, 42, 0.24);
  }

  .phone-frame.menu-open .menu-shade {
    display: block;
    transform: translateX(280px);
  }

  .desktop-only,
  .desktop-only {
    display: none;
  }

  .mobile-only,
  .menu-toggle,
  .mobile-page-title {
    display: block;
  }

  .chat-header {
    position: relative;
    justify-content: flex-start;
    min-height: calc(68px + env(safe-area-inset-top));
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  .chat-header .menu-toggle {
    display: grid;
  }

  .mobile-title-header {
    justify-content: center;
  }

  .mobile-title-header .menu-toggle {
    position: absolute;
    left: 20px;
    bottom: 8px;
    width: 54px;
    height: 54px;
    background: transparent;
    font-size: 34px;
  }

  .write-btn {
    position: absolute;
    right: 14px;
    bottom: 8px;
    width: 54px;
    height: 54px;
    background: transparent;
    font-size: 34px;
  }

  .profile-edit-btn {
    position: absolute;
    right: 14px;
    bottom: 14px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 14px;
  }

  .mobile-page-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    font-weight: 750;
  }

  .desktop-title {
    display: none;
  }

  .compact-header {
    min-height: calc(56px + env(safe-area-inset-top));
  }

  .auth-wrap {
    min-height: 100dvh;
    width: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    align-content: center;
  }

  .bubble {
    max-width: 88%;
  }

  .panel {
    margin: 14px;
  }

  .mobile-only .list {
    margin-top: 0;
    padding: 0 18px 18px;
  }

  .composer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
}
