:root {
  /* Fintech Palette */
  /* Fintech Palette - Adapted to Telegram Theme */
  --h-background: var(--tg-theme-bg-color, hsl(240, 10%, 6%));
  --h-foreground: var(--tg-theme-text-color, hsl(0, 0%, 98%));
  --h-card: var(--tg-theme-secondary-bg-color, hsl(240, 10%, 10%));
  --h-secondary: var(--tg-theme-secondary-bg-color, hsl(240, 10%, 16%));
  --h-secondary-foreground: var(--tg-theme-hint-color, hsl(0, 0%, 85%));
  --h-muted: var(--tg-theme-hint-color, hsl(240, 10%, 20%));
  --h-muted-foreground: var(--tg-theme-hint-color, hsl(240, 5%, 55%));
  --h-border: var(--tg-theme-hint-color, hsl(240, 10%, 18%));
  /* Will use opacity for border */
  --h-primary: hsl(160, 84%, 39%);
  --h-primary-foreground: hsl(0, 0%, 100%);
  --h-success: hsl(160, 84%, 39%);
  --h-destructive: hsl(0, 72%, 51%);
  --h-warning: hsl(38, 92%, 50%);

  /* Gradients */
  --h-gradient-success: linear-gradient(135deg, hsl(160, 84%, 39%), hsl(160, 84%, 25%));
  --h-gradient-failed: linear-gradient(135deg, hsl(0, 72%, 51%), hsl(0, 72%, 35%));
  --h-gradient-pending: linear-gradient(135deg, hsl(38, 92%, 50%), hsl(38, 92%, 35%));
  --h-gradient-partial: linear-gradient(135deg, hsl(0, 72%, 51%), hsl(25, 80%, 45%));
  --h-gradient-card: linear-gradient(145deg, hsl(240, 10%, 12%), hsl(240, 10%, 8%));
  --h-gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));

  /* Shadows */
  --h-shadow-sm: 0 2px 8px -2px rgba(0, 0, 0, 0.4);
  --h-shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --h-shadow-lg: 0 16px 48px -16px rgba(0, 0, 0, 0.6);
  --h-shadow-glow: 0 0 40px -10px hsla(160, 84%, 39%, 0.3);
  --h-shadow-card: 0 4px 20px -4px rgba(0, 0, 0, 0.4), 0 1px 3px -1px rgba(0, 0, 0, 0.3);
}

/* Base Modal Overrides */
.history-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  background: var(--tg-theme-bg-color, var(--h-background));
  overflow: hidden;
  display: none;
  /* Controlled by JS or active class */
}

.history-modal.active {
  display: flex;
  flex-direction: column;
}

.history-modal-content {
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--tg-theme-bg-color, var(--h-background));
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.history-modal.open .history-modal-content {
  transform: translateX(0);
}

.history-modal.closing .history-modal-content {
  transform: translateX(100%);
}

/* Header Refinement */
.modal-header {
  padding: 1rem 1.25rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  background: var(--tg-theme-bg-color, var(--h-background));
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color, var(--h-border));
  backdrop-filter: blur(16px);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(135deg, var(--tg-theme-text-color, #fff), var(--tg-theme-hint-color, #777));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ========================================
       Filter Tabs
       ======================================== */
.filter-tabs {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1rem 1.5rem;
  /* Added top padding for separation */
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  padding: 0.5rem 1rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--h-secondary);
  color: var(--h-muted-foreground);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-tab:hover {
  background: var(--h-muted);
  color: var(--h-foreground);
}

.filter-tab.active {
  background: hsla(160, 84%, 39%, 0.15);
  color: var(--h-primary);
  border-color: hsla(160, 84%, 39%, 0.3);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal-body::-webkit-scrollbar {
  display: none;
}

/* ========================================
   Payment Card
   ======================================== */
.payment-card {
  position: relative;
  border-radius: 1rem;
  padding: 1rem;
  margin-bottom: 0.75rem;
  background: var(--tg-theme-secondary-bg-color, var(--h-gradient-glass));
  /* Use solid secondary in light mode mainly */
  border: 1px solid rgba(128, 128, 128, 0.2);
  /* Universal subtle border */
  box-shadow: var(--h-shadow-card);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  animation: scaleIn 0.25s cubic-bezier(0.4, 0, 0.2, 1) backwards;
  /* Text color reset to foreground to ensure visibility */
  color: var(--h-foreground);
}

.payment-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(135deg, hsla(160, 84%, 39%, 0.1), transparent);
  transition: opacity 0.25s ease;
}

.payment-card:hover::before {
  opacity: 1;
}

.payment-card:hover {
  transform: translateY(-2px);
  border-color: hsla(160, 84%, 39%, 0.3);
  box-shadow: var(--h-shadow-md), var(--h-shadow-glow);
}

.payment-card:active {
  transform: scale(0.98) translateY(0);
}

.payment-card-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: stretch;
  /* Stretches children to full height */
  gap: 1rem;
}

/* Price Bubble */
.price-bubble {
  flex-shrink: 0;
  width: 4rem;
  height: 4rem;
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--h-shadow-sm);
}

.price-bubble.success {
  background: var(--h-gradient-success);
}

.price-bubble.failed {
  background: var(--h-gradient-failed);
}

.price-bubble.pending {
  background: var(--h-gradient-pending);
}

.price-bubble.partial {
  background: var(--h-gradient-partial);
}

.price-bubble-amount {
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1;
  color: var(--h-primary-foreground);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.price-bubble-currency {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.8;
  margin-top: 0.125rem;
  color: var(--h-primary-foreground);
}

/* Payment Info */
.payment-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /* Aligns top, middle, bottom */
  min-height: 4rem;
  /* Matches Price Bubble height */
  gap: 0.25rem;
  /* Breathing room */
}

.payment-plan-name {
  font-size: clamp(0.75rem, 3.5vw, 0.9375rem);
  font-weight: 600;
  color: var(--h-foreground);
  /* Allow wrapping for full visibility */
  white-space: normal;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0;
  /* Optional: Limit to 2 lines if needed, but user said "full" */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Mobile Optimizations to maximize text space */
@media (max-width: 480px) {
  .payment-card {
    padding: 0.625rem;
    /* Further reduce padding */
  }

  .payment-card-inner {
    gap: 0.5rem;
    /* Tightest comfortable gap */
  }

  .price-bubble {
    width: 3.25rem;
    /* Even smaller bubble */
    height: 3.25rem;
    border-radius: 0.75rem;
  }

  .payment-info {
    min-height: 3.25rem;
    /* Match small bubble height */
    gap: 0.15rem;
    /* Slightly smaller gap on mobile */
  }

  .payment-plan-name {
    /* Slightly smaller on mobile to fit more text */
    font-size: 0.75rem;
  }

  .price-bubble-amount {
    font-size: 0.75rem;
  }

  /* Shrink right-side elements to give text more room */
  .status-badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.6rem;
  }

  .history-logo {
    width: 1.5rem;
    height: 1.5rem;
  }
}

.payment-target-number {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--h-foreground);
  margin-top: 0;
  /* Remove gap */
  opacity: 0.9;
  line-height: 1.2;
}

.payment-date {
  font-size: 0.75rem;
  margin-top: 0;
  color: var(--h-muted-foreground);
  line-height: 1.2;
}

/* Payment Meta */
.payment-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  /* Pins Logo to Top, Amount to Bottom */
  gap: 0.25rem;
  /* Tighter gap on meta */
  min-height: 2rem;
  /* Ensure it has some height structure */
}

/* Status Badge */
.status-badge {
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-badge.success {
  background: hsla(160, 84%, 39%, 0.15);
  color: var(--h-success);
  border: 1px solid hsla(160, 84%, 39%, 0.3);
}

.status-badge.failed {
  background: hsla(0, 72%, 51%, 0.15);
  color: var(--h-destructive);
  border: 1px solid hsla(0, 72%, 51%, 0.3);
}

.status-badge.pending {
  background: hsla(38, 92%, 50%, 0.15);
  color: var(--h-warning);
  border: 1px solid hsla(38, 92%, 50%, 0.3);
}

.status-badge.partial {
  background: hsla(0, 72%, 51%, 0.12);
  color: hsl(25, 80%, 55%);
  border: 1px solid hsla(25, 80%, 45%, 0.3);
}

/* history Logo */
.history-logo {
  width: 2rem;
  height: 1.5rem;
  border-radius: 0.375rem;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-logo-fallback {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--h-muted-foreground);
}

/* Residual Amount */
.residual-amount {
  font-size: 0.75rem;
  text-align: right;
  color: var(--h-muted-foreground);
}

/* Force specific color for the amount span */
.residual-amount span {
  color: var(--h-destructive) !important;
  font-weight: 600;
}

/* Chevron (Optional hover effect) */
.payment-chevron {
  color: var(--h-muted-foreground);
  opacity: 0.5;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.payment-card:hover .payment-chevron {
  opacity: 1;
  transform: translateX(2px);
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 1.5rem;
  text-align: center;
}

.empty-state-icon {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  background: var(--h-secondary);
  border: 2px dashed var(--h-border);
}

.empty-state-icon i {
  font-size: 2.5rem;
  color: var(--h-muted-foreground);
}

.empty-state-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--h-foreground);
}

.empty-state-description {
  font-size: 0.875rem;
  max-width: 16rem;
  color: var(--h-muted-foreground);
}

/* Breakdown Modal */
.breakdown-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 90%;
  max-width: 400px;
  max-height: 80vh;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--h-background);
  border: 1px solid var(--h-border);
  border-radius: 1.5rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.breakdown-modal.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.breakdown-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--h-border);
  background: rgba(255, 255, 255, 0.02);
}

.breakdown-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--h-foreground);
  margin: 0;
}

.breakdown-close {
  background: none;
  border: none;
  color: var(--h-muted-foreground);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.breakdown-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* Summary Box */
.breakdown-summary {
  background: var(--h-secondary);
  border-radius: 1.25rem;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--h-border);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.summary-item {
  display: flex;
  flex-direction: column;
}

.summary-label {
  font-size: 0.7rem;
  color: var(--h-muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.summary-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--h-foreground);
}

.summary-value.paid {
  color: var(--h-success);
}

.summary-value.remaining {
  color: var(--h-destructive);
}

/* Progress Container */
.breakdown-progress-container {
  margin-top: 1rem;
}

.breakdown-progress-bar {
  height: 6px;
  background: var(--h-background);
  border-radius: 999px;
  overflow: hidden;
}

.breakdown-progress-fill {
  height: 100%;
  background: var(--h-gradient-success);
  transition: width 1s ease;
}

.breakdown-progress-text {
  font-size: 0.7rem;
  color: var(--h-muted-foreground);
  display: block;
  margin-top: 6px;
  text-align: right;
}

/* Timeline */
.breakdown-section-title {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--h-muted-foreground);
  margin: 1.5rem 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.breakdown-timeline {
  border-left: 2px solid var(--h-border);
  padding-left: 1.5rem;
  margin-left: 0.5rem;
}

.timeline-item {
  position: relative;
  margin-bottom: 1.5rem;
}

.timeline-dot {
  position: absolute;
  left: -1.95rem;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--h-primary);
  box-shadow: 0 0 10px var(--h-primary);
}

.timeline-card {
  background: var(--h-secondary);
  border-radius: 1rem;
  padding: 1rem;
  border: 1px solid var(--h-border);
}

.timeline-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.timeline-journal {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--h-foreground);
}

.timeline-amount {
  font-weight: 800;
  color: var(--h-success);
}

.timeline-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--h-muted-foreground);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Overlay */
.breakdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.breakdown-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Animations */
@keyframes hScaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Dark Mode logic refined */
body.dark-mode .payment-card {
  background: var(--h-gradient-glass);
}

/* ========================================
   Skeleton / Shimmer Loading
   ======================================== */
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.skeleton-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-radius: 1rem;
  background: var(--tg-theme-secondary-bg-color, var(--h-secondary));
  border: 1px solid rgba(128, 128, 128, 0.1);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

/* Apply shimmer to the inner elements */
.skeleton-bubble,
.skeleton-line {
  background: linear-gradient(90deg,
      rgba(128, 128, 128, 0.1) 25%,
      rgba(128, 128, 128, 0.2) 50%,
      rgba(128, 128, 128, 0.1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Dark mode adjustment for visibility */
body.dark-mode .skeleton-bubble,
body.dark-mode .skeleton-line {
  background: linear-gradient(90deg,
      rgba(255, 255, 255, 0.05) 25%,
      rgba(255, 255, 255, 0.1) 50%,
      rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
}

.skeleton-bubble {
  width: 4rem;
  height: 4rem;
  border-radius: 1rem;
  flex-shrink: 0;
}

.skeleton-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-line {
  height: 0.8rem;
  border-radius: 4px;
}

.skeleton-line.short {
  width: 40%;
}

.skeleton-line.medium {
  width: 70%;
}
