/* ================================================================
   Bsky Dreams — Main Stylesheet
   Mobile-first. CSS custom properties throughout.
   WCAG AA contrast maintained on all text/background pairs.
================================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Enforce the [hidden] attribute even when CSS sets an explicit display value */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: clip; /* prevent fixed/transformed elements from creating horizontal scroll */
}

/* ---- Design Tokens ---- */
:root {
  /* Brand */
  --color-accent:         #0085ff;
  --color-accent-dark:    #006fd6;
  --color-accent-light:   #e8f3ff;

  /* Surfaces */
  --color-bg:             #f4f6f9;
  --color-surface:        #ffffff;
  --color-surface-alt:    #f0f3f7;
  --color-border:         #dde2ea;

  /* Text */
  --color-text:           #1a1d23;
  --color-text-muted:     #5a6275;
  --color-text-light:     #8892a4;

  /* States */
  --color-error-bg:       #fff0f0;
  --color-error-text:     #c0392b;
  --color-error-border:   #f5c6c2;
  --color-success-bg:     #f0fff4;
  --color-success-text:   #1a7a40;
  --color-success-border: #b7e4c7;

  /* Spacing scale */
  --space-xs:   4px;
  --space-sm:   8px;
  --space-md:   16px;
  --space-lg:   24px;
  --space-xl:   40px;

  /* Radii */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-card: 0 1px 4px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
  --shadow-elevated: 0 4px 16px rgba(0,0,0,0.12);

  /* Layout */
  --top-bar-height: 56px;
  --max-content-width: 640px;

  /* Thread depth line colors (8 distinct colors, cycling per nesting level) */
  --td-1: #0085ff;  /* blue    */
  --td-2: #9061f9;  /* violet  */
  --td-3: #06b6d4;  /* cyan    */
  --td-4: #10b981;  /* emerald */
  --td-5: #f59e0b;  /* amber   */
  --td-6: #ef4444;  /* red     */
  --td-7: #f97316;  /* orange  */
  --td-8: #ec4899;  /* pink    */
}

/* ---- Utility ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
}

/* ---- Screens ---- */
.screen {
  min-height: 100dvh;
}

/* ================================================================
   AUTH SCREEN
================================================================ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: linear-gradient(160deg, #e8f3ff 0%, #f4f6f9 60%);
}

.auth-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-elevated);
  padding: var(--space-xl) var(--space-lg);
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-md);
}

.auth-title {
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  color: var(--color-text);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-xs);
}

.auth-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xl);
  font-size: 0.95rem;
}

/* ================================================================
   FORM ELEMENTS
================================================================ */
.field-group {
  margin-bottom: var(--space-md);
}

.field-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.field-input {
  display: block;
  width: 100%;
  padding: 10px var(--space-md);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.field-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0,133,255,0.15);
}

.field-hint {
  margin-top: var(--space-xs);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 10px var(--space-lg);
  border: none;
  border-radius: var(--radius-pill);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-accent-dark);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
}

.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-full {
  width: 100%;
  margin-top: var(--space-md);
}

/* ---- Banners ---- */
.error-banner {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  margin-bottom: var(--space-md);
}

.success-banner {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border: 1px solid var(--color-success-border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  font-size: 0.9375rem;
  margin-top: var(--space-md);
}

/* ================================================================
   APP SCREEN LAYOUT
================================================================ */
#app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---- Top Bar ---- */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--top-bar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.top-bar-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 var(--space-md);
  gap: var(--space-md);
  max-width: var(--max-content-width);
  margin: 0 auto;
}

.nav-logo-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 4px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.nav-logo-btn:focus-visible {
  outline: 3px solid var(--color-accent);
}

.nav-logo-mark {
  font-size: 1.3rem;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-left: auto;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px var(--space-sm);
  border-radius: var(--radius-pill);
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.nav-btn.active {
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.nav-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 1px;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-label {
  display: none;
}

@media (min-width: 480px) {
  .nav-label {
    display: inline;
  }
}

.nav-avatar-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: none;
  border: none;
  margin-left: var(--space-sm);
  border-radius: var(--radius-pill);
  padding: 4px;
}

.nav-avatar-btn:focus-visible {
  outline: 3px solid var(--color-accent);
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-surface-alt);
  object-fit: cover;
  flex-shrink: 0;
}

.nav-handle-text {
  display: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 600px) {
  .nav-handle-text {
    display: block;
  }
}

/* ================================================================
   VIEWS
================================================================ */
.view {
  flex: 1;
  overflow-y: auto;
}

.view-inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-md);
}

.view-heading {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-lg);
}

/* ================================================================
   SEARCH VIEW
================================================================ */
.search-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-card);
}

.search-input {
  display: block;
  width: 100%;
  padding: 10px var(--space-md);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface-alt);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  margin-bottom: var(--space-sm);
}

.search-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0,133,255,0.15);
  background: var(--color-surface);
}

.search-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
}

.filter-chip {
  padding: 5px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: all 0.15s;
}

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

.filter-chip.active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.filter-chip:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.search-submit {
  width: 100%;
}

/* Adult-content toggle + advanced-search toggle row */
.search-options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
  gap: var(--space-sm);
}

.adult-toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
  user-select: none;
}

.adult-toggle-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.advanced-toggle-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.advanced-toggle-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.advanced-toggle-btn[aria-expanded="true"] {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.adv-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.advanced-toggle-btn[aria-expanded="true"] .adv-arrow {
  transform: rotate(180deg);
}

/* Advanced search panel */
.advanced-panel {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xs) var(--space-sm);
}

@media (max-width: 400px) {
  .advanced-grid {
    grid-template-columns: 1fr;
  }
}

.adv-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.adv-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.adv-input {
  padding: 6px var(--space-sm);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
  appearance: none;
}

.adv-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(0, 133, 255, 0.12);
}

/* ---- Rich text: hashtag and mention styling ---- */
.hashtag-link {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

.hashtag-link:hover {
  text-decoration: underline;
}

.mention-text {
  color: var(--color-accent);
  font-weight: 500;
}

/* ================================================================
   FEED — shared by search results and future timeline
================================================================ */
.feed {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.feed-empty {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.feed-loading {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-light);
}

/* ================================================================
   POST CARD
================================================================ */
.post-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.15s;
}

.post-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}

.post-card-clickable {
  cursor: pointer;
}

.post-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.post-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-surface-alt);
  object-fit: cover;
  flex-shrink: 0;
}

.post-meta {
  flex: 1;
  min-width: 0;
}

.post-display-name {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-handle {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-timestamp {
  font-size: 0.8125rem;
  color: var(--color-text-light);
  flex-shrink: 0;
  white-space: nowrap;
}

.post-text {
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: var(--space-sm);
}

/* ---- Post media ---- */
.post-images {
  display: grid;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.post-images.count-1 { grid-template-columns: 1fr; }
.post-images.count-2 { grid-template-columns: 1fr 1fr; }
.post-images.count-3 { grid-template-columns: 1fr 1fr; }
.post-images.count-4 { grid-template-columns: 1fr 1fr; }

.post-image-wrap {
  position: relative;
  overflow: hidden;
}

/* Single image: natural aspect ratio, capped between 3:1 wide and 1:2 tall */
.post-images.count-1 .post-image-wrap img {
  width: 100%;
  height: auto;
  max-height: 480px;
  min-height: 120px;
  object-fit: contain;
  display: block;
  background: #000;
}

/* 2–4 images: uniform crop at a consistent height */
.post-images.count-2 .post-image-wrap img,
.post-images.count-3 .post-image-wrap img,
.post-images.count-4 .post-image-wrap img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.post-image-alt {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  padding: var(--space-xs) var(--space-sm);
  line-height: 1.4;
  border-top: 1px solid var(--color-border);
  font-style: italic;
}

/* ---- Post actions ---- */
.post-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--color-border);
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--color-text-light);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.action-btn:hover {
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.action-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 1px;
}

.action-btn svg {
  width: 16px;
  height: 16px;
}

.action-btn.liked {
  color: #e0245e;
}

.action-btn.reposted {
  color: #17bf63;
}

/* Share / copy-link button — pushed to the far right of the actions row */
.share-action-btn {
  margin-left: auto;
  color: var(--color-text-light);
}

.share-action-btn svg {
  width: 15px;
  height: 15px;
}

.action-count {
  font-variant-numeric: tabular-nums;
}

/* ================================================================
   COMPOSE VIEW
================================================================ */
.compose-form {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-card);
}

.compose-row {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
}

.compose-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-surface-alt);
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
}

.compose-body {
  flex: 1;
  min-width: 0;
}

.compose-textarea {
  display: block;
  width: 100%;
  min-height: 100px;
  padding: var(--space-sm);
  font-size: 1rem;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
  border: none;
  resize: vertical;
  line-height: 1.55;
}

.compose-textarea:focus {
  outline: none;
}

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--space-sm);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-sm);
}

.char-count {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.char-count.warn {
  color: #e6a817;
}

.char-count.over {
  color: var(--color-error-text);
}

.compose-footer-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.compose-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  cursor: pointer;
}

.compose-attach-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
  background: var(--color-accent-light);
}

.compose-attach-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.compose-attach-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Image previews in compose form */
.compose-images-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-sm);
  margin: var(--space-sm) 0;
}

.compose-image-item {
  position: relative;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--color-surface-alt);
}

.compose-image-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}

.compose-image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s;
}

.compose-image-remove:hover {
  background: rgba(0,0,0,0.85);
}

.compose-alt-input {
  display: block;
  width: 100%;
  padding: 4px var(--space-xs);
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
  border: none;
  border-top: 1px solid var(--color-border);
  resize: none;
  line-height: 1.3;
}

.compose-alt-input:focus {
  outline: none;
  background: var(--color-accent-light);
}

.compose-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-sm);
}

/* ================================================================
   THREAD / CONVERSATION VIEW
================================================================ */
.thread-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.back-btn {
  flex-shrink: 0;
}

.thread-heading {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.thread-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

/* Thread root post gets special treatment */
.post-card.thread-root {
  border-color: var(--color-accent);
  border-width: 2px;
}

/* Replies are nested with a depth-colored left border — no overlapping connectors */
.reply-group {
  position: relative;       /* for .reply-collapse-btn absolute positioning */
  margin-left: 12px;
  margin-top: var(--space-xs);
  padding-left: 16px;       /* extra room for the collapse button */
  border-left: 2px solid var(--thread-line-color, var(--color-border));
  border-bottom-left-radius: 3px;
}

/* Post cards inside a reply group inherit the depth color as their left border */
.reply-group-body > .post-card {
  border-left-color: var(--thread-line-color, var(--color-border));
  border-left-width: 2px;
}

/* Cycle through 8 depth colors */
.reply-group[data-depth="1"],
.reply-group[data-depth="9"]  { --thread-line-color: var(--td-1); }

.reply-group[data-depth="2"],
.reply-group[data-depth="10"] { --thread-line-color: var(--td-2); }

.reply-group[data-depth="3"],
.reply-group[data-depth="11"] { --thread-line-color: var(--td-3); }

.reply-group[data-depth="4"],
.reply-group[data-depth="12"] { --thread-line-color: var(--td-4); }

.reply-group[data-depth="5"],
.reply-group[data-depth="13"] { --thread-line-color: var(--td-5); }

.reply-group[data-depth="6"],
.reply-group[data-depth="14"] { --thread-line-color: var(--td-6); }

.reply-group[data-depth="7"],
.reply-group[data-depth="15"] { --thread-line-color: var(--td-7); }

.reply-group[data-depth="8"],
.reply-group[data-depth="16"] { --thread-line-color: var(--td-8); }

/* ---- Collapse/expand controls ---- */

/* Small circle button sitting on the connector line at the top of the group */
.reply-collapse-btn {
  position: absolute;
  top: 6px;
  left: -9px;               /* centers the 16px button on the 2px border-left */
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1.5px solid var(--thread-line-color, var(--color-border));
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--thread-line-color, var(--color-text-muted));
  padding: 0;
  transition: background 0.12s, color 0.12s;
  z-index: 2;
}

.reply-collapse-btn:hover {
  background: var(--thread-line-color, var(--color-border));
  color: #fff;
}

.reply-collapse-btn:focus-visible {
  outline: 2px solid var(--thread-line-color, var(--color-accent));
  outline-offset: 2px;
}

/* "↓ Show N replies" button shown when a group is collapsed */
.reply-expand-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  background: none;
  border: none;
  color: var(--thread-line-color, var(--color-accent));
  font-size: 0.8125rem;
  font-weight: 500;
  padding: var(--space-xs) 0;
  margin-top: var(--space-xs);
  cursor: pointer;
}

.reply-expand-btn:hover {
  text-decoration: underline;
}

.reply-expand-btn:focus-visible {
  outline: 2px solid var(--thread-line-color, var(--color-accent));
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Collapse toggle for long reply threads */
.collapse-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: none;
  border: none;
  color: var(--color-accent);
  font-size: 0.875rem;
  font-weight: 500;
  padding: var(--space-xs) 0;
  margin: var(--space-xs) 0;
}

.collapse-toggle:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.reply-area-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-md);
}

.reply-to-label {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.thread-reply-area {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

/* ----------------------------------------------------------------
   INLINE REPLY COMPOSE BOX (M9)
---------------------------------------------------------------- */
.inline-reply-box {
  margin-top: var(--space-sm);
  margin-bottom: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

/* Mini read-only quote of the post being replied to */
.inline-reply-quote {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.inline-reply-quote-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
}

.inline-reply-quote-content {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

.inline-reply-quote-author {
  font-weight: 600;
  color: var(--color-text);
  margin-right: 2px;
}

/* Compose row: user avatar + textarea */
.inline-reply-compose {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}

.inline-reply-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.inline-reply-body {
  flex: 1;
  min-width: 0;
}

.inline-reply-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-sm);
  gap: var(--space-sm);
}

.inline-reply-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.inline-reply-error {
  font-size: 0.8125rem;
  color: var(--color-error-text);
}

/* ================================================================
   PROFILE DROPDOWN MENU
================================================================ */
.dropdown-menu {
  position: fixed;
  top: calc(var(--top-bar-height) + 8px);
  right: var(--space-md);
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  min-width: 200px;
  overflow: hidden;
}

.dropdown-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
}

.dropdown-display-name {
  display: block;
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--color-text);
}

.dropdown-handle {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  font-size: 0.9375rem;
  color: var(--color-error-text);
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: var(--color-surface-alt);
}

.dropdown-item:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -2px;
}

/* ================================================================
   LOADING OVERLAY
================================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================================================
   RESPONSIVE BREAKPOINTS
================================================================ */
@media (min-width: 640px) {
  .view-inner {
    padding: var(--space-lg);
  }

  .top-bar-inner {
    padding: 0 var(--space-lg);
  }
}

@media (min-width: 768px) {
  /* Multi-image grids get a bit more height on wider screens */
  .post-images.count-2 .post-image-wrap img,
  .post-images.count-3 .post-image-wrap img,
  .post-images.count-4 .post-image-wrap img {
    height: 220px;
  }
}

/* ================================================================
   IMAGE LIGHTBOX — carousel-capable
================================================================ */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px var(--space-lg) var(--space-lg);
  cursor: zoom-out;
}

.lightbox-img {
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 1;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-close:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Prev / Next arrow buttons */
.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  z-index: 1;
}

.lightbox-arrow:hover {
  background: rgba(255, 255, 255, 0.3);
}

.lightbox-arrow:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.lightbox-arrow-prev { left: var(--space-md); }
.lightbox-arrow-next { right: var(--space-md); }

/* Footer: counter + caption + dots */
.lightbox-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.lightbox-counter {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.lightbox-caption {
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.875rem;
  font-style: italic;
  text-align: center;
  max-width: 600px;
  line-height: 1.5;
}

.lightbox-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lightbox-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  display: inline-block;
}

.lightbox-dot.active {
  background: #fff;
  transform: scale(1.3);
}

/* Images in feed are clickable */
.post-image-wrap {
  cursor: zoom-in;
}

/* ================================================================
   VIDEO EMBED
================================================================ */
.post-video-wrap {
  position: relative;
  width: 100%;
  margin-bottom: var(--space-sm);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

.post-video {
  display: block;
  width: 100%;
  max-height: 400px;
  object-fit: contain;
}

/* Poster + play button shown before video is activated */
.post-video-poster {
  position: relative;
  cursor: pointer;
  display: block;
}

.post-video-poster:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.post-video-thumb {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}

.post-video-play-btn {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  transition: background 0.15s;
}

.post-video-poster:hover .post-video-play-btn {
  background: rgba(0, 0, 0, 0.5);
}

.post-video-play-btn svg {
  width: 56px;
  height: 56px;
  color: #fff;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}

.post-video-fallback {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
}

/* ================================================================
   EXTERNAL LINK CARD
================================================================ */
.post-external-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-sm);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--color-surface);
}

.post-external-card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(0, 133, 255, 0.1);
  text-decoration: none;
}

.post-external-card:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.post-external-thumb {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}

.post-external-info {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface-alt);
}

.post-external-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-external-desc {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 2px;
}

.post-external-hostname {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-top: var(--space-xs);
}

/* ================================================================
   HOME FEED
================================================================ */
.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-md) var(--space-sm);
}

.feed-refresh-btn {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.feed-item {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Repost attribution bar above the post card */
.feed-repost-bar,
.feed-reply-bar {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md) 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.feed-repost-bar svg,
.feed-reply-bar svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

/* Remove the card's own box-shadow when it's inside a feed-item wrapper */
.feed-item > .post-card {
  box-shadow: none;
  border-radius: 0;
  background: transparent;
}

.feed-load-more {
  display: flex;
  justify-content: center;
  padding: var(--space-md);
}

/* ================================================================
   FOLLOW BUTTON (actor cards)
================================================================ */
.follow-btn {
  flex-shrink: 0;
  padding: 5px var(--space-md);
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  background: var(--color-accent);
  color: #fff;
  border: 1.5px solid var(--color-accent);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.follow-btn.following {
  background: transparent;
  color: var(--color-accent);
}

.follow-btn:hover:not(:disabled) {
  opacity: 0.8;
}

.follow-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Author name/avatar in post cards are clickable — open profile view */
.author-link {
  cursor: pointer;
}

.author-link:hover .post-display-name,
.post-header .author-link:hover {
  text-decoration: underline;
  text-decoration-color: var(--color-text-muted);
}

/* Actor card layout: avatar | meta (grows) | follow button */
.actor-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.actor-card-header .post-meta {
  flex: 1;
  min-width: 0;
}

/* ================================================================
   PROFILE VIEW
================================================================ */
.profile-header {
  padding: var(--space-md);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.profile-top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.profile-avatar-lg {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface-alt);
}

.profile-identity {
  flex: 1;
  min-width: 0;
}

.profile-display-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text);
  word-break: break-word;
}

.profile-handle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.profile-bio {
  font-size: 0.9375rem;
  color: var(--color-text);
  line-height: 1.5;
  margin-bottom: var(--space-md);
  white-space: pre-wrap;
  word-break: break-word;
}

.profile-stats {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
}

.profile-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.profile-stat-count {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
}

.profile-stat-label {
  color: var(--color-text-muted);
  font-size: 0.8125rem;
}

/* ================================================================
   NOTIFICATION BADGE (nav bell)
================================================================ */
.nav-notif-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: #e0245e;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
}

/* ================================================================
   NOTIFICATIONS VIEW
================================================================ */
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.notif-item:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}

.notif-item.notif-unread {
  border-left: 3px solid var(--color-accent);
  background: var(--color-accent-light);
}

.notif-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.notif-icon svg {
  width: 16px;
  height: 16px;
}

.notif-icon-like    { background: #fce7ef; color: #e0245e; }
.notif-icon-repost  { background: #e3f9ee; color: #17bf63; }
.notif-icon-follow  { background: var(--color-accent-light); color: var(--color-accent); }
.notif-icon-reply   { background: var(--color-surface-alt); color: var(--color-text-muted); }
.notif-icon-mention { background: var(--color-surface-alt); color: var(--color-text-muted); }
.notif-icon-quote   { background: var(--color-surface-alt); color: var(--color-text-muted); }

.notif-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface-alt);
}

.notif-body {
  flex: 1;
  min-width: 0;
}

.notif-meta {
  display: flex;
  align-items: baseline;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.notif-author {
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--color-text);
}

.notif-action {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.notif-time {
  font-size: 0.75rem;
  color: var(--color-text-light);
  white-space: nowrap;
  margin-left: auto;
}

.notif-preview {
  margin-top: 2px;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================================================
   QUOTED POST (embedded quote card inside a post card)
================================================================ */
.quoted-post-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
  background: var(--color-surface-alt);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.quoted-post-card:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.quoted-post-card:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.quoted-post-unavailable {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-style: italic;
  cursor: default;
}

.quoted-post-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-xs);
}

.quoted-post-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface);
}

.quoted-post-author {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.quoted-post-handle {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.quoted-post-text {
  font-size: 0.875rem;
  color: var(--color-text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Small reposter avatar in the feed repost attribution bar */
.feed-repost-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface-alt);
}

/* ================================================================
   FEED REPLY CONTEXT — compact parent post preview
================================================================ */
.feed-parent-preview {
  padding: var(--space-xs) var(--space-md) 0;
}

.feed-reply-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.feed-reply-label svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.feed-parent-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
  background: var(--color-surface-alt);
  cursor: pointer;
  margin-bottom: var(--space-xs);
  transition: border-color 0.15s, background 0.15s;
}

.feed-parent-card:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.feed-parent-header {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-bottom: 2px;
}

.feed-parent-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--color-surface);
}

.feed-parent-author {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.feed-parent-handle {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.feed-parent-text {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================================================
   CHANNELS SIDEBAR (M11)
================================================================ */

/* CSS custom property for sidebar width — used by both sidebar and content offset */
:root {
  --sidebar-width: 220px;
}

/* ---- Hamburger / channels toggle button in nav (mobile only) ---- */
.channels-nav-btn {
  /* visible on mobile, hidden on desktop */
}

@media (min-width: 768px) {
  .channels-nav-btn {
    display: none;
  }
}

/*
 * Hide the "Bsky Dreams" logo text on small screens to make room for the
 * channels nav button. The cloud icon (☁) alone keeps the logo identifiable.
 * This prevents the nav bar from overflowing, which would cause horizontal
 * scroll and rubber-banding across the entire page on mobile.
 */
@media (max-width: 479px) {
  .nav-logo-text {
    display: none;
  }
}

/* ---- Sidebar panel ---- */
.channels-sidebar {
  position: fixed;
  left: calc(-1 * var(--sidebar-width)); /* hidden off-screen left — avoids transform compositing issues */
  top: var(--top-bar-height);
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 150;
  display: flex;
  flex-direction: column;
  transition: left 0.25s ease;
  overscroll-behavior: contain;
}

.channels-sidebar.open {
  left: 0;
}

@media (min-width: 768px) {
  /* Desktop: always visible */
  .channels-sidebar {
    left: 0;
  }

  /* Push view content right to make room for the sidebar */
  .view {
    padding-left: var(--sidebar-width);
  }

  /* Shift top bar content right to align with content area */
  .top-bar-inner {
    max-width: none;
    padding-left: calc(var(--sidebar-width) + var(--space-md));
    padding-right: var(--space-md);
  }
}

/* ---- Mobile sidebar backdrop overlay ---- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 140;
  backdrop-filter: blur(1px);
}

@media (min-width: 768px) {
  /* Overlay never shown on desktop */
  .sidebar-overlay {
    display: none !important;
  }
}

/* ---- Sidebar header (title + close button) ---- */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  height: 44px;
}

.sidebar-heading {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.sidebar-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  padding: 4px;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar-close-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

@media (min-width: 768px) {
  /* Close button not needed on desktop */
  .sidebar-close-btn {
    display: none;
  }
}

/* ---- Channel list ---- */
.channels-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xs) 0;
}

.channels-empty {
  padding: var(--space-md);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ---- Channel item row ---- */
.channel-item {
  display: flex;
  align-items: center;
  position: relative;
}

/* Main click target: channel name + badge */
.channel-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  background: none;
  border: none;
  padding: 9px var(--space-md);
  text-align: left;
  font-size: 0.875rem;
  color: var(--color-text);
  cursor: pointer;
  min-width: 0;
  transition: background 0.12s;
}

.channel-btn:hover {
  background: var(--color-surface-alt);
}

.channel-btn.active {
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
}

.channel-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.channel-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* Unread count badge */
.channel-badge {
  flex-shrink: 0;
  background: var(--color-accent);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}

/* ⋯ options button — revealed on hover */
.channel-menu-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--color-text-light);
  width: 28px;
  height: 36px;
  opacity: 0;
  transition: opacity 0.15s;
  border-radius: var(--radius-sm);
  margin-right: 4px;
}

.channel-item:hover .channel-menu-btn,
.channel-item:focus-within .channel-menu-btn {
  opacity: 1;
}

.channel-menu-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.channel-menu-btn:focus-visible {
  opacity: 1;
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

/* Inline dropdown menu for channel options */
.channel-dropdown {
  position: absolute;
  right: 4px;
  top: calc(100% - 4px);
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-elevated);
  min-width: 128px;
  overflow: hidden;
}

.channel-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--color-text);
  cursor: pointer;
}

.channel-dropdown-item:hover {
  background: var(--color-surface-alt);
}

.channel-dropdown-delete {
  color: var(--color-error-text);
}

/* ---- "Save as channel" button (injected below search form) ---- */
.save-channel-area {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-sm);
}

.save-channel-btn {
  font-size: 0.8125rem;
  padding: 6px 14px;
  gap: 6px;
  border-radius: var(--radius-pill);
}
