:root {
  color-scheme: dark;
  --bg: #05070b;
  --panel: #0b1118;
  --panel-2: #091018;
  --ink: #d9fff6;
  --text: #d7dde6;
  --muted: #70808f;
  --line: #1d3440;
  --line-strong: #2f6f75;
  --primary: #00d1b2;
  --primary-strong: #39ffe0;
  --danger: #ff4f6d;
  --locked: #261a0a;
  --locked-line: #a86b16;
  --shadow: 0 0 0 1px rgba(0, 209, 178, 0.04), 0 18px 42px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    radial-gradient(circle at top left, rgba(0, 209, 178, 0.12), transparent 34rem),
    var(--bg);
  background-size: 22px 22px, 22px 22px, auto, auto;
  color: var(--text);
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 7, 11, 0.94);
  backdrop-filter: blur(12px);
}

.brand,
.session {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: 0;
}

.brand__mark {
  width: 16px;
  height: 16px;
  border: 1px solid #6affea;
  border-radius: 2px;
  background:
    linear-gradient(135deg, #e0372d 0 44%, transparent 45%),
    linear-gradient(315deg, #00a887 0 48%, #dfb72f 49%);
  box-shadow: 0 0 12px rgba(0, 209, 178, 0.32);
}

.status {
  min-width: 86px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  background: #071018;
  text-transform: uppercase;
}

.status.is-online {
  border-color: rgba(0, 209, 178, 0.5);
  color: var(--primary-strong);
  background: rgba(0, 209, 178, 0.08);
  box-shadow: inset 0 0 18px rgba(0, 209, 178, 0.06);
}

.current-user {
  min-width: 64px;
  color: var(--text);
  font-weight: 700;
}

.auth {
  min-height: calc(100vh - 58px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(100%, 410px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(0, 209, 178, 0.035), transparent 130px), var(--panel);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  margin: 0;
  color: var(--ink);
  font-size: 26px;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.key-details dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--ink);
  background: #060b11;
  outline: none;
}

input {
  min-height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 82px;
  padding: 10px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #596877;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(0, 209, 178, 0.32), 0 0 18px rgba(0, 209, 178, 0.11);
}

.button,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--ink);
  background: #07141a;
  cursor: pointer;
  text-transform: uppercase;
}

.button {
  padding: 0 14px;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 18px;
}

.button:hover,
.icon-button:hover {
  border-color: var(--primary);
  background: #092027;
  box-shadow: 0 0 14px rgba(0, 209, 178, 0.12);
}

.button--primary {
  border-color: var(--primary);
  color: #02110f;
  background: var(--primary);
}

.button--primary:hover {
  border-color: var(--primary-strong);
  background: var(--primary-strong);
}

.button--ghost {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
}

.button:disabled,
.icon-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.auth-error {
  margin: 0;
  padding: 10px;
  border: 1px solid rgba(255, 79, 109, 0.38);
  border-radius: 3px;
  color: var(--danger);
  background: rgba(255, 79, 109, 0.08);
}

.auth-switch {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--primary);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.messenger {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(270px, 330px);
  gap: 14px;
  width: min(1520px, calc(100vw - 28px));
  height: calc(100vh - 82px);
  margin: 12px auto;
}

.sidebar,
.chat,
.key-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(11, 17, 24, 0.94);
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.sidebar__head,
.chat__head,
.key-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 11, 17, 0.72);
}

.sidebar__head h2,
.chat__head h1,
.key-panel__head h2 {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.sidebar__head h2,
.key-panel__head h2 {
  font-size: 17px;
}

.chat__head h1 {
  min-width: 140px;
  font-size: 22px;
}

.key-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.key-panel__actions,
.key-editor__actions {
  display: flex;
  gap: 8px;
}

.key-panel__actions .button {
  padding: 0 10px;
}

.key-editor {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 209, 178, 0.035);
}

.key-error {
  margin: 0;
  padding: 8px;
  border: 1px solid rgba(255, 79, 109, 0.38);
  border-radius: 3px;
  color: var(--danger);
  background: rgba(255, 79, 109, 0.08);
  font-size: 12px;
}

.key-details {
  display: grid;
  align-content: start;
  gap: 13px;
  margin: 0;
  overflow: auto;
  padding: 14px;
}

.key-details div {
  display: grid;
  gap: 6px;
}

.key-details dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.key-details code {
  display: block;
  max-height: 168px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--primary-strong);
  background: #061016;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.user-list {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
  padding: 10px;
}

.user-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 0 10px;
  color: var(--text);
  text-align: left;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
}

.user-button:hover {
  border-color: var(--line);
  background: rgba(0, 209, 178, 0.04);
}

.user-button.is-active {
  border-color: rgba(0, 209, 178, 0.45);
  color: var(--primary-strong);
  background: rgba(0, 209, 178, 0.09);
}

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

.message-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 16px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.014) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 1px, transparent 1px),
    #070b11;
  background-size: 18px 18px;
}

.message {
  display: grid;
  gap: 6px;
  width: min(74%, 680px);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #0d141c;
}

.message--own {
  justify-self: end;
  border-color: rgba(0, 209, 178, 0.45);
  background: rgba(0, 209, 178, 0.08);
}

.message--peer {
  justify-self: start;
}

.message--locked {
  border-color: var(--locked-line);
  background: var(--locked);
}

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

.message__body {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: rgba(6, 11, 17, 0.92);
}

.composer textarea {
  min-height: 72px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  color: var(--muted);
  background: rgba(6, 11, 17, 0.54);
}

.empty--small {
  min-height: 78px;
  margin: 10px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar {
    padding: 0 12px;
  }

  .session {
    gap: 6px;
  }

  .current-user {
    display: none;
  }

  .messenger {
    grid-template-columns: 1fr;
    height: auto;
    width: min(100vw - 20px, 760px);
  }

  .sidebar {
    max-height: 240px;
  }

  .chat {
    min-height: 620px;
  }

  .chat__head,
  .composer {
    grid-template-columns: 1fr;
  }

  .chat__head {
    display: grid;
  }

  .message {
    width: min(92%, 680px);
  }
}
