/* ============================================
   Usage Analytics View - Main Container
   ============================================ */

.usage-analytics-view {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
}

.analytics-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  gap: 24px;
  flex-wrap: wrap;
}

.header-content {
  flex: 1;
  min-width: 300px;
}

.analytics-title {
  font-size: 28px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 8px 0;
}

.analytics-subtitle {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

/* ============================================
   Period Filter
   ============================================ */

.period-filter {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 14px;
  font-weight: 500;
  color: #475569;
}

.filter-select {
  padding: 8px 32px 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  background-color: white;
  cursor: pointer;
  transition: border-color 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23475569' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.filter-select:hover {
  border-color: #94a3b8;
}

.filter-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.date-inputs {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.date-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-label {
  font-size: 14px;
  color: #64748b;
}

.date-input {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  background-color: white;
  cursor: pointer;
  transition: border-color 0.2s;
}

.date-input:hover {
  border-color: #94a3b8;
}

.date-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.date-separator {
  color: #94a3b8;
  font-size: 14px;
}

/* ============================================
   Metric Cards
   ============================================ */

.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.metric-card {
  background: white;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s;
}

.metric-card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.metric-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.metric-icon {
  font-size: 28px;
}

.metric-title {
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-value {
  font-size: 36px;
  font-weight: 700;
  color: #1e293b;
  margin: 12px 0;
  line-height: 1;
}

.metric-change {
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.metric-change.positive {
  color: #10b981;
}

.metric-change.negative {
  color: #ef4444;
}

.metric-arrow {
  font-size: 16px;
  font-weight: bold;
}

/* ============================================
   Sections
   ============================================ */

.section {
  background: white;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.section-header {
  margin-bottom: 24px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 8px 0;
}

.section-subtitle {
  font-size: 14px;
  color: #64748b;
  margin: 0;
}

/* ============================================
   Top Users Grid
   ============================================ */

.top-users-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.top-user-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: all 0.2s;
}

.top-user-card:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.rank-badge {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  font-weight: 700;
  font-size: 16px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-info-compact {
  flex: 1;
  min-width: 0;
}

.user-name-compact {
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-stats-compact {
  font-size: 13px;
  color: #64748b;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-item {
  white-space: nowrap;
}

.stat-divider {
  color: #cbd5e1;
}

/* ============================================
   Top Models Table
   ============================================ */

.top-models-table-wrapper {
  overflow-x: auto;
}

.top-models-table {
  width: 100%;
  border-collapse: collapse;
}

.top-models-table thead {
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
}

.top-models-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.top-models-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
}

.top-models-table tbody tr:hover {
  background: #f8fafc;
}

.rank-cell {
  font-weight: 600;
  color: #64748b;
  font-size: 14px;
}

.model-name-cell {
  font-weight: 500;
}

.model-badge-large {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  display: inline-block;
}

.number-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #475569;
}

.cost-cell {
  font-weight: 600;
}

/* ============================================
   Aggregated Stats Pills
   ============================================ */

.aggregated-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-pill {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 12px 20px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.stat-label {
  font-size: 13px;
  color: #0369a1;
  font-weight: 500;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  color: #0c4a6e;
}

.cost-highlight {
  color: #059669;
  font-weight: 700;
}

/* ============================================
   User Token Usage Table
   ============================================ */

.user-table-container {
  width: 100%;
}

.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 400px;
  min-width: 200px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 10px 40px 10px 40px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.clear-search {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: #e2e8f0;
  border: none;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: #475569;
  transition: all 0.2s;
}

.clear-search:hover {
  background: #cbd5e1;
}

.table-info {
  font-size: 13px;
  color: #64748b;
  white-space: nowrap;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.user-usage-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.user-usage-table thead {
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
}

.user-usage-table th {
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.user-usage-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.user-usage-table th.sortable:hover {
  background: #f1f5f9;
}

.th-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sort-icon {
  color: #cbd5e1;
  font-size: 14px;
}

.sort-icon.active {
  color: #3b82f6;
}

.user-usage-table td {
  padding: 16px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 14px;
}

.user-usage-table tbody tr {
  transition: background 0.15s;
}

.user-usage-table tbody tr:hover {
  background: #f8fafc;
}

.user-cell {
  min-width: 250px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 2px;
}

.user-email {
  font-size: 12px;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-breakdown {
  text-align: right;
}

.token-total {
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 4px;
}

.token-detail {
  font-size: 12px;
  color: #94a3b8;
}

.token-type {
  font-weight: 500;
}

.model-cell {
  white-space: nowrap;
}

.model-badge {
  background: #ede9fe;
  color: #7c3aed;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
}

.status-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  display: inline-block;
}

.status-badge.status-active {
  background: #d1fae5;
  color: #065f46;
}

.status-badge.status-inactive {
  background: #fee2e2;
  color: #991b1b;
}

/* ============================================
   Pagination
   ============================================ */

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  gap: 16px;
  flex-wrap: wrap;
}

.pagination-button {
  padding: 8px 16px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  color: #475569;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.pagination-button:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
}

.pagination-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-numbers {
  display: flex;
  gap: 6px;
}

.page-number {
  width: 36px;
  height: 36px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: white;
  color: #475569;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-number:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.page-number.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

.page-text {
  font-size: 14px;
  color: #64748b;
  white-space: nowrap;
}

/* ============================================
   Daily Usage Preview
   ============================================ */

.daily-usage-preview {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.daily-bar {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  transition: background 0.2s;
}

.daily-bar:hover {
  background: #f1f5f9;
}

.daily-date {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.daily-bar-container {
  background: #e2e8f0;
  height: 24px;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.daily-bar-fill {
  background: linear-gradient(90deg, #3b82f6, #2563eb);
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
  min-width: 2px;
}

.daily-stats {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: #64748b;
}

.daily-stats span {
  white-space: nowrap;
}

/* ============================================
   Loading & Empty States
   ============================================ */

.loading-spinner,
.table-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-spinner p,
.table-loading p {
  font-size: 14px;
  color: #64748b;
}

.error-message {
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  margin: 40px 0;
}

.error-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.error-message h3 {
  font-size: 20px;
  font-weight: 700;
  color: #991b1b;
  margin: 0 0 12px 0;
}

.error-message p {
  font-size: 14px;
  color: #7f1d1d;
  margin: 0 0 24px 0;
}

.retry-button {
  padding: 10px 24px;
  background: #dc2626;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.retry-button:hover {
  background: #b91c1c;
}

.empty-state,
.table-empty {
  text-align: center;
  padding: 60px 20px;
  color: #64748b;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: #475569;
  margin: 0 0 8px 0;
}

.empty-state p,
.table-empty p {
  font-size: 14px;
  color: #94a3b8;
  margin: 0;
}

/* ============================================
   Refresh Section
   ============================================ */

.refresh-section {
  display: flex;
  justify-content: center;
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid #e2e8f0;
}

.refresh-button {
  padding: 12px 24px;
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  color: #475569;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.refresh-button:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #3b82f6;
  color: #3b82f6;
}

.refresh-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
  .analytics-header {
    flex-direction: column;
  }

  .metrics-row {
    grid-template-columns: 1fr;
  }

  .top-users-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .analytics-title {
    font-size: 24px;
  }

  .metric-value {
    font-size: 28px;
  }

  .section {
    padding: 16px;
  }

  .table-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: none;
  }

  .user-usage-table th,
  .user-usage-table td {
    padding: 12px 8px;
    font-size: 13px;
  }

  .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  .pagination {
    flex-direction: column;
  }

  .daily-bar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .aggregated-stats {
    flex-direction: column;
  }
}
