/* Threads and letters to the future (the workbench parts live in
   workbench.css). */

/* ---- Threads page ---- */
.threads-view {
  width: min(var(--record-column), 100%);
  margin: 0 auto;
  padding: clamp(28px, 5vh, 56px) 0 clamp(56px, 10vh, 120px);
}
.threads-intro { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.threads-intro p { margin: 0; color: var(--label-3); font-size: 14px; }
.threads-intro .primary { padding: 9px 18px; font-size: 13px; }
.threads-group { margin-top: 34px; }
.threads-group h2 { margin: 0; color: var(--label-2); font: 600 15px/1.5 var(--font-display); }
.thread-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.thread-card {
  display: flex;
  align-items: stretch;
  gap: 16px;
  min-height: 116px;
  padding: 18px 20px;
  border: 0;
  border-radius: var(--radius-l);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  color: var(--label);
  text-decoration: none;
  transition: box-shadow .2s ease;
}
.thread-card:hover { box-shadow: var(--shadow-raised); }
.thread-card:hover .thread-card-title { color: var(--accent); }
.thread-card-body { display: flex; flex: 1; flex-direction: column; gap: 4px; min-width: 0; }
.thread-card-title { overflow: hidden; font: 600 17px/1.45 var(--font-display); text-overflow: ellipsis; white-space: nowrap; }
.thread-card-goal { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: var(--label-3); font-size: 13px; line-height: 1.6; }
.thread-card-meta { margin-top: auto; color: var(--label-4); font-size: 12px; }
.thread-card-cover { flex: 0 0 auto; width: 80px; height: 80px; align-self: center; border-radius: var(--radius-m); object-fit: cover; background: var(--fill); }
.threads-group:last-of-type .thread-card { opacity: .92; }

.thread-back { color: var(--label-3); font-size: 13px; text-decoration: none; }
.thread-back:hover { color: var(--accent); }
.thread-header { margin-top: 16px; padding: 24px 28px; border: 0; border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-card); }
.thread-status { display: inline-block; margin: 0 0 8px; padding: 1px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; }
.thread-status.is-done { background: var(--fill); color: var(--label-3); }
.thread-header h2 { font: 700 clamp(24px, 2.6vw, 30px)/1.3 var(--font-display); letter-spacing: -.01em; overflow-wrap: anywhere; }
.thread-goal { margin: 8px 0 0; color: var(--label-2); font-size: 15px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.thread-meta { margin: 8px 0 0; color: var(--label-4); font-size: 12px; }
.thread-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.thread-actions .primary,
.thread-actions .secondary { padding: 7px 14px; font-size: 13px; }
.thread-actions-more { display: flex; gap: 2px; margin-left: auto; }
.thread-text-action { padding: 6px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--label-3); font-size: 12px; }
.thread-text-action:hover { background: var(--fill); color: var(--label); }
#thread-delete:hover { color: var(--danger); }
.thread-timeline-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 32px 0 12px; }
.thread-timeline-heading h3 { margin: 0; color: var(--label-2); font: 600 15px/1.5 var(--font-display); }
.thread-timeline-heading button { padding: 0; border: 0; background: transparent; color: var(--label-3); font-size: 12px; }
.thread-timeline-heading button::after { content: " ⇅"; }
.thread-timeline-heading button:hover { color: var(--accent); }
.thread-timeline { position: relative; margin: 0; padding: 0 0 0 22px; list-style: none; }
.thread-timeline::before { content: ""; position: absolute; top: 24px; bottom: 24px; left: 5px; width: 2px; border-radius: 2px; background: var(--separator); }
.thread-item { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; margin-bottom: 10px; }
.thread-item::before { content: ""; position: absolute; top: 20px; left: -22px; width: 10px; height: 10px; border: 2px solid var(--accent); border-radius: 50%; background: var(--bg); }
.thread-item-year { position: absolute; top: 17px; left: -66px; color: var(--label-3); font-size: 10px; }
.thread-item .record-row { grid-column: 1; padding: 14px 20px; border: 0; border-radius: var(--radius-m); background: var(--surface); box-shadow: var(--shadow-card); transition: box-shadow .2s ease; }
.thread-item .record-row:hover { box-shadow: var(--shadow-raised); }
.thread-item-remove { grid-column: 2; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--label-3); font-size: 11px; opacity: 0; }
.thread-item:hover .thread-item-remove,
.thread-item-remove:focus-visible { opacity: 1; }
.thread-item-remove:hover { background: var(--fill); color: var(--danger); }

/* ---- Dialogs ---- */
.thread-dialog { width: 520px; }
.thread-dialog select,
.letter-open-on select { display: block; width: 100%; margin-top: 6px; padding: 9px 10px; border: 1px solid var(--separator); border-radius: 6px; background: var(--surface); color: var(--label); font: inherit; font-size: 14px; }
.thread-dialog textarea { min-height: 84px; }
.thread-dialog .error { margin: 14px 0 0; }
.thread-picker { width: 560px; }
.thread-picker input[type=text] { margin-top: 0; }
.thread-picker-status { min-height: 20px; margin: 8px 0 0; color: var(--label-3); font-size: 12px; }
.thread-picker-results { display: grid; max-height: min(52dvh, 460px); margin: 4px 0 0; padding: 0; overflow: auto; list-style: none; }
.thread-picker-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--separator); }
.thread-picker-text { display: grid; flex: 1; min-width: 0; }
.thread-picker-text strong { overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.thread-picker-text small { color: var(--label-3); font-size: 11px; }
.thread-picker-item .secondary { padding: 5px 12px; font-size: 12px; }
.thread-picker-item .secondary.is-linked { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.thread-picker .form-footer { margin-top: 14px; padding-top: 14px; }

.letters-dialog { width: 560px; }
.letters-dialog textarea { margin-top: 0; min-height: 170px; font: 16px/1.9 "Songti SC", STSong, serif; }
.letter-open-on { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 14px; font-size: 13px; }
.letter-open-on select { width: auto; margin: 0; }
.letter-open-on input[type=date] { width: auto; min-height: 0; margin: 0; padding: 8px 10px; }
.letter-when-hint { color: var(--label-3); font-size: 12px; }
.letter-note { margin: 10px 0 0; color: var(--label-3); font-size: 12px; }
.letters-dialog .error { margin: 12px 0 0; }
.letters-dialog .form-footer { margin-top: 16px; padding-top: 16px; }
.letters-group { margin-top: 24px; }
.letters-group h3 { margin: 0 0 6px; font-size: 13px; color: var(--label-3); font-weight: 600; }
.letters-list { display: grid; margin: 0; padding: 0; list-style: none; }
.letters-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--separator); }
.letters-item-text { display: grid; flex: 1; min-width: 0; }
.letters-item-text strong,
.letters-opened strong { font-size: 14px; font-weight: 500; }
.letters-item-text small,
.letters-opened small { color: var(--label-3); font-size: 11px; }
.letters-item .primary { padding: 5px 14px; font-size: 12px; }
.letters-withdraw { padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--label-3); font-size: 12px; }
.letters-withdraw:hover { background: #f3e5df; color: var(--danger); }
.letters-opened { display: grid; width: 100%; padding: 0; border: 0; background: transparent; color: var(--label); text-align: left; }
.letters-opened strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.letters-opened:hover strong { color: var(--accent); }

.letter-reader { width: 600px; background: #fbf6ea; }
.letter-reader-meta { margin: 0 0 4px; color: #8a6c3c; font-size: 12px; }
.letter-paper {
  max-height: 58dvh;
  padding: 32px 26px;
  overflow: auto;
  border: 1px solid #eadfc8;
  border-radius: 10px;
  background: repeating-linear-gradient(#fffdf6 0 31px, #efe6d2 31px 32px);
  background-attachment: local;
  color: #3a352c;
  font: 16px/32px "Songti SC", STSong, serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.letter-reader .error { margin: 12px 0 0; }
.letter-reader .form-footer { border-top-color: #eadfc8; }

/* ---- Editor ---- */
.editor-thread { margin: 4px 0 0; color: var(--accent); font-size: 12px; }

@media (max-width: 760px) {
  .threads-view { padding: 22px 0 92px; }
  .threads-intro { align-items: flex-start; flex-direction: column; gap: 12px; }
  .thread-grid { grid-template-columns: 1fr; }
  .thread-header { padding: 18px; }
  .thread-actions-more { width: 100%; margin-left: 0; }
  .thread-item-remove { opacity: 1; }
  .thread-item-year { display: none; }
}
