/* Vehicle Photo App v2 - Apple-native design language */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --blue: #007AFF;
  --blue-dark: #0051D5;
  --green: #34C759;
  --green-dark: #248A3D;
  --red: #FF3B30;
  --orange: #FF9500;
  --gray1: #8E8E93;
  --gray2: #AEAEB2;
  --gray3: #C7C7CC;
  --gray4: #D1D1D6;
  --gray5: #E5E5EA;
  --gray6: #F2F2F7;
  --label: #000000;
  --label-secondary: #3C3C43;
  --label-tertiary: #3C3C4399;
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --separator: #C6C6C8;
  --radius-sm: 10px;
  --radius: 12px;
  --radius-lg: 16px;
}

html, body {
  height: 100%;
  font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--label);
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}
/* Lock page scroll when camera screen is active */
body.camera-active {
  overflow: hidden;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  padding: 0 20px 20px;
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}
/* Camera screen: locked to viewport, no scrolling on the screen itself */
#camera-screen.active {
  min-height: 0;
}

/* ===== HOME SCREEN ===== */
#home-screen {
  padding-top: max(20px, env(safe-area-inset-top));
}

.home-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 6px;
  margin-top: 10px;
}
.home-logo img {
  width: 150px;
  height: 150px;
  object-fit: contain;
}

.app-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.app-subtitle {
  font-size: 15px;
  color: var(--label-tertiary);
  text-align: center;
  margin-bottom: 28px;
  font-weight: 400;
}

.btn-new-vehicle {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: -0.2px;
}
.btn-new-vehicle:active {
  background: var(--blue-dark);
  transform: scale(0.98);
}

/* History section */
.history-section {
  margin-top: 28px;
}
.history-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 4px;
  color: var(--label-tertiary);
}
.history-list {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-card {
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 0.5px solid var(--gray5);
}
.history-card:last-child {
  border-bottom: none;
}
.history-car-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.history-vin {
  font-size: 13px;
  color: var(--gray1);
  margin-top: 2px;
}
.history-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.history-status.uploading {
  background: #FFF3CD;
  color: #92400e;
}
.history-status.done {
  background: rgba(52, 199, 89, 0.12);
  color: var(--green-dark);
}
.history-status.error {
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
}
.history-empty {
  text-align: center;
  color: var(--gray1);
  font-size: 15px;
  padding: 40px 0;
  background: var(--card);
  border-radius: var(--radius);
}

/* ===== VIN ENTRY SCREEN ===== */
#vin-screen {
  padding-top: 80px;
  align-items: center;
}

.vin-label {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

.vin-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  outline: none;
  letter-spacing: 3px;
  transition: box-shadow 0.2s;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: 0 0 0 0.5px var(--gray4);
}
.vin-input:focus {
  box-shadow: 0 0 0 2px var(--blue);
}
.vin-input.invalid {
  box-shadow: 0 0 0 2px var(--red);
}
.vin-input::placeholder {
  color: var(--gray3);
  letter-spacing: 1px;
  font-weight: 400;
}

.vin-hint {
  font-size: 13px;
  color: var(--gray1);
  margin-top: 10px;
}

.vin-error {
  font-size: 14px;
  color: var(--red);
  margin-top: 10px;
  min-height: 20px;
  font-weight: 500;
}

.btn-row {
  display: flex;
  gap: 12px;
  width: 100%;
  margin-top: 28px;
}

.btn-back {
  flex: 1;
  padding: 14px;
  font-size: 17px;
  font-weight: 400;
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--blue);
  cursor: pointer;
  box-shadow: 0 0 0 0.5px var(--gray4);
  transition: all 0.15s ease;
}
.btn-back:active {
  background: var(--gray6);
  transform: scale(0.98);
}

.btn-start {
  flex: 2;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-start:disabled {
  background: var(--gray3);
  cursor: not-allowed;
}
.btn-start:not(:disabled):active {
  background: var(--blue-dark);
  transform: scale(0.98);
}

/* ===== CAMERA SCREEN ===== */
#camera-screen {
  padding: 10px 16px 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  min-height: 0;
  justify-content: flex-start;
}

.camera-header {
  text-align: center;
  margin-bottom: 6px;
  flex-shrink: 0;
  padding-top: max(6px, env(safe-area-inset-top));
}
.camera-car-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.camera-vin {
  font-size: 13px;
  color: var(--gray1);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.camera-match-status {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
  padding: 3px 12px;
  border-radius: 20px;
  display: inline-block;
}
.camera-match-status.found {
  background: rgba(52, 199, 89, 0.12);
  color: var(--green-dark);
}
.camera-match-status.not-found {
  background: rgba(255, 149, 0, 0.12);
  color: #C27800;
}

/* Top section: counter + grid (scrollable, takes remaining space) */
.camera-top-section,
.camera-center-section {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  gap: 16px;
}

/* Photo counter */
.photo-counter {
  text-align: center;
  font-size: 44px;
  font-weight: 800;
  color: var(--blue);
  margin: 6px 0 0;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.photo-counter-label {
  text-align: center;
  font-size: 13px;
  color: var(--gray1);
  margin-bottom: 8px;
  font-weight: 500;
}

/* Photo grid */
.photo-grid {
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(6, 1fr);
}
.photo-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.photo-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
.photo-grid.cols-6 { grid-template-columns: repeat(6, 1fr); }
.photo-grid.cols-7 { grid-template-columns: repeat(7, 1fr); }
.photo-grid.cols-8 { grid-template-columns: repeat(8, 1fr); }

.photo-thumb {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: var(--gray5);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hidden file input */
#camera-input {
  display: none;
}

/* ===== BOTTOM BUTTONS (always pinned to bottom) ===== */
.camera-bottom-buttons {
  flex-shrink: 0;
  padding: 12px 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.btn-capture {
  width: 100%;
  padding: 18px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  cursor: pointer;
  letter-spacing: -0.2px;
  transition: all 0.12s ease;
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}
.btn-capture:active {
  background: var(--blue-dark);
  transform: scale(0.97);
  box-shadow: 0 1px 4px rgba(0, 122, 255, 0.2);
}

.btn-finish {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--green);
  color: white;
  cursor: pointer;
  transition: all 0.12s ease;
}
.btn-finish:active {
  background: var(--green-dark);
  transform: scale(0.97);
}

/* ===== UPLOAD PROGRESS OVERLAY ===== */
.upload-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.upload-overlay.active {
  display: flex;
}

.upload-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  text-align: center;
  width: calc(100% - 48px);
  max-width: 360px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
}

.upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
  line-height: 1;
}

.upload-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 20px;
}

.progress-bar-container {
  width: 100%;
  height: 10px;
  background: var(--gray5);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--blue);
  border-radius: 5px;
  transition: width 0.3s ease;
}

.upload-subtext {
  font-size: 15px;
  color: var(--label-secondary);
  font-weight: 500;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}

.upload-warning {
  font-size: 13px;
  color: var(--red);
  font-weight: 600;
  padding: 10px 16px;
  background: rgba(255, 59, 48, 0.08);
  border-radius: var(--radius-sm);
}

.btn-upload-done {
  width: 100%;
  padding: 14px;
  margin-top: 20px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: white;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-upload-done:active {
  background: var(--blue-dark);
  transform: scale(0.98);
}

.btn-retry-failed {
  width: 100%;
  padding: 14px;
  margin-top: 10px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--orange);
  color: white;
  cursor: pointer;
}

.btn-retry-failed:active {
  background: #E08600;
  transform: scale(0.98);
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.loading-overlay.active {
  display: flex;
}
.loading-box {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray5);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-text {
  font-size: 15px;
  color: var(--label-secondary);
  font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 380px) {
  .photo-counter { font-size: 36px; }
  .home-logo img { width: 120px; height: 120px; }
  .app-title { font-size: 24px; }
}

/* iOS safe areas */
@supports (padding: env(safe-area-inset-bottom)) {
  .camera-bottom-buttons {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* Touch handling */
html {
  touch-action: manipulation;
}
