/* =========================
   Threads list view
   ========================= */

.fsapp-threads-list-view .threads-meta {
  margin-bottom: 1rem;
  color: #666;
}

.thread-list-grid {
  display: grid;
  gap: 0.75rem;
}

.thread-list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid #e7e7e7;
  border-radius: 12px;
  background: #fff;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  cursor: pointer;
}

.thread-list-item:hover {
  border-color: #cfcfcf;
  background: #fafafa;
  transform: translateY(-1px);
}

.thread-list-item.is-unread {
  border-color: #cfdcff;
  background: #f8fbff;
}

.thread-list-item.is-unread:hover {
  border-color: #b9cbff;
  background: #f2f7ff;
}

.thread-list-item.is-unread .thread-unread-count {
  color: #1d4ed8;
}

.thread-list-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  gap: 0.5rem;
}

.thread-list-main strong {
  font-size: 1rem;
  line-height: 1.3;
}

.thread-list-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.thread-row-action {
  border: 1px solid #dcdcdc;
  background: #fff;
  color: #111;
  padding: 0.45rem 0.75rem;
  border-radius: 9px;
  font-size: 0.85rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thread-row-action:hover {
  background: #f3f3f3;
  border-color: #cfcfcf;
}

.thread-row-action.danger {
  color: #8d1d1d;
  border-color: #e8c6c6;
  background: #fff;
}

.thread-row-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.thread-unread-count {
  font-weight: 600;
}

.thread-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: #666;
}

.thread-list-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* =========================
   Thread panel
   ========================= */

.fsapp-thread-panel-view .panel-body {
  display: grid;
  gap: 1rem;
}

.thread-panel-subtitle {
  margin-top: 0.35rem;
  font-size: 0.92rem;
  color: #666;
}

.thread-back-button {
  border: 1px solid #d9d9d9;
  background: #fff;
  color: #111;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thread-delete-button {
  border: 1px solid #d9d9d9;
  background: #fff;
  color: #111;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thread-delete-button.danger {
  color: #8d1d1d;
  border-color: #e8c6c6;
  background: #fff;
}

.thread-back-button:hover {
  background: #f5f5f5;
  border-color: #cfcfcf;
}

.thread-participant-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-participant-current-list {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-participant-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: #f3f3f3;
  border: 1px solid #e2e2e2;
  font-size: 0.9rem;
}

.thread-participant-search-results {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-top: 0.5em;
  border-radius: var(--br-l);
  background-color: white;
  width: max-content;
  border: 1px solid #ccc;
  overflow: hidden;
}

.thread-participant-search-results button {
  width: 100%;
  text-align: left;
  background-color: transparent;
}

.thread-participant-search-results button:hover {
  background-color: whitesmoke;
}

.thread-panel-messages {
  scroll-margin-top: 100px;
}

.thread-panel-messages .card {
  padding-bottom: 1.25rem;
}

/* =========================
   Thread meta
   ========================= */

.thread-meta-grid {
  display: grid;
  gap: 0.75rem;
}

.thread-meta-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  align-items: start;
}

.thread-meta-label {
  font-weight: 600;
  opacity: 0.7;
}

.thread-meta-value {
  word-break: break-word;
}

/* =========================
   Messages
   ========================= */

.thread-message[data-visual-depth="1"] {
  margin-left: 1.25rem;
}

.thread-message[data-visual-depth="2"] {
  margin-left: 2.5rem;
}

.thread-message-replies {
  margin-top: 0.75rem;
  padding-left: 0.75rem;
  border-left: 1px solid rgba(255,255,255,0.12);
}

.thread-message-replies-hidden {
  display: none;
}

.thread-replies-toggle {
  margin-top: 0.5rem;
}

.thread-replies-toggle-button {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.thread-message.depth-2,
.thread-message[data-visual-depth="2"] {
  opacity: 0.98;
}

.thread-reply-input-wrap {
  position: relative;
}

.thread-edit-input-wrap,
.thread-reply-input-wrap {
  position: relative;
}

.thread-messages-tree {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.thread-message {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ececec;
  border-radius: 12px;
  background: #fafafa;
  transition: box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.thread-message.is-own {
  background: #f4f8ff;
  border-color: #dbe7ff;
}

.thread-message.is-reply-target {
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.22);
  border-color: #60a5fa;
  background: #f8fbff;
}

.thread-message-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.thread-message-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  flex: 0 0 auto;
}

.thread-message-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.thread-message-author {
  font-size: 0.95rem;
  line-height: 1.2;
}

.thread-message-time {
  font-size: 0.82rem;
  color: #666;
}

.thread-message-body p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.thread-message-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-message-action {
  border: 1px solid #dcdcdc;
  background: #fff;
  color: #111;
  padding: 0.45rem 0.75rem;
  border-radius: 9px;
  font-size: 0.88rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.thread-message-action:hover {
  background: #f3f3f3;
  border-color: #cfcfcf;
}

.thread-message-action.danger {
  color: #8d1d1d;
  border-color: #e8c6c6;
  background: #fff;
}

.thread-message-action.danger:hover {
  background: #fff3f3;
  border-color: #dca8a8;
}

.thread-message-replies {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
  margin-left: 2rem;
  padding-left: 1rem;
  border-left: 2px solid #ececec;
}

.thread-message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.thread-message-attachment {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.7rem;
  border: 1px solid #dcdcdc;
  border-radius: 9px;
  background: #fff;
  font-size: 0.88rem;
  gap: 0.5em;
}

.thread-message-attachment:hover {
  background: #f5f5f5;
}

/* =========================
   Reply form
   ========================= */

.thread-reply-wrap {
  scroll-margin-top: 100px;
}

.thread-reply-context[hidden] {
  display: none !important;
}

.thread-reply-context .card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.thread-reply-target-label {
  color: #2563eb;
  font-weight: 600;
}

.thread-cancel-reply {
  border: 1px solid #d9d9d9;;
  background: #eef2f7;
  color: #111827;
  border-radius: var(--br-l);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.thread-reply-form {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  border: 1px solid #ececec;
  border-radius: 12px;
  background: #fff;
}

.thread-reply-form textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 0.9rem 1rem;
  border: 1px solid #dcdcdc;
  border-radius: 10px;
  background: #fff;
  color: #111;
  outline: none;
}

.thread-reply-form textarea:focus {
  border-color: #bdbdbd;
}

.thread-reply-actions {
  display: flex;
  justify-content: flex-end;
}

.thread-reply-actions button {
  border: 1px solid #111;
  background: #111;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  transition: opacity 0.15s ease;
}

.thread-reply-actions button:hover {
  opacity: 0.92;
}

.thread-reply-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================
   Message Edit Box
   ========================= */

.thread-edit-box {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.thread-edit-textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid #d7dbe3;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  font: inherit;
  background: #fff;
  color: #111827;
  box-sizing: border-box;
}

.thread-edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.thread-save-edit,
.thread-cancel-edit {
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.thread-save-edit {
  background: #111827;
  color: #fff;
}

.thread-cancel-edit {
  background: #eef2f7;
  color: #111827;
}

.thread-save-edit:disabled,
.thread-cancel-edit:disabled,
.thread-edit-textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}