/* ==============================
   VFM Review Dashboard — Style
   ============================== */

:root {
  /* VFM Brand Colors (Architecture Note 7) */
  --vfm-green: #2d8a4e;
  --vfm-orange: #e67e22;
  --vfm-bg: #f5f5f0;
  --vfm-card-bg: #ffffff;
  --vfm-text: #2c3e50;

  /* Extended palette */
  --green-900: #1a3a2a;
  --green-500: #40916c;
  --green-300: #74c69d;
  --green-100: #d8f3dc;
  --orange-light: #f4a261;
  --gold: #e9c46a;
  --gray-900: #1a1a2e;
  --gray-700: #333;
  --gray-500: #666;
  --gray-300: #bbb;
  --gray-border: #d4d4c8;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.12);
  --card-shadow-hover: 0 4px 16px rgba(0,0,0,0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--vfm-bg);
  color: var(--vfm-text);
  min-height: 100vh;
}

/* ---------- Header ---------- */
header {
  background: var(--vfm-green);
  color: white;
  padding: 18px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--green-300);
  margin-top: 2px;
}

.header-right { display: flex; align-items: center; }

#stats-bar {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--green-100);
}

.stat-item { display: flex; align-items: center; gap: 4px; }
.stat-num { font-weight: 700; font-size: 1rem; }
.stat-pending { color: var(--gold); }
.stat-approved { color: var(--green-300); }
.stat-needs-changes { color: var(--vfm-orange); }

/* ---------- Filter Bar ---------- */
#filter-bar {
  display: flex;
  gap: 4px;
  padding: 12px 28px;
  background: var(--vfm-card-bg);
  border-bottom: 1px solid var(--gray-border);
  overflow-x: auto;
}

.filter-btn {
  padding: 7px 18px;
  border: 1px solid var(--gray-border);
  border-radius: 20px;
  background: var(--vfm-card-bg);
  color: var(--gray-700);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-btn:hover { border-color: var(--green-500); color: var(--green-500); }
.filter-btn.active {
  background: var(--vfm-green);
  color: white;
  border-color: var(--vfm-green);
}

/* ---------- Post Grid ---------- */
#post-grid {
  padding: 24px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

#post-grid.grid-loading { display: block; }
#post-grid.grid-empty {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
  color: var(--gray-500);
  font-size: 1.1rem;
}

/* ---------- Skeleton ---------- */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.skeleton-card {
  height: 280px;
  background: linear-gradient(90deg, var(--gray-border) 25%, var(--vfm-bg) 50%, var(--gray-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

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

/* ---------- Post Card ---------- */
.post-card {
  background: var(--vfm-card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.post-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--card-shadow-hover);
}

.post-card-thumb {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
  background: var(--gray-border);
}

.post-card-body {
  padding: 12px 14px 14px;
}

.post-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--gray-500);
}

/* ---------- Status Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-pending_review { background: #fff8e1; color: #f57f17; }
.badge-approved { background: #e8f5e9; color: #2e7d32; }
.badge-needs_changes { background: #fbe9e7; color: #c62828; }

/* ---------- Modal ---------- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.2s;
}

#modal-overlay.modal-hidden {
  display: none;
  opacity: 0;
}

#modal {
  background: var(--vfm-card-bg);
  border-radius: 14px;
  width: 90%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

#modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--gray-500);
  z-index: 10;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}

#modal-close:hover { background: var(--vfm-bg); color: var(--vfm-text); }

#modal-body {
  padding: 24px;
}

/* ---------- Modal Header ---------- */
.modal-header {
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.modal-header .modal-meta {
  font-size: 0.85rem;
  color: var(--gray-500);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

/* ---------- Carousel ---------- */
.carousel {
  position: relative;
  margin: 16px 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.carousel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.85);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.carousel-btn:hover { background: white; }
.carousel-btn:disabled { display: none; }
.carousel-prev { left: 10px; }
.carousel-next { right: 10px; }

.carousel-counter {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 0.8rem;
}

/* ---------- Review Actions ---------- */
.review-actions {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.review-btn {
  padding: 9px 22px;
  border: 2px solid;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.btn-approve {
  border-color: var(--green-500);
  color: var(--vfm-green);
  background: var(--vfm-card-bg);
}
.btn-approve:hover:not(:disabled) {
  background: var(--green-500);
  color: white;
}

.btn-reject {
  border-color: var(--vfm-orange);
  color: var(--vfm-orange);
  background: var(--vfm-card-bg);
}
.btn-reject:hover:not(:disabled) {
  background: var(--vfm-orange);
  color: white;
}

.btn-reset {
  border-color: var(--gray-300);
  color: var(--gray-500);
  background: var(--vfm-card-bg);
}
.btn-reset:hover:not(:disabled) {
  background: var(--vfm-bg);
}

.review-status-text {
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ---------- Load Error Banner ---------- */
.load-error-banner {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-700);
}
.load-error-banner p { margin-bottom: 8px; font-size: 1.1rem; }
.load-error-banner .load-error-detail { font-size: 0.85rem; color: var(--gray-500); }
.retry-btn {
  margin-top: 16px;
  padding: 10px 28px;
  background: var(--vfm-green);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}
.retry-btn:hover { background: var(--green-500); }

/* ---------- Refresh & Reset ---------- */
#refresh-btn {
  margin-left: auto;
  padding: 7px 16px;
  border: 1px solid var(--gray-border);
  border-radius: 20px;
  background: var(--vfm-card-bg);
  color: var(--vfm-green);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
#refresh-btn:hover { border-color: var(--green-500); background: var(--green-100); }
.filter-reset {
  color: var(--gray-500) !important;
  border-color: transparent !important;
  font-size: 0.8rem !important;
}
.filter-reset:hover { color: var(--vfm-green) !important; }

/* ---------- Fallback Thumb ---------- */
.fallback-thumb {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: var(--gray-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-300);
  font-size: 2rem;
}

/* ---------- Carousel Fallback ---------- */
.carousel-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Review Comment Section ---------- */
.review-comment-section {
  margin: 12px 0;
}
.review-comment-section label {
  display: block;
  font-size: 0.82rem;
  color: var(--gray-500);
  margin-bottom: 4px;
}
#review-comment-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  resize: vertical;
  transition: border-color 0.15s;
}
#review-comment-input:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 2px rgba(45, 138, 78, 0.15);
}

/* ---------- Review Error ---------- */
.review-error {
  padding: 8px 12px;
  margin: 8px 0;
  background: #fbe9e7;
  color: #c62828;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.review-error.hidden { display: none; }

/* ---------- Review Comment Display ---------- */
.review-comment-display {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--vfm-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--gray-700);
}

/* ========================================
   Mobile-Responsive Overrides
   ========================================
   These make the review dashboard usable
   on a phone — tested down to 320px width.
   ======================================== */

@media (max-width: 640px) {

  /* Header — stack vertically, reduce padding */
  header {
    padding: 12px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  header h1 {
    font-size: 1.15rem;
  }

  .subtitle {
    font-size: 0.75rem;
  }

  .header-right {
    width: 100%;
  }

  #stats-bar {
    flex-wrap: wrap;
    gap: 8px 14px;
    font-size: 0.72rem;
  }

  /* Filter bar — tighter */
  #filter-bar {
    padding: 8px 10px;
    gap: 3px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .filter-btn {
    padding: 6px 12px;
    font-size: 0.78rem;
    min-height: 36px;
  }

  /* Post grid — single column on small phones */
  #post-grid {
    padding: 12px 10px;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .skeleton-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .skeleton-card {
    height: 220px;
  }

  /* Post cards */
  .post-card-body {
    padding: 8px 10px 10px;
  }

  .post-card-title {
    font-size: 0.85rem;
    -webkit-line-clamp: 2;
  }

  .post-card-meta {
    font-size: 0.7rem;
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Modal — full-width on mobile */
  #modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
  }

  #modal-body {
    padding: 16px;
  }

  #modal-close {
    top: 8px;
    right: 8px;
    font-size: 1.8rem;
    padding: 8px 12px;
  }

  .modal-header h2 {
    font-size: 1.1rem;
  }

  .modal-header .modal-meta {
    font-size: 0.78rem;
    gap: 10px;
  }

  /* Carousel — full width on mobile */
  .carousel {
    aspect-ratio: 9 / 16;
    margin: 12px 0;
    border-radius: var(--radius-sm);
  }

  .carousel-btn {
    width: 44px;
    height: 44px;
    font-size: 1.3rem;
  }

  .carousel-prev { left: 6px; }
  .carousel-next { right: 6px; }

  .carousel-counter {
    bottom: 6px;
    padding: 3px 12px;
    font-size: 0.72rem;
  }

  /* Review actions — full-width buttons on mobile */
  .review-actions {
    flex-direction: column;
    gap: 8px;
  }

  .review-btn {
    width: 100%;
    justify-content: center;
    padding: 12px 22px;
    font-size: 0.95rem;
    min-height: 44px;
  }

  /* Comment input */
  #review-comment-input {
    font-size: 16px; /* prevent iOS zoom on focus */
    padding: 10px 12px;
  }

  /* Toast container */
  #toast-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }

  .toast {
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  /* Refresh button */
  #refresh-btn {
    padding: 6px 12px;
    font-size: 0.78rem;
    min-height: 36px;
  }

  /* Load error banner */
  .load-error-banner {
    padding: 40px 14px;
  }

  .load-error-banner p {
    font-size: 1rem;
  }

  .retry-btn {
    padding: 12px 28px;
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  /* Very narrow phones */
  #post-grid {
    grid-template-columns: 1fr;
    padding: 8px 8px;
  }

  .skeleton-grid {
    grid-template-columns: 1fr;
  }

  header h1 {
    font-size: 1rem;
  }

  #stats-bar {
    gap: 4px 8px;
    font-size: 0.68rem;
  }

  .filter-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
  }
}

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toast-in 0.3s ease;
  max-width: 360px;
}

.toast-success { background: var(--vfm-green); color: white; }
.toast-error { background: #c62828; color: white; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-dismiss {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  header { flex-direction: column; align-items: flex-start; }
  #stats-bar { flex-wrap: wrap; gap: 8px; }
  #post-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); padding: 16px; gap: 12px; }
  #filter-bar { padding: 10px 16px; }
  #modal { width: 95%; max-height: 95vh; }
  #modal-body { padding: 16px; }
}

@media (max-width: 480px) {
  #post-grid { grid-template-columns: 1fr 1fr; padding: 12px; gap: 10px; }
  .review-actions { flex-direction: column; }
}
