:root {
  color-scheme: dark;
  --rail: #0e1621;
  --sidebar: #17212b;
  --stage: #0e1621;
  --hover: #202b36;
  --active: #2b5278;
  --line: rgba(255, 255, 255, 0.06);
  --text: #f5f5f5;
  --muted: #7f91a4;
  --accent: #5288c1;
  --badge: #40a7e3;
  --in: #182533;
  --out: #2b5278;
  --composer: #17212b;
  --danger: #e25c5c;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.app[data-theme="light"] {
  color-scheme: light;
  --rail: #ffffff;
  --sidebar: #ffffff;
  --stage: #8eabdb;
  --hover: #f4f4f5;
  --active: #3390ec;
  --line: rgba(0, 0, 0, 0.08);
  --text: #222;
  --muted: #707579;
  --accent: #3390ec;
  --badge: #3390ec;
  --in: #ffffff;
  --out: #eeffde;
  --composer: #ffffff;
  --shadow: 0 8px 24px rgba(22, 40, 70, 0.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b1118; color: var(--text); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail svg { fill: currentColor; stroke: none; }

.app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: 68px 360px minmax(0, 1fr);
  min-width: 960px;
}

.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
}
.rail-avatar, .avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  font-weight: 650;
  color: white;
  flex: none;
}
.rail-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}
.rail-btn.is-active, .rail-btn:hover { color: var(--accent); background: var(--hover); }
.rail-bottom { margin-top: auto; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.side-head {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px 6px;
}
.icon-btn, .send, .ghost {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon-btn:hover, .send:hover, .ghost:hover { background: var(--hover); color: var(--text); }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hover);
  border-radius: 22px;
  padding: 0 12px;
  min-width: 0;
}
.search svg { width: 18px; height: 18px; color: var(--muted); }
.search input {
  border: 0;
  background: transparent;
  outline: none;
  width: 100%;
  height: 40px;
}
.folders { display: flex; gap: 6px; padding: 8px 12px 10px; }
.folder {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 16px;
  padding: 6px 12px;
}
.folder.is-active { background: var(--active); color: white; }
.chat-list { overflow: auto; flex: 1; }
.chat-row {
  width: 100%;
  border: 0;
  background: transparent;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 8px 12px;
}
.chat-row:hover { background: var(--hover); }
.chat-row.is-active { background: var(--active); color: white; }
.chat-row.is-active .muted, .chat-row.is-active .preview { color: rgba(255,255,255,.82); }
.chat-row > span:nth-child(2) { min-width: 0; overflow: hidden; }
.name-line, .preview-line { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.name { min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview, .muted, .time { color: var(--muted); font-size: 13px; }
.time { flex: 0 0 auto; }
.preview { display: block; min-width: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--badge);
  color: white;
  font-size: 12px;
  display: grid;
  place-items: center;
  justify-self: end;
}

.stage { background: var(--stage); min-width: 0; display: flex; flex-direction: column; position: relative; }
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.04) 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,.035) 0 1px, transparent 1.5px);
  background-size: 28px 28px, 36px 36px;
  pointer-events: none;
}
.app[data-theme="light"] .stage::before { opacity: .35; }
.topbar, .composer, .composer-wrap, .chat-search, .messages, .panel { position: relative; z-index: 1; }
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: color-mix(in srgb, var(--sidebar) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.who { min-width: 0; flex: 1; }
.who strong, .who span { display: block; }
.who span { color: var(--muted); font-size: 13px; }
.messages {
  flex: 1;
  overflow: auto;
  padding: 16px 12% 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.day {
  align-self: center;
  background: rgba(0,0,0,.25);
  color: white;
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 13px;
  margin: 8px 0;
}
.app[data-theme="light"] .day { background: rgba(255,255,255,.75); color: #3d4d63; }
.bubble {
  max-width: min(68%, 560px);
  padding: 6px 10px 4px;
  border-radius: 12px;
  background: var(--in);
  box-shadow: 0 1px 1px rgba(0,0,0,.12);
  position: relative;
}
.bubble.out { align-self: flex-end; background: var(--out); border-bottom-right-radius: 4px; }
.bubble.in { align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble .text { white-space: pre-wrap; word-break: break-word; line-height: 1.35; }
.meta { display: flex; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 12px; margin-top: 2px; }
.reply-quote {
  border-left: 2px solid var(--accent);
  padding: 2px 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  background: rgba(0,0,0,.12);
  border-radius: 4px;
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px 14px;
}
.composer-box {
  flex: 1;
  background: var(--composer);
  border-radius: 16px;
  min-height: 48px;
  display: flex;
  flex-direction: column;
}
.reply-bar, .empty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 0;
  color: var(--accent);
  font-size: 13px;
}
#draft {
  border: 0;
  resize: none;
  background: transparent;
  outline: none;
  padding: 12px 14px;
  max-height: 140px;
  min-height: 48px;
}
.send.is-ready { color: var(--accent); }
.panel { padding: 28px 32px; overflow: auto; }
.panel h1 { margin: 0 0 8px; font-size: 28px; }
.card {
  background: var(--sidebar);
  border-radius: 16px;
  padding: 8px;
  box-shadow: var(--shadow);
  max-width: 520px;
}
.card button, .contact {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.card button:hover, .contact:hover { background: var(--hover); }
.dialog-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: grid;
  place-items: center;
  z-index: 5;
}
.dialog {
  width: min(420px, calc(100% - 32px));
  background: var(--sidebar);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.dialog h2 { margin: 0 0 12px; }
.dialog input {
  width: 100%;
  border: 0;
  background: var(--hover);
  border-radius: 10px;
  padding: 12px;
  outline: none;
  margin-bottom: 12px;
}
.row { display: flex; justify-content: flex-end; gap: 8px; }
.primary, .quiet {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
}
.primary { background: var(--accent); color: white; }
.quiet { background: transparent; color: var(--muted); }
.photo { max-width: 240px; border-radius: 8px; display: block; margin-bottom: 4px; }
.empty-stage { margin: auto; color: var(--muted); text-align: center; }
.back-btn { display: none; }
.install-note { color: var(--muted); font-size: 14px; line-height: 1.45; padding: 4px 12px 12px; }
.who { background: transparent; border: 0; text-align: left; color: inherit; padding: 0; }
.folders { overflow-x: auto; scrollbar-width: none; }
.folder { flex: none; }
#draft, .search input, .dialog input, .chat-search { font-size: 16px; }
.chat-search {
  width: calc(100% - 24px);
  margin: 8px 12px 0;
  border: 0;
  background: var(--hover);
  color: inherit;
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.author { font-size: 13px; font-weight: 650; margin-bottom: 2px; }
.forwarded { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.deleted { font-style: italic; color: var(--muted); }
.ticks { color: #8ec8f5; letter-spacing: -1px; }
.app[data-theme="light"] .ticks { color: #2f8f4e; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  border: 0;
  background: rgba(127, 145, 164, 0.16);
  color: inherit;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 13px;
}
.reaction.is-mine { outline: 1px solid var(--accent); }
audio { width: min(240px, 72vw); height: 32px; display: block; margin: 4px 0; }
.section-label {
  padding: 10px 16px 4px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
}
.chat-row.is-muted { opacity: 0.72; }
.file-input { display: none; }
.mic-btn.is-recording { background: var(--danger); color: white; }
.composer-wrap { background: var(--stage); }
.sheet-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 6;
}
.sheet {
  width: min(560px, 100%);
  background: var(--sidebar);
  border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(12px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.sheet h2 { margin: 0; padding: 12px 12px 4px; font-size: 16px; }
.sheet button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 10px;
  padding: 13px 12px;
  font-size: 16px;
}
.sheet button:hover, .sheet button:focus { background: var(--hover); }
.emoji-row { display: flex; justify-content: space-between; gap: 4px; padding: 4px 8px 8px; }
.emoji-row button {
  border: 0;
  background: transparent;
  font-size: 24px;
  padding: 4px;
  border-radius: 10px;
}
#profile-name {
  width: 100%;
  border: 0;
  background: var(--hover);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  outline: none;
  font-size: 16px;
}

@media (max-width: 960px) {
  html, body { overflow: hidden; }
  .app {
    min-width: 0;
    height: var(--vvh, 100dvh);
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    padding-top: env(safe-area-inset-top);
  }
  .sidebar, .stage { grid-row: 1; grid-column: 1; min-height: 0; }
  .rail {
    grid-row: 2;
    flex-direction: row;
    justify-content: space-around;
    border-right: 0;
    border-top: 1px solid var(--line);
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  }
  .rail-avatar { display: none; }
  .rail-bottom { margin-top: 0; }
  .app.view-chats:not(.show-chat) .stage { display: none; }
  .app.is-signed-out.view-chats .stage { display: block; }
  .app.view-chats.show-chat .sidebar,
  .app.view-chats.show-chat .rail { display: none; }
  .app.view-contacts .sidebar,
  .app.view-settings .sidebar { display: none; }
  .back-btn { display: grid; }
  .folder { padding: 6px 10px; font-size: 14px; }
  .messages { padding: 12px 12px 8px; }
  .bubble { max-width: 84%; }
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .panel { padding: 20px 16px; }
}

/* bstacht professional */
.app.is-signed-out {
  grid-template-columns: 1fr;
}
.app.is-signed-out .rail,
.app.is-signed-out .sidebar {
  display: none;
}
.app.is-signed-out .stage {
  grid-column: 1;
}
.rail-avatar {
  padding: 0;
  overflow: hidden;
  background: transparent;
}
.rail-avatar img,
.profile-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
}
.bstacht-login {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 20px;
  text-align: center;
}
.login-logo {
  width: 92px;
  height: 96px;
  object-fit: cover;
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0, 80, 255, .25);
}
.bstacht-login h1 {
  margin: 8px 0 0;
  font-size: 34px;
  letter-spacing: -1px;
}
.bstacht-login p { margin: 0 0 12px; opacity: .72; }
.login-form {
  width: min(360px, 100%);
  display: grid;
  gap: 10px;
}
.login-form input {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line, rgba(255,255,255,.12));
  padding: 0 14px;
  font: inherit;
  background: var(--panel, #17212b);
  color: inherit;
}
.login-error { min-height: 20px; color: #f06b72; font-size: 13px; }
.profile-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 16px;
}
.profile-summary .profile-logo { width: 52px; height: 54px; }
.profile-summary div { display: grid; gap: 3px; }
.profile-summary span { opacity: .65; font-size: 13px; }
button.danger { color: #ff777f; }
.ticks[data-state="READ"] { color: #42a5ff; }
