:root {
  --ink: #12181F;
  --surface: #1B2430;
  --surface-raised: #232E3D;
  --line: #2C3847;
  --text: #EDEFF2;
  --muted: #7C8798;
  --signal: #5EEAD4;
  --signal-dim: #2E6C64;
  --call: #F2795A;
  --danger: #E05252;
  --font-display: "IBM Plex Mono", monospace;
  --font-body: "IBM Plex Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- Auth ---------- */

#screen-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, rgba(94,234,212,0.08), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(242,121,90,0.06), transparent 40%),
    var(--ink);
}

.auth-wrap { width: 100%; max-width: 380px; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--signal); margin-bottom: 18px; }
.brand-mark { color: var(--signal); }
.brand-name { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; letter-spacing: 0.02em; color: var(--text); }

.tagline {
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 28px;
  max-width: 34ch;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
}

.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--ink); border-radius: 9px; padding: 3px; }
.auth-tabs button {
  flex: 1; padding: 8px 10px; border: none; background: transparent; color: var(--muted);
  border-radius: 7px; font-size: 0.88rem; font-weight: 500; transition: background 0.15s, color 0.15s;
}
.auth-tabs button.active { background: var(--surface-raised); color: var(--text); }

#auth-form { display: flex; flex-direction: column; gap: 14px; }
#auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; color: var(--muted); }
#auth-form input {
  background: var(--ink); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 0.95rem; outline: none;
}
#auth-form input:focus { border-color: var(--signal); }

.auth-error { color: var(--danger); font-size: 0.82rem; min-height: 1em; margin: 0; }

.btn-primary {
  background: var(--signal); color: #062420; border: none; border-radius: 8px;
  padding: 11px 16px; font-weight: 600; font-size: 0.95rem; transition: filter 0.15s;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-secondary {
  background: transparent; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; font-size: 0.9rem; font-weight: 500;
}
.btn-secondary:hover { border-color: var(--signal); }

.btn-danger { background: var(--danger); color: white; border: none; border-radius: 8px; padding: 11px 18px; font-weight: 600; }

.full-width { width: 100%; }

.fine-print { font-size: 0.75rem; line-height: 1.5; color: var(--muted); margin: 16px 0 0; }

/* ---------- App shell ---------- */

#screen-app { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 280px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px;
}

.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal); flex-shrink: 0; box-shadow: 0 0 8px var(--signal); }
.me-name { font-weight: 600; font-size: 0.92rem; }
.me-fingerprint { font-family: var(--font-display); font-size: 0.68rem; color: var(--muted); }

.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; width: 34px; height: 34px; font-size: 1rem; flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--signal); }

.convo-list { list-style: none; margin: 14px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.convo-item {
  padding: 10px 12px; border-radius: 8px; font-size: 0.9rem; color: var(--text);
  cursor: pointer; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo-item:hover { background: var(--surface-raised); }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }

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

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.chat-header h2 { font-size: 1rem; margin: 0; font-weight: 600; }
.chat-actions { display: flex; gap: 8px; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }

.msg {
  max-width: 62%; padding: 9px 13px; border-radius: 12px; background: var(--surface-raised);
  align-self: flex-start; font-size: 0.92rem; line-height: 1.45; word-wrap: break-word;
}
.msg.me { background: var(--signal-dim); align-self: flex-end; }
.msg img, .msg video { max-width: 100%; border-radius: 8px; display: block; }

.send-form { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
#message-input {
  flex: 1; background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 14px; font-size: 0.92rem; outline: none;
}
#message-input:focus { border-color: var(--signal); }
.send-btn { padding: 10px 18px; }

/* ---------- Call overlay ---------- */

.call-overlay {
  position: fixed; inset: 0; background: #05080B; z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.call-overlay video#remote-video { width: 100%; height: 100%; object-fit: cover; }
.local-video {
  position: absolute; bottom: 24px; right: 24px; width: 150px; height: 110px;
  border-radius: 10px; object-fit: cover; border: 2px solid var(--surface-raised);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
}
.call-controls {
  position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center; background: rgba(18,24,31,0.85);
  padding: 14px 22px; border-radius: 999px; backdrop-filter: blur(6px);
}
.call-controls p { margin: 0; color: var(--text); font-size: 0.9rem; }

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  #screen-app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
  .msg { max-width: 82%; }
  .local-video { width: 100px; height: 74px; bottom: 100px; }
}
