/* ============================================================
   CampusMarket — Design System v2
   Tailwind CSS CDN + Google Inter + Custom Components
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --primary:          #6366f1;
  --primary-dark:     #4f46e5;
  --primary-light:    #a5b4fc;
  --primary-50:       #eef2ff;
  --secondary:        #f59e0b;
  --secondary-dark:   #d97706;
  --danger:           #ef4444;
  --success:          #22c55e;
  --warning:          #eab308;
  --text-dark:        #0f172a;
  --text-body:        #334155;
  --text-muted:       #64748b;
  --bg-page:          #f1f5f9;
  --border:           #e2e8f0;
  --border-focus:     #a5b4fc;
  --radius:           0.875rem;
  --radius-sm:        0.5rem;
  --radius-lg:        1.25rem;
  --shadow-xs:        0 1px 3px rgba(0,0,0,.07);
  --shadow:           0 4px 12px -2px rgba(0,0,0,.09), 0 2px 6px -1px rgba(0,0,0,.05);
  --shadow-md:        0 8px 24px -4px rgba(0,0,0,.12), 0 3px 10px -2px rgba(0,0,0,.07);
  --shadow-lg:        0 20px 40px -8px rgba(0,0,0,.14), 0 6px 16px -4px rgba(0,0,0,.08);
  --grad-primary:     linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --grad-hero:        linear-gradient(135deg, #4338ca 0%, #7c3aed 50%, #c026d3 100%);
  --hero-dot-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='6' cy='6' r='2'/%3E%3Ccircle cx='30' cy='6' r='2'/%3E%3Ccircle cx='54' cy='6' r='2'/%3E%3Ccircle cx='6' cy='30' r='2'/%3E%3Ccircle cx='30' cy='30' r='2'/%3E%3Ccircle cx='54' cy='30' r='2'/%3E%3Ccircle cx='6' cy='54' r='2'/%3E%3Ccircle cx='30' cy='54' r='2'/%3E%3Ccircle cx='54' cy='54' r='2'/%3E%3C/g%3E%3C/svg%3E");
  --transition:       all 0.18s cubic-bezier(.4,0,.2,1);
}

/* ── Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Nav ────────────────────────────────────────────────────── */
.nav-link {
  color: #475569;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  transition: var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.nav-link:hover { background: var(--primary-50); color: var(--primary); }
.nav-link.active { background: var(--primary-50); color: var(--primary); font-weight: 600; }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(226,232,240,.6);
  transition: box-shadow 0.22s ease, transform 0.22s ease;
  overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); }

/* ── Listing Card ───────────────────────────────────────────── */
.listing-card .listing-img {
  width: 100%;
  height: 185px;
  object-fit: cover;
  transition: transform 0.38s ease;
  display: block;
}
.listing-card:hover .listing-img { transform: scale(1.06); }
.listing-card .img-wrapper { overflow: hidden; position: relative; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-new  { background: #d1fae5; color: #065f46; }
.badge-good { background: #dbeafe; color: #1e40af; }
.badge-fair { background: #fef3c7; color: #92400e; }
.badge-poor { background: #fee2e2; color: #991b1b; }

/* ── Urgent Badge ───────────────────────────────────────────── */
.badge-urgent {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 2px 8px rgba(239,68,68,.3);
  animation: pulse-urgent 1.4s ease-in-out infinite;
}
@keyframes pulse-urgent {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.82; transform: scale(1.03); }
}

/* ── Bid Countdown ──────────────────────────────────────────── */
.bid-countdown {
  font-family: 'Courier New', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.05em;
}
.bid-countdown.ending-soon { color: var(--danger); animation: blink 0.8s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── Price Tag ──────────────────────────────────────────────── */
.price-tag {
  color: var(--primary);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.5rem 1.25rem;
  border-radius: 0.625rem;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  font-family: inherit;
}
.btn:active { transform: scale(0.97) !important; }

.btn-primary {
  background: var(--grad-primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(99,102,241,.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  box-shadow: 0 6px 18px rgba(99,102,241,.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 3px 10px rgba(245,158,11,.28);
}
.btn-secondary:hover {
  background: linear-gradient(135deg, #d97706, #b45309);
  box-shadow: 0 6px 18px rgba(245,158,11,.38);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: #fff; transform: translateY(-1px); }

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 3px 10px rgba(239,68,68,.28);
}
.btn-danger:hover { background: linear-gradient(135deg, #dc2626, #b91c1c); transform: translateY(-1px); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--primary-50); color: var(--primary); }

.btn-sm  { padding: 0.3rem 0.8rem;  font-size: 0.8rem;  border-radius: 0.5rem; }
.btn-lg  { padding: 0.8rem 2rem;    font-size: 1rem;    border-radius: 0.75rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-dark);
}
.form-control {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 0.625rem;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
  color: var(--text-dark);
  font-family: inherit;
}
.form-control:hover:not(:focus) { border-color: #cbd5e1; }
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(99,102,241,.14);
}
.form-control::placeholder { color: #94a3b8; }
textarea.form-control { resize: vertical; min-height: 100px; }
.form-error {
  font-size: 0.78rem;
  color: var(--danger);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Alert / Flash ──────────────────────────────────────────── */
.alert {
  padding: 0.875rem 1.25rem;
  border-radius: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid transparent;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.alert-error   { background: #fff1f2; color: #9f1239; border-color: #fecdd3; }
.alert-warning { background: #fffbeb; color: #78350f; border-color: #fde68a; }
.alert-info    { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }

/* ── Toast ──────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 0.875rem 1.25rem;
  border-radius: 0.875rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 260px;
  max-width: 380px;
  animation: toastIn 0.3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: all;
  border: 1px solid rgba(255,255,255,.07);
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-info    { border-left: 4px solid var(--primary); }
@keyframes toastIn {
  from { transform: translateX(110%) scale(.9); opacity: 0; }
  to   { transform: translateX(0)   scale(1);   opacity: 1; }
}

/* ── Chat ───────────────────────────────────────────────────── */
.chat-container { height: calc(100vh - 160px); display: flex; overflow: hidden; }
.conversations-panel {
  width: 300px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  background: #fafafa;
}
.chat-window { flex: 1; display: flex; flex-direction: column; background: #fff; }
.messages-area { flex: 1; overflow-y: auto; padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 0.625rem; }
.message-bubble {
  max-width: 72%;
  padding: 0.65rem 0.95rem;
  border-radius: 1.125rem;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}
.message-bubble.sent {
  background: var(--grad-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  box-shadow: 0 2px 8px rgba(99,102,241,.22);
}
.message-bubble.received {
  background: #f1f5f9;
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.message-time { font-size: 0.68rem; opacity: 0.58; margin-top: 3px; }
.chat-input-area {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.625rem;
  align-items: center;
  background: #fafafa;
}
.online-dot {
  width: 9px; height: 9px;
  background: var(--success);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px #fff;
  flex-shrink: 0;
}
.conv-item { padding: 0.875rem 1rem; border-bottom: 1px solid rgba(226,232,240,.7); cursor: pointer; transition: background 0.15s; }
.conv-item:hover, .conv-item.active { background: var(--primary-50); }

/* ── Image Gallery ──────────────────────────────────────────── */
.gallery-main { width: 100%; height: 380px; object-fit: cover; border-radius: var(--radius); display: block; }
.gallery-thumb {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 0.5rem;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}
.gallery-thumb:hover { transform: scale(1.05); }
.gallery-thumb.active { border-color: var(--primary); }
.gallery-thumbs { display: flex; gap: 0.625rem; flex-wrap: wrap; margin-top: 0.75rem; }

/* ── Skeleton Loader ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f8fafc 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 0.5rem;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skeleton-card { height: 290px; }
.skeleton-text { height: 1rem; margin-bottom: 0.5rem; border-radius: 0.25rem; }
.skeleton-text.short { width: 45%; }

/* ── Mobile Bottom Nav ──────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 100;
  justify-content: space-around;
  align-items: center;
}
.mobile-bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 0.625rem;
  transition: var(--transition);
}
.mobile-bottom-nav a.active, .mobile-bottom-nav a:hover { color: var(--primary); }
.mobile-bottom-nav a i { font-size: 1.15rem; }
.mobile-bottom-nav .post-btn {
  background: var(--grad-primary);
  color: #fff;
  border-radius: 50%;
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(99,102,241,.4);
  transition: var(--transition);
}
.mobile-bottom-nav .post-btn:hover { transform: scale(1.1) translateY(-1px); }

/* ── Hero ───────────────────────────────────────────────────── */
.hero-gradient {
  background: var(--grad-hero);
  position: relative;
  overflow: hidden;
}
.hero-gradient::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--hero-dot-pattern) repeat;
  pointer-events: none;
}

/* ── Stats Card ─────────────────────────────────────────────── */
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.375rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(226,232,240,.5);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
  width: 54px; height: 54px;
  border-radius: 0.875rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.stat-icon.indigo { background: linear-gradient(135deg, #eef2ff, #e0e7ff); color: var(--primary); }
.stat-icon.amber  { background: linear-gradient(135deg, #fffbeb, #fef3c7); color: var(--secondary); }
.stat-icon.green  { background: linear-gradient(135deg, #f0fdf4, #dcfce7); color: var(--success); }
.stat-icon.red    { background: linear-gradient(135deg, #fff1f2, #fee2e2); color: var(--danger); }
.stat-icon.blue   { background: linear-gradient(135deg, #eff6ff, #dbeafe); color: #2563eb; }

/* ── Section Headers ────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.section-title::before {
  content: '';
  display: block;
  width: 4px;
  height: 1.25rem;
  background: var(--grad-primary);
  border-radius: 2px;
}

/* ── Price History Chart ────────────────────────────────────── */
.chart-container { position: relative; height: 260px; }

/* ── Notification badge ─────────────────────────────────────── */
.notif-badge {
  position: absolute;
  top: -5px; right: -5px;
  background: var(--danger);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  min-width: 17px; height: 17px;
  border-radius: 9999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  border: 2px solid #fff;
}

/* ── Steps ──────────────────────────────────────────────────── */
.steps { display: flex; gap: 0; margin-bottom: 2rem; }
.step { flex: 1; text-align: center; position: relative; }
.step:not(:last-child)::after {
  content: '';
  position: absolute;
  top: 17px; left: 50%;
  width: 100%; height: 2px;
  background: var(--border);
  z-index: 0;
}
.step.done::after { background: var(--grad-primary); }
.step-circle {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #e2e8f0; color: #94a3b8;
  font-weight: 700; font-size: 0.875rem;
  display: inline-flex; align-items: center; justify-content: center;
  position: relative; z-index: 1;
  transition: all 0.2s;
}
.step.active .step-circle { background: var(--grad-primary); color: #fff; }
.step.done .step-circle { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }

/* ── Utility ────────────────────────────────────────────────── */
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ring-primary { box-shadow: 0 0 0 3px rgba(99,102,241,.22); }
.transition-fast { transition: var(--transition); }

/* ── Tab Styles ─────────────────────────────────────────────── */
.tab-bar { display: flex; gap: 4px; background: #f1f5f9; padding: 4px; border-radius: 0.75rem; }
.tab-btn {
  flex: 1; padding: 0.5rem; text-align: center;
  border-radius: 0.625rem; border: none; background: transparent;
  cursor: pointer; font-size: 0.875rem; font-weight: 500;
  color: var(--text-muted); transition: var(--transition);
  font-family: inherit;
}
.tab-btn.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-xs); font-weight: 600; }
a.tab-btn { text-decoration: none; display: block; }

/* ── Image Edit Grid ────────────────────────────────────────── */
#existing-images-grid .group { transition: transform 0.15s; }
#existing-images-grid .group:hover { transform: scale(1.02); }

/* ── Profile Cover ──────────────────────────────────────────── */
.profile-cover { background: var(--grad-hero); }

/* ── Password Strength ──────────────────────────────────────── */
#strength-bar { transition: width 0.35s ease, background 0.35s ease; }

/* ── Auth Card ──────────────────────────────────────────────── */
.auth-bg {
  background: linear-gradient(135deg, #eef2ff 0%, #faf5ff 50%, #fefce8 100%);
  min-height: 100vh;
}

/* ── Feature Icon Circles ───────────────────────────────────── */
.feature-icon {
  width: 3.5rem; height: 3.5rem;
  border-radius: 1rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  margin: 0 auto 1rem;
  transition: var(--transition);
}
.card:hover .feature-icon { transform: scale(1.1) rotate(-3deg); }

/* ==============================================================
   RESPONSIVE FIXES — Mobile-first
   360px · 640px · 768px · 1024px · 1440px
   ============================================================== */

/* ── Chat back button (desktop: hidden) ─────────────────────── */
.chat-back-btn { display: none; }

/* ── All screens ≤ 768px ────────────────────────────────────── */
@media (max-width: 768px) {
  body { padding-bottom: 60px; }
  .mobile-bottom-nav { display: flex; }

  /* Toast above mobile nav */
  #toast-container { bottom: 76px; right: 1rem; left: 1rem; max-width: 100%; }
  .toast { min-width: 0; max-width: 100%; width: 100%; }

  /* Chat: overlay conversations on mobile */
  .chat-container { position: relative; height: calc(100vh - 130px); }
  .conversations-panel {
    position: absolute; inset: 0; z-index: 10;
    width: 100% !important;
    background: #fafafa;
    overflow-y: auto;
    display: block !important;
  }
  .conversations-panel.chat-open { display: none !important; }
  .chat-back-btn { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
}

/* ── Screens ≤ 640px (phones) ───────────────────────────────── */
@media (max-width: 640px) {
  /* Stat cards: compact */
  .stat-card { padding: 1rem 0.75rem; gap: 0.625rem; }
  .stat-icon { width: 44px; height: 44px; font-size: 1.1rem; border-radius: 0.625rem; }

  /* Gallery shorter on phone */
  .gallery-main { height: 240px; }

  /* Listing card image height */
  .listing-card .listing-img { height: 160px; }

  /* Wider message bubbles */
  .message-bubble { max-width: 88%; }

  /* Large buttons: slightly smaller */
  .btn-lg { padding: 0.65rem 1.25rem; font-size: 0.9375rem; }

  /* Section title smaller */
  .section-title { font-size: 1.05rem; }
}

/* ── Screens ≤ 400px (very small phones) ───────────────────── */
@media (max-width: 400px) {
  /* Stat cards: stack vertically */
  .stat-card {
    flex-direction: column; align-items: center;
    text-align: center; padding: 0.875rem 0.5rem; gap: 0.375rem;
  }
  .stat-icon { width: 40px; height: 40px; font-size: 1rem; }
}
