:root {
  --bg: #0f1412;
  --panel: #1a221e;
  --ink: #e8f0ea;
  --muted: #8fa399;
  --accent: #3dba7a;
  --accent-ink: #062012;
  --line: #2a3830;
  --danger: #e07171;
  --out: #244836;
  --in: #24303a;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1e3a2c 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a2a38 0%, transparent 50%),
    var(--bg);
}

.shell {
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow: hidden;
}

.top {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--accent);
}

h1 {
  margin: 0.2rem 0 0;
  font-size: 1.35rem;
  font-weight: 600;
}

h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.chat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.chat-badge[hidden] { display: none !important; }

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.check-row input { width: auto; margin: 0; }

.status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
  max-width: 55%;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  flex: 0 0 auto;
}

.chat-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.send-panel {
  max-height: 34vh;
  overflow: auto;
}

.pair-panel {
  max-height: 28vh;
  overflow: auto;
}

.pair-panel summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.pair-panel summary::-webkit-details-marker { display: none; }

.pair-panel[open] summary {
  margin-bottom: 0.65rem;
}

.hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

label {
  display: block;
  margin: 0.5rem 0 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.muted { color: var(--muted); font-weight: 400; }

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

input, textarea, select {
  width: 100%;
  background: #101714;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

textarea {
  font-family: var(--mono);
  font-size: 0.78rem;
  resize: vertical;
}

.row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.row.between {
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
}

.row textarea, .row input { flex: 1; }

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex-shrink: 0;
}

button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { filter: brightness(1.05); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.ghost, button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.secondary { width: 100%; margin-top: 0.75rem; }

.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.25rem;
}

.bubble {
  max-width: 92%;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 0.92rem;
  line-height: 1.4;
}

.bubble.out {
  align-self: flex-end;
  background: var(--out);
}

.bubble.in {
  align-self: flex-start;
  background: var(--in);
}

.bubble .meta {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
}

.toast {
  position: fixed;
  top: 0.85rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: min(92vw, 420px);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.toast[hidden] { display: none !important; }

/* Ensure hidden attribute works even when sections use display:flex/grid */
[hidden] { display: none !important; }

.error { color: var(--danger); }

.link-screen { max-width: 480px; }
.link-panel { text-align: center; }
.qr-wrap {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  padding: 0.75rem;
  background: #fff;
  border-radius: 12px;
}
.qr-wrap img { display: block; }

.wa-shell {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  height: 100dvh;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
}
.wa-sidebar {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, black);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.wa-sidebar-head, .wa-main-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
.wa-sidebar-head h1, .wa-main-head h2 { margin: 0; font-size: 1rem; }
.friends-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.friend-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.friend-row:hover, .friend-row.active { background: #24352c; }
.friend-row .name { font-weight: 600; }
.friend-row .preview { grid-column: 1 / -1; color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-badge {
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 999px;
  min-width: 1.4rem;
  height: 1.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
}
.wa-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: color-mix(in srgb, var(--panel) 88%, black);
}
.wa-main .thread { flex: 1; padding: 0.75rem 1rem; }
.wa-main .send-panel { border-top: 1px solid var(--line); border-radius: 0; }

@media (max-width: 760px) {
  .wa-shell { grid-template-columns: 1fr; }
  .wa-sidebar { max-height: 40vh; }
}

@media (max-width: 560px) {
  .top { flex-direction: column; align-items: flex-start; }
  .status { text-align: left; max-width: 100%; }
  .row { flex-direction: column; }
  .send-panel { max-height: 40vh; }
}
