.tenant-dashboard {
  padding: 1.5rem;
  max-width: 1200px;

  &--empty {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    color: var(--theme-elevation-500);
  }

  &__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
  }

  &__title-section {
    flex: 1;
    min-width: 200px;
  }

  &__title {
    margin: 0 0 0.25rem 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--theme-elevation-800);
  }

  &__subtitle {
    margin: 0;
    font-size: 0.875rem;
    color: var(--theme-elevation-500);
  }

  &__controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }

  &__period-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--theme-elevation-200);
    border-radius: var(--style-radius-s, 4px);
    background-color: var(--theme-input-background);
    font-size: 0.875rem;
    color: var(--theme-elevation-800);
    cursor: pointer;

    &:focus {
      outline: none;
      border-color: var(--theme-success-500);
    }
  }

  &__refresh-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--theme-elevation-200);
    border-radius: var(--style-radius-s, 4px);
    background-color: var(--theme-input-background);
    cursor: pointer;
    color: var(--theme-elevation-600);
    transition: all 0.15s ease;

    &:hover:not(:disabled) {
      background-color: var(--theme-elevation-100);
      color: var(--theme-elevation-800);
    }

    &:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
  }

  &__refresh-icon {
    &--spinning {
      animation: tenant-dashboard-spin 1s linear infinite;
    }
  }

  &__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem;
    color: var(--theme-elevation-500);
  }

  &__spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--theme-elevation-200);
    border-top-color: var(--theme-success-500);
    border-radius: 50%;
    animation: tenant-dashboard-spin 0.8s linear infinite;
  }

  &__error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background-color: rgba(var(--theme-error-500-rgb), 0.1);
    border: 1px solid var(--theme-error-500);
    border-radius: var(--style-radius-s, 4px);
    color: var(--theme-error-600);
    font-size: 0.875rem;
  }

  &__stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }

  &__stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background-color: var(--theme-elevation-50);
    border: 1px solid var(--theme-elevation-150);
    border-radius: var(--style-radius-m, 8px);
    transition: transform 0.15s ease, box-shadow 0.15s ease;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    &--success {
      border-left: 3px solid var(--theme-success-500);
    }

    &--error {
      border-left: 3px solid var(--theme-error-500);
    }

    &--rate {
      border-left: 3px solid var(--theme-elevation-500);
    }
  }

  &__stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--style-radius-s, 4px);
    flex-shrink: 0;

    &--total {
      background-color: rgba(var(--theme-elevation-500-rgb), 0.1);
      color: var(--theme-elevation-600);
    }

    &--sent {
      background-color: rgba(var(--theme-success-500-rgb), 0.1);
      color: var(--theme-success-600);
    }

    &--failed {
      background-color: rgba(var(--theme-error-500-rgb), 0.1);
      color: var(--theme-error-600);
    }

    &--rate {
      background-color: rgba(var(--theme-elevation-500-rgb), 0.1);
      color: var(--theme-elevation-600);
    }
  }

  &__stat-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }

  &__stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--theme-elevation-800);
    line-height: 1;
  }

  &__stat-label {
    font-size: 0.8125rem;
    color: var(--theme-elevation-500);
  }

  &__section {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
    background-color: var(--theme-elevation-50);
    border: 1px solid var(--theme-elevation-150);
    border-radius: var(--style-radius-m, 8px);

    &--failures {
      border-left: 3px solid var(--theme-warning-500);
    }
  }

  &__section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 1rem 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--theme-elevation-700);
  }

  &__source-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
  }

  &__source-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--theme-elevation-100);
    border-radius: var(--style-radius-s, 4px);
  }

  &__source-label {
    font-size: 0.8125rem;
    color: var(--theme-elevation-600);
  }

  &__source-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--theme-elevation-800);
  }

  &__failures-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  &__failure-item {
    padding: 0.75rem;
    background-color: rgba(var(--theme-error-500-rgb), 0.05);
    border: 1px solid rgba(var(--theme-error-500-rgb), 0.2);
    border-radius: var(--style-radius-s, 4px);
  }

  &__failure-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
  }

  &__failure-to {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-elevation-800);
  }

  &__failure-date {
    font-size: 0.75rem;
    color: var(--theme-elevation-500);
  }

  &__failure-subject {
    font-size: 0.8125rem;
    color: var(--theme-elevation-600);
    margin-bottom: 0.25rem;
  }

  &__failure-error {
    font-size: 0.75rem;
    color: var(--theme-error-600);
    font-family: var(--font-mono);
    padding: 0.5rem;
    background-color: rgba(var(--theme-error-500-rgb), 0.1);
    border-radius: 2px;
    overflow-x: auto;
  }

  &__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding-top: 0.5rem;
  }

  &__action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background-color: var(--theme-elevation-100);
    border: 1px solid var(--theme-elevation-200);
    border-radius: var(--style-radius-s, 4px);
    font-size: 0.875rem;
    color: var(--theme-elevation-700);
    text-decoration: none;
    transition: all 0.15s ease;

    &:hover {
      background-color: var(--theme-elevation-150);
      border-color: var(--theme-elevation-300);
      color: var(--theme-elevation-800);
    }
  }
}

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

// Dark mode support
.dark .tenant-dashboard {
  &__stat-card {
    background-color: var(--theme-elevation-100);
    border-color: var(--theme-elevation-200);
  }

  &__section {
    background-color: var(--theme-elevation-100);
    border-color: var(--theme-elevation-200);
  }

  &__source-item {
    background-color: var(--theme-elevation-150);
  }
}

// Responsive
@media (max-width: 768px) {
  .tenant-dashboard {
    padding: 1rem;

    &__header {
      flex-direction: column;
    }

    &__stats-grid {
      grid-template-columns: repeat(2, 1fr);
    }

    &__stat-card {
      padding: 1rem;
    }

    &__stat-icon {
      width: 40px;
      height: 40px;
    }

    &__stat-value {
      font-size: 1.5rem;
    }
  }
}
