/* Avezz P2P Encrypted Chat (css/pages/chat.css) */

.chat-guest-card {
  max-width: 460px;
  margin: 48px auto;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.chat-guest-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--surface-alt, rgba(0, 113, 227, 0.08));
  color: var(--accent, #0071e3);
  display: grid;
  place-items: center;
}

.chat-guest-icon .icon { width: 26px; height: 26px; }

.chat-shell {
  max-width: 1180px;
  margin: 12px auto 20px;
  height: calc(100dvh - var(--nav-h, 116px) - 36px);
  min-height: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 18px);
  display: grid;
  grid-template-columns: 310px 1fr;
  overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.chat-sidebar-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-sidebar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.chat-e2ee-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

.chat-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-alt, var(--bg));
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.chat-search-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.chat-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-alt, var(--bg));
}

.chat-tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.chat-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-tab-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--badge-bg, #ef4444);
  color: var(--badge-text, #fff);
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
}

.chat-peer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-peer-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.14s ease;
}

.chat-peer-item:hover { background: var(--surface-hover, rgba(127, 127, 127, 0.08)); }
.chat-peer-item.is-active { background: var(--surface-hover, rgba(0, 113, 227, 0.12)); }

.chat-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-alt, rgba(127, 127, 127, 0.16));
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: visible;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  position: absolute;
  inset: 0;
}

.chat-status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: #9ca3af;
}

.chat-status-dot.is-online { background: #10b981; }
.chat-status-dot.is-p2p { background: #0ea5e9; }

.chat-peer-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-peer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.chat-peer-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-unread {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--badge-bg, #ef4444);
  color: var(--badge-text, #fff);
  font-size: 10px;
  font-weight: 700;
  line-height: 19px;
  text-align: center;
  flex-shrink: 0;
}

.chat-sidebar-empty {
  padding: 24px 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.chat-sidebar-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.chat-new-btn { width: 100%; justify-content: center; gap: 6px; }

/* Main thread */
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  color: var(--text-muted);
  gap: 8px;
}

.chat-empty-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text);
}

.chat-empty-icon .icon { width: 26px; height: 26px; }
.chat-empty-state h2 { margin: 4px 0 0; font-size: 17px; color: var(--text); }
.chat-empty-state p { margin: 0; max-width: 360px; font-size: 13px; }

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

.chat-thread-head {
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-back-btn { display: none; transform: rotate(180deg); }

.chat-peer-head-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  flex: 1;
}

.chat-peer-head-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-peer-head-meta strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-transport-status {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-transport-status.is-p2p { color: #10b981; font-weight: 600; }
.chat-transport-status.is-relay { color: #0ea5e9; font-weight: 600; }

.chat-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-request-banner {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text);
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid var(--border);
}

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

.chat-msg {
  max-width: min(78%, 520px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: flex-start;
}

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

.chat-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.is-out .chat-bubble {
  background: var(--accent, #0071e3);
  border-color: transparent;
  color: #fff;
}

.chat-msg-img {
  display: block;
  max-width: 100%;
  max-height: 300px;
  border-radius: 12px;
  margin-top: 6px;
  object-fit: cover;
  background: rgba(127, 127, 127, 0.12);
}

.chat-img-gate {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  background: var(--surface-alt, rgba(127, 127, 127, 0.08));
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-msg.is-out .chat-img-gate {
  border-color: rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.chat-msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.chat-msg.is-out .chat-msg-meta { justify-content: flex-end; }

/* Composer */
.chat-composer {
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-image-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-image-input {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input {
  flex: 1;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
}

.chat-send-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 12px;
}

.chat-fp-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  word-break: break-all;
}

.chat-fp-note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 780px) {
  .chat-shell {
    grid-template-columns: 1fr;
    border-radius: 14px;
    margin: 6px;
    height: calc(100dvh - var(--nav-h, 110px) - 16px);
  }
  .chat-shell.has-active-peer .chat-sidebar { display: none; }
  .chat-shell:not(.has-active-peer) .chat-main { display: none; }
  .chat-back-btn { display: inline-flex; }
}
