/* ============================================
   ACTION CARD FLIP - 3D Transform
   Matching iOS ActionDetailView flip logic
   ============================================ */

/* Modal Container */
.action-card-flip-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.action-card-flip-modal.visible {
  opacity: 1;
  pointer-events: all;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 400px; /* Constrain to card width + padding */
  height: 100%;
  margin: 0 auto;
  background: var(--brokerly-background);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--brokerly-border-light);
  background: var(--brokerly-secondary-background);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--brokerly-text-primary);
  margin: 0;
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--brokerly-text-secondary);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.modal-close-btn:hover {
  background: rgba(128, 128, 128, 0.1);
}

.modal-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px;
}

/* ============================================
   SHEET VARIANT - Uses standard slide-up-sheet
   ============================================ */

.action-card-flip-sheet {
  z-index: 2000; /* Higher than standard sheets */
}

/* Desktop: 90% height by default */
@media (min-width: 768px) {
  .action-card-flip-sheet .sheet-content {
    max-height: 90vh;
  }
}

/* Drawer-specific card sizing - larger than Actions view for better drawer display */

.action-card-flip-sheet .sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
  align-items: center; /* Center the card horizontally */
  width: 100%; /* Ensure body doesn't constrain width */
}

/* 3D Flip Card Container - Optimized for drawer display */
.flip-card-container {
  position: relative;
  width: 340px; /* Larger than Actions view cards for drawer context */
  min-width: 340px;
  max-width: 340px;
  height: 476px; /* Maintains 1.4 ratio: 340 × 1.4 = 476 */
  min-height: 476px;
  max-height: 476px;
  margin-bottom: 32px;
  perspective: 1500px;
  flex-shrink: 0;
}

/* Ensure action cards inside drawer container fill it */
.flip-card-container .action-card {
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  max-width: 100% !important;
  min-height: 100% !important;
  max-height: 100% !important;
}

/* Scale up on larger screens */
@media (min-width: 1024px) and (max-width: 1439px) {
  .flip-card-container {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
    height: 504px; /* 360 × 1.4 = 504 */
    min-height: 504px;
    max-height: 504px;
  }
}

@media (min-width: 1440px) {
  .flip-card-container {
    width: 380px;
    min-width: 380px;
    max-width: 380px;
    height: 532px; /* 380 × 1.4 = 532 */
    min-height: 532px;
    max-height: 532px;
  }
}

/* Card content padding */
.flip-card-container .card-inner {
  padding: 24px; /* Standard padding */
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-radius: 20px;
}

/* Ensure any deep-cloned action card fills the face */
.flip-card-front .action-card,
.flip-card-front .action-card .card-inner {
  width: 100% !important;
  height: 100% !important;
  border-radius: 20px !important;
  overflow: hidden !important;
}

/* Wrapper that scales the deep-cloned card proportionally */
.flip-card-front .deep-clone-wrapper {
  width: 100%;
  height: 100%;
  transform-origin: top left;
}

.flip-card-front {
  transform: rotateY(0deg);
  z-index: 2;
}

/* Apply gradients to action cards in modal - PARENT ONLY */
.flip-card-front .action-card.urgent {
  background: linear-gradient(135deg,
    #E66152 0%,
    #FF6F61 25%,
    #F26859 50%,
    #D9594A 100%
  ) !important;
  color: white !important;
}

.flip-card-front .action-card.high {
  background: linear-gradient(135deg,
    #D9A621 0%,
    #FFD700 25%,
    #D9A621 50%,
    #B87A0A 100%
  ) !important;
  color: white !important;
}

.flip-card-front .action-card.medium {
  background: linear-gradient(135deg,
    #3DB063 0%,
    #50C878 25%,
    #47BD6E 50%,
    #33A358 100%
  ) !important;
  color: white !important;
}

.flip-card-front .action-card.mediumLow {
  background: linear-gradient(135deg,
    #0099D8 0%,
    #00B4D8 25%,
    #00A8CC 50%,
    #0088BB 100%
  ) !important;
  color: white !important;
}

.flip-card-front .action-card.low {
  background: linear-gradient(135deg,
    #F5F5F7 0%,
    #FFFFFF 25%,
    #FAFAFA 50%,
    #F0F0F2 100%
  ) !important;
  color: #2C3E50 !important;
}

/* Card inner is always transparent in modal */
.flip-card-front .card-inner {
  background: transparent !important; /* default, will be overridden inline by computed background */
  border: none !important;
}

/* Text colors for savings amount */
.flip-card-front .action-card.urgent .savings-amount,
.flip-card-front .action-card.high .savings-amount,
.flip-card-front .action-card.medium .savings-amount,
.flip-card-front .action-card.mediumLow .savings-amount,
.flip-card-front .action-card.urgent .savings-amount *,
.flip-card-front .action-card.high .savings-amount *,
.flip-card-front .action-card.medium .savings-amount *,
.flip-card-front .action-card.mediumLow .savings-amount * {
  color: white !important;
  text-shadow: 
    1px 1px 0 rgba(0, 0, 0, 0.4),
    -1px -1px 0 rgba(255, 255, 255, 0.8);
}

.flip-card-front .action-card.low .savings-amount,
.flip-card-front .action-card.low .savings-amount * {
  color: #50C878 !important;
  text-shadow: none;
}

.flip-card-back {
  transform: rotateY(-180deg);
  z-index: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.flip-card-container.flipped .flip-card-front {
  transform: rotateY(180deg);
  z-index: 1;
}

.flip-card-container.flipped .flip-card-back {
  transform: rotateY(0deg);
  z-index: 2;
}

/* Swipeable Action Card (Front) - Pokémon Card Style */
.swipeable-action-card {
  width: 100%;
  height: 100%;
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-category {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.5px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(0, 0, 0, 0.15);
  padding: 6px 12px;
  border-radius: 12px;
}

.card-savings {
  font-size: 24px;
  font-weight: 700;
  color: white;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  font-size: 22px;
  font-weight: 700;
  color: white;
  margin: 0;
  line-height: 1.3;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.card-description {
  font-size: 15px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
  line-height: 1.5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-timeframe,
.card-impact {
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* AI Response Overlay (Back) - Pokémon Card Style */
.ai-response-overlay {
  width: 100%;
  height: 100%;
  border-radius: 20px;
  padding: 24px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 245, 255, 0.95) 100%);
  box-shadow: 0 8px 24px rgba(79, 172, 254, 0.2);
  border: 1.5px solid rgba(79, 172, 254, 0.3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.ai-response-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  font-size: 16px;
  font-weight: 500;
  color: var(--brokerly-text-secondary);
  text-align: center;
}

/* Thinking Steps */
.thinking-steps-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-avatar-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  overflow: hidden;
}

.ai-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thinking-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--brokerly-text-primary);
}

.thinking-steps-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.thinking-step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px;
  background: rgba(79, 172, 254, 0.08);
  border-radius: 12px;
  width: 95%;
  margin: 0 auto;
}

.step-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--brokerly-primary-light);
  border-top-color: var(--brokerly-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* AI Response Content */
.ai-response-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ai-response-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(79, 172, 254, 0.2);
}

.ai-info {
  flex: 1;
}

.ai-name {
  font-size: 16px;
  font-weight: 600;
  color: white;
}

.ai-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.85);
}

.ai-analysis-section,
.ai-steps-section,
.ai-impact-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

.analysis-text {
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.95);
  margin: 0;
}

.steps-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.step-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.4);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  align-self: flex-start;
}

.step-text {
  width: 100%;
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.95);
  padding: 0;
}

/* Markdown formatting within step text */
.step-text strong {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.98);
}

.step-text em {
  font-style: italic;
}

.step-text code {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 0.9em;
  color: rgba(255, 255, 255, 0.95);
}

.step-text a {
  color: #57CCEA;
  text-decoration: underline;
}

.step-text a:hover {
  color: #6DD5FA;
}

.impact-metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.impact-item {
  padding: 16px;
  background: rgba(79, 172, 254, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.impact-label {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.impact-value {
  font-size: 18px;
  font-weight: 700;
  color: white;
}

.flip-back-button {
  margin-top: 8px;
  padding: 12px 20px;
  background: transparent;
  border: 1px solid var(--brokerly-primary);
  border-radius: 12px;
  color: var(--brokerly-primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.flip-back-button:hover {
  background: rgba(79, 172, 254, 0.08);
}

/* Action Buttons at Top - Side by Side */
.action-buttons-top {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  background: var(--brokerly-secondary-background);
  border-bottom: 1px solid var(--brokerly-border-light);
}

.ai-agent-flip-button-top,
.mark-completed-button-top {
  flex: 1; /* Equal width */
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

/* Default to Clive's purple gradient */
.ai-agent-flip-button-top,
.ai-agent-flip-button-top.clive {
  background: var(--clive-gradient);
  box-shadow: 0 2px 8px var(--clive-glow);
}

.ai-agent-flip-button-top:hover,
.ai-agent-flip-button-top.clive:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--clive-glow);
}

/* Clara's teal gradient */
.ai-agent-flip-button-top.clara {
  background: var(--clara-gradient);
  box-shadow: 0 2px 8px var(--clara-glow);
}

.ai-agent-flip-button-top.clara:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--clara-glow);
}

.ai-agent-flip-button-top.loading {
  background: linear-gradient(135deg, #888 0%, #666 100%);
}

.ai-agent-flip-button-top.complete {
  background: linear-gradient(135deg, #50C878 0%, #34A853 100%);
}

.mark-completed-button-top {
  background: linear-gradient(135deg, #50C878 0%, #34A853 100%);
  box-shadow: 0 2px 8px rgba(80, 200, 120, 0.25);
}

.mark-completed-button-top:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(80, 200, 120, 0.35);
}

.button-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-avatar-flip-top {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--modern-card-background);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.ai-avatar-flip-top img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.button-text {
  font-size: 14px;
  font-weight: 600;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.button-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
}

.button-spinner .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

/* Mobile: Stack buttons vertically */
@media (max-width: 480px) {
  .action-buttons-top {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }
  
  .button-text {
    font-size: 13px;
  }
}

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

/* Responsive */
@media (max-width: 768px) {
  .modal-content {
    max-width: 100%;
  }

  .modal-scroll {
    padding: 20px 16px;
  }

  /* Mobile drawer card sizing - slightly smaller for mobile */
  .flip-card-container {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
    height: 420px; /* 300 × 1.4 = 420 */
    min-height: 420px;
    max-height: 420px;
  }

  .swipeable-action-card,
  .ai-response-overlay {
    padding: 20px;
  }

  .card-title {
    font-size: 20px;
  }

  .card-savings {
    font-size: 20px;
  }

  /* Thinking steps mobile adjustments */
  .thinking-step {
    width: 98%;
    padding: 12px;
    gap: 6px;
  }

  .step-number {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .step-text {
    font-size: 14px;
    line-height: 1.5;
  }
}

