:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #eef2f4;
  --text: #172026;
  --muted: #65727c;
  --line: #dce4e8;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --rose: #e11d48;
  --mine: #dff6ed;
  --theirs: #ffffff;
  --shadow: 0 16px 50px rgba(23, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(246, 248, 247, 0.9), rgba(246, 248, 247, 0.9)),
    url("data:image/svg+xml,%3Csvg width='220' height='220' viewBox='0 0 220 220' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ccd6da' stroke-width='1' opacity='.55'%3E%3Cpath d='M30 120c34-55 80-55 114 0M64 54c18 24 18 56 0 80M156 54c-18 24-18 56 0 80'/%3E%3Ccircle cx='110' cy='110' r='58'/%3E%3C/g%3E%3C/svg%3E");
}

button,
input,
textarea {
  font: inherit;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: min(920px, calc(100vh - 32px));
  min-height: 0;
  max-width: 1220px;
  margin: 16px auto;
  overflow: hidden;
  border: 1px solid rgba(101, 114, 124, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.auth-only .shell {
  grid-template-columns: minmax(0, 430px);
  align-content: center;
  max-width: 470px;
}

.auth-only .sidebar {
  border-right: 0;
}

.auth-only .chat,
.auth-only .conversation-list {
  display: none;
}

.auth-only .auth-card {
  margin-bottom: 20px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: white;
  font-weight: 800;
  background: linear-gradient(135deg, var(--brand), var(--rose));
}

.brand h1,
.brand p,
.chat-title h2,
.chat-title p,
.message-bubble p {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  line-height: 1.15;
}

.brand p,
.chat-title p,
.auth-card span,
.profile-card span,
.presence,
.message-meta,
.auth-note {
  color: var(--muted);
  font-size: 13px;
}

.auth-card,
.profile-card {
  display: grid;
  gap: 10px;
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfc;
}

.auth-card label {
  display: grid;
  gap: 6px;
}

.auth-card input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--text);
  background: var(--panel);
  outline: none;
}

.auth-card input:focus,
.composer textarea:focus {
  border-color: rgba(15, 118, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.auth-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
}

.profile-card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

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

.primary-button,
.secondary-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  font-weight: 750;
  cursor: pointer;
}

.primary-button {
  color: white;
  background: var(--brand);
}

.secondary-button {
  color: var(--text);
  background: var(--panel-strong);
}

.auth-note {
  margin: 0;
}

.conversation-list {
  display: grid;
  gap: 6px;
  min-height: 0;
  padding: 4px 12px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation:hover,
.conversation.active {
  background: var(--panel-strong);
}

.conversation-swatch {
  width: 10px;
  height: 34px;
  border-radius: 999px;
}

.conversation-name {
  display: block;
  overflow: hidden;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-count {
  min-width: 28px;
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  background: #ccfbf1;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-height: 0;
  min-width: 0;
  background: rgba(245, 247, 248, 0.76);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.94);
}

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

.chat-title h2 {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border: 2px solid white;
  border-radius: 999px;
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px;
}

.empty-state {
  margin: auto;
  color: var(--muted);
}

.message {
  display: grid;
  max-width: min(640px, 88%);
  gap: 6px;
  align-self: flex-start;
}

.message.mine {
  align-self: flex-end;
}

.message-bubble {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(101, 114, 124, 0.16);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--theirs);
  box-shadow: 0 8px 22px rgba(23, 32, 38, 0.08);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.mine .message-bubble {
  border-color: rgba(15, 118, 110, 0.18);
  background: var(--mine);
}

.admin-message .message-bubble {
  border-left: 4px solid var(--brand);
}

.message-meta {
  display: flex;
  gap: 8px;
  padding: 0 4px;
}

.message.mine .message-meta {
  justify-content: flex-end;
}

.media {
  display: block;
  width: min(100%, 420px);
  max-height: 380px;
  border-radius: 8px;
  object-fit: cover;
}

.audio {
  width: min(100%, 360px);
}

.file-link {
  color: var(--brand-dark);
  font-weight: 750;
}

.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 9px 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.88);
}

.attachment-preview button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: var(--panel-strong);
  cursor: pointer;
}

.composer {
  display: grid;
  grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.94);
}

.composer.locked {
  background: rgba(255, 255, 255, 0.7);
}

.composer textarea {
  width: 100%;
  max-height: 150px;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--panel);
  outline: none;
}

.icon-button,
.send-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  color: var(--muted);
  background: var(--panel-strong);
}

.icon-button:hover {
  color: var(--text);
}

.icon-button.recording {
  color: white;
  background: var(--rose);
}

.send-button {
  color: white;
  background: var(--brand);
}

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

.icon-button svg,
.send-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.menu-button {
  display: none;
}

.menu-button span,
.menu-button span::before,
.menu-button span::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.menu-button span::before {
  transform: translateY(-6px);
}

.menu-button span::after {
  transform: translateY(4px);
}

.hidden,
.visually-hidden {
  display: none !important;
}

@media (max-width: 760px) {
  body {
    background: var(--bg);
  }

  .shell {
    grid-template-columns: 1fr;
    height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .auth-only .sidebar {
    position: static;
    width: auto;
    transform: none;
    box-shadow: none;
  }

  .menu-button {
    display: grid;
  }

  .presence {
    display: none;
  }

  .chat-header {
    padding: 12px;
  }

  .messages {
    padding: 14px;
  }

  .message {
    max-width: 94%;
  }

  .composer {
    grid-template-columns: 40px 40px minmax(0, 1fr) 40px;
    gap: 8px;
    padding: 10px;
  }

  .icon-button,
  .send-button {
    width: 40px;
    height: 40px;
  }
}
