html,
body {
  height: 100%;
  overflow: hidden;
}

:root {
  color-scheme: light;
  --app-height: 100dvh;
  --bg: #f2e9db;
  --bg-deep: #ead7bf;
  --panel: rgba(255, 250, 244, 0.9);
  --panel-strong: #fffdf8;
  --accent: #1b5e57;
  --accent-strong: #0e3f3a;
  --accent-soft: #d8efe7;
  --text: #1c2430;
  --muted: #68717d;
  --line: rgba(125, 102, 72, 0.18);
  --own-bubble: linear-gradient(180deg, #daf1eb 0%, #cbe9e0 100%);
  --peer-bubble: linear-gradient(180deg, #fffdf8 0%, #f6eee2 100%);
  --shadow: 0 24px 70px rgba(74, 52, 31, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Arial", sans-serif;
  background:
    radial-gradient(circle at top left, #ffddba 0, transparent 28%),
    radial-gradient(circle at bottom right, #d1e8df 0, transparent 22%),
    linear-gradient(180deg, var(--bg) 0, var(--bg-deep) 100%);
  color: var(--text);
}

.shell {
  min-height: var(--app-height);
  height: var(--app-height);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
}

.auth-card,
.chat {
  width: min(100%, 760px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 30px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.auth-card {
  margin: auto 0;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  overflow: hidden;
}

.auth-hero {
  padding: 42px 34px;
  background:
    linear-gradient(160deg, rgba(16, 70, 66, 0.92), rgba(22, 95, 88, 0.72)),
    linear-gradient(180deg, #184b45, #1d6159);
  color: #fff8ef;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 12px;
  opacity: 0.72;
}

.auth-hero h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 0.95;
}

.auth-copy {
  margin: 0;
  max-width: 28ch;
  font-size: 17px;
  line-height: 1.5;
  color: rgba(255, 248, 239, 0.88);
}

.auth-panel {
  padding: 34px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
}

.auth-panel__header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-panel__header strong {
  font-size: 22px;
}

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

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.invite-placeholder {
  padding: 18px 20px;
  border-radius: 18px;
  background: rgba(27, 94, 87, 0.08);
  border: 1px solid rgba(27, 94, 87, 0.12);
  color: var(--accent-strong);
  line-height: 1.5;
}

.invite-placeholder p {
  margin: 0;
}

.field {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid rgba(27, 94, 87, 0.12);
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(27, 94, 87, 0.5);
  box-shadow: 0 0 0 4px rgba(27, 94, 87, 0.08);
  transform: translateY(-1px);
}

.field input[type="file"] {
  padding: 12px;
}

.field-label {
  display: none;
}

button {
  border: 0;
  border-radius: 999px;
  color: white;
  padding: 12px 18px;
  font: inherit;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 16px 26px rgba(27, 94, 87, 0.24);
}

.ghost-button,
.message-tools button {
  background: rgba(27, 94, 87, 0.08);
  color: var(--accent-strong);
}

.icon-button {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
  color: var(--accent-strong);
}

.hidden {
  display: none !important;
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: calc(var(--app-height) - 36px);
  height: calc(var(--app-height) - 36px);
  overflow: hidden;
  position: relative;
}

.topbar {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.96), rgba(248, 239, 228, 0.92));
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.topbar__chat-head {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__title-wrap {
  min-width: 0;
}

.topbar__label {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar__headline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__title {
  display: block;
  font-size: 20px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar__badge {
  min-width: 26px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fffdf8;
  box-shadow: 0 10px 24px rgba(28, 36, 48, 0.18);
}

.topbar__badge--messages {
  background: linear-gradient(180deg, #d84040 0%, #b72a2a 100%);
}

.topbar__badge--topics {
  background: linear-gradient(180deg, #2c7fb8 0%, #1d5f8d 100%);
}

.topbar__user {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(27, 94, 87, 0.08);
  color: var(--accent-strong);
  font-size: 13px;
  white-space: nowrap;
}

.topic-trigger {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  border-radius: 0;
  text-align: left;
}

.topbar__invite-button {
  width: 42px;
  height: 42px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid rgba(27, 94, 87, 0.14);
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 10px 24px rgba(68, 52, 31, 0.08);
}

.topbar__invite-button:disabled {
  opacity: 0.7;
}

.topic-trigger::after {
  content: "▾";
  margin-left: 10px;
  color: var(--muted);
  font-size: 14px;
}

.topic-trigger--offline .topbar__title {
  color: #7d3f2e;
}

.topic-trigger--offline::after {
  color: #a35540;
}

.topic-dock {
  flex: 0 1 46%;
  min-width: 0;
}

.topic-bar__trigger {
  width: 100%;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: 0;
  color: inherit;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 12px;
  text-align: right;
}

.topic-bar__text {
  min-width: 0;
}

.topic-bar__label {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.topic-bar__trigger strong {
  display: block;
  font-size: 17px;
  color: var(--accent-strong);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-bar__trigger > span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  align-self: center;
}

.topic-bar__trigger::after {
  content: "▾";
  color: var(--muted);
  font-size: 14px;
  align-self: center;
}

.topic-sheet {
  position: absolute;
  inset: 0;
  z-index: 35;
}

.topic-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(25, 31, 38, 0.32);
  border-radius: 0;
}

.topic-sheet__panel {
  position: absolute;
  inset: auto 12px 12px;
  max-height: min(70vh, 560px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 245, 0.98);
  box-shadow: 0 30px 80px rgba(40, 25, 12, 0.28);
}

.topic-sheet__header {
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.topic-sheet__header strong {
  font-size: 20px;
}

.topic-sheet__header span {
  color: var(--muted);
  font-size: 13px;
}

.topics {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.topic-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  border: 1px solid transparent;
  text-align: left;
}

.topic-item.active {
  border-color: rgba(27, 94, 87, 0.2);
  background: rgba(216, 239, 231, 0.78);
}

.topic-item__title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-strong);
}

.topic-item__meta {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.topic-item__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.topic-item__time {
  font-size: 12px;
  color: var(--muted);
}

.topic-item__badge {
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #d94e41;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.access-banner {
  margin: 12px 14px 0;
  padding: 14px 16px;
  border-radius: 20px;
  border: 1px solid rgba(27, 94, 87, 0.14);
  background: rgba(255, 251, 245, 0.94);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.access-banner__text {
  min-width: 0;
}

.access-banner__text strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-strong);
}

.access-banner__text p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.4;
  font-size: 14px;
}

.access-banner__input {
  width: min(100%, 420px);
  border: 1px solid rgba(27, 94, 87, 0.12);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.96);
}

.access-banner__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.messages-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 14px 0;
  position: relative;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.unread-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0;
  color: #b43f35;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.unread-divider::before,
.unread-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(180, 63, 53, 0.34);
}

.unread-divider span {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(217, 78, 65, 0.12);
  border: 1px solid rgba(180, 63, 53, 0.2);
}

.message {
  max-width: min(86%, 540px);
  background: var(--peer-bubble);
  border: 1px solid rgba(125, 102, 72, 0.12);
  border-radius: 24px 24px 24px 10px;
  padding: 14px 15px 12px;
  box-shadow: 0 10px 26px rgba(68, 52, 31, 0.08);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.message.own {
  background: var(--own-bubble);
  align-self: flex-end;
  border-radius: 24px 24px 10px 24px;
}

.message.selected {
  border-color: rgba(27, 94, 87, 0.42);
  box-shadow: 0 16px 34px rgba(27, 94, 87, 0.18);
  transform: translateY(-1px);
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.meta strong {
  color: var(--accent-strong);
  font-size: 14px;
}

.text {
  white-space: pre-wrap;
  margin-top: 8px;
  line-height: 1.45;
}

.reply {
  margin-top: 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: 13px;
}

.reply strong {
  display: block;
  color: var(--accent-strong);
  margin-bottom: 4px;
}

.message-tools {
  display: none;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.message-tools.visible {
  display: flex;
}

.message-tools button {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid rgba(27, 94, 87, 0.12);
}

.composer {
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 249, 242, 0.98), rgba(245, 237, 225, 0.94));
  position: sticky;
  bottom: 0;
  z-index: 18;
}

.reply-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(27, 94, 87, 0.09);
  color: var(--accent-strong);
}

.upload-panel {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(27, 94, 87, 0.09);
  border: 1px solid rgba(27, 94, 87, 0.12);
}

.upload-panel__status {
  font-size: 13px;
  color: var(--accent-strong);
}

.upload-preview {
  display: flex;
  gap: 10px;
  overflow-x: auto;
}

.upload-chip {
  position: relative;
  width: 70px;
  height: 70px;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(27, 94, 87, 0.14);
}

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

.upload-chip__label {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(28, 36, 48, 0.72);
  color: #fffdf8;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-field {
  flex: 1;
}

.composer-field textarea {
  min-height: 48px;
  max-height: 132px;
  resize: none;
  border-radius: 22px;
  padding: 13px 16px;
}

.composer-attach,
.composer-send {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.composer-attach {
  background: rgba(27, 94, 87, 0.08);
  color: var(--accent-strong);
  flex: 0 0 auto;
}

.composer-send {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  box-shadow: 0 16px 26px rgba(27, 94, 87, 0.24);
  flex: 0 0 auto;
}

.composer-send:disabled,
.composer-attach:disabled {
  opacity: 0.6;
  cursor: default;
}

.composer-file-input {
  display: none;
}

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

.attachments--album {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.attachment-tile {
  padding: 0;
  border-radius: 16px;
  overflow: hidden;
  background: transparent;
}

.attachments:not(.attachments--album) .attachment-tile {
  width: 100%;
}

.attachment-tile img,
.attachment-tile video {
  width: 100%;
  max-width: 100%;
  display: block;
  border-radius: 16px;
  border: 1px solid rgba(125, 102, 72, 0.12);
  object-fit: cover;
}

.attachments--album .attachment-tile img,
.attachments--album .attachment-tile video {
  aspect-ratio: 1 / 1;
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
}

.viewer__backdrop {
  position: absolute;
  inset: 0;
  border-radius: 0;
  background: rgba(16, 18, 24, 0.92);
}

.viewer__content {
  position: absolute;
  inset: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.viewer__content img,
.viewer__content video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 20px;
  object-fit: contain;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}

.viewer__stage {
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer__stage img {
  transform-origin: center center;
  transition: transform 0.12s ease-out;
}

.viewer__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 61;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 253, 248, 0.18);
  backdrop-filter: blur(10px);
  color: #fffdf8;
  font-size: 32px;
  line-height: 1;
}

.viewer__nav--prev {
  left: 12px;
}

.viewer__nav--next {
  right: 12px;
}

.empty-state {
  margin: auto;
  width: min(100%, 320px);
  padding: 28px 24px;
  border-radius: 28px;
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(125, 102, 72, 0.12);
}

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

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

.scroll-bottom {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 16px 28px rgba(27, 94, 87, 0.28);
  z-index: 8;
}

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

  .auth-card,
  .chat {
    width: 100%;
    min-height: var(--app-height);
    height: var(--app-height);
    border-radius: 0;
  }

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

  .auth-hero {
    min-height: 40vh;
    padding: 28px 22px;
  }

  .auth-panel {
    padding: 22px;
  }

  .topbar {
    padding-inline: 14px;
  }

  .topbar__main {
    gap: 10px;
  }

  .topbar__chat-head {
    gap: 8px;
  }

  .topbar__label {
    font-size: 10px;
  }

  .topic-dock {
    flex-basis: 44%;
  }

  .topic-bar__trigger strong {
    font-size: 15px;
  }

  .topic-bar__trigger > span {
    display: none;
  }

  .topbar__user {
    display: none;
  }

  .topic-sheet__panel {
    inset: auto 8px 8px;
  }

  .message {
    max-width: 92%;
  }

  .access-banner {
    margin: 10px 12px 0;
    padding: 12px;
    flex-direction: column;
  }

  .access-banner__input {
    width: 100%;
  }

  .access-banner__actions {
    width: 100%;
  }

  .composer {
    padding: 12px;
  }

  .scroll-bottom {
    right: 14px;
    bottom: 14px;
  }
}
