/* ============================================================
   discussion-shell.css — the "Discussion Shell"
   ------------------------------------------------------------
   Applies the Shell structure already used by global-search.html,
   series.html and source-series.html to pages/discussion.html and
   pages/discussion-post.html:

     quiet sticky control zone on top, body = content only.

   Tokens: the neutral --ss-* scale from css/series-shell.css
   (loaded BEFORE this file). Panel/sheet behaviour mirrors
   css/reader-settings.css + css/global-search.css.

   Loaded AFTER main.css, series-shell.css and discussion.css on
   these two pages only. discussion.css keeps owning the shared
   comment internals (.comment-input-wrapper, .format-toolbar,
   .format-btn, .tag-chips, spoiler + media styles).

   Spacing scale: 4 / 8 / 12 / 16 / 24 / 32 / 48 only.
   ============================================================ */

/* ---------- Shell frame ---------- */
.ds-shell {
  --ds-measure: 680px;   /* reading measure for post + replies */
  --ds-row-gap: 12px;
  --ds-rail: 2px;        /* reply thread rail */
  --ds-indent: 12px;     /* per nesting level, max 3 */
  max-width: var(--ss-max, 1120px);
  margin: 0 auto;
  padding: 0 16px 48px;
  color: var(--ss-text);
}
.ds-shell *,
.ds-shell *::before,
.ds-shell *::after { box-sizing: border-box; }

/* ---------- Identity strip ---------- */
.ds-identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 24px 0 12px;
}
.ds-h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ss-text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.ds-identity-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons: one neutral set, no purple ---------- */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.ds-btn i { font-size: 16px; }
.ds-btn:disabled { opacity: .55; cursor: not-allowed; }

.ds-btn-primary { background: var(--ss-primary-bg); color: var(--ss-primary-fg); }
.ds-btn-primary:hover:not(:disabled) { background: var(--ss-primary-bg-hover); }

.ds-btn-secondary {
  background: var(--ss-secondary-bg);
  color: var(--ss-secondary-fg);
  border-color: var(--ss-secondary-border);
}
.ds-btn-secondary:hover:not(:disabled) { background: var(--ss-secondary-bg-hover); }

.ds-btn-ghost { background: transparent; color: var(--ss-ghost-fg); }
.ds-btn-ghost:hover:not(:disabled) { background: var(--ss-ghost-bg-hover); }

.ds-btn:focus-visible { outline: 2px solid var(--ss-border-strong); outline-offset: 2px; }

.ds-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- Sticky control zone ---------- */
.ds-controlzone {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ss-bg);
  border-bottom: 1px solid var(--ss-border);
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Segmented board control (the .gs-filter pill pattern) */
.ds-boards {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ss-surface);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-boards::-webkit-scrollbar { display: none; }
.ds-board {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}
.ds-board:hover { background: var(--ss-surface-2); color: var(--ss-text); }
.ds-board.active {
  background: var(--ss-bg);
  border-color: var(--ss-border-strong);
  color: var(--ss-text);
  font-weight: 600;
}

/* Search row */
.ds-searchrow { display: flex; align-items: center; gap: 8px; }
.ds-search {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 8px 0 12px;
  background: var(--ss-surface);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
}
.ds-search:focus-within { border-color: var(--ss-border-strong); }
.ds-search > i { font-size: 14px; color: var(--ss-text-muted); }
.ds-search input {
  flex: 1 1 auto;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ss-text);
  font-family: inherit;
  font-size: 14px;
}
.ds-search input::placeholder { color: var(--ss-text-muted); }
.ds-search input::-webkit-search-cancel-button { display: none; }
.ds-search button {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--ss-ghost-fg); cursor: pointer;
}
.ds-search button:hover { background: var(--ss-ghost-bg-hover); }

.ds-filters-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ss-primary-bg);
  color: var(--ss-primary-fg);
  font-size: 11px;
  font-weight: 600;
}
.ds-filters-count[hidden] { display: none; }

/* ---------- List head: count + active filter chips ---------- */
.ds-listhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 0 12px;
}
.ds-listhead-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ss-text);
}
.ds-listhead-count { color: var(--ss-text-muted); font-weight: 500; }
.ds-active { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ds-active-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ss-border);
  background: var(--ss-surface);
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.ds-active-chip.is-static { cursor: default; }
.ds-active-chip:not(.is-static):hover {
  background: var(--ss-surface-2);
  color: var(--ss-text);
  border-color: var(--ss-border-strong);
}

/* ---------- Notices (guest / staff-only) ---------- */
.ds-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin: 12px 0 0;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: var(--ss-surface);
  color: var(--ss-text-muted);
  font-size: 13px;
}
.ds-notice p { margin: 0; }

/* ---------- Thread list ---------- */
.ds-list { display: flex; flex-direction: column; }
.ds-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "meta  meta"
    "title media"
    "excerpt media"
    "stats stats";
  column-gap: 12px;
  row-gap: 4px;
  padding: var(--ds-row-gap) 0;
  border-bottom: 1px solid var(--ss-border);
  cursor: pointer;
  transition: background-color 120ms ease;
}
.ds-row:hover { background: var(--ss-surface); }
.ds-row.pinned { background: var(--ss-surface); }

.ds-row-meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 12px;
  color: var(--ss-text-muted);
}
.ds-row-avatar {
  width: 20px; height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.ds-row-author {
  color: var(--ss-text);
  font-weight: 500;
  text-decoration: none;
  font-size: 12px;
}
.ds-row-author:hover { text-decoration: underline; }
.ds-row-dot { color: var(--ss-text-muted); }
.ds-row-pin {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  height: 18px;
  border-radius: 4px;
  background: var(--ss-surface-2);
  color: var(--ss-text-muted);
  font-size: 11px;
}

.ds-row-title {
  grid-area: title;
  display: block;
  color: var(--ss-text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ds-row-title:hover { text-decoration: underline; }

.ds-row-excerpt {
  grid-area: excerpt;
  color: var(--ss-text-muted);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.ds-row-excerpt img,
.ds-row-excerpt .comment-image-wrap { display: none; }

.ds-row-media {
  grid-area: media;
  display: grid;
  grid-template-columns: 72px;
  width: 72px; height: 72px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--ss-surface-2);
  align-self: start;
}
.ds-row-media.multi {
  grid-template-columns: 36px 36px;
  grid-auto-rows: 36px;
  gap: 0;
}
.ds-row-media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.ds-row-stats {
  grid-area: stats;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 4px;
  font-size: 12px;
  color: var(--ss-text-muted);
}
.ds-row-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
}
button.ds-row-stat { cursor: pointer; }
button.ds-row-stat:hover { color: var(--ss-text); }
.ds-row-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.ds-row .tag-badge {
  background: var(--ss-surface-2);
  border: 1px solid var(--ss-border);
  color: var(--ss-text-muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.ds-row .tag-badge:hover { color: var(--ss-text); border-color: var(--ss-border-strong); }

/* Skeleton rows match the final row height */
.ds-skeleton {
  height: 108px;
  border-bottom: 1px solid var(--ss-border);
  background: linear-gradient(90deg, var(--ss-surface) 25%, var(--ss-surface-2) 37%, var(--ss-surface) 63%);
  background-size: 400% 100%;
  animation: dsShimmer 1.4s ease infinite;
}
@keyframes dsShimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Empty / error state */
.ds-empty {
  padding: 48px 16px;
  text-align: center;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: var(--ss-surface);
  color: var(--ss-text-muted);
}
.ds-empty i { font-size: 24px; display: block; margin-bottom: 12px; }
.ds-empty h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; color: var(--ss-text); }
.ds-empty p { margin: 0; font-size: 13px; }

.ds-loadmore { display: flex; justify-content: center; padding: 24px 0 0; }

/* ============================================================
   Panels / sheets — bottom sheet on mobile, docked panel ≥720px
   ============================================================ */
.ds-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 1600;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  overflow: hidden;
}
.ds-panel-overlay[hidden] { display: none; }

.ds-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 85dvh;
  background: var(--ss-surface);
  color: var(--ss-text);
  border: 1px solid var(--ss-border);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .4);
  animation: dsSheetIn 180ms ease-out;
}
@keyframes dsSheetIn { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }

.ds-panel-handle {
  flex: 0 0 auto;
  height: 16px;
  display: flex; align-items: center; justify-content: center;
}
.ds-panel-handle::after {
  content: '';
  width: 36px; height: 4px; border-radius: 999px;
  background: var(--ss-border-strong);
}
.ds-panel-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--ss-border);
}
.ds-panel-title { margin: 0; font-size: 16px; font-weight: 600; }
.ds-panel-x {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--ss-ghost-fg); cursor: pointer;
}
.ds-panel-x:hover { background: var(--ss-ghost-bg-hover); }
.ds-panel-body { flex: 1 1 auto; overflow-y: auto; padding: 16px; }
.ds-panel-foot {
  flex: 0 0 auto;
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--ss-border);
}

.ds-sec { padding-bottom: 24px; }
.ds-sec + .ds-sec { padding-top: 24px; border-top: 1px solid var(--ss-border); }
.ds-sec-label {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ss-text-muted);
}

/* Sort pills inside the Filters panel */
.ds-sorts { display: flex; gap: 8px; flex-wrap: wrap; }
.ds-sorts .sort-pill,
.ds-sort-pill {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--ss-border);
  background: var(--ss-surface);
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
.ds-sorts .sort-pill.active,
.ds-sort-pill.active {
  background: var(--ss-secondary-bg);
  border-color: var(--ss-border-strong);
  color: var(--ss-text);
  font-weight: 600;
}

/* Tag chips inside the Filters panel */
.ds-panel .tag-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ds-panel .tag-chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ss-border);
  background: var(--ss-surface);
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ds-panel .tag-chip.active {
  background: var(--ss-secondary-bg);
  border-color: var(--ss-border-strong);
  color: var(--ss-text);
  font-weight: 600;
}

/* Composer inside the "New discussion" sheet */
.ds-composer { display: flex; flex-direction: column; gap: 12px; }
.ds-composer-row { display: flex; align-items: center; gap: 12px; }
.ds-composer-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.ds-composer-title {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: var(--ss-bg);
  color: var(--ss-text);
  font-family: inherit;
  font-size: 14px;
}
.ds-composer-title:focus { outline: none; border-color: var(--ss-border-strong); }
.ds-composer .comment-input {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--ss-border);
  border-radius: 0 0 8px 8px;
  background: var(--ss-bg);
  color: var(--ss-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
}
.ds-composer .comment-input:focus { outline: none; border-color: var(--ss-border-strong); }
.ds-composer .format-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px;
  border: 1px solid var(--ss-border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--ss-surface-2);
}
.ds-composer .format-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--ss-ghost-fg); cursor: pointer;
}
.ds-composer .format-btn:hover { background: var(--ss-ghost-bg-hover); color: var(--ss-text); }

/* ============================================================
   discussion-post.html — reading layout
   ============================================================ */
.ds-threadbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 0;
  background: var(--ss-bg);
  border-bottom: 1px solid var(--ss-border);
}
.ds-threadbar-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border-radius: 8px;
  color: var(--ss-ghost-fg);
  text-decoration: none;
}
.ds-threadbar-back:hover { background: var(--ss-ghost-bg-hover); color: var(--ss-text); }
.ds-threadbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ss-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ds-threadbar-count {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--ss-text-muted);
  white-space: nowrap;
}
.ds-threadbar .ds-btn { min-height: 40px; padding: 0 12px; }

/* Reading measure for the OP and the replies */
.ds-article,
.ds-replies-head,
.ds-replies,
.ds-reply-inline {
  max-width: var(--ds-measure);
  margin-left: auto;
  margin-right: auto;
}
.ds-article { padding: 24px 0 16px; }
.ds-article .thread-op {
  background: transparent;
  border: 0;
  padding: 0;
}
.ds-article .thread-title {
  margin: 12px 0 8px;
  font-size: 22px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ss-text);
}
.ds-article .thread-body {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ss-text);
}
.ds-article .thread-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.ds-article .tag-badge {
  background: var(--ss-surface-2);
  border: 1px solid var(--ss-border);
  color: var(--ss-text-muted);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
}
.ds-article .thread-op-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px solid var(--ss-border);
}

.ds-replies-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 0 12px;
  border-top: 1px solid var(--ss-border);
}
.ds-replies-title { margin: 0; font-size: 14px; font-weight: 600; color: var(--ss-text); }
.ds-replies-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ds-replies-tools .sort-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--ss-border);
  background: var(--ss-surface);
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ds-replies-tools .sort-btn.active {
  background: var(--ss-secondary-bg);
  border-color: var(--ss-border-strong);
  color: var(--ss-text);
  font-weight: 600;
}

.ds-replies { padding-bottom: 24px; }

/* Nested replies: one 2px rail, 12px indent per level, capped at 3 */
.ds-replies .replies-container {
  margin-left: var(--ds-indent);
  padding-left: var(--ds-indent);
  border-left: var(--ds-rail) solid var(--ss-border);
}
.ds-replies .replies-container .replies-container .replies-container .replies-container {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}
.ds-replies .comment-content,
.ds-replies .comment-text { font-size: 14px; line-height: 1.6; }

/* Inline composer (desktop) at the top of the reply list */
.ds-reply-inline { padding: 0 0 16px; }

@media (max-width: 719px) {
  .ds-identity-actions { width: 100%; }
  .ds-identity-actions .ds-btn { flex: 1 1 auto; }
  .ds-row {
    grid-template-areas:
      "meta  meta"
      "title media"
      "excerpt media"
      "stats stats";
  }
  .ds-article .thread-title { font-size: 20px; }
}

/* Desktop: right-docked 380px full-height panel */
@media (min-width: 720px) {
  .ds-panel-overlay {
    background: rgba(0, 0, 0, .35);
    align-items: center;
    justify-content: center;
  }
  .ds-panel {
    width: 560px;
    max-width: 560px;
    max-height: 82dvh;
    border: 1px solid var(--ss-border);
    border-radius: 12px;
    animation: none;
  }
  .ds-panel-handle { display: none; }
  .ds-panel-filters { width: 420px; max-width: 420px; }
}

/* Keep inherited composer avatars in scale inside the shell. */
.ds-shell .comment-avatar,
.ds-sheet .comment-avatar {
  width: 36px; height: 36px; min-width: 36px; flex: 0 0 36px;
}
