:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-soft: #f0f4fb;
  --line: #e4e9f2;
  --text: #101828;
  --muted: #667085;
  --primary: #0a84ff;
  --primary-dark: #0067d8;
  --primary-soft: #e7f1ff;
  --bubble: #eef6ff;
  --danger: #d92d20;
  --shadow: 0 18px 50px rgba(16, 24, 40, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(10, 132, 255, 0.28);
  outline-offset: 2px;
}

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

.hidden {
  display: none !important;
}

.connection-banner {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 30;
  max-width: calc(100vw - 24px);
  padding: 9px 14px;
  transform: translateX(-50%);
  border: 1px solid #f3c889;
  border-radius: 8px;
  background: #fff7e8;
  color: #7a4100;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.12);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9;
  border: 0;
  background: rgba(16, 24, 40, 0.28);
  backdrop-filter: blur(2px);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 24, 40, 0.34);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(440px, 100%);
  max-height: min(680px, calc(100dvh - 36px));
  display: grid;
  gap: 16px;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: var(--shadow);
}

.modal-head,
.people-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.modal-list {
  display: grid;
  gap: 8px;
}

.check-row,
.target-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbff;
  color: var(--text);
  text-align: left;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.target-chat {
  cursor: pointer;
}

.target-chat:hover,
.check-row:hover {
  border-color: #bfdbfe;
  background: var(--primary-soft);
}

.login {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand,
.sidebar-head,
.conversation-head,
.person,
.chat-item {
  display: flex;
  align-items: center;
}

.brand {
  gap: 14px;
  margin-bottom: 26px;
}

.brand-mark,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  font-weight: 850;
}

.brand h1,
.sidebar h2,
.conversation h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 30px;
}

.brand p,
.sidebar p,
.conversation-head p,
.hint,
.error {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 15px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f9fbff;
  color: var(--text);
  outline: none;
}

input {
  min-height: 48px;
  padding: 0 14px;
}

textarea {
  min-height: 46px;
  max-height: 130px;
  resize: none;
  padding: 12px 14px;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.12);
}

.primary,
.small-button,
.icon-button {
  border: 0;
}

.primary {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font-weight: 800;
}

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

.error {
  min-height: 20px;
  color: var(--danger);
}

.app {
  width: min(1180px, 100%);
  height: min(840px, calc(100dvh - 36px));
  min-height: 0;
  display: grid;
  grid-template-columns: 330px 1fr;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.sidebar {
  min-width: 0;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto minmax(120px, 1fr) minmax(110px, 32%);
  background: #f7f9fd;
}

.sidebar-head,
.conversation-head {
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
}

.sidebar-head h2,
.conversation-head h2 {
  font-size: 20px;
  font-weight: 850;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 20px;
}

.icon-button:hover {
  background: #d9eaff;
}

.invite-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
  margin: 14px;
  padding: 12px;
  border: 1px solid #cfe2ff;
  border-radius: 8px;
  background: var(--primary-soft);
}

.invite-panel span {
  color: var(--muted);
  font-size: 12px;
}

.invite-panel strong {
  color: var(--primary-dark);
  font-size: 14px;
}

.small-button {
  grid-row: 1 / span 2;
  grid-column: 2;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  background: white;
  color: var(--primary-dark);
  font-weight: 800;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.chat-item {
  width: 100%;
  gap: 12px;
  min-height: 66px;
  padding: 10px;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
}

.chat-item:hover,
.chat-item.active {
  background: white;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.07);
}

.chat-item.active .avatar {
  background: var(--primary);
}

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

.chat-main strong,
.chat-main span {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-main span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.people {
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding: 14px;
}

.people-head .small-button {
  grid-row: auto;
  grid-column: auto;
  flex: 0 0 auto;
}

.section-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.people-head .section-title {
  margin-bottom: 0;
}

.person {
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  text-align: left;
}

.person:hover {
  background: white;
}

.person .avatar,
.chat-item .avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 14px;
}

.person small {
  color: var(--muted);
}

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

.person-main strong,
.person-main small {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  background: #f8fbff;
}

.mobile-only {
  display: none;
}

.messages {
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 22px;
  scrollbar-gutter: stable;
}

.empty-conversation {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 5px;
  color: var(--muted);
  text-align: center;
}

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

.day-divider {
  width: fit-content;
  margin: 0 auto 18px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(16, 24, 40, 0.06);
  color: var(--muted);
  font-size: 12px;
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 620px);
  gap: 10px;
  margin: 0 0 10px;
}

.message > .avatar {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 13px;
}

.message.own {
  grid-template-columns: minmax(0, 620px) 38px;
  justify-content: end;
}

.message.own .avatar {
  grid-column: 2;
}

.bubble {
  width: fit-content;
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 18px 18px 18px 6px;
  background: white;
  box-shadow: 0 4px 18px rgba(16, 24, 40, 0.06);
}

.message.own .bubble {
  grid-column: 1;
  grid-row: 1;
  border-radius: 18px 18px 6px 18px;
  background: var(--primary);
  color: white;
  justify-self: end;
}

.message.own .message-meta,
.message.own .message-meta span {
  color: rgba(255, 255, 255, 0.78);
}

.message-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: baseline;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.message-action {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.message.own .message-action {
  color: rgba(255, 255, 255, 0.92);
}

.forwarded {
  width: fit-content;
  max-width: 100%;
  margin-bottom: 6px;
  padding-left: 8px;
  border-left: 3px solid currentColor;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  opacity: 0.78;
}

.message.own .forwarded {
  color: rgba(255, 255, 255, 0.86);
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.26);
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.message:not(.own) .attachment {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.attachment img {
  max-width: min(320px, 100%);
  max-height: 220px;
  border-radius: 6px;
  object-fit: contain;
}

.image-attachment img {
  display: none;
}

.image-attachment.loaded img {
  display: block;
}

.image-attachment.loaded .attachment-loading {
  display: none;
}

.attachment-failed {
  pointer-events: none;
  opacity: 0.72;
}

.file-attachment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.file-attachment strong {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.file-attachment small {
  font-weight: 600;
  opacity: 0.72;
}

.composer {
  min-height: 74px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  z-index: 3;
}

.send {
  min-width: 118px;
}

.attachment-preview {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px 0 66px;
  color: var(--muted);
  background: white;
  font-size: 13px;
}

.attachment-preview span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.preview-clear {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 18px;
}

.composer-error {
  min-height: 0;
  margin: 0;
  padding: 6px 14px 0 66px;
  background: white;
  color: var(--danger);
  font-size: 13px;
}

.composer-error:empty {
  display: none;
}

@media (min-width: 821px) and (max-width: 1050px) {
  .app {
    grid-template-columns: 290px minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  html,
  body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .shell {
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    width: 100%;
    height: var(--app-height, 100dvh);
    min-height: 0;
    padding: 0;
    display: block;
    overflow: hidden;
  }

  .login {
    width: 100%;
    min-height: var(--app-height, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: max(28px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    display: grid;
    align-content: center;
  }

  .modal {
    align-items: end;
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .modal-card {
    max-height: min(74dvh, 620px);
    border-radius: 12px;
    padding: 18px;
  }

  .brand {
    margin-bottom: 22px;
  }

  .brand h1 {
    font-size: 34px;
  }

  input,
  textarea {
    font-size: 16px;
  }

  .app {
    width: 100%;
    height: var(--app-height, 100dvh);
    border: 0;
    border-radius: 0;
    grid-template-columns: 1fr;
    box-shadow: none;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: var(--app-height, 100dvh);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transform: none;
    box-shadow: none;
    border-right: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .sidebar-head {
    min-height: 70px;
    padding: 16px;
  }

  .sidebar-head h2 {
    font-size: 28px;
  }

  .sidebar-head p {
    font-size: 13px;
  }

  .app.chat-open .sidebar {
    display: none;
  }

  .conversation {
    display: none;
    height: var(--app-height, 100dvh);
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    background: #f7fbff;
  }

  .app.chat-open .conversation {
    display: grid;
  }

  .mobile-only {
    display: grid;
  }

  .conversation-head {
    justify-content: start;
    min-height: 76px;
    padding: max(14px, env(safe-area-inset-top)) 14px 14px;
    gap: 12px;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 2;
  }

  .conversation-head .icon-button {
    width: 46px;
    height: 46px;
    font-size: 34px;
    line-height: 1;
  }

  .conversation-head h2 {
    font-size: 21px;
    line-height: 1.12;
    max-width: calc(100vw - 96px);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .conversation-head p {
    margin-top: 3px;
    font-size: 14px;
    line-height: 1.2;
  }

  .messages {
    padding: 12px 10px 10px;
    overscroll-behavior: contain;
  }

  .composer {
    min-height: 66px;
    grid-template-columns: 42px minmax(0, 1fr) 46px;
    align-items: end;
    gap: 8px;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    position: relative;
  }

  html.keyboard-open .composer {
    padding-bottom: 10px;
  }

  .send {
    min-width: 46px;
    width: 46px;
    padding: 0;
    overflow: hidden;
    color: transparent;
    position: relative;
  }

  .send::after {
    content: "→";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: white;
    font-size: 22px;
  }

  .message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
    width: 100%;
    margin-bottom: 8px;
  }

  .message .avatar {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    font-size: 14px;
  }

  .message.own {
    grid-template-columns: minmax(0, 1fr);
    justify-items: end;
  }

  .message.own .avatar {
    display: none;
  }

  .message.own .bubble {
    grid-column: 1;
    max-width: calc(100vw - 28px);
    justify-self: end;
  }

  .message:not(.own) .bubble {
    max-width: calc(100vw - 62px);
    justify-self: start;
  }

  .bubble {
    padding: 9px 11px;
    border-radius: 17px 17px 17px 6px;
  }

  .message-meta {
    font-size: 11px;
    line-height: 1.2;
  }

  .message-meta strong {
    max-width: 58vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .attachment {
    padding: 6px;
    border-radius: 8px;
  }

  .attachment img {
    width: auto;
    max-width: calc(100vw - 94px);
    max-height: 46dvh;
    display: block;
    border-radius: 6px;
  }

  .invite-panel {
    margin: 10px;
    border-radius: 8px;
  }

  .chat-list {
    padding: 6px 10px 12px;
  }

  .chat-item {
    min-height: 74px;
    padding: 12px 10px;
    border-radius: 8px;
    background: white;
    margin-bottom: 8px;
    box-shadow: 0 4px 18px rgba(16, 24, 40, 0.05);
  }

  .chat-item.active {
    box-shadow: 0 4px 18px rgba(16, 24, 40, 0.05);
  }

  .chat-item .avatar,
  .person .avatar {
    width: 46px;
    height: 46px;
    border-radius: 10px;
  }

  .chat-main strong {
    font-size: 16px;
  }

  .chat-main span {
    font-size: 14px;
  }

  .people {
    max-height: none;
    overflow: auto;
    padding: 12px 14px max(16px, env(safe-area-inset-bottom));
    background: #f7f9fd;
  }

  .people-head .small-button {
    min-height: 32px;
  }

  .person {
    padding: 10px 4px;
  }

  .attachment-preview {
    padding: 8px 12px 0 62px;
  }

  .composer-error {
    padding: 6px 12px 0 62px;
  }
}

@media (max-width: 420px) {
  .login {
    padding-left: 16px;
    padding-right: 16px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .sidebar {
    width: 100%;
  }

  .messages {
    padding-left: 8px;
    padding-right: 8px;
  }

  .message:not(.own) .bubble {
    max-width: calc(100vw - 58px);
  }

  .message.own .bubble {
    max-width: calc(100vw - 24px);
  }
}
