/* ── Reset & Variables ──────────────────────────────────────────────────── */
:root {
  --bg:        #0a0a0f;
  --surface:   #13131a;
  --surface2:  #1c1c28;
  --border:    #2a2a3a;
  --accent:    #6c63ff;
  --accent-d:  #5a52e0;
  --green:     #4ade80;
  --red:       #f87171;
  --yellow:    #fbbf24;
  --text:      #e8e8f0;
  --muted:     #6b6b80;
  --muted2:    #9898b0;
  --radius:    14px;
  --radius-sm: 8px;
  --nav-h:     60px;
  --hdr-h:     56px;
}

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

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
textarea, input { font-family: inherit; }

/* ── App Shell ─────────────────────────────────────────────────────────── */
#app { height: 100dvh; overflow: hidden; }

.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(var(--nav-h) + 16px);
}

/* ── Bottom Navbar ─────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
  transition: color .2s;
}

.nav-item span:first-child { font-size: 20px; }
.nav-item.active { color: var(--accent); }

/* ── Page Header ───────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }

/* ── Auth ──────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
}

.logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 4px;
}
.logo span { color: var(--accent); }

.auth-sub   { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.auth-link  { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }

.auth-error {
  background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 16px;
}
.hidden { display: none !important; }

/* ── Form Fields ───────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 500;
}

input[type=text],
input[type=email],
input[type=password],
input[type=file],
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

input:focus, textarea:focus { border-color: var(--accent); }

textarea { resize: vertical; min-height: 70px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, opacity .2s;
}
.btn-primary:hover { background: var(--accent-d); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background .2s;
}
.btn-secondary:hover { background: var(--border); }

.btn-danger-outline {
  width: 100%;
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 12px;
}

.btn-icon {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 34px; height: 34px;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}

.btn-sm {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}
.btn-success { background: rgba(74,222,128,.15); border-color: rgba(74,222,128,.4); color: var(--green); }
.btn-danger  { background: rgba(248,113,113,.1);  border-color: rgba(248,113,113,.3); color: var(--red); }

/* ── Avatar ────────────────────────────────────────────────────────────── */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-initial {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 16px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* ── Chat List ─────────────────────────────────────────────────────────── */
.chat-list { display: flex; flex-direction: column; gap: 2px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.chat-item:hover { background: var(--surface2); }

.chat-item-info  { flex: 1; min-width: 0; }
.chat-item-top   { display: flex; align-items: center; justify-content: space-between; margin-bottom: 3px; }
.chat-name       { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-pin        { font-size: 11px; color: var(--muted); font-family: monospace; }
.chat-meta       { font-size: 12px; color: var(--muted); }
.chat-last       { font-size: 13px; color: var(--muted2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status     { font-size: 12px; color: var(--muted); }

.dot-online {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 3px;
}

/* ── Chat Shell ────────────────────────────────────────────────────────── */
.chat-shell { overflow: hidden; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--hdr-h);
  flex-shrink: 0;
}

.btn-back {
  background: none; border: none;
  color: var(--accent); font-size: 20px; cursor: pointer; padding: 4px;
}

.peer-name   { font-weight: 600; font-size: 15px; }
.peer-status { font-size: 12px; color: var(--muted); }

#chat-peer-info { display: flex; align-items: center; gap: 10px; flex: 1; }

.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg);
}

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

/* ── Messages ──────────────────────────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  margin-bottom: 2px;
}

.msg-out {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-in {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sender {
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 3px;
  font-weight: 600;
}

.msg-text {
  background: var(--surface2);
  padding: 9px 13px;
  border-radius: 16px 16px 16px 4px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.msg-out .msg-text {
  background: var(--accent);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}

.msg-img {
  max-width: 220px;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid var(--border);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}

.msg-time { font-size: 11px; color: var(--muted); }

.receipt      { font-size: 12px; }
.receipt.sent { color: var(--muted); }
.receipt.delivered { color: var(--muted2); }
.receipt.read      { color: var(--accent); }

/* ── Chat Input Bar ────────────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-bar input[type=text] {
  flex: 1;
  background: var(--surface2);
  border-radius: 24px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  font-size: 14px;
}

.btn-attach, .btn-send {
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  color: var(--muted2);
  padding: 4px;
  transition: color .2s;
}
.btn-send { color: var(--accent); font-size: 22px; }
.btn-attach:hover { color: var(--text); }
.btn-send:hover   { color: var(--accent-d); }

.channel-readonly {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 10px;
}

/* ── Contacts ──────────────────────────────────────────────────────────── */
.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  color: var(--muted2);
  cursor: pointer;
  transition: all .2s;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border-bottom: 1px solid var(--border);
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 14px; }
.contact-pin  { font-size: 12px; color: var(--muted); font-family: monospace; }
.contact-actions { display: flex; gap: 6px; }

/* ── Profile ───────────────────────────────────────────────────────────── */
.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.profile-name  { font-size: 20px; font-weight: 700; margin-top: 12px; }
.profile-bio   { font-size: 14px; color: var(--muted2); margin-top: 6px; text-align: center; }

.pin-badge {
  display: inline-block;
  background: rgba(108,99,255,.15);
  border: 1px solid rgba(108,99,255,.4);
  border-radius: 6px;
  padding: 5px 12px;
  font-family: monospace;
  font-size: 15px;
  color: var(--accent);
  margin-top: 8px;
  letter-spacing: 2px;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.section-card h3 { font-size: 15px; margin-bottom: 14px; font-weight: 600; }

.badge-once {
  background: rgba(251,191,36,.15);
  border: 1px solid rgba(251,191,36,.4);
  color: var(--yellow);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 6px;
}

/* ── Modal ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .2s;
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; }
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  animation: slideUp .25s ease;
}

@media (min-width: 480px) {
  .modal-card { border-radius: var(--radius); }
}

.modal-card h3 { font-size: 17px; font-weight: 700; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.found-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
}

/* ── Image Overlay ─────────────────────────────────────────────────────── */
.img-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
}
.img-overlay img { max-width: 96vw; max-height: 90dvh; border-radius: 8px; }
.img-overlay button {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,.1); border: none;
  color: #fff; font-size: 22px; cursor: pointer;
  border-radius: 50%; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 20px;
  font-size: 13px;
  z-index: 400;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show          { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-success { border-color: rgba(74,222,128,.5); color: var(--green); }
.toast.toast-error   { border-color: rgba(248,113,113,.5); color: var(--red); }
.toast.toast-info    { border-color: rgba(108,99,255,.5); color: var(--accent); }

/* ── States ────────────────────────────────────────────────────────────── */
.loading     { color: var(--muted); font-size: 14px; text-align: center; padding: 32px; }
.loading-sm  { color: var(--muted); font-size: 13px; }
.empty-state { color: var(--muted); font-size: 14px; text-align: center; padding: 48px 16px; line-height: 1.8; }
.muted       { color: var(--muted); }
.muted-sm    { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.text-error  { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ── Animations ────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  #app { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ── Discover & Search ─────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.search-bar input  { flex: 1; margin: 0; }
.search-bar select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge-red {
  display: inline-flex;
  align-items: center; justify-content: center;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  vertical-align: middle;
}

.badge-admin {
  display: inline-block;
  background: rgba(108,99,255,.15);
  border: 1px solid rgba(108,99,255,.4);
  color: var(--accent);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 4px;
  vertical-align: middle;
}

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  min-width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}
