/* xpost post: faithful X-style post replica */
/* CONTRACT: uses base.css tokens for design tokens (:text, :bg, :surface, :border, :accent, --r-*) */
/*           uses [data-theme="light|dim|dark"] attribute for post-specific colors */

/* Base post styles - Real X font stack (no CJK fonts in main stack) */
.x-post {
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 23px;
  color: #0f1419;
  background: #ffffff;
  border-bottom: 1px solid #eff3f4;
}

[data-theme="dim"] .x-post {
  border-bottom-color: #38444d;
}

[data-theme="dark"] .x-post {
  border-bottom-color: #2f3336;
}

/* Header styles */
.x-row {
  display: flex;
  padding: 16px 0 8px;
}

.x-avatar,
.x-avatar-gradient,
.x-avatar-initials {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 9999px;
  flex-shrink: 0;
  object-fit: cover;
  transition: transform 0.1s ease;
}
.x-avatar:active { transform: scale(0.98); }
.x-avatar:hover { box-shadow: 0 0 0 3px rgba(29,155,240,0.25); }

.x-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

.x-header-body {
  margin-left: 12px;
  line-height: 1.3;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Replying-to line (above header) */
.x-replying {
  font-size: 15px;
  color: #657786;
  margin-bottom: 2px;
}
.x-replying-text {
  color: #657786;
}
.x-replying-handle {
  color: #1d9bf0;
  text-decoration: none;
}
.x-replying-handle:hover { text-decoration: underline; }

.x-name {
  font-size: 15px;
  font-weight: 700;
  color: #0f1419;
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.x-name:hover {
  text-decoration: underline;
}

.x-name:active { opacity: 0.7; }

.x-handle,
.x-sep,
.x-time,
.x-src {
  font-size: 15px;
  font-weight: 400;
  color: #71767b;
}

.x-handle { color: #71767b; white-space: nowrap; }
.x-handle:hover { color: #1d9bf0; text-decoration: underline; }
.x-handle:active { text-decoration: underline; opacity: 0.7; }
.x-sep { color: #71767b; margin: 0 4px; }
.x-time { color: #71767b; }
.x-src { color: #71767b; opacity: 0.85; font-size: 14px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Symbol", Roboto, Helvetica, Arial, "Noto Sans", sans-serif; }
.x-more-icon { color: #71767b; margin-left: 8px; flex-shrink: 0; }

/* Text content - clamp to 6 lines for long posts (real X feed behavior) */
.x-text {
  font-size: 15px;
  line-height: 23px;
  margin: 12px 0;
  text-rendering: optimizeLegibility;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.x-text br {
  content: '';
  display: block;
}

/* Empty-state placeholder */
.x-text-placeholder {
  color: #71767b;
  font-style: italic;
}

.x-link {
  color: #1d9bf0;
  text-decoration: none;
  font-weight: 400;
}

.x-link:hover {
  color: #1a8cd8;
  text-decoration: underline;
}

/* Verified badge */
.x-verified {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-left: 2px;
  vertical-align: middle;
  transition: opacity 0.15s ease;
}
.x-verified:hover { opacity: 0.85; }

.x-verified-blue { color: #1d9bf0; }
.x-verified-gold { color: #d97706; }
.x-verified-gray { color: #6b7280; }

/* Media grid */
.x-media {
  display: grid;
  gap: 3px;
  margin-top: 12px;
  border-radius: 16px;
  overflow: hidden;
}

.x-media[data-count="1"] {
  grid-template-columns: 1fr;
}
.x-media[data-count="1"] .x-mg-img {
  max-height: 512px;
}

.x-media[data-count="2"] {
  grid-template-columns: 1fr 1fr;
}

.x-media[data-count="3"] {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto;
}

.x-media[data-count="3"] .x-mg-cell-large {
  grid-column: 1 / 2;
  grid-row: 1 / 3;
}

.x-media[data-count="3"] .x-mg-cell-large + .x-mg-cell {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
}

.x-media[data-count="3"] .x-mg-cell-large + .x-mg-cell + .x-mg-cell {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
}

.x-media[data-count="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.x-mg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.x-media:active .x-mg-img { opacity: 0.95; }
.x-media { cursor: pointer; }
.x-media:hover .x-mg-img { opacity: 0.97; }

/* Engagement row */
.x-eng {
  display: flex;
  border-top: 1px solid #eff3f4;
  padding-top: 12px;
  margin-top: 12px;
}

.x-eng-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  color: #657786;
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease, border-radius 0.15s ease;
  border-radius: 9999px;
  padding: 6px 8px;
}

.x-eng-cell:hover {
  color: #1d9bf0;
  background-color: var(--accent-soft);
}

.x-eng svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.x-count {
  color: #657786;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}
.x-eng-label {
  font-size: 12px;
  color: #657786;
  margin-left: 4px;
}

/* Watermark for exported image */
.x-watermark {
  display: block;
  text-align: right;
  font-size: 10px;
  color: rgba(113, 118, 123, 0.5);
  margin-top: 12px;
  padding: 0 16px;
  letter-spacing: 0.3px;
  position: relative;
  right: 0;
}

/* Theme overrides for light */
[data-theme="light"] {
  color: #0f1419;
}

[data-theme="light"] .x-name {
  color: #0f1419;
}

[data-theme="light"] .x-handle,
[data-theme="light"] .x-sep,
[data-theme="light"] .x-time,
[data-theme="light"] .x-src {
  font-weight: 400;
  color: #71767b;
  margin: 0 4px;
}

[data-theme="light"] .x-text .x-link {
  color: #1d9bf0;
}

[data-theme="light"] .x-verified-blue { color: #1d9bf0; }
[data-theme="light"] .x-verified-gold { color: #d97706; }
[data-theme="light"] .x-verified-gray { color: #6b7280; }

[data-theme="light"] .x-eng {
  border-top-color: #eff3f4;
}

[data-theme="light"] .x-eng-cell {
  color: #657786;
}

[data-theme="light"] .x-eng-cell:hover {
  color: #1d9bf0;
  background-color: var(--accent-soft);
}

[data-theme="light"] .x-count {
  color: #657786;
}
[data-theme="light"] .x-eng-label {
  color: #657786;
}
[data-theme="light"] .x-watermark {
  color: #657786;
  opacity: 0.5;
}
[data-theme="light"] .x-replying {
  color: #657786;
}
[data-theme="light"] .x-replying-handle {
  color: #1d9bf0;
}

/* Theme overrides for dim (X dim mode colors) */
[data-theme="dim"] {
  background: #15202b;
  color: #e7e9ea;
}

[data-theme="dim"] .x-name {
  color: #e7e9ea;
}

[data-theme="dim"] .x-handle,
[data-theme="dim"] .x-sep,
[data-theme="dim"] .x-time,
[data-theme="dim"] .x-src {
  font-weight: 400;
  color: #71767b;
  margin: 0 4px;
}

[data-theme="dim"] .x-text .x-link {
  color: #1d9bf0;
}

[data-theme="dim"] .x-verified-blue { color: #1d9bf0; }
[data-theme="dim"] .x-verified-gold { color: #d97706; }
[data-theme="dim"] .x-verified-gray { color: #6b7280; }

[data-theme="dim"] .x-eng {
  border-top-color: #38444d;
}

[data-theme="dim"] .x-eng-cell {
  color: #71767b;
}

[data-theme="dim"] .x-eng-cell:hover {
  color: #1d9bf0;
  background-color: var(--accent-soft);
}

[data-theme="dim"] .x-count {
  color: #71767b;
}
[data-theme="dim"] .x-eng-label {
  color: #71767b;
}

[data-theme="dim"] .x-watermark {
  color: #71767b;
  opacity: 0.5;
}
[data-theme="dim"] .x-replying {
  color: #71767b;
}
[data-theme="dim"] .x-replying-handle {
  color: #1d9bf0;
}

/* Theme overrides for dark (X dark mode - pure #000) */
[data-theme="dark"] {
  background: #000000;
  color: #e7e9ea;
}

[data-theme="dark"] .x-name {
  color: #e7e9ea;
}

[data-theme="dark"] .x-handle,
[data-theme="dark"] .x-sep,
[data-theme="dark"] .x-time,
[data-theme="dark"] .x-src {
  font-weight: 400;
  color: #71767b;
  margin: 0 4px;
}

[data-theme="dark"] .x-text .x-link {
  color: #1d9bf0;
}

[data-theme="dark"] .x-verified-blue { color: #1d9bf0; }
[data-theme="dark"] .x-verified-gold { color: #d97706; }
[data-theme="dark"] .x-verified-gray { color: #6b7280; }

[data-theme="dark"] .x-eng {
  border-top-color: #2f3336;
}

[data-theme="dark"] .x-eng-cell {
  color: #71767b;
}

[data-theme="dark"] .x-eng-cell:hover {
  color: #1d9bf0;
  background-color: var(--accent-soft);
}

[data-theme="dark"] .x-count {
  color: #71767b;
}
[data-theme="dark"] .x-eng-label {
  color: #71767b;
}
[data-theme="dark"] .x-watermark {
  color: #71767b;
  opacity: 0.5;
}

[data-theme="dark"] .x-replying {
  color: #71767b;
}
[data-theme="dark"] .x-replying-handle {
  color: #1d9bf0;
}

/* Accessibility: focus-visible for keyboard navigation */
:focus-visible {
  outline: 3px solid rgba(29, 155, 240, 0.4);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .x-eng-cell, .x-avatar, .x-name, .x-verified, .x-media {
    transition: none;
  }
}

/* Responsive */
@media (max-width: 600px) {
  .x-avatar,
  .x-avatar-gradient,
  .x-avatar-initials {
    width: 40px;
    height: 40px;
  }

  .x-avatar-initials {
    font-size: 16px;
  }

  .x-header-body {
    margin-left: 10px;
  }
}

/* R5: feed-post bottom border (real X posts separated by border) */
.x-subpost { border-bottom: 1px solid #eff3f4; padding: 0 16px 12px; }
[data-theme="dim"] .x-subpost { border-bottom-color: #38444d; }
[data-theme="dark"] .x-subpost { border-bottom-color: #2f3336; }

/* P6: Light theme muted text color fix - #657786 for handles/time/sources */
/* P6: Line-height fix - .x-text now matches .x-post at 23px */

.x-eng-cell-icon { flex: 0 0 auto; }
.x-eng-cell-icon:first-of-type { margin-left: auto; }
.x-eng-cell-icon .x-eng-icon { opacity: 0.7; }

/* R96: prevent mobile flex overflow (box-sizing + min-width:0) */
.x-row, .x-eng, .x-header-body, .x-eng-cell { box-sizing: border-box; min-width: 0; }

/* R103: text selection highlight (accent tint) */
.x-post ::selection { background: rgba(29,155,240,0.3); color: inherit; }
.x-post ::-moz-selection { background: rgba(29,155,240,0.3); color: inherit; }
