/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --error-color: #ef4444;
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --radius-md: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  line-height: 1.5;
}

/* App layout */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: var(--bg-primary);
  padding: 1.5rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

.header-content {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em;
}

.header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.sign-out-button {
  padding: 0.5rem 1rem;
  background-color: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.sign-out-button:hover {
  background-color: var(--bg-secondary);
  color: var(--error-color);
  border-color: var(--error-color);
}

.main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.footer {
  background-color: var(--bg-primary);
  padding: 2rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-top: auto;
}

.footer a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
}

.footer a:hover {
  color: var(--primary-color);
}

/* Upload form */
.upload-form {
  background-color: var(--bg-primary);
  padding: 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.upload-drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 2rem;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: var(--bg-secondary);
  position: relative;
}

.upload-drop-zone:hover:not(.dragging) {
  border-color: var(--primary-color);
  background-color: #eff6ff;
}

.upload-drop-zone.dragging {
  border-color: var(--primary-color);
  background-color: #dbeafe;
}

.file-input {
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  top: 0;
  left: 0;
}

.drop-hint {
  text-align: center;
  pointer-events: none;
}

.drop-hint p {
  color: var(--text-secondary);
  margin: 0.25rem 0;
}

.click-text {
  color: var(--primary-color);
  font-weight: 600;
}

.file-info {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-md);
  color: #166534;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-primary);
  font-size: 1rem;
  color: var(--text-primary);
  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 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
}

.analyze-button {
  width: 100%;
  padding: 1rem;
  background-color: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.analyze-button:hover:not(:disabled) {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.analyze-button:disabled {
  background-color: var(--text-secondary);
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Recent uploads */
.recent-uploads {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.recent-header h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.recent-list {
  display: grid;
  gap: 0.75rem;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background-color: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
}

.recent-item:hover {
  background-color: var(--bg-primary);
  border-color: var(--border-color);
  box-shadow: var(--shadow-sm);
}

.recent-filename {
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.recent-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.75rem;
}

.recent-type {
  background-color: var(--text-primary);
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
}

.recent-time {
  color: var(--text-secondary);
}

/* Loading State */
.loading-spinner {
  background-color: var(--bg-primary);
  padding: 4rem 2rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  text-align: center;
  border: 1px solid var(--border-color);
}

.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 1.5rem;
  border: 3px solid var(--bg-tertiary);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.progress-bar {
  width: 100%;
  max-width: 320px;
  height: 6px;
  background-color: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin: 1.5rem auto;
}

.progress-fill {
  height: 100%;
  background-color: var(--primary-color);
  transition: width 0.3s ease;
}

/* --- Results Dashboard Styles --- */

.video-preview-container {
  margin-bottom: 2rem;
  background-color: black;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.analysis-video-player {
  width: 100%;
  height: 100%;
  max-height: 500px;
  display: block;
}

.results-container {
  background-color: var(--bg-primary);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.results-header h2 {
  font-size: 1.5rem;
  color: var(--text-primary);
  font-weight: 700;
}

.results-meta {
  display: flex;
  gap: 0.75rem;
}

.meta-tag {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Validation Banner */
.validation-banner {
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  margin-bottom: 2rem;
}

.validation-banner.pass {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}

.validation-banner.fail, .validation-banner.warning {
  background-color: #fff7ed;
  border: 1px solid #fed7aa;
  color: #c2410c;
}

.validation-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.validation-list {
  margin-top: 0.5rem;
  padding-left: 1.5rem;
  font-size: 0.875rem;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.metric-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 120px;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
  border-color: var(--primary-color);
}

.metric-card.highlight {
  background: linear-gradient(to bottom right, #eff6ff, #ffffff);
  border-color: #bfdbfe;
}

.metric-card-header {
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
}

.metric-card-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.info-icon {
  font-size: 0.75rem;
  color: var(--primary-color);
  cursor: help;
  opacity: 0.6;
}

.info-icon:hover {
  opacity: 1;
}

.metric-card-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.25rem;
}

.value-text {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.value-unit {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Detailed Breakdown */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-color);
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.detail-item {
  background-color: var(--bg-tertiary);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.detail-label {
  color: var(--text-secondary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-value {
  color: var(--text-primary);
  font-weight: 600;
}

/* Actions */
.actions-bar {
  display: flex;
  justify-content: center;
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
}

.download-button.primary {
  background-color: var(--text-primary);
  color: white;
  padding: 0.875rem 2rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.download-button.primary:hover {
  background-color: black;
  transform: translateY(-1px);
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-fade-in { animation: fadeIn 0.4s ease-out forwards; }

/* Responsive adjustments */
@media (max-width: 640px) {
  .header-content { flex-direction: column; text-align: center; gap: 1rem; }
  .user-info { flex-direction: column; width: 100%; }
  .sign-out-button { width: 100%; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .results-container { padding: 1.5rem; }
  .results-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
}

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