:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --text: #172033;
  --muted: #637083;
  --line: #d9e0ea;
  --accent: #246bfe;
  --accent-strong: #1557d4;
  --ok: #1d9a63;
  --warn: #c76b00;
  --danger: #c73535;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(36, 107, 254, 0.12), rgba(29, 154, 99, 0.08)),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

select {
  font: inherit;
}

.shell {
  width: min(100%, 1180px);
  height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  min-height: 0;
}

.auth-panel,
.chat {
  width: 100%;
  height: calc(100vh - 48px);
  min-height: 0;
  background: var(--surface);
  border: 1px solid rgba(217, 224, 234, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  align-self: center;
  min-height: auto;
  padding: 24px;
}

.auth-panel__header {
  margin-bottom: 20px;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.auth-form input {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.14);
}

.auth-form button,
.logout-button {
  height: 44px;
  padding: 0 16px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.auth-form button:hover,
.logout-button:hover {
  background: var(--accent-strong);
}

.auth-message {
  min-height: 20px;
  margin: 16px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.chat {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
}

.sidebar__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

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

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.identity {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.identity code {
  color: var(--text);
  overflow-wrap: anywhere;
}

.status {
  min-width: 0;
  height: 36px;
  margin: 12px 14px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
}

.logout-button {
  flex: 0 0 auto;
  height: 36px;
}

.room-list {
  min-height: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.room-item {
  width: 100%;
  min-height: 72px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 10px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}

.room-item:hover {
  background: rgba(36, 107, 254, 0.08);
}

.room-item--active {
  background: rgba(36, 107, 254, 0.14);
}

.room-item__title {
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item__meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.room-item__preview {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item__badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  align-self: center;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: var(--accent);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.room-list-state {
  min-height: 72px;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 4px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.room-list-state__title {
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.room-list-state__detail {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.room-actions {
  min-height: 0;
  padding: 12px;
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  overflow-y: auto;
}

.room-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.room-form input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.room-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.14);
}

.room-form button {
  height: 38px;
  padding: 0 12px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.contacts-panel {
  display: grid;
  gap: 8px;
}

.contacts-panel input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.contacts-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.14);
}

.user-results,
.contacts-list {
  display: grid;
  gap: 4px;
}

.contacts-heading {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.empty-state {
  margin: 0 2px;
  color: var(--muted);
  font-size: 13px;
}

.user-result {
  min-width: 0;
  padding: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-result__info {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-result button {
  height: 30px;
  padding: 0 10px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.contact-item {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}

.contact-item:hover {
  background: rgba(36, 107, 254, 0.08);
}

.contact-item__name {
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-item__username {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.conversation__header {
  min-height: 76px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.conversation__header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.conversation__header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.call-button,
.call-panel button {
  height: 38px;
  padding: 0 12px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.call-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.call-panel {
  min-height: 58px;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.call-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.call-panel__actions {
  display: flex;
  gap: 8px;
}

.call-panel__actions .call-action--secondary {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

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

.status__dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--warn);
}

.status[data-state="connected"] {
  color: var(--ok);
}

.status[data-state="connected"] .status__dot {
  background: var(--ok);
}

.status[data-state="disconnected"] {
  color: var(--danger);
}

.status[data-state="disconnected"] .status__dot {
  background: var(--danger);
}

.messages {
  min-height: 0;
  height: 100%;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.84)),
    repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(217, 224, 234, 0.55) 32px);
}

.message {
  width: min(78%, 620px);
  padding: 10px 12px;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-state {
  align-self: center;
  padding: 4px 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}

.message--own {
  align-self: flex-end;
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.message__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
}

.message--own .message__meta {
  color: rgba(255, 255, 255, 0.76);
}

.message__sender {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.message__time {
  flex: 0 0 auto;
}

.message__text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.45;
}

.attachment {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  color: inherit;
  text-decoration: none;
}

.attachment img {
  max-width: min(100%, 360px);
  max-height: 260px;
  border-radius: 8px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.7);
}

.attachment__label {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.composer {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px minmax(0, 180px) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.composer input,
.composer select {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.composer input:focus,
.composer select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 254, 0.14);
}

.composer__send {
  min-width: 116px;
  height: 44px;
  padding: 0 16px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.composer__file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.composer__attach {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
}

.composer__attach:hover,
.composer__attach:has(+ .composer__file:focus) {
  border-color: var(--accent);
}

.composer__filename {
  min-width: 0;
  height: 44px;
  display: flex;
  align-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.composer__send:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media (max-width: 720px) {
  .shell {
    padding: 0;
  }

  .chat {
    height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 42vh) minmax(0, 1fr);
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .status {
    align-self: stretch;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  .composer__send {
    width: 100%;
  }

  .message {
    width: min(92%, 620px);
  }
}
