/* Enhanced Offers Styling for Finansguiden.se - UC Card Parity */

/* CSS Isolation - Minimal reset for offers */
.offers-container,
.offers-container * {
  box-sizing: border-box;
}

/* Essential text protection only where needed */
.offers-container .badge {
  writing-mode: horizontal-tb !important;
  text-orientation: mixed !important;
}

/* Match UC card container and grid layout */
.offers-container {
  max-width: 84rem; /* max-w-7xl to match UC cards */
  margin: 0 auto;
  padding: 0 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  color: #0f172a; /* Match UC cards dark text */
  
  /* Force light theme variables locally - override dark mode */
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 222.2 84% 4.9%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --accent: 210 40% 96.1%;
  --accent-foreground: 222.2 47.4% 11.2%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
}

.lender-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 2rem 0;
}

@media (min-width: 640px) {
  .lender-grid {
    gap: 1.5rem;
  }
}

@media (min-width: 768px) {
  .lender-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
  }
}

@media (min-width: 1280px) {
  .lender-grid {
    grid-template-columns: repeat(2, minmax(360px, 1fr)); /* Keep 2 columns if cards >= 360px */
    gap: 2rem;
  }
}

/* Match UC card styling exactly */
.lender-card {
  background: white;
  border-radius: 0.75rem; /* rounded-xl to match UC */
  border: 1px solid #e5e7eb; /* border-gray-200 */
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-sm */
  color: #111827; /* text-gray-900 */
  transition: all 0.15s ease-in-out;
  padding: 1.5rem; /* p-6 */
  
  /* Enable container queries for responsive features */
  container-type: inline-size;
  container-name: offer-card;
  
  /* Mobile: stack layout */
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Desktop: grid layout (logo | content | CTA) */
@media (min-width: 768px) {
  .lender-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 1.5rem;
    align-items: start;
  }
}

.lender-card:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); /* shadow-md */
  transform: translateY(-1px); /* subtle lift */
}

/* Match UC featured card styling - subtle ring instead of heavy styling */
.lender-card.featured {
  box-shadow: 0 0 0 1px #a7f3d0, 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* subtle emerald ring + normal shadow */
  background: white;
}

/* Logo column - proper sizing without clipping */
.lender-logo {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  
  /* Mobile: flexible sizing */
  max-height: 36px;
  max-width: 100px;
}

@media (min-width: 768px) {
  .lender-logo {
    max-height: 40px;
    max-width: 120px;
  }
}

.lender-logo img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
  width: auto;
  height: auto;
  
  /* Remove any dark theme filters that may invert logos */
  filter: none !important;
  mix-blend-mode: normal !important;
}

/* Fallback text for missing logos - truncate with ellipsis */
.lender-logo:not(:has(img)) {
  font-size: 0.875rem;
  font-weight: 600;  
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}

/* Content column - expandable with min-width for text wrapping */
.lender-info {
  min-width: 0; /* Critical: allows text to wrap properly */
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Prevent min-content collapse on feature items */
.lender-features > * {
  min-width: 0;
  max-width: none;
}

.lender-info h3 {
  font-size: 1.125rem; /* text-lg */
  font-weight: 600;
  color: #111827;
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

/* Features grid - use container queries instead of viewport breakpoints */
.lender-features {
  display: grid;
  grid-template-columns: 1fr; /* Default: single column */
  gap: 0.5rem;
  min-width: 0; /* Allow text to wrap properly */
}

/* Container query: 2 columns only when card is definitely wide enough */
@container offer-card (min-width: 680px) {
  .lender-features {
    grid-template-columns: repeat(2, minmax(240px, 1fr)); /* Never below 240px per column */
    gap: 0.75rem;
  }
}

/* Fallback for browsers without container query support */
@supports not (container-type: inline-size) {
  @media (min-width: 1024px) {
    .lender-features {
      grid-template-columns: repeat(2, minmax(240px, 1fr)); /* Never below 240px per column */
      gap: 0.75rem;
    }
  }
  
  /* Single column for smaller screens */
  @media (max-width: 1023px) {
    .lender-features {
      grid-template-columns: 1fr;
    }
  }
}

/* iPad Safari JavaScript fallback classes - HIGH SPECIFICITY */
.lender-card.cq-narrow .lender-features {
  grid-template-columns: 1fr !important;
  gap: 0.5rem !important;
}

.lender-card.cq-wide .lender-features {
  grid-template-columns: repeat(2, minmax(240px, 1fr)) !important;
  gap: 0.75rem !important;
}

/* Debug classes for visual feedback */
.lender-card.cq-narrow .lender-features {
  /* outline: 2px solid red; */
}

.lender-card.cq-wide .lender-features {
  /* outline: 2px solid green; */
}

/* Match UC card feature styling with proper typography and dividers */
.lender-feature {
  font-size: 0.875rem; /* text-sm */
  line-height: 1.5; /* leading-6 */
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid #f3f4f6; /* subtle divider like UC */
  min-width: 0; /* Critical: Allow text to wrap */
  max-width: none; /* Prevent min-content collapse */
  white-space: normal; /* Normal text flow */
  word-break: normal; /* Prevent character-by-character breaking */
  overflow-wrap: anywhere; /* Break long words naturally */
  hyphens: auto; /* Allow hyphenation for long words */
}

.lender-feature:last-child {
  border-bottom: none;
}

.lender-feature strong {
  color: #111827; /* text-gray-900 */
  font-weight: 600; /* semibold */
  min-width: fit-content;
  flex-shrink: 0;
}

.lender-feature span {
  color: #374151; /* text-gray-700 */
  font-weight: 400; /* normal */
}

/* CTA column - auto width with proper alignment and no text wrapping */
.lender-cta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  white-space: nowrap; /* Prevent button text from wrapping */
  flex-shrink: 0; /* Don't let CTA shrink */
}

@media (min-width: 768px) {
  .lender-cta {
    justify-self: end;
    align-self: end; /* Align to bottom of card */
    text-align: right;
  }
}

/* Rating display - match UC cards positioning */
.lender-rating {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: #6b7280; /* text-gray-500 */
}

@media (min-width: 768px) { 
  .lender-rating {
    justify-self: end; /* Right-align rating on desktop */
  }
}

/* Stars styling for ratings */
.stars {
  color: #facc15; /* yellow-400 */
  font-size: 0.875rem;
}

/* Amount display - match UC card styling */
.lender-amount {
  font-size: 1.125rem; /* text-lg */
  font-weight: 600;
  color: #16a34a; /* green-600 - match UC cards */
  margin-bottom: 0.5rem;
}

/* Match UC card button styling exactly */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  white-space: nowrap;
  border-radius: 0.375rem; /* rounded-md */
  font-size: 0.875rem; /* text-sm */
  font-weight: 500;
  padding: 0.5rem 1rem; /* h-10 px-4 py-2 */
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  line-height: 1.25;
}

/* Dark green button for featured/partner offers - EXACT UC shade */
.btn-primary {
  background: #059669; /* UC dark green */
  color: white;
  border: 1px solid #059669;
}

.btn-primary:hover {
  background: #047857; /* Darker on hover */
  border-color: #047857;
  color: white;
}

/* Match UC outline button for non-featured */
.btn-secondary {
  background: white;
  color: #374151; /* text-gray-700 */
  border: 1px solid #d1d5db; /* border-gray-300 */
}

.btn-secondary:hover {
  background: #f9fafb; /* hover:bg-gray-50 */
  color: #374151;
}

.btn-full {
  width: 100%;
}

/* Sponsored text - match UC card muted styling */
.text-muted {
  color: #9ca3af; /* text-gray-400 */
  font-size: 0.75rem; /* text-xs */
  text-align: center;
  margin-top: 0.5rem;
  line-height: 1.5;
}

/* Match UC card badge styling exactly */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px; /* rounded-full */
  padding: 0.125rem 0.625rem; /* px-2.5 py-0.5 */
  font-size: 0.75rem; /* text-xs */
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

/* Partner badge - green to signal trusted partnership */
.badge-partner {
  background: #059669; /* UC dark green */
  color: white;
}

/* Match UC "Ingen UC" badge - green */
.badge-utan-uc {
  background: #dcfce7; /* bg-green-100 */
  color: #166534; /* text-green-800 */
}

/* Featured badge */
.badge-featured {
  background: #dcfce7; /* bg-green-100 */
  color: #166534; /* text-green-800 */
}

/* Comparison/other badges */
.badge-comparison {
  background: #dbeafe; /* bg-blue-100 */
  color: #1e40af; /* text-blue-800 */
}

.badge-low-rate {
  background: #fef2f2; /* bg-red-100 */
  color: #dc2626; /* text-red-800 */
}

/* Mobile responsive adjustments for logo */
@media (max-width: 640px) {
  .lender-logo {
    height: 36px;
    width: 100px;
    max-width: 100px;
  }
}