:root {
  color-scheme: light;
  --bg: #edf1f6;
  --surface: #ffffff;
  --surface-muted: #f6f8fb;
  --ink: #141b2d;
  --muted: #667085;
  --border: #d9e0ea;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e8f5f3;
  --sent: #0f766e;
  --received: #ffffff;
  --shadow: 0 18px 50px rgba(20, 27, 45, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 2px;
}

.boot-status {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 9999;
  padding: 12px 14px;
  border: 1px solid #b7c7e8;
  border-radius: 12px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(23, 32, 51, 0.12);
}

.boot-status-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
  width: min(1440px, calc(100vw - 24px));
  height: min(920px, calc(100vh - 24px));
  min-height: 620px;
  margin: 12px auto;
}

.sidebar,
.chat {
  border: 1px solid rgba(221, 227, 238, 0.9);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-radius: 10px;
  overflow: hidden;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #141b2d;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

.brand-block h1 {
  font-size: 22px;
  line-height: 1.1;
}

.brand-block p,
.chat-header p,
.profile-row small,
.auth-dialog p,
.typing-line {
  color: var(--muted);
}

.brand-block p {
  margin-top: 4px;
  font-size: 13px;
}

.panel {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
  color: #394154;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface-muted);
  color: #344054;
}

.icon-button:hover,
.ghost-button:hover {
  background: #eef3ff;
}

.profile-row,
.user-list li {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-row strong,
.user-list strong {
  display: block;
  overflow: hidden;
  max-width: 190px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 260px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.user-list small {
  color: var(--muted);
}

.network-panel {
  margin-top: auto;
}

.conversation-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
}

.conversation-button,
.contact-button {
  display: grid;
  grid-template-columns: 24px 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #172033;
  text-align: left;
}

.conversation-button {
  grid-template-columns: 34px minmax(0, 1fr) auto;
}

.conversation-button:hover,
.contact-button:hover,
.conversation-button.active,
.contact-button.active {
  border-color: #bfe3de;
  background: var(--accent-soft);
}

.conversation-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  font-weight: 800;
}

.contact-list {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  max-height: 330px;
  overflow: auto;
}

.conversation-search {
  margin-bottom: 2px;
}

.conversation-search input {
  width: 100%;
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: var(--surface-muted);
  color: var(--ink);
}

.conversation-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
}

.presence-dot.online {
  background: #16a34a;
}

.avatar.compact {
  width: 34px;
  height: 34px;
}

.group-avatar {
  background: #7c3aed;
}

.contact-copy {
  min-width: 0;
}

.contact-copy strong,
.contact-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-copy small {
  color: var(--muted);
  font-size: 12px;
}

.contact-security {
  margin-top: 2px;
  color: #8490a3;
}

.contact-empty {
  padding: 18px 8px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.request-list,
.search-results,
.member-picker,
.admin-user-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.request-item,
.search-row,
.admin-user-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.request-item button,
.search-row button,
.admin-user-row button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.request-item button:last-child {
  background: #e8edf5;
  color: #344054;
}

.search-row button:disabled {
  cursor: not-allowed;
  background: #e8edf5;
  color: #667085;
}

.unread-pill {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
}

.address {
  overflow-wrap: anywhere;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-muted);
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  border-radius: 10px;
  overflow: hidden;
}

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

.mobile-menu-button {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: #344054;
  font-size: 20px;
}

.header-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #141b2d;
  color: #ffffff;
  font-weight: 900;
}

.chat-heading {
  min-width: 0;
}

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

.chat-header p {
  margin-top: 5px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.privacy-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #bfd8d5;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.privacy-badge.public {
  border-color: #d7deea;
  background: #f6f8fb;
  color: #475467;
}

.privacy-badge.secure {
  border-color: #bfd8d5;
  background: #e8f5f3;
  color: #0b5f59;
}

.ghost-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 22px;
  overflow: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.72)),
    radial-gradient(circle at top right, rgba(15, 118, 110, 0.08), transparent 38%);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(420px, 100%);
  margin: auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 17px;
}

.empty-state span {
  max-width: 340px;
  font-size: 13px;
  line-height: 1.5;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #141b2d;
  color: #ffffff;
  font-weight: 900;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(76%, 680px);
}

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

.message-row.system {
  align-self: center;
  max-width: 90%;
}

.bubble {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 16px 16px 16px 5px;
  background: var(--received);
  line-height: 1.45;
  box-shadow: 0 7px 18px rgba(23, 32, 51, 0.06);
}

.mine .bubble {
  border-color: transparent;
  border-radius: 16px 16px 5px 16px;
  background: var(--sent);
  color: #ffffff;
}

.system .bubble {
  border: 0;
  border-radius: 999px;
  background: rgba(23, 32, 51, 0.08);
  color: #526071;
  font-size: 12px;
  box-shadow: none;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.mine .message-meta {
  color: rgba(255, 255, 255, 0.78);
}

.secure-label {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 11px;
  opacity: 0.8;
}

.message-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.revoked-text {
  color: var(--muted);
  font-style: italic;
}

.mine .revoked-text {
  color: rgba(255, 255, 255, 0.78);
}

.message-action {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 800;
  opacity: 0.82;
}

.secure-failed {
  color: #b42318;
}

.mine .secure-failed {
  color: #ffe4e6;
}

.media-block {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.media-block img,
.media-block video {
  display: block;
  width: min(360px, 100%);
  max-height: 360px;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(23, 32, 51, 0.08);
}

.media-block audio {
  width: min(320px, 100%);
}

.file-card {
  display: grid;
  gap: 3px;
  min-width: min(300px, 100%);
  padding: 10px;
  border-radius: 8px;
  background: rgba(23, 32, 51, 0.06);
  color: inherit;
  text-decoration: none;
}

button.file-card {
  border: 0;
  cursor: pointer;
  text-align: left;
}

.mine .file-card {
  background: rgba(255, 255, 255, 0.16);
}

.file-card strong,
.file-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-card small {
  opacity: 0.72;
}

.typing-line {
  min-height: 24px;
  padding: 0 22px 4px;
  font-size: 13px;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
}

.composer-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 88px;
  gap: 10px;
}

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

.attach-button {
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  color: #344054;
  font-size: 24px;
  font-weight: 500;
}

.attach-button:hover {
  background: #eef3ff;
}

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

.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  color: #344054;
  font-size: 13px;
}

.attachment-preview[hidden] {
  display: none;
}

.attachment-preview button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: #ffffff;
  color: #344054;
}

.composer textarea:focus,
.auth-dialog input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.composer button[type="submit"],
.auth-dialog button[type="submit"] {
  min-height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.composer button[type="submit"]:hover,
.auth-dialog button[type="submit"]:hover {
  background: var(--accent-strong);
}

.composer button[type="submit"]:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.auth-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

.wide-dialog {
  width: min(680px, calc(100vw - 32px));
}

.auth-dialog.is-open {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 10;
  height: fit-content;
  margin: auto;
  background: #ffffff;
}

.auth-dialog::backdrop {
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(4px);
}

.auth-dialog form {
  display: grid;
  gap: 12px;
  padding: 22px;
}

.auth-dialog h2 {
  font-size: 22px;
}

.auth-dialog label {
  font-size: 13px;
  font-weight: 800;
  color: #344054;
}

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

.auth-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.auth-mode {
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  color: #475467;
  font-weight: 800;
}

.auth-mode.active {
  background: #ffffff;
  color: #172033;
  box-shadow: 0 1px 5px rgba(23, 32, 51, 0.12);
}

.auth-field {
  display: grid;
  gap: 12px;
}

.field-title {
  font-size: 13px;
  font-weight: 800;
  color: #344054;
}

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

.member-option {
  display: grid;
  grid-template-columns: auto 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
  font-weight: 700;
}

.member-option input {
  min-height: auto;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat-grid div {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.stat-grid strong {
  font-size: 22px;
}

.stat-grid span {
  color: var(--muted);
  font-size: 12px;
}

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

.sidebar-overlay {
  display: none;
}

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

  .shell {
    grid-template-columns: 1fr;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    gap: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    display: flex;
    width: min(340px, calc(100vw - 48px));
    border-radius: 0;
    transform: translateX(-104%);
    transition: transform 180ms ease;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 19;
    display: block;
    background: rgba(15, 23, 42, 0.34);
    backdrop-filter: blur(3px);
  }

  .sidebar-overlay[hidden] {
    display: none;
  }

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

  .chat {
    border: 0;
    border-radius: 0;
  }

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

  .mobile-menu-button {
    display: grid;
  }

  .header-avatar {
    width: 38px;
    height: 38px;
  }

  .chat-header h2 {
    font-size: 18px;
  }

  .header-actions {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  .ghost-button {
    min-height: 34px;
    max-width: 116px;
    white-space: normal;
  }

  .messages {
    padding: 16px;
  }

  .message-row {
    max-width: 88%;
  }

  .composer {
    padding: 10px;
  }

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

  .attach-button {
    width: 40px;
    min-height: 42px;
  }
}
