:root {
  --page: #ffffff;
  --page-tint: #f4fbfc;
  --panel: rgba(255, 255, 255, 0.98);
  --panel-strong: #ffffff;
  --ink: #24424a;
  --muted: #69868d;
  --line: rgba(19, 147, 164, 0.14);
  --accent: #1393a4;
  --accent-strong: #0f7d8b;
  --accent-soft: rgba(19, 147, 164, 0.1);
  --highlight: #f3a66f;
  --success: #55a47c;
  --danger: #c96554;
  --shadow: 0 18px 44px rgba(19, 147, 164, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Poppins", "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(19, 147, 164, 0.07), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, var(--page-tint) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(19, 147, 164, 0.03), rgba(19, 147, 164, 0));
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  min-height: 100vh;
  padding: 24px;
}

.sidebar,
.chat-panel {
  position: relative;
  z-index: 1;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-card,
.chat-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar-card {
  padding: 18px;
}

.brand-card h1 {
  margin: 4px 0 10px;
  font-size: clamp(2rem, 3vw, 2.7rem);
  line-height: 1.05;
  font-weight: 500;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  letter-spacing: 0.02em;
  font-size: 0.82rem;
  font-weight: 500;
}

.brand-copy,
.help-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.status-pill,
.status-chip,
.presence-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  background: rgba(19, 147, 164, 0.08);
  color: var(--accent-strong);
  border: 1px solid rgba(19, 147, 164, 0.16);
}

.status-pill::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.status-chip,
.presence-tag {
  min-height: auto;
  padding: 4px 10px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(19, 147, 164, 0.06);
  color: var(--muted);
  border-color: rgba(19, 147, 164, 0.10);
}

.presence-tag {
  margin-left: auto;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2,
.chat-header h2,
.access-panel h3 {
  margin: 0;
  font-size: 1.05rem;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.presence-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.presence-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(19, 147, 164, 0.04);
}

.presence-list li::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--success);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(19, 147, 164, 0.18);
  border-radius: 10px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 13px 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(19, 147, 164, 0.5);
  box-shadow: 0 0 0 4px rgba(19, 147, 164, 0.12);
}

textarea {
  resize: vertical;
  min-height: 84px;
  max-height: 180px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 13px 18px;
  font-weight: 500;
  cursor: pointer;
  background: linear-gradient(var(--accent), var(--accent));
  color: white;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
  letter-spacing: 0.02em;
}

button:hover {
  transform: translateY(-1px);
}

.secondary-button {
  background: rgba(19, 147, 164, 0.08);
  color: var(--accent-strong);
  border: 1px solid rgba(19, 147, 164, 0.18);
}

.danger-button {
  background: rgba(201, 101, 84, 0.12);
  color: var(--danger);
  border: 1px solid rgba(201, 101, 84, 0.22);
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
  transform: none;
}

.stack-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.auth-placeholder {
  color: var(--muted);
}

.auth-session p {
  margin: 0;
  color: var(--muted);
}

.auth-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: calc(100vh - 48px);
  overflow: hidden;
}

.chat-header,
.composer,
.access-panel {
  padding: 20px 24px;
}

.chat-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19, 147, 164, 0.03), rgba(19, 147, 164, 0));
}

.access-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  align-items: start;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(19, 147, 164, 0.04);
}

.access-panel-copy {
  display: grid;
  gap: 6px;
}

.access-panel-form {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(19, 147, 164, 0.14);
}

#auth-step-request,
#auth-step-verify {
  display: grid;
  gap: 10px;
}

#auth-request-button,
#auth-verify-button {
  margin-top: 4px;
}

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

.message-feed {
  padding: 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  align-self: flex-start;
  max-width: min(82%, 680px);
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(19, 147, 164, 0.04);
  border: 1px solid rgba(19, 147, 164, 0.1);
}

.message.is-own {
  align-self: flex-end;
  background: rgba(243, 166, 111, 0.16);
  border-color: rgba(243, 166, 111, 0.28);
}

.message-meta,
.message-actions {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.message-meta {
  margin-bottom: 8px;
}

.message-actions {
  margin-top: 10px;
}

.message-action-button {
  padding: 8px 10px;
  font-size: 0.78rem;
}

.message-author {
  font-size: 0.95rem;
  font-weight: 500;
}

.message-time {
  color: var(--muted);
  font-size: 0.83rem;
}

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

.message-link {
  color: var(--accent-strong);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
}

.message-link:hover {
  color: var(--accent);
}

.message-images {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.message-images[data-count="1"] {
  grid-template-columns: 1fr;
}

.message-images[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.message-images[data-count="3"],
.message-images[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.message-image-button {
  display: block;
  padding: 0;
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid rgba(19, 147, 164, 0.14);
  background: rgba(255, 255, 255, 0.8);
}

.message-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 140px;
  max-height: 220px;
  object-fit: cover;
}

.composer {
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.selected-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.selected-upload {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(19, 147, 164, 0.14);
  background: rgba(19, 147, 164, 0.04);
  aspect-ratio: 1;
}

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

.selected-upload-remove {
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 6px 8px;
  font-size: 0.75rem;
  line-height: 1;
}

.composer-footer,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.composer-footer {
  justify-content: space-between;
  margin-top: 12px;
}

.composer-actions .help-text {
  max-width: 420px;
}

#add-images {
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: linear-gradient(var(--accent), var(--accent));
  color: white;
  border: 0;
}

#add-images:hover {
  background: linear-gradient(var(--accent-strong), var(--accent-strong));
}

#auth-signout {
  background: linear-gradient(var(--accent), var(--accent));
  color: white;
  border: 0;
}

.admin-member-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.admin-member-row,
.admin-empty {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(19, 147, 164, 0.04);
}

.admin-member-copy {
  display: grid;
  gap: 4px;
}

.admin-member-copy span {
  color: var(--muted);
  font-size: 0.86rem;
}

.admin-member-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.empty-state {
  margin: auto;
  max-width: 480px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
  padding: 32px 24px;
  border-radius: 18px;
  background: rgba(19, 147, 164, 0.03);
}

.empty-state h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.7rem;
  font-weight: 500;
}

.lightbox-open {
  overflow: hidden;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 43, 49, 0.72);
}

.lightbox-dialog {
  width: min(92vw, 960px);
  max-height: 92vh;
  border-radius: 20px;
  background: white;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.lightbox-dialog img {
  width: 100%;
  max-height: calc(92vh - 90px);
  object-fit: contain;
  display: block;
  border-radius: 14px;
  background: rgba(19, 147, 164, 0.04);
}

.lightbox-caption {
  margin: 10px 0 0;
  color: var(--muted);
}

.lightbox-close {
  display: inline-flex;
  margin-left: auto;
  margin-bottom: 12px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .chat-panel {
    min-height: 70vh;
  }
}

@media (max-width: 640px) {
  .chat-header,
  .composer,
  .message-feed,
  .access-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .message {
    max-width: 100%;
  }

  .composer-footer,
  .chat-header,
  .section-heading,
  .access-panel {
    display: block;
  }

  .access-panel-form {
    margin-top: 14px;
  }

  .composer-actions {
    display: block;
  }

  .section-heading span,
  .help-text {
    margin-top: 8px;
  }

  #auth-request-button,
  #auth-verify-button,
  #auth-back-button,
  #add-images,
  #send-button,
  #clear-room-button,
  #refresh-members-button {
    width: 100%;
    margin-top: 10px;
  }

  .message-images[data-count="2"],
  .message-images[data-count="3"],
  .message-images[data-count="4"] {
    grid-template-columns: 1fr 1fr;
  }
}
