/* messages.css — Message bubbles, replies, reactions, threads, attachments */

.message {
  margin-bottom: var(--space-sm);
  line-height: 1.4;
  padding: var(--space-md) var(--space-lg);
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius);
}

.message .meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-md);
}

.message .author {
  font-weight: 600;
  color: var(--accent);
  font-size: var(--text-sm);
}

.message .author.bot { color: #7aa4d8; }
.message .author.you { color: var(--success); }

.identicon {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-sm);
  vertical-align: middle;
  margin-right: var(--space-xs);
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  padding-left: 1.6rem;
}
.reactions:empty { display: none; }
.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.05rem var(--space-md);
  font-size: var(--text-sm);
  cursor: pointer;
  user-select: none;
}
.reaction-badge:hover { border-color: var(--accent); }
.reaction-badge.mine { border-color: var(--accent); background: var(--accent-dim); }
.reaction-badge .count { font-size: var(--text-xs); color: var(--text-muted); }

.sig-badge {
  font-size: var(--text-xs);
  color: var(--success);
  background: rgba(68,170,153,0.15);
  padding: 0 var(--space-sm);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
/* Signature present but not yet verified (history loaded before crypto ready) */
.sig-badge.unverified {
  color: var(--text-muted);
  background: rgba(128,128,128,0.12);
}
/* Signature present but verification failed — possible tampering */
.sig-badge.invalid {
  color: #e55;
  background: rgba(220,60,60,0.15);
  cursor: help;
}

.message .time {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.message .body {
  font-size: var(--text-base);
  margin-top: var(--space-sm);
  margin-left: 1.6rem;
  padding: var(--space-sm) var(--space-md);
  background: rgba(255,255,255,0.025);
  border-radius: var(--radius);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.system {
  color: var(--text-muted);
  font-style: italic;
  font-size: var(--text-sm);
  padding: var(--space-xs) 0;
  margin-bottom: var(--space-sm);
  background: none;
  border-radius: 0;
}

/* Ephemeral notices — color-coded, auto-dismiss */
.notice {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: noticeFadeIn 0.2s ease;
}
.notice .notice-text { flex: 1; }
.notice .notice-timer {
  font-size: var(--text-xs);
  opacity: 0.7;
  margin-left: var(--space-md);
  white-space: nowrap;
}
.notice.notice-red    { background: rgba(220,50,50,0.12); border-left: 3px solid #dc3232; color: #ff6b6b; }
.notice.notice-yellow { background: rgba(220,180,50,0.10); border-left: 3px solid #dcb432; color: #e0c860; }
.notice.notice-green  { background: rgba(50,180,80,0.10); border-left: 3px solid #32b450; color: #60d080; }
.notice.notice-blue   { background: rgba(50,120,220,0.10); border-left: 3px solid #3278dc; color: #60a0e0; }
.notice.notice-cyan   { background: rgba(50,200,200,0.10); border-left: 3px solid #32c8c8; color: #60e0e0; }
.notice.notice-magenta { background: rgba(180,50,200,0.10); border-left: 3px solid #b432c8; color: #d060e0; }
@keyframes noticeFadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.notice.fading { transition: opacity 0.5s ease; opacity: 0; }

.date-separator {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-xs);
  padding: var(--space-lg) 0 var(--space-md);
  position: relative;
}

.date-separator::before,
.date-separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}

.date-separator::before { left: 5%; }
.date-separator::after { right: 5%; }

#history-notice {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-xs);
  padding: var(--space-md);
  font-style: italic;
}

/* ── Message hover actions ── */
.message { position: relative; cursor: pointer; border-radius: var(--radius-sm); padding: var(--space-sm) var(--space-md); }
.message:hover { background: var(--bg-hover); }
.message .msg-actions {
  display: none;
  position: absolute;
  right: var(--space-md);
  top: var(--space-xs);
  gap: var(--space-sm);
}
.message:hover .msg-actions { display: flex; }
.msg-actions button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-xs);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.msg-actions button:hover { color: var(--text); border-color: var(--accent); }

/* ── Quote/reply styling ── */
.body .quote-block {
  border-left: 3px solid var(--accent);
  padding: var(--space-xs) 0 var(--space-xs) var(--space-md);
  margin: 0 0 var(--space-xs) 0;
  color: var(--text-muted);
  font-size: 0.82em;
  line-height: 1.3;
  cursor: pointer;
}
.body .quote-block:hover { background: var(--bg-hover); }
.body .quote-block .quote-expand {
  color: var(--accent);
  font-size: 0.75em;
  display: inline;
  margin-left: var(--space-sm);
}
.body .quote-block .quote-full { display: none; }
.body .quote-block.expanded .quote-full { display: block; }
.body .quote-block.expanded .quote-preview { display: none; }

/* ── Image messages ── */
.body .img-placeholder {
  display: inline-flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-lg);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--accent);
  margin: var(--space-xs) 0;
}
.body .img-placeholder:hover { border-color: var(--accent); }
.body .img-loaded {
  max-width: 400px;
  max-height: 300px;
  border-radius: var(--radius-sm);
  margin: var(--space-xs) 0;
  cursor: pointer;
}
.body .img-loaded:hover { opacity: 0.9; }

/* ── New messages divider ── */
.new-messages-divider {
  text-align: center;
  color: var(--danger);
  font-size: var(--text-xs);
  padding: var(--space-md) 0;
  position: relative;
}
.new-messages-divider::before,
.new-messages-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--danger);
}
.new-messages-divider::before { left: 5%; }
.new-messages-divider::after { right: 5%; }

/* ── Reply indicator on messages ── */
.reply-indicator {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.reply-indicator:hover { color: var(--accent); }
.reply-indicator .reply-indicator-author { color: var(--accent); font-weight: 600; }
.reply-indicator .reply-indicator-preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 300px;
  opacity: 0.7;
}
.message.has-reply { border-left: 2px solid var(--accent-dim, rgba(88,166,255,0.2)); padding-left: var(--space-md); }

/* ── Thread count badge ── */
.thread-badge {
  font-size: var(--text-xs);
  color: var(--accent);
  cursor: pointer;
  margin-top: var(--space-xs);
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}
.thread-badge:hover { text-decoration: underline; }

/* ── Inline code & bold/italic from markdown ── */
.body code {
  background: var(--bg-hover);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-size: 0.85em;
  font-family: monospace;
}

/* ── Edited marker ── */
.edited-marker {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-style: italic;
  margin-left: var(--space-sm);
}

/* ── Edit mode (inline editing) ── */
.edit-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}
.edit-area textarea {
  background: var(--bg-input);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-family: inherit;
  resize: vertical;
  min-height: 36px;
  outline: none;
}
.edit-area .edit-buttons {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}
.edit-area .edit-buttons button {
  font-size: var(--text-xs);
  padding: var(--space-xs) var(--space-lg);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
}
.edit-area .edit-save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.edit-area .edit-save:hover { background: var(--accent-hover); }
.edit-area .edit-cancel {
  background: var(--bg-input);
  color: var(--text-muted);
}
.edit-area .edit-cancel:hover { color: var(--text); }

/* DM message visual distinction */
.message.dm-message {
  border-left: 3px solid var(--accent);
  background: rgba(224,112,32,0.04);
}

/* ── Code Blocks ── */
.code-block-wrapper {
  position: relative;
  margin: var(--space-sm) 0;
}
.code-block-wrapper pre {
  background: #1a1a1a;
  color: #e0e0e0;
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius);
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: var(--text-sm);
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
  margin: 0;
  border: 1px solid #333;
}
.code-block-wrapper .code-lang {
  position: absolute;
  top: var(--space-xs);
  right: 2.5rem;
  font-size: 0.6rem;
  color: #666;
  text-transform: uppercase;
}
.code-block-wrapper .code-copy {
  position: absolute;
  top: var(--space-xs);
  right: var(--space-sm);
  background: #333;
  border: 1px solid #555;
  color: #aaa;
  font-size: var(--text-xs);
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.code-block-wrapper:hover .code-copy { opacity: 1; }
.code-block-wrapper .code-copy:hover { color: #fff; border-color: var(--accent); }

/* ── Blockquote (from markdown) ── */
.body blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--space-xs) 0 var(--space-xs) var(--space-md);
  margin: var(--space-xs) 0;
  color: var(--text-muted);
  font-size: 0.85em;
}
.body ul.md-list {
  margin: var(--space-xs) 0 var(--space-xs) 1.2rem;
  padding: 0;
  list-style: disc;
}
.body ul.md-list li {
  margin: var(--space-xs) 0;
}

/* ── Link Previews ── */
.link-preview {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-sm) 0 var(--space-sm) 1.6rem;
  font-size: var(--text-sm);
  max-width: 500px;
  cursor: pointer;
  display: flex;
  gap: var(--space-md);
}
.link-preview:hover { background: var(--bg-hover); }
.link-preview.collapsed { display: none; }
.link-preview .lp-text { flex: 1; min-width: 0; }
.link-preview .lp-site { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; }
.link-preview .lp-title { font-weight: 600; color: var(--accent); margin: var(--space-xs) 0; }
.link-preview .lp-title a { color: var(--accent); text-decoration: none; }
.link-preview .lp-title a:hover { text-decoration: underline; }
.link-preview .lp-desc { color: var(--text-muted); font-size: var(--text-sm); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.link-preview .lp-thumb { width: 80px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }

/* ── File Cards (documents, archives) ── */
.file-card {
  display: inline-flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-xs) 0;
  font-size: var(--text-sm);
  max-width: 350px;
}
.file-card .file-icon { font-size: 1.3rem; }
.file-card .file-info { flex: 1; min-width: 0; }
.file-card .file-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .file-size { font-size: var(--text-xs); color: var(--text-muted); }
.file-card .file-download { color: var(--accent); text-decoration: none; font-size: var(--text-sm); }
.file-card .file-download:hover { text-decoration: underline; }

/* ── Inline audio/video ── */
.body audio { max-width: 100%; margin: var(--space-xs) 0; }
.body video { max-width: 400px; max-height: 300px; border-radius: var(--radius-sm); margin: var(--space-xs) 0; }

/* ── Todo Channel Sections ── */
.todo-section {
  border-radius: var(--radius);
  padding: var(--space-lg) var(--space-xl);
  margin: var(--space-sm) 0;
}
.todo-section summary {
  cursor: pointer;
  font-weight: 700;
  font-size: var(--text-sm);
  padding: var(--space-xs) 0;
  user-select: none;
  list-style: none;
}
.todo-section summary::-webkit-details-marker { display: none; }
.todo-section summary::before {
  content: '▼ ';
  font-size: var(--text-xs);
  margin-right: var(--space-sm);
  display: inline-block;
  transition: transform 0.15s;
}
.todo-section:not([open]) summary::before {
  transform: rotate(-90deg);
}
.todo-section .todo-items {
  padding: var(--space-sm) 0 0 var(--space-md);
  font-size: var(--text-sm);
  line-height: 1.6;
  white-space: pre-wrap;
}
.todo-section.todo-active {
  background: #1a2a4a;
  border: 1px solid #2a3a5a;
}
.todo-section.todo-active summary { color: #6ab0ff; }
.todo-section.todo-completed {
  background: #1a3a2a;
  border: 1px solid #2a4a3a;
}
.todo-section.todo-completed summary { color: #6adb8a; }
.todo-section.todo-inactive {
  background: #3a1a1a;
  border: 1px solid #4a2a2a;
}
.todo-section.todo-inactive summary { color: #db6a6a; }

/* ── Feature 4: Message Deletion (enhanced) ── */
.message-deleted-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-md);
  opacity: 0.6;
  animation: fadeOutSlow 3s forwards;
}
@keyframes fadeOutSlow { 0% { opacity: 0.6; } 80% { opacity: 0.6; } 100% { opacity: 0; } }

.delete-confirm {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-sm);
  display: inline-flex;
  gap: var(--space-md);
  align-items: center;
  margin-top: var(--space-xs);
}
.delete-confirm button {
  padding: var(--space-xs) var(--space-lg);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  border: 1px solid var(--border);
}
.delete-confirm .confirm-yes { background: #dc3232; color: #fff; border-color: #dc3232; }
.delete-confirm .confirm-yes:hover { background: #e54545; }
.delete-confirm .confirm-no { background: var(--bg-input); color: var(--text-muted); }
.delete-confirm .confirm-no:hover { color: var(--text); }

/* Mobile message tweaks */
@media (max-width: 640px) {
  /* Message bubbles: more breathing room */
  .message {
    padding: var(--space-sm) var(--space-md);
    margin-bottom: var(--space-xs);
  }
  .message .body {
    font-size: var(--text-base);
    line-height: 1.45;
  }
  .message .time {
    font-size: 0.6rem;
  }

  /* Hide message hover actions on mobile (use long-press or context menu) */
  .message .msg-actions {
    display: none !important;
  }
  /* Instead, show actions on tap (added via JS) */
  .message.mobile-selected .msg-actions {
    display: flex !important;
    position: static;
    margin-top: var(--space-sm);
    gap: var(--space-md);
  }
  .message.mobile-selected .msg-actions button {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--text-sm);
    min-height: 32px;
  }

  /* Image placeholders: easier to tap */
  .body .img-placeholder {
    padding: var(--space-md) var(--space-xl);
    font-size: var(--text-sm);
    min-height: 40px;
  }
  .body .img-loaded {
    max-width: calc(100vw - 2rem);
    max-height: 250px;
  }

  /* Reaction badges: bigger on mobile */
  .reaction-badge {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--text-sm);
    min-height: 30px;
  }
  .reaction-badge .count {
    font-size: var(--text-xs);
  }
}
