/* Shared base styles for Xchange */
:root {
  --primary: #4a6fa5;
  --secondary: #6b8cbc;
  --accent: #ff7e5f;
  --light: #f8f9fa;
  --dark: #343a40;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f5f7fa; color: #222; line-height: 1.6; }

/* Visually hidden class for screen readers only */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Make header container slightly wider so user buttons fit side-by-side */
@media (min-width: 1024px) {
  header .container { max-width: 1400px; }
}

/* Header */
header { background-color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.1); position: sticky; top: 0; z-index: 100; }
.header-content { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; min-height: 70px; }
.logo { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: bold; color: var(--primary); text-decoration: none; }
.logo svg { display: block; }
.logo i { color: var(--accent); }
nav ul { display: flex; list-style: none; gap: 20px; margin: 0; padding: 0; }
nav a { text-decoration: none; color: var(--dark); font-weight: 500; transition: color 0.3s; }
nav a:hover, nav a.active { color: var(--primary); }

/* Preserve space for authed-only nav items even when hidden, so header height/positions don't shift */
.nav-authed.hide-preserve { visibility: hidden; pointer-events: none; }

/* Auth/User buttons container - always reserve space, toggle visibility instead of display */
.auth-buttons,
.user-buttons { 
  display: flex !important; /* Always use flex layout */
  align-items: center; 
  gap: 12px;
  min-width: 200px; /* Reserve minimum space to prevent shifting */
  justify-content: flex-end;
}

/* Default state (before JavaScript runs): hide both to prevent flash */
.auth-buttons { 
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.user-buttons { 
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* When signed OUT - show auth buttons, hide user buttons */
html.auth-signed-out .auth-buttons {
  visibility: visible !important;
  opacity: 1 !important;
  position: relative !important;
  pointer-events: auto !important;
}
html.auth-signed-out .user-buttons {
  visibility: hidden !important;
  opacity: 0 !important;
  position: absolute !important;
  pointer-events: none !important;
}

/* When signed IN - hide auth buttons, show user buttons */
html.auth-signed-in .auth-buttons {
  visibility: hidden !important;
  opacity: 0 !important;
  position: absolute !important;
  pointer-events: none !important;
}
html.auth-signed-in .user-buttons {
  visibility: visible !important;
  opacity: 1 !important;
  position: relative !important;
  pointer-events: auto !important;
}

/* Legacy class support for JavaScript toggles */
.auth-buttons.hidden { 
  visibility: hidden;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}
.user-buttons.show { 
  visibility: visible !important;
  opacity: 1 !important;
  position: relative !important;
  pointer-events: auto !important;
}

.user-name { font-weight: 600; color: var(--dark); cursor: pointer; }
.user-menu { position: relative; }
.user-name-btn { background: transparent; border: none; display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; color: var(--dark); padding: 6px 8px; border-radius: 4px; }
.user-name-btn:hover { background: #f0f2f6; }
.dropdown-menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 10px 24px rgba(0,0,0,0.12); padding: 6px; display: none; min-width: 200px; z-index: 200; }
.dropdown-menu.open { display: block; }
.dropdown-menu button { width: 100%; text-align: left; padding: 8px 10px; background: transparent; border: none; cursor: pointer; border-radius: 6px; color: #222; }
.dropdown-menu button:hover { background: #f5f7fa; }
/* Add spacing between icon and text on logout */
#logoutBtn i { margin-right: 6px; }
.user-summary { display: flex; align-items: center; gap: 8px; font-size: 13px; background: #f3f4f6; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.user-summary strong { color: var(--primary); }

/* Dropup variant for bottom-docked menu */
.dropdown-menu.dropup { top: auto; bottom: calc(100% + 6px); }

/* Floating utility dock for Notifications + Account */
.utility-dock { position: fixed; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 10px; z-index: 1000; }
.utility-dock .btn { box-shadow: 0 6px 16px rgba(0,0,0,0.12); }
.utility-dock .user-menu { position: relative; }

@media (max-width: 480px) {
  .utility-dock { right: 12px; bottom: 12px; gap: 8px; }
}

/* Buttons */
.btn { padding: 8px 16px; border-radius: 4px; border: none; cursor: pointer; font-weight: 500; transition: all 0.3s; text-decoration: none; display: inline-block; }
.btn.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-primary { background-color: var(--primary); color: #fff; }
.btn-primary:hover { background-color: var(--secondary); }
.btn-outline { background-color: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background-color: var(--primary); color: #fff; }
.btn-accent { background-color: var(--accent); color: #fff; }
.btn-accent:hover { opacity: 0.9; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* General page structure */
.section { padding: 60px 0; }
.section-title { text-align: center; margin-bottom: 40px; font-size: 2rem; color: var(--primary); }

/* Item selection grids (used on multiple pages) */
.items-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; max-height: 260px; overflow-y: auto; }
.item-card { border: 1px dashed #ddd; border-radius: 8px; padding: 15px; text-align: center; cursor: pointer; transition: all 0.3s; min-height: 120px; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.item-card:hover { border-color: var(--primary); background-color: #f8f9fa; }
.item-card.selected { border-color: var(--accent); background-color: rgba(255, 126, 95, 0.1); }
.item-icon { font-size: 24px; margin-bottom: 10px; color: var(--primary); }
.category-selector { margin-top: 20px; }
.category-selector select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; }

/* Footer */
footer { background-color: var(--dark); color: #fff; padding: 40px 0; margin-top: 60px; }
.footer-content { display: grid; grid-template-columns: repeat(4, 1fr); gap: 30px; }
.footer-column h3 { margin-bottom: 20px; color: var(--light); }
.footer-column ul { list-style: none; margin: 0; padding: 0; }
.footer-column ul li { margin-bottom: 10px; }
.footer-column a { color: #ccc; text-decoration: none; transition: color 0.3s; }
.footer-column a:hover { color: #fff; }
.copy { text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #444; color: #ccc; }

/* Modal (shared across pages) */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal .modal-content { background-color: #fff; border-radius: 8px; padding: 30px; max-width: 500px; width: 90%; max-height: 90vh; overflow-y: auto; }
.modal .modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.close-modal { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--dark); }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; }
.form-control { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; }
.otp-inputs { display: flex; gap: 10px; justify-content: center; margin: 20px 0; }
.otp-input { width: 40px; height: 40px; text-align: center; font-size: 18px; border: 1px solid #ddd; border-radius: 4px; }

/* Responsive */
@media (max-width: 768px) {
  .footer-content { grid-template-columns: repeat(2, 1fr); }
  .header-content { flex-direction: column; gap: 15px; }
  nav ul { flex-wrap: wrap; justify-content: center; }
  /* Hide 'Sign Out' label on small screens; show only the icon */
  #logoutBtn .logout-text { display: none; }
  #logoutBtn i { margin-right: 0; }
  .items-grid { grid-template-columns: 1fr; }
}

/* Styles from trade.html */
.page-header { padding: 30px 0; text-align: center; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; }
.trade-wrap { margin: 20px auto; padding: 0 20px; }
.trade-card { display: grid; grid-template-columns: 300px 1fr; gap: 16px; background:#fff; border-radius:8px; box-shadow:0 3px 10px rgba(0,0,0,0.06); padding: 16px; }
.trade-card img { width: 100%; height: auto; border-radius:6px; object-fit: cover; }
.badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:12px; background:#eee; color:#333; }
.offers { margin-top: 24px; }
.offer { background: #fff; border-radius:8px; padding: 12px; box-shadow:0 2px 8px rgba(0,0,0,0.05); }
.offer + .offer { margin-top: 10px; }
.offer .meta { color:#666; font-size:12px; }
.offer .actions { margin-top:8px; display:flex; gap:8px; }
.muted { color:#666; }
.comment-form textarea { width: 100%; min-height: 80px; padding: 10px; border: 1px solid #ddd; border-radius: 4px; }

/* Error/Success Notification Toast */
.notification-toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  min-width: 300px;
  max-width: 500px;
  padding: 16px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10000;
  animation: slideInLeft 0.3s ease-out;
  font-size: 14px;
  line-height: 1.5;
}

.notification-toast.error {
  background-color: #fee;
  border-left: 4px solid #d32f2f;
  color: #a00;
}

.notification-toast.success {
  background-color: #e6ffed;
  border-left: 4px solid #137333;
  color: #0a5d1e;
}

.notification-toast.warning {
  background-color: #fff4e5;
  border-left: 4px solid #f57c00;
  color: #c65100;
}

.notification-toast.info {
  background-color: #e3f2fd;
  border-left: 4px solid #1976d2;
  color: #0d47a1;
}

.notification-toast .icon {
  font-size: 20px;
  flex-shrink: 0;
}

.notification-toast .message {
  flex: 1;
  word-wrap: break-word;
}

.notification-toast .close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  padding: 0;
  margin-left: 8px;
  flex-shrink: 0;
}

.notification-toast .close-btn:hover {
  opacity: 1;
}

@keyframes slideInLeft {
  from {
    transform: translateX(-400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOutLeft {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(-400px);
    opacity: 0;
  }
}

.notification-toast.hiding {
  animation: slideOutLeft 0.3s ease-in forwards;
}

@media (max-width: 768px) {
  .notification-toast {
    bottom: 10px;
    left: 10px;
    right: auto;
    min-width: auto;
    max-width: calc(100vw - 20px);
  }
}

/* Utility classes to replace inline styles */
.text-center { text-align: center; }
.flex-center { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; }
.flex-row { display: flex; align-items: center; }
.flex-nowrap { flex-wrap: nowrap; white-space: nowrap; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.ml-8 { margin-left: 8px; }
.text-no-decoration { text-decoration: none; }
.hidden { display: none; }
.hidden-space { display: none; height: 8px; }

/* Form help text */
.form-text { display: block; margin-top: 4px; color: #666; font-size: 0.875rem; }

/* User buttons in header - hidden by default, shown when logged in */
.user-buttons { display: none; }
.user-buttons.show { display: flex !important; align-items: center; gap: 8px; flex-wrap: nowrap; white-space: nowrap; }

/* User summary display */
.user-summary { display: flex; align-items: center; gap: 10px; color: var(--dark); }

/* Logout button */
#logoutBtn { display: flex; align-items: center; gap: 6px; }

/* OTP Section - hidden by default */
#otpSection { display: none; }
#otpSection.show { display: block !important; }

/* Trade card hidden by default */
#tradeCard { display: none; }
#tradeCard.show { display: grid !important; }

/* Utility Dock buttons */
.utility-dock .btn { display: flex; align-items: center; gap: 6px; }

/* User menu toggle */
#userMenuToggle { display: flex; align-items: center; gap: 6px; }
#userMenuToggle i.fa-chevron-up { font-size: 12px; color: #666; }

/* Notification badge */
#notifBadge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 6px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 12px; text-align: center; }

/* User menu dropdown */
#userMenu { display: none; }
#userMenu.open { display: block !important; }

/* Badge styles for trade status */
.badge-closed { background: #fee; color: #900; margin-top: 8px; }
.badge-accepted { background: #e6ffed; color: #137333; }
.badge-rejected { background: #ffe6e6; color: #a00; }
.badge-you { background: #eef; color: #225; }

/* Offer message */
.offer-message { margin-top: 6px; white-space: pre-wrap; }

/* Trade row link */
.trade-row { text-decoration: none; color: inherit; }

/* Trade details heading */
.trade-details-heading { margin: 8px 0 6px; }
