:root {
  --primary: #3157d5;
  --primary-dark: #233f9f;
  --primary-soft: #e8edff;
  --background: #eef3f9;
  --surface: #ffffff;
  --surface-muted: #f6f8fb;
  --text: #142033;
  --muted: #64748b;
  --border: #dbe3ef;
  --success: #14804a;
  --error: #c2413a;
  --warning: #a16207;
  --shadow: 0 24px 70px rgba(20, 32, 51, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.join-page {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #f8fbff 0%, #e9eef8 100%);
}

.join-shell {
  width: min(100%, 480px);
}

.join-card {
  padding: 34px;
  border: 1px solid rgba(219, 227, 239, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.brand-mark,
.room-avatar,
.empty-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #36a3ff);
  box-shadow: 0 12px 30px rgba(49, 87, 213, 0.25);
}

.eyebrow {
  margin: 20px 0 8px;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.join-card h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1.02;
}

.join-description,
.privacy-note {
  color: var(--muted);
  line-height: 1.6;
}

.join-description {
  margin: 14px 0 26px;
}

.join-form {
  display: grid;
  gap: 18px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group label {
  font-weight: 700;
}

.field-group input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-muted);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field-group input:focus,
.message-input-wrap:focus-within {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(49, 87, 213, 0.12);
}

.field-error {
  min-height: 18px;
  color: var(--error);
  font-weight: 600;
}

.primary-button,
.secondary-button,
.danger-button,
.copy-button,
.send-button,
.icon-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button,
.send-button {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), #2478ef);
  box-shadow: 0 12px 26px rgba(49, 87, 213, 0.28);
}

.primary-button:hover,
.send-button:hover,
.copy-button:hover,
.secondary-button:hover,
.danger-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.privacy-note {
  margin: 22px 0 0;
  font-size: 0.92rem;
}

.app-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.app-action-button {
  width: 100%;
}

.chat-page {
  min-height: 100dvh;
  padding: 20px;
  background:
    linear-gradient(rgba(238, 243, 249, 0.88), rgba(238, 243, 249, 0.88)),
    repeating-linear-gradient(45deg, rgba(49, 87, 213, 0.07) 0 1px, transparent 1px 18px);
}

.chat-shell {
  display: grid;
  min-height: calc(100dvh - 40px);
  place-items: center;
}

.chat-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 1020px);
  height: min(860px, calc(100dvh - 40px));
  overflow: hidden;
  border: 1px solid rgba(219, 227, 239, 0.9);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chat-header {
  display: grid;
  grid-template-columns: 44px 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  align-items: center;
}

.icon-button {
  display: grid;
  place-items: center;
  color: var(--primary-dark);
  text-decoration: none;
  background: var(--primary-soft);
}

.room-avatar {
  width: 48px;
  height: 48px;
}

.room-details {
  min-width: 0;
}

.room-details h1 {
  overflow: hidden;
  margin: 0 0 5px;
  font-size: 1.08rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-details p {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.dot-divider {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
}

.status::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  content: "";
}

.status-connected {
  color: var(--success);
}

.status-connected::before {
  background: var(--success);
}

.status-disconnected {
  color: var(--error);
}

.status-disconnected::before {
  background: var(--error);
}

.status-reconnecting,
.status-connecting {
  color: var(--warning);
}

.status-reconnecting::before,
.status-connecting::before {
  background: var(--warning);
}

.secondary-button {
  padding: 0 14px;
  color: var(--text);
  border: 1px solid var(--border);
  background: #ffffff;
}

.danger-button {
  padding: 0 16px;
  color: #ffffff;
  background: var(--error);
}

.lock-button-active {
  color: #ffffff;
  border-color: transparent;
  background: var(--primary-dark);
}

.messages {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 22px;
  overflow-y: auto;
  background:
    linear-gradient(rgba(246, 248, 251, 0.9), rgba(246, 248, 251, 0.9)),
    repeating-linear-gradient(135deg, rgba(49, 87, 213, 0.05) 0 1px, transparent 1px 22px);
}

.empty-state {
  width: min(100%, 430px);
  margin: auto;
  padding: 28px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.empty-icon {
  margin: 0 auto 16px;
}

.empty-state h2 {
  margin: 0 0 10px;
  font-size: 1.35rem;
}

.empty-state p {
  margin: 8px 0;
  color: var(--muted);
  line-height: 1.5;
}

.copy-button {
  margin-top: 14px;
  padding: 0 16px;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.copy-status {
  display: block;
  min-height: 18px;
  margin-top: 8px;
  color: var(--success);
  font-weight: 800;
}

.message-row {
  display: flex;
  animation: messageIn 180ms ease-out both;
}

.own-message {
  justify-content: flex-end;
}

.other-message {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(78%, 620px);
  padding: 11px 13px 8px;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(20, 32, 51, 0.08);
}

.own-message .message-bubble {
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), #2478ef);
}

.other-message .message-bubble {
  color: var(--text);
  border: 1px solid rgba(219, 227, 239, 0.82);
  background: #ffffff;
}

.message-sender {
  display: block;
  margin-bottom: 5px;
  font-size: 0.78rem;
}

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

.message-time {
  display: block;
  margin-top: 7px;
  font-size: 0.72rem;
  text-align: right;
  opacity: 0.76;
}

.system-message {
  align-self: center;
  max-width: min(92%, 520px);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 700;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  animation: messageIn 180ms ease-out both;
}

.system-message time {
  margin-left: 8px;
  color: #94a3b8;
  font-weight: 600;
}

.composer {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.typing-indicator {
  min-height: 20px;
  padding-left: 4px;
  color: var(--primary-dark);
  font-size: 0.86rem;
  font-weight: 800;
}

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: end;
}

.message-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  min-height: 52px;
  padding: 8px 10px 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.message-input-wrap textarea {
  width: 100%;
  max-height: 140px;
  min-height: 28px;
  padding: 4px 0;
  resize: none;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
}

.character-counter {
  padding-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.send-button {
  min-height: 52px;
  padding: 0 16px;
}

.composer-note {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  max-width: min(92vw, 440px);
  padding: 12px 16px;
  color: #ffffff;
  font-weight: 800;
  text-align: center;
  border-radius: 8px;
  background: var(--text);
  box-shadow: 0 14px 32px rgba(20, 32, 51, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-error {
  background: var(--error);
}

.toast-success {
  background: var(--success);
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(20, 32, 51, 0.54);
}

.modal-visible {
  display: grid;
}

.modal {
  width: min(100%, 420px);
  padding: 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.modal h2 {
  margin: 0 0 10px;
}

.modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .chat-page {
    padding: 0;
  }

  .chat-shell {
    min-height: 100dvh;
  }

  .chat-app {
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .chat-header {
    grid-template-columns: 42px 44px minmax(0, 1fr);
    padding: 10px;
  }

  .room-avatar {
    width: 44px;
    height: 44px;
  }

  .header-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .header-actions .secondary-button {
    flex: 1;
    min-width: min(100%, 108px);
  }

  .messages {
    padding: 14px;
  }

  .message-bubble {
    max-width: 86%;
  }

  .composer {
    padding: 8px 10px 10px;
  }

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

  .send-button {
    padding: 0 12px;
  }

  .join-page {
    padding: 14px;
  }

  .join-card {
    padding: 24px;
  }

  .app-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .message-form {
    grid-template-columns: 1fr;
  }

  .send-button {
    width: 100%;
  }

  .message-bubble {
    max-width: 92%;
  }

  .modal-actions {
    flex-direction: column;
  }
}
