:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1f2330;
  --border: #2a2f3d;
  --text: #e6e8ef;
  --muted: #8b92a5;
  --accent: #5865f2;
  --ok: #57f287;
  --warn: #fee75c;
  --bad: #ed4245;
  --in: #262b3a;
  --out: #3a45c7;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  font: 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden {
  display: none !important;
}
.muted {
  color: var(--muted);
}
.error {
  color: var(--bad);
  min-height: 1.2em;
  margin: 8px 0 0;
}
button {
  font: inherit;
  color: var(--text);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:disabled {
  opacity: .5;
  cursor: default;
}
input,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus,
textarea:focus {
  border-color: var(--accent);
}

/* login */
.login {
  height: 100%;
  display: grid;
  place-items: center;
}
.login form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

/* layout */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 600;
  white-space: nowrap;
}
.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  height: 100%;
}
.tab {
  background: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0 12px;
  white-space: nowrap;
}
.tab .sub {
  font-size: 12px;
  opacity: .7;
  margin-left: 6px;
}
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tab.offline {
  text-decoration: line-through;
}
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.status .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.status.online .dot {
  background: var(--ok);
}
.status.offline .dot {
  background: var(--bad);
}
.pair-btn {
  font-size: 13px;
  padding: 5px 10px;
  white-space: nowrap;
}

/* pairing modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  display: grid;
  place-items: center;
  z-index: 10;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: min(380px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.modal-card h2 {
  margin: 0;
  font-size: 18px;
}
.modal-card p {
  margin: 0;
  font-size: 13px;
}
.qr {
  width: 260px;
  height: 260px;
  background: #fff;
  border-radius: 8px;
  padding: 8px;
  display: grid;
  place-items: center;
  color: #000;
}
.qr svg {
  width: 100%;
  height: 100%;
}
#pair-url {
  font-size: 12px;
  word-break: break-all;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
}
.threads {
  width: 300px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}
.threads-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.threads-header button {
  padding: 2px 10px;
  font-size: 18px;
  line-height: 1.2;
}
#thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
#thread-list li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#thread-list li:hover {
  background: var(--panel-2);
}
#thread-list li.active {
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
}
#thread-list .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
#thread-list .peer {
  font-weight: 600;
}
#thread-list .time {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
#thread-list .preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#thread-list .preview.out::before {
  content: "You: ";
}
#thread-list .badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
  margin-left: 6px;
}

.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
}
#conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.conv-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: baseline;
  font-weight: 600;
}
.conv-header .muted {
  font-weight: 400;
  font-size: 13px;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.in {
  align-self: flex-start;
  background: var(--in);
  border-bottom-left-radius: 4px;
}
.msg.out {
  align-self: flex-end;
  background: var(--out);
  border-bottom-right-radius: 4px;
}
.msg .meta {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: .65;
  text-align: right;
}
.msg.pending {
  opacity: .7;
}
.msg.failed {
  background: #5c2326;
}
.msg.failed .meta {
  color: var(--warn);
  opacity: 1;
}
.day {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  margin: 10px 0 4px;
}
.compose {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.compose textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
}
.compose input {
  width: 200px;
}

@media (max-width: 720px) {
  .threads {
    width: 100%;
  }
  .app.has-conv .threads {
    display: none;
  }
  .app:not(.has-conv) .conversation {
    display: none;
  }
  .msg {
    max-width: 88%;
  }
}
