/* Frontier Marketplace Custom Styles */

:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --light-bg: #f9fafb;
  --border-color: #e5e7eb;
  --sidebar-bg: #0b2a5e;
  --sidebar-bg-hover: rgba(255, 255, 255, 0.08);
  --sidebar-bg-active: rgba(255, 255, 255, 0.14);
  --sidebar-text: rgba(255, 255, 255, 0.72);
  --sidebar-text-active: #ffffff;
  --sidebar-border: rgba(255, 255, 255, 0.12);
  --sidebar-accent: #60a5fa;
}

* {
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  color: #1f2937;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

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

.animate-fade-in {
  animation: fadeIn 0.3s ease-in-out;
}

.animate-slide-in {
  animation: slideIn 0.3s ease-in-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: #6b7280;
  color: white;
}

.btn-secondary:hover {
  background-color: #4b5563;
}

.btn-danger {
  background-color: var(--error-color);
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover {
  background-color: #059669;
}

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

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #374151;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.3s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
}

.form-error {
  color: var(--error-color);
  font-size: 0.875rem;
  margin-top: 4px;
}

.form-help {
  color: #6b7280;
  font-size: 0.875rem;
  margin-top: 4px;
}

/* Cards */
.card {
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.card-header {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 12px;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
}

.card-body {
  color: #6b7280;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
}

.badge-primary {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-success {
  background-color: #dcfce7;
  color: #166534;
}

.badge-error {
  background-color: #fee2e2;
  color: #991b1b;
}

.badge-warning {
  background-color: #fef3c7;
  color: #b45309;
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.alert-info {
  background-color: #dbeafe;
  border-left: 4px solid #3b82f6;
  color: #1e40af;
}

.alert-success {
  background-color: #dcfce7;
  border-left: 4px solid #10b981;
  color: #166534;
}

.alert-error {
  background-color: #fee2e2;
  border-left: 4px solid #ef4444;
  color: #991b1b;
}

.alert-warning {
  background-color: #fef3c7;
  border-left: 4px solid #f59e0b;
  color: #b45309;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead {
  background-color: var(--light-bg);
  border-bottom: 2px solid var(--border-color);
}

.table th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: #374151;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover {
  background-color: #f3f4f6;
}

/* Listings */
.listing-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.listing-image {
  width: 100%;
  height: 200px;
  background-color: #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.listing-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.listing-price {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.listing-species {
  font-size: 0.875rem;
  color: #6b7280;
}

/* Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.875rem;
  color: #6b7280;
}

/* Responsive */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .card {
    padding: 16px;
  }

  .table {
    font-size: 0.875rem;
  }

  .table th,
  .table td {
    padding: 8px;
  }
}

/* ==========================================================================
   Brand mark
   ========================================================================== */
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 15%;
  transform: scale(1.35);
}

.brand-mark-lg {
  width: 96px;
  height: 96px;
  border-radius: 20px;
}

/* Header brand mark: the full logo (cow + lettering), uncropped, standing
   in for a text wordmark now that headers carry the logo alone. */
.brand-mark-full {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.brand-mark-full img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ==========================================================================
   Pictorial species icons / badges
   ========================================================================== */
.species-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 9999px;
  background: #eff6ff;
  color: var(--primary-color);
}

.species-icon svg {
  width: 55%;
  height: 55%;
}

.species-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 9999px;
  background: #eff6ff;
  color: #1e40af;
  font-size: 0.8rem;
  font-weight: 600;
}

.species-chip .species-icon {
  width: 22px;
  height: 22px;
  background: white;
}

/* Selectable species picker (marketplace filters): neutral until chosen */
#species-picker .species-chip {
  background: #f3f4f6;
  color: #374151;
  border: 1.5px solid transparent;
  cursor: pointer;
}

#species-picker .species-chip.active {
  background: #eff6ff;
  color: #1e40af;
  border-color: var(--primary-color);
}

/* Small inline icon used next to listing card text (e.g. location) */
.meta-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: #9ca3af;
}

.meta-icon svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   Listing image gallery: a single frame with prev/next controls instead of
   a thumbnail strip, so all listing photos share one consistent viewport.
   ========================================================================== */
.gallery-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #d1d5db;
  overflow: hidden;
}

.gallery-frame img,
.gallery-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  color: #1f2937;
}

.gallery-nav svg {
  width: 18px;
  height: 18px;
}

.gallery-nav:hover {
  background: #fff;
}

.gallery-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

.gallery-nav-prev {
  left: 10px;
}

.gallery-nav-next {
  right: 10px;
}

.gallery-dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.gallery-dot {
  width: 7px;
  height: 7px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.6);
  border: none;
  padding: 0;
  cursor: pointer;
}

.gallery-dot.active {
  background: #fff;
  width: 18px;
}

.gallery-favorite {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  color: #374151;
}

.gallery-favorite svg {
  width: 20px;
  height: 20px;
}

.gallery-favorite.active {
  color: #ef4444;
}

.gallery-favorite.active svg {
  fill: #ef4444;
}

/* ==========================================================================
   Seller "My Listings" cards: a top-right kebab menu with Edit/Delete
   ========================================================================== */
.listing-menu-toggle svg {
  width: 18px;
  height: 18px;
}

/* Chat conversation header: back-to-list arrow on phone screens */
#close-chat svg {
  width: 20px;
  height: 20px;
}

/* Profile page: pencil icon that reveals the edit form */
#edit-profile-btn svg {
  width: 18px;
  height: 18px;
}

/* Hero banner: auto-transitioning photo slideshow behind a fixed gradient */
.hero-photo {
  position: relative;
  background-color: #0b2a5e;
  isolation: isolate;
}

.hero-photo > .hero-slides {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}

.hero-slide {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 1.5s ease-in-out;
}

.hero-slide.active {
  opacity: 1;
}

.hero-photo::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    115deg,
    rgba(11, 42, 94, 0.92) 0%,
    rgba(30, 64, 152, 0.82) 45%,
    rgba(30, 64, 152, 0.55) 100%
  );
  z-index: 0;
}

.hero-photo > * {
  position: relative;
  z-index: 1;
}

/* Stat / dashboard widget cards */
.stat-tile {
  display: flex;
  align-items: center;
  gap: 14px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 18px;
}

.stat-tile-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-tile-icon svg {
  width: 24px;
  height: 24px;
}

/* ==========================================================================
   Mobile app bottom navigation
   ========================================================================== */
.app-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--border-color);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
}

.app-bottom-nav a,
.app-bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 500;
  color: #6b7280;
  background: transparent;
  border: none;
  cursor: pointer;
}

.app-bottom-nav svg {
  width: 22px;
  height: 22px;
}

.app-bottom-nav .active {
  color: var(--primary-color);
}

@media (min-width: 1024px) {
  .app-bottom-nav {
    display: none;
  }
}

@media (max-width: 1023px) {
  body:has(.app-bottom-nav) {
    padding-bottom: 74px;
  }
}

/* ==========================================================================
   Desktop dashboard sidebar shell (authenticated app pages)
   ========================================================================== */
.app-sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 250px;
    background: var(--sidebar-bg);
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    z-index: 40;
    overflow-y: auto;
  }

  /* !important: overrides Tailwind's .mx-auto margin-left:auto utility,
     which the CDN build injects after this stylesheet regardless of
     source order, on the same element. */
  .app-content-shifted {
    margin-left: 250px !important;
  }

  body:has(.app-sidebar) .tab-frame-host {
    margin-left: 250px !important;
  }

  /* The sidebar already carries the brand mark and (in its footer) a
     logout control, so the top bar - otherwise just a duplicate logo
     plus a mobile-only logout button - is redundant chrome on desktop.
     Without this, its full-width sticky bar (z-index 50) painted over
     the sidebar's own brand block (z-index 40) at the same top-left
     corner, showing two overlapping logos. */
  body:has(.app-sidebar) #page-topnav {
    display: none;
  }

  body:has(.app-sidebar) .tab-frame {
    height: 100vh;
  }
}

/* ==========================================================================
   Seamless bottom-tab switching: each tab a page loads into is kept alive
   in its own hidden same-origin iframe (see setupTabRouter() in
   app-shell.js) instead of a real navigation, so the header/bottom-nav
   never unmount and switching tabs is instant on repeat visits. The page
   you land on directly is shown as #tab-self-content; every other tab you
   visit gets its own iframe here.
   ========================================================================== */
.tab-frame-host {
  position: relative;
}

.tab-frame {
  display: none;
  width: 100%;
  height: calc(100vh - 64px);
  border: 0;
}

.tab-frame.active {
  display: block;
}

@media (max-width: 1023px) {
  .tab-frame {
    height: calc(100vh - 64px - 74px);
  }
}

/* A page loaded inside another page's tab-frame iframe suppresses its own
   header/bottom-nav/sidebar so only the outer shell's chrome shows. */
html.embedded-tab #page-topnav,
html.embedded-tab #app-bottom-nav,
html.embedded-tab #app-sidebar {
  display: none !important;
}

html.embedded-tab .app-content-shifted {
  margin-left: 0 !important;
}

html.embedded-tab body {
  padding-bottom: 0 !important;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.app-sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.app-sidebar-nav a,
.app-sidebar-nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.925rem;
  text-align: left;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  cursor: pointer;
}

.app-sidebar-nav a svg,
.app-sidebar-nav button svg,
.app-sidebar-footer button svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.app-sidebar-nav a:hover,
.app-sidebar-nav button:hover {
  background: var(--sidebar-bg-hover);
  color: var(--sidebar-text-active);
}

.app-sidebar-nav a.active {
  background: var(--sidebar-bg-active);
  color: var(--sidebar-text-active);
  border-left-color: var(--sidebar-accent);
}

.app-sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
}

.app-sidebar-footer button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #fca5a5;
  font-weight: 500;
  background: rgba(239, 68, 68, 0.14);
  border: none;
  cursor: pointer;
}

.app-sidebar-footer button:hover {
  background: rgba(239, 68, 68, 0.22);
  color: #fecaca;
}

/* Utility Classes */
.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.mt-4 {
  margin-top: 16px;
}

.mb-4 {
  margin-bottom: 16px;
}

.gap-4 {
  gap: 16px;
}

.cursor-pointer {
  cursor: pointer;
}

.opacity-50 {
  opacity: 0.5;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
