/* Authentic X (Twitter) Timeline & Expanded Post Card Styles */

.export-stage-frame {
  width: 100%;
  max-width: 598px;
  transition: padding 180ms ease, background 180ms ease, border-radius 180ms ease;
}

.export-stage-frame.is-framed {
  max-width: 662px;
  padding: 32px;
  border-radius: 24px;
  background: linear-gradient(145deg, hsl(220 16% 18%), hsl(220 16% 11%));
  box-shadow: var(--shadow-stage);
}

.x-feed-column {
  width: 100%;
  background: var(--x-bg);
  color: var(--x-text);
  border-radius: 16px;
  border: 1px solid var(--x-card-border);
  overflow: hidden;
  box-shadow: var(--shadow-stage);
}

[data-x-theme="light"] .x-feed-column {
  box-shadow: var(--shadow-card-light);
}

.x-post-article {
  position: relative;
  padding: 14px 16px 12px;
  transition: background 120ms ease;
}

.x-post-article + .x-post-article {
  border-top: 1px solid var(--x-border);
}

.x-post-article.is-thread-parent {
  border-bottom: 0;
  padding-bottom: 4px;
}

.x-post-article.is-thread-parent + .x-post-article {
  border-top: 0;
  padding-top: 8px;
}

.x-post-article.is-selected-in-thread {
  outline: 2px solid rgba(29, 155, 240, 0.45);
  outline-offset: -2px;
}

/* Timeline Row Layout */
.x-timeline-layout {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  column-gap: 12px;
}

.x-avatar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.x-avatar {
  width: 40px;
  height: 40px;
  border-radius: 9999px;
  object-fit: cover;
  background: var(--x-media-bg);
  flex-shrink: 0;
  cursor: pointer;
}

.x-avatar.is-org {
  border-radius: 8px;
}

.x-thread-connector {
  width: 2px;
  flex: 1;
  min-height: 16px;
  margin-top: 4px;
  background: var(--x-thread-line);
  border-radius: 2px;
}

/* Header Meta */
.x-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.x-author-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  line-height: 20px;
}

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

.x-verified-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: text-bottom;
}

.x-handle-time {
  color: var(--x-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
}

.x-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.x-follow-pill {
  height: 30px;
  padding: 0 15px;
  border-radius: 9999px;
  border: 0;
  background: var(--x-follow-bg);
  color: var(--x-follow-text);
  font-size: 14px;
  font-weight: 700;
}

.x-more-dots {
  width: 32px;
  height: 32px;
  margin-right: -6px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--x-secondary);
  display: grid;
  place-items: center;
}

.x-more-dots:hover {
  background: rgba(29, 155, 240, 0.12);
  color: #1d9bf0;
}

/* Expanded Detail Header */
.x-expanded-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.x-expanded-author {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.x-expanded-names {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.x-expanded-name-line {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 20px;
}

.x-expanded-handle {
  font-size: 15px;
  line-height: 20px;
  color: var(--x-secondary);
}

/* Post Body Caption */
.x-caption {
  margin-top: 2px;
  font-size: 15px;
  line-height: 20px;
  font-weight: 400;
  color: var(--x-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.x-caption.is-expanded-view {
  font-size: 17px;
  line-height: 24px;
  margin-top: 4px;
}

.x-entity {
  color: var(--x-link);
}

.x-show-more {
  color: var(--x-link);
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  cursor: pointer;
}

/* Media Grid Container (1, 2, 3, 4+ Photos) */
.x-media-wrapper {
  margin-top: 12px;
  position: relative;
}

.x-media-grid {
  display: grid;
  gap: 2px;
  border-radius: 16px;
  overflow: clip;
  border: 1px solid var(--x-border);
  background: var(--x-border);
}

/* 1 Image */
.x-media-grid[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.x-media-grid[data-count="1"] .x-media-cell {
  max-height: 510px;
}

.x-media-grid[data-count="1"][data-aspect="16:9"] .x-media-cell {
  aspect-ratio: 16 / 9;
}

.x-media-grid[data-count="1"][data-aspect="4:5"] .x-media-cell {
  aspect-ratio: 4 / 5;
}

.x-media-grid[data-count="1"][data-aspect="1:1"] .x-media-cell {
  aspect-ratio: 1 / 1;
}

/* 2 Images: Side-by-Side Split */
.x-media-grid[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  aspect-ratio: 16 / 9;
}

/* 3 Images: Tall Left Hero + 2 Stacked Right */
.x-media-grid[data-count="3"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  aspect-ratio: 16 / 9;
}

.x-media-grid[data-count="3"] .x-media-cell:nth-child(1) {
  grid-row: 1 / span 2;
}

/* 4+ Images: Classic 2x2 X Grid */
.x-media-grid[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  aspect-ratio: 16 / 9;
}

.x-media-cell {
  position: relative;
  overflow: hidden;
  background: var(--x-media-bg);
  cursor: pointer;
  user-select: none;
}

.x-media-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform-origin: center center;
  pointer-events: none;
}

.x-media-grid[data-count="1"][data-aspect="auto"] .x-media-cell img {
  height: auto;
  max-height: 510px;
}

/* Interactive Pan & Crop Mode inside Live X Preview */
.is-crop-mode .x-media-cell {
  cursor: grab;
  outline: 1px dashed rgba(29, 155, 240, 0.85);
  outline-offset: -2px;
}

.is-crop-mode .x-media-cell:active {
  cursor: grabbing;
}

.x-crop-pill-hint {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.78);
  backdrop-filter: blur(4px);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
}

/* Authentic X ALT Badge & +N More Overlay */
.x-alt-badge {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  left: 10px;
  bottom: 10px;
  height: 22px;
  padding: 0 8px;
  border-radius: 5px;
  border: 0;
  background: rgba(15, 20, 25, 0.78);
  backdrop-filter: blur(4px);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.x-alt-badge:hover {
  background: rgba(15, 20, 25, 0.92);
}

.x-more-count-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.56);
  color: #ffffff;
  font-size: 28px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Swipeable X Carousel Gallery Mode */
.x-carousel-shell {
  position: relative;
}

.x-carousel-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  border-radius: 16px;
  border: 1px solid var(--x-border);
  background: var(--x-media-bg);
}

.x-carousel-track::-webkit-scrollbar {
  display: none;
}

.x-carousel-slide {
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
}

.x-carousel-img-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: 460px;
  width: 100%;
  overflow: hidden;
  background: var(--x-media-bg);
  cursor: pointer;
}

.x-carousel-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.x-carousel-slide-caption {
  padding: 10px 14px;
  background: var(--x-bg);
  border-top: 1px solid var(--x-border);
  font-size: 14px;
  line-height: 18px;
  color: var(--x-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.x-carousel-slide-index {
  font-size: 12px;
  color: var(--x-secondary);
  flex-shrink: 0;
}

.x-carousel-count-pill {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(15, 20, 25, 0.77);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

.x-carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(15, 20, 25, 0.74);
  color: #ffffff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
}

.x-carousel-nav:hover {
  background: rgba(15, 20, 25, 0.9);
}

.x-carousel-nav.is-prev {
  left: 10px;
}

.x-carousel-nav.is-next {
  right: 10px;
}

.x-carousel-dots {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-top: 8px;
}

.x-carousel-dot {
  width: 6px;
  height: 6px;
  padding: 0;
  border-radius: 50%;
  border: 0;
  background: var(--x-border);
}

.x-carousel-dot.is-active {
  background: #1d9bf0;
  width: 14px;
  border-radius: 999px;
}

/* Expanded Post Timestamp & Views Line */
.x-expanded-meta-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 14px 0;
  border-bottom: 1px solid var(--x-border);
  font-size: 15px;
  color: var(--x-secondary);
}

.x-expanded-meta-line strong {
  color: var(--x-text);
  font-weight: 700;
}

/* Action Bar */
.x-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  margin-left: -8px;
  color: var(--x-secondary);
}

.x-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--x-secondary);
  padding: 0 6px;
  height: 34px;
  border-radius: 999px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: color 130ms ease, background 130ms ease;
}

.x-action-icon-ring {
  width: 34px;
  height: 34px;
  margin-left: -6px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: background 130ms ease;
}

.x-action-btn svg {
  width: 18.75px;
  height: 18.75px;
  fill: currentColor;
}

.x-action-btn.is-reply:hover,
.x-action-btn.is-views:hover,
.x-action-btn.is-bookmark:hover,
.x-action-btn.is-share:hover {
  color: #1d9bf0;
}

.x-action-btn.is-reply:hover .x-action-icon-ring,
.x-action-btn.is-views:hover .x-action-icon-ring,
.x-action-btn.is-bookmark:hover .x-action-icon-ring,
.x-action-btn.is-share:hover .x-action-icon-ring {
  background: rgba(29, 155, 240, 0.12);
}

.x-action-btn.is-repost:hover,
.x-action-btn.is-repost.is-active {
  color: #00ba7c;
}

.x-action-btn.is-repost:hover .x-action-icon-ring {
  background: rgba(0, 186, 124, 0.12);
}

.x-action-btn.is-like:hover,
.x-action-btn.is-like.is-active {
  color: #f91880;
}

.x-action-btn.is-like:hover .x-action-icon-ring {
  background: rgba(249, 24, 128, 0.12);
}

.x-action-btn.is-bookmark.is-active {
  color: #1d9bf0;
}

.x-action-right-pair {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

/* Native Top-Layer Lightbox Dialog */
dialog.lightbox-dialog {
  width: min(1080px, 94vw);
  max-height: 90dvh;
  padding: 0;
  border: 1px solid hsl(220 12% 24%);
  border-radius: 18px;
  background: #0b0e11;
  color: #f7f9f9;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8);
}

dialog.lightbox-dialog::backdrop {
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
}

.lightbox-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  height: min(740px, 88dvh);
}

.lightbox-stage {
  position: relative;
  background: #000000;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 24px 60px;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: calc(88dvh - 80px);
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(15, 20, 25, 0.78);
  color: #ffffff;
  font-size: 18px;
  display: grid;
  place-items: center;
}

.lightbox-side {
  border-left: 1px solid #2f3336;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  overflow-y: auto;
  background: #0f1419;
}

.lightbox-thumbs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.lightbox-thumbs button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #000;
}

.lightbox-thumbs button.is-active {
  border-color: #1d9bf0;
}

.lightbox-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (max-width: 820px) {
  .lightbox-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .lightbox-side {
    border-left: 0;
    border-top: 1px solid #2f3336;
  }
}
