*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --surface: #111;
  --surface-2: #181818;
  --border: #222;
  --border-2: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #666;
  --accent: #ff6a00;
  --accent-dim: rgba(255,106,0,.12);
  --danger: #e53e3e;
  --radius: 0px;
  --font: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .font-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }
.hidden { display: none !important; }
.mt-2 { margin-top: 1.5rem; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: .5rem 1.25rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #e05e00; border-color: #e05e00; text-decoration: none; }
.btn-ghost {
  border-color: var(--border-2);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); text-decoration: none; }
.btn-sm { padding: .3rem .75rem; font-size: 13px; }
.full-width { width: 100%; }

/* ── Topbar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: -.5px;
}
.logo:hover { text-decoration: none; }
.topbar-nav { display: flex; gap: 1.25rem; align-items: center; }
.topbar-nav a { color: var(--text-muted); font-size: 13px; }
.topbar-nav a:hover { color: var(--text); text-decoration: none; }
.logout-link { color: var(--text-muted) !important; }

/* ── Flash ──────────────────────────────────────────────────────────────── */

.flash-container { padding: .5rem 1.25rem; }
.flash {
  background: var(--surface-2);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: .6rem 1rem;
  font-size: 13px;
  margin-bottom: .5rem;
}

/* ── Auth forms ─────────────────────────────────────────────────────────── */

.auth-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 4rem 1rem;
  min-height: calc(100vh - 48px);
}
.auth-box {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem;
}
.auth-box--wide { max-width: 540px; }
.auth-box h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 1.5rem; }
.auth-footer { margin-top: 1.25rem; text-align: center; color: var(--text-muted); font-size: 13px; }

label {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1rem;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
label .hint { font-weight: 400; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .55rem .75rem;
  font-family: var(--font);
  font-size: 14px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }

/* ── QR / backup codes ──────────────────────────────────────────────────── */

.qr-wrap { display: flex; justify-content: center; margin: 1.5rem 0; }
.qr-img { width: 180px; height: 180px; image-rendering: pixelated; }

.secret-details { margin-bottom: 1rem; }
.secret-details summary { color: var(--text-muted); font-size: 13px; cursor: pointer; }
.secret-code {
  display: block;
  margin-top: .75rem;
  padding: .6rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 14px;
  word-break: break-all;
  color: var(--accent);
  letter-spacing: .1em;
}

.backup-codes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin: 1.25rem 0;
}
.backup-code {
  display: block;
  padding: .6rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 14px;
  text-align: center;
  color: var(--accent);
  letter-spacing: .1em;
}

/* ── Landing ────────────────────────────────────────────────────────────── */

.landing {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 2rem;
}
.landing-inner { max-width: 560px; }
.landing-title {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 1rem;
}
.landing-sub { color: var(--text-muted); font-size: 1rem; margin-bottom: 2rem; line-height: 1.6; }
.landing-features {
  list-style: none;
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.landing-features li {
  padding-left: 1rem;
  color: var(--text-muted);
  font-size: 13px;
  position: relative;
}
.landing-features li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--accent);
}
.landing-actions { display: flex; gap: .75rem; }

/* ── Chat layout ────────────────────────────────────────────────────────── */

.chat-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: calc(100vh - 48px);
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-search {
  padding: .75rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sidebar-search input {
  width: 100%;
  padding: .45rem .65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-top: none;
  z-index: 50;
  max-height: 240px;
  overflow-y: auto;
}
.search-result {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--surface); }
.search-result-name { font-size: 13px; font-weight: 500; }
.search-result-username { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

.conversation-list { flex: 1; overflow-y: auto; }
.conversation-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background .1s;
}
.conversation-item:hover { background: var(--surface-2); text-decoration: none; }
.conversation-item.active { background: var(--accent-dim); border-left: 2px solid var(--accent); }
.conversation-delete { display: none; background: none; border: none; color: var(--text-muted); font-size: 16px; line-height: 1; padding: 2px 4px; cursor: pointer; margin-left: .25rem; flex-shrink: 0; }
.conversation-delete:hover { color: #e53935; }
.conversation-item:hover .conversation-delete { display: block; }
.conversation-name { font-size: 13px; font-weight: 500; }
.conversation-username { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }
.conversation-meta { margin-left: auto; text-align: right; flex-shrink: 0; }
.conversation-time { font-size: 11px; color: var(--text-muted); }
.unread-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: .1rem .35rem;
  min-width: 18px;
  text-align: center;
  margin-top: .2rem;
}
.loading-text { padding: 1rem; color: var(--text-muted); font-size: 13px; text-align: center; }

/* ── Chat main ──────────────────────────────────────────────────────────── */

.chat-main {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.chat-main--empty { justify-content: center; align-items: center; }
.empty-state { color: var(--text-muted); font-size: 14px; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: .75rem; }
.chat-display-name { font-size: 14px; font-weight: 600; }
.chat-username { font-size: 12px; font-family: var(--font-mono); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  gap: .2rem;
}
.msg--mine { align-self: flex-end; align-items: flex-end; }
.msg--theirs { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: .5rem .75rem;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg--mine .msg-bubble {
  background: var(--accent);
  color: #fff;
}
.msg--theirs .msg-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.msg-bubble--encrypted {
  font-style: italic;
  color: var(--text-muted) !important;
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: 11px;
  color: var(--text-muted);
}
.msg-read { color: var(--accent); }

.chat-input-wrap {
  display: flex;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.msg-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: .5rem .75rem;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
}
.msg-input:focus { border-color: var(--accent); }

.key-warning {
  padding: .5rem 1rem;
  background: var(--surface-2);
  border-top: 1px solid var(--danger);
  color: var(--danger);
  font-size: 12px;
  text-align: center;
}

/* ── Avatar ─────────────────────────────────────────────────────────────── */

.avatar {
  width: 36px;
  height: 36px;
  object-fit: cover;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar--sm { width: 32px; height: 32px; }
.avatar--lg { width: 80px; height: 80px; font-size: 2rem; }
.avatar--placeholder {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .9rem;
  font-weight: 600;
}

/* ── Profile ────────────────────────────────────────────────────────────── */

.profile-wrap {
  display: flex;
  justify-content: center;
  padding: 3rem 1rem;
}
.profile-card {
  display: flex;
  gap: 2rem;
  max-width: 640px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem;
}
.profile-avatar-wrap { flex-shrink: 0; }
.profile-display-name { font-size: 1.25rem; font-weight: 600; margin-bottom: .3rem; }
.profile-username { font-family: var(--font-mono); font-size: 13px; margin-bottom: .75rem; }
.profile-bio { color: var(--text-muted); font-size: 14px; line-height: 1.6; margin-bottom: 1rem; }
.profile-actions { display: flex; gap: .5rem; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); }

.search-dropdown {
  position: absolute;
  background: white;
  border: 1px solid #ccc;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
}

.search-result {
  padding: 5px;
  cursor: pointer;
}

.search-result:hover {
  background: #f0f0f0;
}

.sidebar-search {
  position: relative;
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  border: 1px solid #ccc;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  width: 100%;
}

.search-result {
  padding: 5px;
  cursor: pointer;
}

.search-result:hover {
  background: #f0f0f0;
}
