/* ============================================================
   topics.css
   Owns: Topics board · topic cards · chat thread ·
         message bubbles · composer bar.

   Does NOT own:
     • Any popup / sheet chrome  → dialog.css
     • Font imports               → styles.css
     • Base tokens                → styles.css / district_styles.css
     • File list / grid           → fileworker.css
   ============================================================ */


/* ── 1. TOPICS PANEL SHELL ───────────────────────────────────
   Full-height column that fills dash-main.
   ──────────────────────────────────────────────────────────── */

.topics-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}


/* ── 2. PANEL TOPBAR (board-level) ──────────────────────────
   Title + "New Topic" button.
   ──────────────────────────────────────────────────────────── */

.topics-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--separator);
}

.topics-topbar-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topics-topbar-sub {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* "New Topic" button — accent pill */
.topics-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.topics-new-btn:hover  { background: var(--accent-hover); }
.topics-new-btn:active { transform: scale(0.96); }


/* ── 3. FILTER CHIPS ────────────────────────────────────────
   Horizontal scrollable row: All · Help · Clarification · Reference
   ──────────────────────────────────────────────────────────── */

.topics-filters {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid var(--separator);
}

.topics-filters::-webkit-scrollbar { display: none; }

.topics-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 13px;
  border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.13s, background 0.13s, color 0.13s;
  -webkit-tap-highlight-color: transparent;
}

.topics-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.topics-chip.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

/* Type-specific active colours */
.topics-chip--help.active {
  border-color: var(--danger);
  background: var(--danger-light);
  color: var(--danger);
}

.topics-chip--clarification.active {
  border-color: var(--warning);
  background: var(--warning-light);
  color: var(--warning);
}

.topics-chip--reference.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}


/* ── 4. PINNED STRIP ────────────────────────────────────────
   Horizontal scroll of pinned topic titles above the feed.
   ──────────────────────────────────────────────────────────── */

.topics-pinned-strip {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--warning-light);
  border-bottom: 1px solid var(--separator);
}

.topics-pinned-strip::-webkit-scrollbar { display: none; }
.topics-pinned-strip:empty { display: none; }

.topics-pinned-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--warning-light);
  border: 1px solid var(--warning);
  color: var(--warning);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s;
}

.topics-pinned-item:hover { opacity: 0.8; }


/* ── 5. BOARD FEED ──────────────────────────────────────────
   Scrollable list of topic cards (Level 1 view).
   ──────────────────────────────────────────────────────────── */

.topics-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 80px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Empty state */
.topics-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 48px 24px;
  gap: 10px;
  text-align: center;
}

.topics-empty-icon {
  font-size: 2.4rem;
  opacity: 0.4;
}

.topics-empty-text {
  font-size: 0.875rem;
  color: var(--text-tertiary);
  max-width: 260px;
  line-height: 1.55;
}


/* ── 6. TOPIC CARD ──────────────────────────────────────────
   Single row in the board feed.
   ──────────────────────────────────────────────────────────── */

.topic-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--separator);
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.topic-card:hover  { background: var(--bg-elevated); }
.topic-card:active { background: var(--accent-light); }

/* Left: type icon badge */
.topic-card-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.topic-card-icon--help          { background: var(--danger-light);  }
.topic-card-icon--clarification { background: var(--warning-light); }
.topic-card-icon--reference     { background: var(--accent-light);  }

/* Middle: title + meta */
.topic-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.topic-card-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-card-preview {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Badge row: visibility + expiry + pin */
.topic-card-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 3px;
}

.topic-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.topic-badge--public  { background: var(--success-light);  color: var(--success); }
.topic-badge--private { background: var(--border);         color: var(--text-tertiary); }
.topic-badge--expiry  { background: var(--warning-light);  color: var(--warning); }
.topic-badge--pinned  { background: var(--warning-light);  color: var(--warning); }
.topic-badge--help    { background: var(--danger-light);   color: var(--danger); }
.topic-badge--clarif  { background: var(--warning-light);  color: var(--warning); }
.topic-badge--ref     { background: var(--accent-light);   color: var(--accent); }

/* Right: timestamp + message count */
.topic-card-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.topic-card-time {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.topic-card-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.62rem;
  font-weight: 800;
}

/* Pin icon beside title */
.topic-card--pinned .topic-card-title::before {
  content: '📌 ';
  font-size: 0.8em;
}

/* ── Delete button on topic card (board view) ── */
.topic-card-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
/* Always visible on touch devices — no hover */
@media (hover: none) {
  .topic-card-delete-btn { opacity: 1; }
}
.topic-card:hover .topic-card-delete-btn,
.topic-card:focus-within .topic-card-delete-btn {
  opacity: 1;
}
.topic-card-delete-btn:hover {
  background: var(--danger-light, #fee2e2);
  color: var(--danger, #ef4444);
}
.topic-card-delete-btn:active {
  transform: scale(0.92);
}

/* ── Delete button in topic view topbar ── */
.topic-topbar-delete-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  margin-left: auto;
}
.topic-topbar-delete-btn:hover {
  background: var(--danger-light, #fee2e2);
  color: var(--danger, #ef4444);
}
.topic-topbar-delete-btn:active {
  transform: scale(0.92);
}


/* ── 7. TOPIC CHAT VIEW (Level 2) ────────────────────────────
   Full-height column: back topbar · message feed · composer.
   ──────────────────────────────────────────────────────────── */

.topic-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}


/* Back topbar */
.topic-view-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--separator);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
}

.topic-back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 4px 2px;
  -webkit-tap-highlight-color: transparent;
}

.topic-back-btn:hover { opacity: 0.75; }

.topic-view-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.topic-view-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-view-meta {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}


/* Message feed */
.topic-msg-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}


/* ── 8. MESSAGE BUBBLE ───────────────────────────────────────
   WhatsApp-style: own messages right-aligned.
   ──────────────────────────────────────────────────────────── */

.tmsg-wrap {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  max-width: 100%;
}

.tmsg-wrap--own { flex-direction: row-reverse; }

/* Avatar beside other's messages */
.tmsg-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 1.5px solid var(--border);
  align-self: flex-end;
}

.tmsg-av--initials {
  display: grid;
  place-items: center;
  font-size: 0.58rem;
  font-weight: 800;
  color: var(--accent-fg);
  background: var(--accent);
}

/* Bubble */
.tmsg-bubble {
  max-width: 72%;
  padding: 9px 13px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
  word-break: break-word;
}

.tmsg-wrap--own .tmsg-bubble {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-fg);
}

.tmsg-bubble--pinned {
  border-color: var(--warning);
  background: var(--warning-light);
}

/* Sender name (shown on others' messages) */
.tmsg-name {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.tmsg-wrap--own .tmsg-name { display: none; }

/* Body text */
.tmsg-text {
  font-size: 0.875rem;
  line-height: 1.5;
  color: inherit;
}

.tmsg-wrap--own .tmsg-text { color: var(--accent-fg); }

/* Inline hashtag / mention */
.tmsg-tag     { color: var(--accent);   font-weight: 700; cursor: pointer; }
.tmsg-mention { color: var(--success);  font-weight: 700; }
.tmsg-wrap--own .tmsg-tag { color: rgba(255,255,255,0.85); }

/* Timestamp + privacy icon row */
.tmsg-foot {
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: flex-end;
}

.tmsg-time {
  font-size: 0.62rem;
  color: var(--text-tertiary);
}

.tmsg-wrap--own .tmsg-time { color: rgba(255,255,255,0.65); }

.tmsg-priv-icon {
  font-size: 0.65rem;
  color: var(--text-tertiary);
}

/* Attachment row */
.tmsg-attachment { margin-top: 6px; }

.tmsg-file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.06);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.12s;
}

.tmsg-file-link:hover { background: rgba(0, 0, 0, 0.1); }

.tmsg-wrap--own .tmsg-file-link {
  background: rgba(255, 255, 255, 0.2);
  color: var(--accent-fg);
}

/* Bubble action buttons (delete / pin) */
.tmsg-actions {
  display: flex;
  gap: 3px;
  margin-top: 5px;
  justify-content: flex-end;
}

.tmsg-action-btn {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.tmsg-action-btn:hover        { background: var(--danger-light);  color: var(--danger); }
.tmsg-action-btn--pin:hover   { background: var(--warning-light); color: var(--warning); }

/* Date separator between messages */
.tmsg-date-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.tmsg-date-sep::before,
.tmsg-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--separator);
}

.tmsg-date-sep span {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-tertiary);
  white-space: nowrap;
}


/* ── 9. COMPOSER BAR ─────────────────────────────────────────
   Sticky bottom composer for typing and sending messages.
   ──────────────────────────────────────────────────────────── */

.topic-composer {
  flex-shrink: 0;
  border-top: 1px solid var(--separator);
  padding: 10px 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* File previews above the input row */
.topic-file-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.topic-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px 4px 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.topic-file-chip-icon { font-size: 1rem; flex-shrink: 0; }
.topic-file-chip-name { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-file-chip-rm {
  color: var(--text-tertiary);
  font-size: 0.7rem;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0 1px;
  transition: color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.topic-file-chip-rm:hover { color: var(--danger); }

/* Visibility bar above input — now uses .cd-vis-pill from dialog.css */
.topic-vis-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  overflow: hidden;
}

.topic-vis-label {
  color: var(--text-tertiary);
  font-weight: 600;
  flex-shrink: 0;
  font-size: 0.73rem;
}

/* Input row */
.topic-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px 7px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.topic-composer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.topic-input-wrap { flex: 1; }

.topic-input {
  width: 100%;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
}

.topic-input:focus    { outline: none; }
.topic-input::placeholder { color: var(--text-placeholder); }

/* Action icon buttons inside the composer */
.topic-composer-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: none;
  background: none;
  color: var(--text-tertiary);
  flex-shrink: 0;
  cursor: pointer;
  transition: color 0.14s, background 0.14s;
  -webkit-tap-highlight-color: transparent;
}

.topic-composer-btn:hover { color: var(--accent); background: var(--accent-light); }
.topic-composer-btn.active { color: var(--warning); background: var(--warning-light); }

/* Send button */
.topic-send-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.14s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.topic-send-btn:hover  { background: var(--accent-hover); }
.topic-send-btn:active { transform: scale(0.9); }
.topic-send-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }


/* ── 10. RESPONSIVE ─────────────────────────────────────────
   ──────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .topic-card { padding: 11px 14px; }
  .tmsg-bubble { max-width: 84%; }
  .topic-msg-feed { padding: 10px 10px 8px; }
  .topic-composer { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .topic-card,
  .tmsg-bubble,
  .topics-chip,
  .topic-vis-btn { transition: none; }
}

/* ── Schema v2 message layout additions ─────────────────────────────────────
   New structure per message:
     .tmsg-header  — avatar + username + role badge (others only)
     .tmsg-bubble  — message text (unchanged)
     .tmsg-foot    — type-badge + vis-icon + fading time + actions
   ──────────────────────────────────────────────────────────────────────── */

/* Header row: avatar inline with name */
.tmsg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.tmsg-header .tmsg-av {
  align-self: center;
}

.tmsg-header .tmsg-name {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
}

/* tmsg-wrap is now a column so header, bubble, foot stack vertically */
.tmsg-wrap {
  flex-direction: column;
  align-items: flex-start;
}
.tmsg-wrap--own {
  align-items: flex-end;
}

/* foot is now below the bubble */
.tmsg-foot {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 3px;
  gap: 4px;
}
.tmsg-wrap--own .tmsg-foot {
  justify-content: flex-end;
}

/* Disappearing timestamp: visible on hover / focus, fades out after 4s */
.tmsg-time--fade {
  opacity: 0;
  transition: opacity 0.3s ease;
}
.tmsg-wrap:hover .tmsg-time--fade,
.tmsg-wrap:focus-within .tmsg-time--fade {
  opacity: 1;
}

/* Keep own-message bubble max-width consistent */
.tmsg-wrap--own .tmsg-bubble {
  max-width: 72%;
}
