:root {
  --background: #101014;
  --foreground: #f5f4f2;
  --card: #18181d;
  --card-2: #1b1b21;
  --muted: #222229;
  --muted-fg: rgba(245, 244, 242, 0.5);
  --primary: #84e4ba;
  --primary-fg: #102018;
  --border: rgba(255, 255, 255, 0.10);
  --text-dim: rgba(255, 255, 255, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* === TOP BAR === */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.tb-icon {
  background: transparent;
  border: 0;
  color: var(--foreground);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}
.tb-icon:hover { background: var(--muted); }
.tb-icon .material-symbols-outlined { font-size: 24px; }

.tb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}
.tb-logo { font-size: 22px; line-height: 1; color: var(--primary); }
.tb-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--foreground);
}

.tb-spacer { flex: 1; }

/* === MAIN SHELL === */
.shell {
  display: grid;
  grid-template-columns: 88px 1fr;
  padding-top: 56px;
  height: 100vh;
}

/* === LEFT NAV (Flawer-style) === */
.nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  background: var(--background);
  border-right: 1px solid var(--border);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 56px;
  width: 72px;
  border-radius: 14px;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.68);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  overflow: hidden;
  padding: 0;
}
.nav-item:hover {
  color: var(--foreground);
  background: var(--muted);
}
.nav-item.active {
  color: var(--background);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 -2px 4px rgba(0,0,0,0.12);
}

.nav-icon {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 56px;
  flex-shrink: 0;
}
.nav-icon .material-symbols-outlined {
  font-size: 26px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 40;
}
.nav-item.active .nav-icon .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 40;
}

.nav-label {
  display: none;
}

@media (min-width: 1024px) {
  .shell { grid-template-columns: 232px 1fr; }
  .nav-item {
    width: auto;
    padding: 0 14px;
    gap: 12px;
  }
  .nav-icon { width: 32px; height: 100%; flex-shrink: 0; }
  .nav-icon .material-symbols-outlined { font-size: 26px; }
  .nav-label {
    display: inline;
    font-size: 15px;
    font-weight: 500;
    position: relative;
    z-index: 1;
    white-space: nowrap;
  }
}

/* === CONTENT === */
.content {
  background: var(--background);
  overflow: hidden;
}

.content-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.content-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.search:focus-within {
  border-color: var(--primary);
  background: var(--card-2);
}
.search-icon {
  color: var(--muted-fg);
  font-size: 20px;
}
.search input {
  background: transparent;
  border: 0;
  outline: none;
  color: var(--foreground);
  font-size: 14px;
  flex: 1;
}
.search input::placeholder { color: var(--text-dim); }

/* === CHAT STAGE === */
.chat-stage {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted-fg);
  gap: 12px;
  padding: 32px;
  text-align: center;
}
.empty-icon {
  font-size: 64px;
  opacity: 0.4;
}
.empty-title {
  font-size: 17px;
  font-weight: 500;
  color: var(--foreground);
}
.empty-sub { font-size: 13px; }

/* === ACTIVE CHAT (will be styled when active) === */
.chat-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-peer-bar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
}
.chat-peer-bar .online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}
.chat-peer-bar .offline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}
.msg.me {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
  align-self: flex-end;
}
.msg.peer { align-self: flex-start; }
.msg.time {
  font-size: 11px;
  color: var(--text-dim);
  align-self: center;
  padding: 4px 8px;
  background: transparent;
  border: 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  background: var(--background);
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1;
  padding: 11px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--foreground);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}
.composer input:focus { border-color: var(--primary); }
.composer input::placeholder { color: var(--text-dim); }
.composer button {
  padding: 11px 22px;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  padding: 32px;
  border-radius: 16px;
  width: min(480px, 92vw);
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.modal-logo { color: var(--primary); font-size: 22px; }
.muted { color: var(--muted-fg); font-size: 13px; }
.muted-title { font-weight: 500; margin-bottom: 4px; }
.ts-wrapper { margin: 16px 0; min-height: 65px; }
.hidden { display: none !important; }

.seed {
  background: var(--background);
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 14px;
}
.seed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.seed-grid div {
  background: var(--card-2);
  padding: 8px 10px;
  border-radius: 8px;
}
.pubid-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.pubid-box b { font-family: ui-monospace, monospace; color: var(--foreground); }
.copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-fg);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 10px;
  text-transform: uppercase;
}
.btn-primary {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* === SCROLLBARS === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.14);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }
::-webkit-scrollbar-track { background: transparent; }

/* === AVATAR (topbar) + POPOVER === */
.tb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--primary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.tb-avatar:hover { background: var(--card-2); border-color: rgba(255,255,255,0.18); }
.tb-avatar:active { transform: scale(0.96); }
.tb-avatar[hidden] { display: none; }

.avatar-menu {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 60;
  width: min(280px, calc(100vw - 24px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.avatar-menu.hidden { display: none; }

.am-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--border);
}
.am-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  border: 1px solid var(--border);
}
.am-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.am-name {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--foreground);
  word-break: break-all;
  line-height: 1.3;
}
.am-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-fg);
}
.am-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}
.am-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.am-btn {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s ease;
}
.am-btn:hover { background: var(--muted); }
.am-btn-danger { color: #ff8a8a; border-color: rgba(255,138,138,0.25); }
.am-btn-danger:hover { background: rgba(255,138,138,0.10); border-color: rgba(255,138,138,0.4); }
