/**
 * Usage & Analytics Dashboard Styles
 * Inspired by ElevenLabs Analytics
 */

/* Analytics Container */
.analytics-container {
  padding: 0;
}

/* Analytics Header */
.analytics-header {
  margin-bottom: 24px;
}

.analytics-header h1 {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 8px 0;
  color: #1a1a1a;
}

.analytics-header p {
  color: #6b7280;
  margin: 0;
  font-size: 14px;
}

/* Controls Bar */
.analytics-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
  align-items: center;
}

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

.control-label {
  font-size: 13px;
  color: #6b7280;
  font-weight: 500;
}

.control-select {
  padding: 8px 32px 8px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  background: white;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 16px;
  min-width: 120px;
}

.control-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.control-btn {
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 13px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.control-btn:hover {
  background: #f9fafb;
  border-color: #d1d5db;
}

.control-btn.active {
  background: #1a1a1a;
  color: white;
  border-color: #1a1a1a;
}

.control-btn i {
  font-size: 12px;
}

/* Refresh button */
.refresh-btn {
  margin-left: auto;
}

.refresh-btn.loading i {
  animation: spin 1s linear infinite;
}

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

/* Stats Cards Grid */
.analytics-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card-analytics {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 20px;
  transition: box-shadow 0.2s;
}

.stat-card-analytics:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.stat-card-analytics .stat-label {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat-card-analytics .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 4px;
}

.stat-card-analytics .stat-change {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

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

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

.stat-change.neutral {
  color: #6b7280;
}

/* Quota Cards Row */
.quota-cards-row {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.quota-cards-row .quota-card {
  flex: 1;
  margin-bottom: 0;
}

/* Quota Bar */
.quota-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
}

.quota-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.quota-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: #1a1a1a;
}

.quota-header .quota-text {
  font-size: 14px;
  color: #6b7280;
}

.quota-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.quota-fill.warning {
  background: linear-gradient(90deg, #f59e0b 0%, #ef4444 100%);
}

.quota-fill.danger {
  background: #ef4444;
}

.quota-fill.exceeded {
  background: #ef4444;
  animation: quotaPulse 1.5s ease-in-out infinite;
}

@keyframes quotaPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* AI Quota Card */
.ai-quota-card .ai-quota-fill {
  background: linear-gradient(90deg, #8b5cf6 0%, #a855f7 100%);
}

.ai-quota-card .ai-quota-fill.warning {
  background: linear-gradient(90deg, #f59e0b 0%, #ef4444 100%);
}

.ai-quota-card .ai-quota-fill.danger {
  background: #ef4444;
}

.ai-quota-card .ai-quota-fill.exceeded {
  background: #ef4444;
  animation: quotaPulse 1.5s ease-in-out infinite;
}

.ai-quota-card.exceeded {
  border-color: #fca5a5;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.1), 0 4px 12px rgba(220, 38, 38, 0.08);
}

/* AI card locked state (free plan) */
.ai-quota-card.ai-locked {
  opacity: 0.6;
  border-color: rgba(139, 92, 246, 0.2);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.03) 0%, rgba(168, 85, 247, 0.03) 100%);
}
.ai-quota-card.ai-locked .quota-header h3 {
  color: #7c3aed;
}
.ai-quota-card.ai-locked .quota-text {
  color: #7c3aed;
  font-size: 0.75rem;
  font-style: italic;
}
.ai-quota-card.ai-locked .quota-bar {
  background: rgba(139, 92, 246, 0.08);
}

/* Exceeded banner inside hourly quota card */
.quota-exceeded-banner {
  margin-top: 14px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border: 1px solid #fecaca;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.exceeded-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #991b1b;
}

.exceeded-info i {
  color: #dc2626;
  font-size: 15px;
  flex-shrink: 0;
}

.exceeded-info strong {
  font-variant-numeric: tabular-nums;
}

.exceeded-upgrade-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #dc2626;
  color: white;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.2s, transform 0.15s;
}

.exceeded-upgrade-cta:hover {
  background: #b91c1c;
  transform: translateY(-1px);
}

.exceeded-upgrade-cta i {
  font-size: 11px;
}

/* Hourly card in exceeded state */
.hourly-quota-card.exceeded {
  border-color: #fca5a5;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.1), 0 4px 12px rgba(220, 38, 38, 0.08);
}

@media (max-width: 600px) {
  .quota-exceeded-banner {
    flex-direction: column;
    text-align: center;
  }
}

/* Charts Section */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (min-width: 1200px) {
  .charts-grid.two-col {
    grid-template-columns: 2fr 1fr;
  }
}

.chart-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 20px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.chart-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: #1a1a1a;
}

.chart-actions {
  display: flex;
  gap: 8px;
}

.chart-btn {
  padding: 6px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.chart-btn:hover {
  background: #f9fafb;
}

.chart-btn.active {
  background: #1a1a1a;
  color: white;
  border-color: #1a1a1a;
}

.chart-container {
  position: relative;
  height: 300px;
}

.chart-container canvas {
  max-height: 100%;
}

/* Response Code Breakdown */
.breakdown-section {
  margin-top: 24px;
}

.breakdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e5e7eb;
}

.breakdown-header span {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.breakdown-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.breakdown-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
}

.breakdown-item:last-child {
  border-bottom: none;
}

.breakdown-checkbox {
  width: 16px;
  height: 16px;
  margin-right: 12px;
  accent-color: #667eea;
}

.breakdown-color {
  width: 4px;
  height: 24px;
  border-radius: 2px;
  margin-right: 12px;
}

.breakdown-color.success { background: #4361ee; }
.breakdown-color.error-4xx { background: #f59e0b; }
.breakdown-color.error-5xx { background: #ef4444; }

.breakdown-label {
  font-size: 14px;
  color: #1a1a1a;
  font-weight: 500;
  flex: 1;
}

.breakdown-value {
  font-size: 14px;
  color: #1a1a1a;
  font-weight: 600;
}

/* Filter input */
.filter-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.filter-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Success Rate Card */
.success-rate-card {
  text-align: center;
  padding: 24px;
}

.success-rate-value {
  font-size: 48px;
  font-weight: 700;
  color: #10b981;
  margin-bottom: 8px;
}

.success-rate-label {
  font-size: 14px;
  color: #6b7280;
}

.success-rate-chart {
  height: 150px;
  margin-top: 20px;
}

/* Loading State */
.analytics-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #6b7280;
}

.analytics-loading i {
  font-size: 32px;
  margin-bottom: 16px;
  animation: spin 1s linear infinite;
}

/* Empty State */
.analytics-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: #6b7280;
  text-align: center;
}

.analytics-empty i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.analytics-empty h3 {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 8px 0;
}

.analytics-empty p {
  font-size: 14px;
  margin: 0;
  max-width: 300px;
}

/* Tabs */
.analytics-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 24px;
}

.analytics-tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: #6b7280;
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
}

.analytics-tab:hover {
  color: #1a1a1a;
}

.analytics-tab.active {
  color: #1a1a1a;
  border-bottom-color: #1a1a1a;
}

/* Sub-navigation */
.analytics-subnav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 24px;
  border-right: 1px solid #e5e7eb;
  min-width: 150px;
}

.subnav-item {
  padding: 8px 12px;
  font-size: 14px;
  color: #6b7280;
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s;
  cursor: pointer;
}

.subnav-item:hover {
  background: #f9fafb;
  color: #1a1a1a;
}

.subnav-item.active {
  background: #f3f4f6;
  color: #1a1a1a;
  font-weight: 500;
}

/* Layout with subnav */
.analytics-layout {
  display: flex;
  gap: 24px;
}

.analytics-main {
  flex: 1;
  min-width: 0;
}

/* Endpoint Table */
.endpoint-table {
  width: 100%;
  border-collapse: collapse;
}

.endpoint-table th,
.endpoint-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.endpoint-table th {
  font-size: 12px;
  color: #6b7280;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.endpoint-table td {
  font-size: 14px;
  color: #1a1a1a;
}

.endpoint-table tr:hover {
  background: #f9fafb;
}

.endpoint-name {
  font-family: 'Monaco', 'Menlo', monospace;
  font-size: 13px;
  color: #667eea;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .analytics-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .control-group {
    flex-wrap: wrap;
  }

  .control-select {
    flex: 1;
    min-width: 100px;
  }

  .refresh-btn {
    margin-left: 0;
  }

  .quota-cards-row {
    flex-direction: column;
  }

  .analytics-stats {
    grid-template-columns: 1fr 1fr;
  }

  .chart-container {
    height: 250px;
  }

  .analytics-layout {
    flex-direction: column;
  }

  .analytics-subnav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    padding-right: 0;
    padding-bottom: 12px;
  }
}

@media (max-width: 480px) {
  .analytics-stats {
    grid-template-columns: 1fr;
  }
}
