* { box-sizing: border-box; }

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  color: #1a1a1a;
  background: #fafafa;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #222;
  color: #fff;
}

.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: bold; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.topbar button { background: none; border: 1px solid #666; color: #fff; padding: 0.25rem 0.6rem; cursor: pointer; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

.container.narrow { max-width: 400px; }

section {
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

form { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
input, textarea, button { font: inherit; padding: 0.5rem; }
button { cursor: pointer; }

.error { color: #b00020; min-height: 1.2em; }
.muted { color: #777; }

.notice {
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}
.notice-success { background: #e6f6ea; color: #1a7a34; border: 1px solid #b6e5c4; }

#load-older-btn { margin-bottom: 0.5rem; }

.message-list {
  height: 420px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.bubble {
  display: flex;
  gap: 0.5rem;
  max-width: 80%;
  align-self: flex-start;
}

.bubble.mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bubble-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #999;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.bubble.mine .bubble-avatar { background: #2f6fed; }

.bubble-body {
  background: #f0f0f0;
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  min-width: 0;
}

.bubble.mine .bubble-body { background: #dbe9ff; }

.bubble-meta { display: flex; gap: 0.5rem; align-items: baseline; margin-bottom: 0.15rem; }
.bubble-sender { font-weight: 600; font-size: 0.85rem; }
.bubble-time { color: #888; font-size: 0.7rem; }
.bubble-targeting { font-size: 0.75rem; color: #666; font-style: italic; margin-bottom: 0.15rem; }
.bubble-content { white-space: pre-wrap; word-break: break-word; }

.bubble-attachment { margin-top: 0.4rem; }
.bubble-attachment img { max-width: 240px; max-height: 240px; border-radius: 6px; display: block; }
.bubble-attachment.pending, .bubble-attachment.failed {
  font-size: 0.8rem;
  color: #777;
  background: #e8e8e8;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}
.bubble-attachment.failed { color: #b00020; background: #fbe1e1; }

.bubble-actions { margin-top: 0.3rem; display: flex; gap: 0.4rem; }
.bubble-actions button {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
}
.bubble-actions button.saved {
  background: #fff3cd;
  border-color: #e8c766;
  color: #8a6d1a;
  cursor: default;
}

.composer-row { display: flex; flex-direction: row; align-items: center; gap: 0.5rem; }
.composer-row input[type="text"] { flex: 1; }

.recipient-picker, .share-picker { position: relative; }
.recipient-picker summary {
  cursor: pointer;
  font-size: 0.85rem;
  list-style: none;
  padding: 0.4rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
}
.recipient-picker summary::-webkit-details-marker { display: none; }
.recipient-options, .share-options {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 5;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  padding: 0.5rem;
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 180px;
}
.recipient-options label, .share-options label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
}

/* Radio/checkbox options (invite question templates, verification-answer
   choices) — same row-layout override as above, so the input sits next to
   its own text instead of the default `form label` column stack meant for
   "label text above input" fields like Email/Password. */
.template-option, .question-option {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
}

.q-option-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.attachment-preview { font-size: 0.85rem; color: #555; min-height: 1.2em; }
.attachment-preview button { margin-left: 0.3rem; }

/* Upload confirmation/progress text — kept visually separate (its own
   background/padding) from the gallery grid below it, and collapses to
   nothing when empty instead of leaving a stray empty bar. */
#upload-status {
  margin: 0.5rem 0;
  padding: 0.4rem 0.6rem;
  background: #f0f0f0;
  border-radius: 4px;
  font-size: 0.9rem;
}
#upload-status:empty { display: none; margin: 0; padding: 0; }

.memory-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}

.memory-item { display: flex; flex-direction: column; gap: 0.25rem; }
.memory-item img { width: 100%; height: 140px; object-fit: cover; border-radius: 4px; }
.memory-placeholder {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eee;
  border-radius: 4px;
  color: #777;
  font-size: 0.85rem;
  text-align: center;
  padding: 0.5rem;
}
.memory-placeholder.failed { background: #fbe1e1; color: #b00020; }
.memory-text {
  height: 140px;
  overflow-y: auto;
  background: #f5f0e6;
  border-radius: 4px;
  padding: 0.5rem;
  font-size: 0.85rem;
  white-space: pre-wrap;
}
.memory-text-meta { display: flex; gap: 0.4rem; align-items: baseline; margin-bottom: 0.2rem; white-space: nowrap; }
.memory-text-sender { font-weight: 600; font-size: 0.8rem; }
.memory-text-time { color: #888; font-size: 0.65rem; }

.memory-badge {
  font-size: 0.7rem;
  color: #6a4bd1;
  background: #efe9ff;
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  align-self: flex-start;
}

.memory-provenance { font-size: 0.7rem; color: #777; }

.memory-item .promote-btn, .share-confirm-btn {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  align-self: flex-start;
}

/* Dashboard: silenced clusters */
#cluster-list li.silenced { opacity: 0.6; display: flex; align-items: center; gap: 0.5rem; }
.resume-btn { font-size: 0.8rem; padding: 0.2rem 0.5rem; }

/* Admin */
.admin-filters { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; font-size: 0.85rem; }
.admin-filters a { color: #555; text-decoration: none; padding: 0.2rem 0.5rem; border-radius: 4px; }
.admin-filters a.active { background: #222; color: #fff; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid #eee; }
.admin-table th { color: #666; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

.admin-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.admin-actions button {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}
.admin-actions .delete-btn { color: #b00020; border-color: #e7b3ba; }

.status-badge { font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 4px; text-transform: capitalize; }
.status-badge.status-pending { background: #fff3cd; color: #8a6d1a; }
.status-badge.status-approved { background: #e6f6ea; color: #1a7a34; }
.status-badge.status-rejected { background: #fbe1e1; color: #b00020; }
.status-badge.status-needs_review { background: #fff3cd; color: #8a6d1a; }
.status-badge.status-accepted { background: #e6f6ea; color: #1a7a34; }
.status-badge.status-revoked, .status-badge.status-expired { background: #fbe1e1; color: #b00020; }

/* Nav unread-count badge */
.badge-count {
  display: inline-block;
  min-width: 1.1rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #d92c2c;
  color: #fff;
  font-size: 0.7rem;
  text-align: center;
  line-height: 1.3rem;
  margin-left: 0.15rem;
}

/* Notifications list */
#notification-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
#notification-list li { padding: 0.5rem 0.7rem; border: 1px solid #eee; border-radius: 4px; }
#notification-list li.unread { background: #f5f8ff; border-color: #cddcff; }

/* Invite review detail */
.attempt-block { margin-bottom: 0.75rem; }
.review-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
