/* ============================================
   FeediX Mini App - Telegram WebApp Stylesheet
   ============================================ */

/* --- Theme Variables --- */
:root {
  --tg-bg: var(--tg-theme-bg-color, #ffffff);
  --tg-text: var(--tg-theme-text-color, #000000);
  --tg-hint: var(--tg-theme-hint-color, #999999);
  --tg-link: var(--tg-theme-link-color, #2678b6);
  --tg-button: var(--tg-theme-button-color, #3390ec);
  --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);

  --card-bg: var(--tg-secondary-bg);
  --card-radius: 12px;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
  --feed-gap: 12px;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-stack);
  font-size: 15px;
  line-height: 1.5;
  color: var(--tg-text);
  background-color: var(--tg-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
}

#app {
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

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

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

/* --- Loading Skeleton --- */
.loading-container {
  padding: 16px;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--tg-secondary-bg) 25%,
    rgba(0, 0, 0, 0.04) 50%,
    var(--tg-secondary-bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-header {
  padding: 8px 0 20px;
}

.skeleton-title {
  height: 24px;
  width: 55%;
  margin-bottom: 10px;
}

.skeleton-subtitle {
  height: 14px;
  width: 35%;
}

.skeleton-card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  padding: 0;
  margin-bottom: var(--feed-gap);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.skeleton-image {
  height: 180px;
  width: 100%;
  border-radius: 0;
}

.skeleton-card .skeleton-line {
  height: 14px;
  width: 90%;
  margin: 14px 16px 0;
}

.skeleton-card .skeleton-line.short {
  width: 60%;
  margin-top: 8px;
}

.skeleton-card .skeleton-button {
  height: 44px;
  margin: 16px;
  border-radius: 10px;
}

/* --- Tenant Header --- */
.tenant-header {
  padding: 16px 16px 8px;
  animation: fadeIn 0.3s ease;
}

.tenant-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--tg-text);
}

.tenant-meta {
  font-size: 13px;
  color: var(--tg-hint);
  margin-top: 2px;
}

/* --- Feed Layout --- */
.feed {
  padding: 8px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: var(--feed-gap);
}

/* --- Card Base --- */
.card {
  background: var(--card-bg);
  border-radius: var(--card-radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
  opacity: 0;
  transform: translateY(12px);
  animation: cardEnter 0.4s ease forwards;
}

.card:active {
  transform: scale(0.985);
  box-shadow: var(--card-shadow-hover);
}

@keyframes cardEnter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Staggered card entrance */
.card:nth-child(1) { animation-delay: 0.00s; }
.card:nth-child(2) { animation-delay: 0.06s; }
.card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.18s; }
.card:nth-child(5) { animation-delay: 0.24s; }
.card:nth-child(6) { animation-delay: 0.30s; }
.card:nth-child(7) { animation-delay: 0.36s; }
.card:nth-child(8) { animation-delay: 0.42s; }
.card:nth-child(9) { animation-delay: 0.48s; }
.card:nth-child(10) { animation-delay: 0.54s; }

/* --- Card Media --- */
.card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--tg-secondary-bg);
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity var(--transition-normal);
}

.card-media img.loading {
  opacity: 0;
}

.card-media img.loaded {
  opacity: 1;
}

.card-media-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-hint);
  font-size: 32px;
}

/* Video overlay */
.card-media .video-indicator {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
}

.video-play-btn {
  width: 56px;
  height: 56px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.video-play-btn::after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent #ffffff;
  margin-left: 3px;
}

/* --- Card Body --- */
.card-body {
  padding: 14px 16px 16px;
}

/* --- Card Badges --- */
.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-deal {
  background: rgba(52, 199, 89, 0.12);
  color: #30b350;
}

.badge-announcement {
  background: rgba(255, 149, 0, 0.12);
  color: #e68a00;
}

.badge-price {
  background: rgba(255, 59, 48, 0.1);
  color: #ff3b30;
}

.badge-hashtag {
  background: rgba(0, 122, 255, 0.08);
  color: var(--tg-link);
  text-transform: none;
  font-weight: 500;
}

/* --- Card Text --- */
.card-text {
  font-size: 15px;
  line-height: 1.45;
  color: var(--tg-text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.card-text.expanded {
  -webkit-line-clamp: unset;
  overflow: visible;
}

/* --- Coupon --- */
.card-coupon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1.5px dashed var(--tg-button);
  border-radius: 10px;
  background: rgba(51, 144, 236, 0.06);
  cursor: pointer;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.card-coupon:active {
  background: rgba(51, 144, 236, 0.14);
}

.coupon-code {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--tg-button);
  letter-spacing: 0.8px;
}

.coupon-hint {
  font-size: 12px;
  color: var(--tg-hint);
}

.coupon-copied {
  color: #34c759;
  font-weight: 600;
}

/* --- CTA Button --- */
.card-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  margin-top: 12px;
  padding: 0 20px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.card-cta:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.card-cta-icon {
  margin-left: 6px;
  font-size: 14px;
}

/* --- Secondary Links --- */
.card-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-link {
  display: flex;
  align-items: center;
  padding: 8px 0;
  font-size: 13px;
  color: var(--tg-link);
  min-height: 36px;
}

.card-link-icon {
  margin-right: 6px;
  font-size: 14px;
  opacity: 0.7;
}

/* --- Card Meta --- */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.card-date {
  font-size: 12px;
  color: var(--tg-hint);
}

.card-hashtags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* --- Announcement Card --- */
.announcement-card {
  border-left: 3px solid #ff9500;
}

.announcement-card .card-body {
  padding: 16px;
}

.announcement-icon {
  font-size: 18px;
  margin-bottom: 6px;
}

.announcement-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--tg-text);
}

/* --- Image Card --- */
.image-card .card-media {
  aspect-ratio: auto;
  max-height: 400px;
}

/* --- Text Card --- */
.text-card .card-body {
  padding: 16px;
}

.text-card .card-text {
  font-size: 15px;
  line-height: 1.55;
  -webkit-line-clamp: 5;
}

/* --- Detail View --- */
.detail-view {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--tg-bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.detail-view .card-media {
  aspect-ratio: auto;
  max-height: 50vh;
}

.detail-view .card-body {
  padding: 16px 20px 32px;
}

.detail-view .card-text {
  -webkit-line-clamp: unset;
  overflow: visible;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* --- Error State --- */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 32px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.error-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--tg-text);
  margin-bottom: 8px;
}

.error-message {
  font-size: 14px;
  color: var(--tg-hint);
  line-height: 1.5;
  max-width: 280px;
}

.error-retry {
  margin-top: 24px;
  padding: 12px 32px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

/* --- Empty State --- */
.empty-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  padding: 32px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--tg-text);
}

.empty-message {
  font-size: 14px;
  color: var(--tg-hint);
  margin-top: 6px;
}

/* --- Preview Banner --- */
.preview-banner {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: linear-gradient(135deg, #ff9500, #ff6b00);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.preview-banner-icon {
  margin-right: 6px;
}

/* --- Preview CTA Footer --- */
.preview-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--tg-bg);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
  animation: slideFromBottom 0.4s ease 0.5s both;
}

@keyframes slideFromBottom {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.preview-cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 20px;
  background: linear-gradient(135deg, #34c759, #28a745);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
}

.preview-cta-btn:active {
  opacity: 0.9;
  transform: scale(0.98);
}

/* --- Pull to Refresh --- */
.pull-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transition: height 0.2s ease;
  color: var(--tg-hint);
  font-size: 13px;
}

.pull-indicator.active {
  height: 40px;
}

.pull-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--tg-secondary-bg);
  border-top-color: var(--tg-button);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
}

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

/* --- Toast / Notification --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Utility Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Scrollbar (for platforms that show them) --- */
::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* --- Dark mode refinements --- */
@media (prefers-color-scheme: dark) {
  :root {
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .card-meta {
    border-top-color: rgba(255, 255, 255, 0.06);
  }

  .detail-close {
    background: rgba(255, 255, 255, 0.2);
  }
}
