/* ============================================
   ACTIONS VIEW - RESPONSIVE LAYOUTS
   iOS-style vertical on mobile, card table on desktop
   ============================================ */

/* ============================================
   BASE - Mobile First (< 768px)
   iOS-style vertical stack
   ============================================ */

#actions-view .view-content {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Mobile: Ensure content isn't cut off at bottom */
@media (max-width: 768px) {

  /* Override app-container grey background when actions view is active */
  #actions-view.active~#main-app,
  #actions-view.active,
  #main-app:has(#actions-view.active) {
    background: var(--brokerly-background) !important;
  }

  #actions-view {
    padding-bottom: 0 !important;
    background: transparent !important;
  }

  #actions-view .view-content {
    background: transparent !important;
    min-height: 100vh;
  }

  #actions-view .filters-section {
    margin: 0;
    width: 100%;
  }

  #actions-view .actions-container {
    padding: 16px;
    padding-bottom: calc(var(--tab-height, 80px) + env(safe-area-inset-bottom, 0px) + 120px) !important;
    min-height: 100vh;
    /* Fill entire viewport height */
  }
}

#actions-view .filters-section {
  padding: 16px 0;
  /* Vertical padding only */
  border-bottom: none;
  background: var(--brokerly-background);
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  max-width: var(--view-max-width);
  margin: 0 auto;
}

#actions-view .actions-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  padding-bottom: calc(16px + 20px);
  width: 100%;
  background: var(--brokerly-background);
}

#actions-view .action-card-wrapper {
  width: 100%;
  max-width: var(--view-max-width);
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
}

#actions-view .action-card {
  width: 100%;
  min-height: 180px;
  height: auto;
  /* Allow content to dictate height on mobile */
  background: var(--modern-card-background);
  border-radius: 16px;
  padding: 0;
  /* Let .card-inner handle padding */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: none;
  transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  contain: layout style paint;
  display: flex;
  flex-direction: column;
}

/* Card Content Layout */
#actions-view .action-card .card-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#actions-view .action-card .card-header {
  flex: 0 0 auto;
}

#actions-view .action-card .card-footer {
  flex: 0 0 auto;
  margin-top: auto;
}

#actions-view .action-card .action-title {
  font-size: 18px;
  font-weight: 600;
  margin: 8px 0 6px 0;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#actions-view .action-card .action-description {
  font-size: 14px;
  font-weight: 400;
  margin: 0;
  line-height: 1.4;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#actions-view .action-card:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* Card Inner Styling - matching discover view */
#actions-view .card-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: transparent !important;
  /* ALWAYS transparent - gradient on parent only */
  box-shadow: none !important;
  /* Remove inner shadow */
  border: none !important;
  /* No border on inner */
}

#actions-view .card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

#actions-view .category-badge {
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  /* Increased horizontal padding */
  border-radius: 12px;
  margin-left: 2px;
  /* Safety buffer to avoid clipping by parent border */
  flex-shrink: 0;
}


#actions-view .priority-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 12px;
}


#actions-view .savings-display {
  text-align: right;
  margin: 12px 0;
}

#actions-view .savings-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

#actions-view .savings-amount {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 32px;
  font-weight: 900;
}

#actions-view .savings-amount .currency {
  font-size: 0.8em;
}

#actions-view .card-divider {
  height: 1px;
  margin: 16px 0;
}

#actions-view .card-title {
  font-size: 18px;
  font-weight: 700;
  margin: 12px 0;
  line-height: 1.3;
}


#actions-view .card-description-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#actions-view .card-description {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}


#actions-view .time-to-complete {
  text-align: right;
}

#actions-view .time-label {
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1.0px;
  margin-bottom: 2px;
}


#actions-view .time-value {
  font-size: 13px;
  font-weight: 700;
}


#actions-view .card-spacer {
  flex: 1;
}

/* Removed obsolete .colored class rules - now using priority classes directly */

/* ============================================
   TABLET (768px - 1023px)
   2-column card grid
   ============================================ */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Match Overview header layout */
  #actions-view .view-header {
    max-width: var(--view-max-width);
    margin: 0 auto;
    padding: 16px 24px;
  }

  #actions-view .filters-section {
    padding: 0 24px 16px 24px;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }

  #actions-view .actions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    /* Responsive columns */
    gap: 20px;
    padding: 24px;
    max-width: 100%;
    margin: 0 auto;
    justify-content: center;
    /* Center cards */
  }

  #actions-view .action-card {
    width: 100%;
    /* Fill grid column */
    height: auto;
    min-height: 336px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  }

  #actions-view .action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }
}

/* Enforce single-column at genuinely small widths (below 640px) */
@media (max-width: 640px) {
  #actions-view .actions-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
    padding: 16px !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  #actions-view .action-card {
    width: 100% !important;
    height: auto !important;
    min-height: 180px !important;
  }
}

@media (min-width: 1024px) and (max-width: 1439px) {
  /* Match Global header layout */
  #actions-view .view-header {
    max-width: var(--view-max-width);
    margin: 0 auto;
    padding: 20px 32px;
  }

  #actions-view .filters-section {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    padding: 0 32px 20px 32px;
  }

  #actions-view .actions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 32px;
    padding: 32px;
    max-width: 100%;
    margin: 0 auto;
    justify-content: center;
    /* PERFECT CENTERING */
  }

  #actions-view .action-card {
    width: 100%;
    max-width: 320px;
    height: auto;
    min-height: 448px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    margin: 0 auto;
  }

  #actions-view .action-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }
}

/* ============================================
   LARGE DESKTOP (≥ 1440px)
   Expanded card table layout
   ============================================ */
@media (min-width: 1440px) {
  /* Match Global header layout */
  #actions-view .view-header {
    max-width: var(--view-max-width);
    margin: 0 auto;
    padding: 24px 48px;
  }

  #actions-view .filters-section {
    padding: 0 48px 24px 48px;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }

  #actions-view .actions-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 40px;
    padding: 32px 48px;
    max-width: 100%;
    margin: 0 auto;
    justify-content: center;
    /* PERFECT CENTERING */
  }

  #actions-view .action-card {
    width: 100%;
    max-width: 320px;
    height: auto;
    min-height: 448px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
  }

  #actions-view .action-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  }
}

/* ============================================
   ULTRA-WIDE (≥ 1920px)
   Maximum card table spread
   ============================================ */
@media (min-width: 1920px) {

  /* Match Overview header layout */
  #actions-view .view-header {
    max-width: 1100px;
    margin: 0 auto;
  }

  #actions-view .filters-section {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
  }

  #actions-view .actions-container {
    grid-template-columns: repeat(3, 300px);
    /* Fixed 3-column layout */
    gap: 32px;
    padding: 60px;
    max-width: 1100px;
    margin: 0 auto;
    justify-content: center;
  }

  #actions-view .action-card {
    width: 300px;
    /* Fixed Pokémon card width */
    height: 420px;
    /* Pokémon ratio 1.4 (300 × 1.4 = 420) */
    min-height: 420px;
  }
}

/* ============================================
   MOBILE DEVICE DETECTION
   Force iOS-style on actual mobile browsers
   ============================================ */
html[data-device="mobile"] #actions-view .actions-container {
  display: flex !important;
  flex-direction: column !important;
  gap: 16px !important;
  padding: 16px !important;
  grid-template-columns: unset !important;
}

html[data-device="mobile"] #actions-view .action-card {
  width: 100% !important;
  transform: none !important;
}

html[data-device="mobile"] #actions-view .action-card:active {
  transform: scale(0.98) !important;
}

/* ============================================
   ACCESSIBILITY & TOUCH
   ============================================ */

/* Larger tap targets on mobile */
@media (max-width: 767px) {
  #actions-view .action-card {
    min-height: 180px;
    height: 180px;
    /* Uniform height */
    padding: 20px;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  #actions-view .action-card {
    transform: none !important;
    transition: box-shadow 0.2s, opacity 0.2s !important;
  }

  #actions-view .action-card:hover {
    transform: none !important;
  }
}

/* ============================================
   EMPTY STATE
   ============================================ */
#actions-view .actions-container:empty::after {
  content: 'No actions yet. Tap Discover to find opportunities!';
  display: block;
  text-align: center;
  padding: 48px 24px;
  color: var(--brokerly-text-secondary);
  font-size: 16px;
  grid-column: 1 / -1;
}

/* ============================================
   LOADING STATE
   ============================================ */
#actions-view .actions-container.loading {
  opacity: 0.6;
  pointer-events: none;
}

#actions-view .actions-container.loading .action-card {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* ============================================
   LAYOUT TOGGLE STYLES
   ============================================ */
#actions-view .layout-toggle {
  margin-left: 12px;
  flex-shrink: 0;
}

#actions-view .layout-btn {
  color: var(--brokerly-text-secondary) !important;
}

#actions-view .layout-btn:hover {
  background: var(--brokerly-secondary-background) !important;
  color: var(--brokerly-text-primary) !important;
}

#actions-view .layout-btn.active {
  background: var(--brokerly-primary) !important;
  color: white !important;
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.3) !important;
}

/* ============================================
   LIST LAYOUT SPACING OVERRIDES 
   ============================================ */
#actions-view .actions-container.list-layout-active {
  display: block; /* Override default CSS grid for action-cards */
}

#actions-view .actions-container.list-layout-active .priority-mini-card {
  width: 100%;
}

/* ============================================
   DISCOVER BUTTON PULSE
   Gentle pulse animation when new actions available
   ============================================ */
.discover-button-header.discover-pulse {
  animation: discoverPulse 2s ease-in-out infinite;
}

@keyframes discoverPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(0, 122, 255, 0);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(0, 122, 255, 0.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .discover-button-header.discover-pulse {
    animation: none;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
  }
}

/* ============================================
   ACTION CARD HOVER GLOW BY CATEGORY
   ============================================ */
#actions-view .action-card.alert-card:hover {
  box-shadow: 0 8px 32px rgba(230, 97, 82, 0.2) !important;
}

#actions-view .action-card.insight-card:hover {
  box-shadow: 0 8px 32px rgba(16, 185, 129, 0.2) !important;
}

#actions-view .action-card.action-card-quick:hover {
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.2) !important;
}

#actions-view .action-card.comparison-card:hover {
  box-shadow: 0 8px 32px rgba(139, 92, 246, 0.2) !important;
}