:root {
  --ink: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --paper: #f8fafc;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --green: #4d7c0f;
  --green-soft: #d9f99d;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b91c1c;
  --violet: #6d28d9;
  --shadow: 0 16px 45px rgba(15, 23, 42, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(120deg, rgba(217, 249, 157, 0.34), transparent 30%),
    linear-gradient(320deg, rgba(37, 99, 235, 0.12), transparent 34%),
    var(--paper);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  align-items: center;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 8px;
  color: white;
  cursor: pointer;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  min-height: 40px;
  padding: 9px 12px;
}

button.secondary {
  background: var(--panel);
  color: var(--ink);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink);
}

button.danger {
  background: var(--red);
  border-color: var(--red);
}

button.small {
  min-height: 30px;
  padding: 4px 8px;
}

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

input,
textarea,
select {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 40px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  min-height: 44px;
  resize: none;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 6px;
  line-height: 1.25;
}

.app-shell {
  min-height: 100%;
}

.boot,
.onboarding {
  align-items: center;
  display: grid;
  gap: 18px;
  justify-items: center;
  min-height: 100vh;
  padding: 24px;
  text-align: center;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border-radius: 8px;
  color: var(--green-soft);
  display: inline-flex;
  font-size: 28px;
  font-weight: 800;
  height: 62px;
  justify-content: center;
  width: 62px;
}

.onboarding-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  max-width: 620px;
  padding: 22px;
  width: min(100%, 620px);
}

.onboarding h1,
.onboarding p {
  margin: 0;
}

.passphrase {
  background: var(--panel-2);
  border: 1px dashed #94a3b8;
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 1fr);
  padding: 12px;
}

.passphrase span {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
  padding: 8px;
}

.split-actions {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.workspace {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr) minmax(260px, 360px);
  min-height: 100vh;
}

.rail,
.side-panel {
  background: rgba(255, 255, 255, 0.88);
  border-color: var(--line);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.rail {
  border-right: 1px solid var(--line);
}

.side-panel {
  border-left: 1px solid var(--line);
}

.rail-header,
.chat-header,
.side-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  min-height: 68px;
  padding: 12px;
}

.identity {
  min-width: 0;
}

.identity strong,
.chat-title strong,
.side-header strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity span,
.chat-title span,
.side-header span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  background: var(--green);
  border: 2px solid white;
  border-radius: 999px;
  flex: 0 0 auto;
  height: 13px;
  width: 13px;
}

.search-wrap {
  padding: 12px;
}

.chat-list {
  display: grid;
  gap: 4px;
  overflow: auto;
  padding: 0 8px 12px;
}

.chat-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 8px;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  justify-content: stretch;
  min-height: 56px;
  padding: 8px;
  text-align: left;
}

.chat-item:hover,
.chat-item.active {
  background: var(--panel-2);
  border-color: var(--line);
}

.avatar {
  align-items: center;
  background: var(--green-soft);
  border-radius: 8px;
  color: #365314;
  display: inline-flex;
  font-weight: 800;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.avatar.group {
  background: #dbeafe;
  color: #1d4ed8;
}

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

.chat-meta strong,
.chat-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.badge {
  background: #fee2e2;
  border-radius: 999px;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 6px;
}

.rail-actions {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding: 12px;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
}

.chat-header {
  background: rgba(248, 250, 252, 0.9);
  justify-content: space-between;
}

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

.chat-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.messages {
  align-content: end;
  display: grid;
  gap: 10px;
  overflow: auto;
  padding: 18px;
}

.empty-chat {
  align-self: center;
  color: var(--muted);
  justify-self: center;
  max-width: 320px;
  text-align: center;
}

.message {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  justify-self: start;
  max-width: min(72ch, 78%);
  padding: 10px 12px;
}

.message.mine {
  background: #ecfccb;
  border-color: #bef264;
  justify-self: end;
}

.message.deleted {
  color: var(--muted);
  font-style: italic;
}

.message-sender {
  color: #334155;
  display: none;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.message-sender.visible {
  display: block;
}

.message.mine .message-sender {
  text-align: right;
}

.reply-chip {
  background: rgba(37, 99, 235, 0.08);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  color: #1e3a8a;
  display: none;
  font-size: 12px;
  padding: 6px 8px;
}

.reply-chip.visible {
  display: block;
}

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

.message footer {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 11px;
  gap: 8px;
  justify-content: flex-end;
}

.message-actions {
  display: none;
  gap: 4px;
}

.message:hover .message-actions,
.message:focus-within .message-actions {
  display: inline-flex;
}

.message-actions button {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 11px;
  min-height: 24px;
  padding: 2px 4px;
}

.attachment {
  display: grid;
  gap: 8px;
}

.attachment img,
.attachment video {
  border-radius: 8px;
  max-height: 260px;
  max-width: 100%;
  object-fit: contain;
}

.attachment audio {
  width: min(320px, 100%);
}

.attachment-file {
  align-items: center;
  background: rgba(15, 23, 42, 0.05);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  padding: 8px;
}

.typing-row {
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
  padding: 0 18px 8px;
}

.composer {
  background: rgba(255, 255, 255, 0.92);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.reply-bar {
  align-items: center;
  background: var(--panel-2);
  border-radius: 8px;
  display: none;
  gap: 8px;
  justify-content: space-between;
  padding: 8px;
}

.reply-bar.visible {
  display: flex;
}

.composer-row {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.file-picker {
  display: none;
}

.side-body {
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 12px;
}

.section {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
}

.section:last-child {
  border-bottom: 0;
}

.section h2 {
  font-size: 15px;
  margin: 0;
}

.section p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin: 0;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 12px;
  gap: 6px;
  padding: 6px 9px;
}

.pill.good {
  background: #ecfccb;
  border-color: #bef264;
}

.pill.warn {
  background: #fef3c7;
  border-color: #fcd34d;
}

.pill.info {
  background: #dbeafe;
  border-color: #93c5fd;
}

.toggle-row,
.field-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.toggle-row input {
  height: 20px;
  min-height: 20px;
  width: 20px;
}

.call-stage {
  background: #0f172a;
  border-radius: 8px;
  color: white;
  display: none;
  gap: 10px;
  padding: 10px;
}

.call-stage.visible {
  display: grid;
}

.video-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 2fr 1fr;
}

.video-tile {
  align-items: center;
  background: #1f2937;
  border: 1px solid #334155;
  border-radius: 8px;
  display: grid;
  min-height: 150px;
  overflow: hidden;
  place-items: center;
  position: relative;
}

.video-tile video {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.video-tile span {
  color: #cbd5e1;
  position: absolute;
}

.toast-stack {
  bottom: 16px;
  display: grid;
  gap: 8px;
  position: fixed;
  right: 16px;
  width: min(360px, calc(100vw - 32px));
  z-index: 10;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: white;
  padding: 10px 12px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 16px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop.visible {
  display: flex;
}

.modal {
  background: white;
  border-radius: 8px;
  display: grid;
  gap: 14px;
  max-width: 560px;
  padding: 18px;
  width: min(100%, 560px);
}

.modal h2,
.modal p {
  margin: 0;
}

.modal p {
  color: var(--muted);
}

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  }

  .side-panel {
    display: none;
  }

  .side-panel.open {
    display: flex;
    inset: 0 0 0 auto;
    max-width: 380px;
    position: fixed;
    width: min(92vw, 380px);
    z-index: 9;
  }
}

@media (max-width: 720px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .rail {
    display: none;
  }

  .rail.open {
    display: flex;
    inset: 0 auto 0 0;
    max-width: 330px;
    position: fixed;
    width: min(92vw, 330px);
    z-index: 9;
  }

  .chat-header {
    align-items: stretch;
    flex-direction: column;
  }

  .chat-tools {
    justify-content: stretch;
  }

  .chat-tools button {
    flex: 1 1 auto;
  }

  .message {
    max-width: 92%;
  }

  .composer-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .composer-row button[type="submit"] {
    grid-column: 1 / -1;
  }

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