*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #1a56db;
  --blue-dark: #1e3a5f;
  --blue-light: #dbeafe;
  --blue-glow: #3b82f6;
  --green: #059669;
  --green-light: #d1fae5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;
  --toggle-h: 52px;
  --footer-h: 80px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  z-index: 1;
}
.screen.active {
  display: flex;
  z-index: 10;
}

/* ======================== LOADING SCREEN ======================== */

#screen-loading {
  background: #0a0e27;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.loading-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.grid-overlay {
  position: absolute;
  inset: -50%;
  background-image:
    linear-gradient(rgba(59,130,246,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,130,246,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: grid-drift 20s linear infinite;
}

@keyframes grid-drift {
  to { transform: translate(40px, 40px); }
}

.scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--blue-glow) 50%, transparent 100%);
  opacity: 0.6;
  animation: scan 3s ease-in-out infinite;
}

@keyframes scan {
  0%, 100% { top: -2px; opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.6; }
  50% { top: 100%; }
}

.loading-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.loading-rings {
  position: relative;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid transparent;
}

.ring-outer {
  inset: 0;
  border-top-color: var(--blue-glow);
  border-right-color: rgba(59,130,246,0.3);
  animation: spin 2s linear infinite;
}

.ring-inner {
  inset: 12px;
  border-bottom-color: var(--blue-glow);
  border-left-color: rgba(59,130,246,0.2);
  animation: spin 1.5s linear infinite reverse;
}

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

.loading-icon {
  width: 48px;
  height: 48px;
  color: var(--blue-glow);
  opacity: 0;
  animation: icon-in 0.6s ease-out 0.3s forwards;
}

@keyframes icon-in {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

.check-anim { stroke-dasharray: 20; stroke-dashoffset: 20; }
.c1 { animation: draw 0.4s ease-out 1.2s forwards; }
.c2 { animation: draw 0.4s ease-out 1.8s forwards; }
.c3 { animation: draw 0.4s ease-out 2.4s forwards; }

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

.loading-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 6px;
  color: #fff;
  opacity: 0;
  animation: fade-up 0.5s ease-out 0.5s forwards;
}

.loading-subtitle {
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
  opacity: 0;
  animation: fade-up 0.5s ease-out 0.7s forwards;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.loading-steps {
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 240px;
}

.loading-step {
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.3s, transform 0.3s;
}

.loading-step.visible {
  opacity: 1;
  transform: translateX(0);
}

.loading-step.done .step-spinner { display: none; }
.loading-step.done .step-check { display: block; }

.step-indicator {
  width: 20px;
  height: 20px;
  position: relative;
  flex-shrink: 0;
}

.step-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(59,130,246,0.2);
  border-top-color: var(--blue-glow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.step-check {
  display: none;
  width: 20px;
  height: 20px;
}

.step-text {
  font-size: 14px;
  color: rgba(255,255,255,0.7);
}

.loading-step.done .step-text {
  color: rgba(255,255,255,0.9);
}

.loading-ready {
  margin-top: 32px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--green);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.5s, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.loading-ready.visible {
  opacity: 1;
  transform: scale(1);
}

#screen-loading.exit {
  animation: screen-up 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes screen-up {
  to { transform: translateY(-100%); opacity: 0; }
}

/* ======================== HEADER ======================== */

.header {
  height: var(--header-h);
  padding: 0 16px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--blue);
  color: #fff;
  flex-shrink: 0;
  z-index: 5;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-badge {
  background: rgba(255,255,255,0.2);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
}

.header-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-driver {
  font-size: 14px;
  font-weight: 600;
}

.header-date {
  font-size: 11px;
  opacity: 0.75;
}

.header-back {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  display: flex;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
}

.type-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 20 20'%3E%3Cpath d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

/* ======================== VEHICLE TOGGLE ======================== */

.vehicle-toggle {
  padding: 10px 16px 6px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 4;
}

.toggle-track {
  position: relative;
  display: flex;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.toggle-pill {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  z-index: 2;
  transition: color 0.25s;
  border-radius: 8px;
}

.toggle-pill.active {
  color: #fff;
}

.toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--blue);
  border-radius: 8px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.toggle-slider.right {
  transform: translateX(100%);
}

/* ======================== INSPECTION BODY ======================== */

.inspection-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px;
  padding-bottom: calc(var(--footer-h) + var(--safe-bottom) + 16px);
}

.section {
  margin-bottom: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.section-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-count {
  font-size: 12px;
  color: var(--text-muted);
}

.section-chevron {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: transform 0.25s;
}

.section.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.section-items {
  border-top: 1px solid var(--border);
}

.section.collapsed .section-items {
  display: none;
}

/* ======================== INSPECTION ITEMS ======================== */

.item {
  border-bottom: 1px solid var(--border);
}

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

.item-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.item-row:active {
  background: rgba(0,0,0,0.02);
}

.item-status {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  background: var(--surface);
  position: relative;
}

.item-status svg {
  width: 16px;
  height: 16px;
  opacity: 0;
  transition: opacity 0.2s;
  position: absolute;
}

.item.pass .item-status {
  border-color: var(--green);
  background: var(--green-light);
}

.item.pass .item-status svg.icon-check {
  opacity: 1;
  color: var(--green);
}

.item.pass .item-status svg.icon-x {
  opacity: 0;
}

.item.defect .item-status {
  border-color: var(--red);
  background: var(--red-light);
}

.item.defect .item-status svg.icon-x {
  opacity: 1;
  color: var(--red);
}

.item.defect .item-status svg.icon-check {
  opacity: 0;
}

.item-name {
  flex: 1;
  font-size: 15px;
  color: var(--text);
}

.item.defect .item-name {
  color: var(--red);
  font-weight: 500;
}

.item-defect-btn {
  padding: 5px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.item.defect .item-defect-btn {
  border-color: var(--red);
  background: var(--red-light);
  color: var(--red);
}

/* ======================== DEFECT DETAIL ======================== */

.defect-detail {
  display: none;
  padding: 0 16px 14px;
  animation: detail-in 0.25s ease-out;
}

.item.defect .defect-detail {
  display: block;
}

@keyframes detail-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.defect-notes {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  min-height: 60px;
  color: var(--text);
  transition: border-color 0.2s;
}

.defect-notes:focus {
  outline: none;
  border-color: var(--blue);
}

.defect-notes::placeholder {
  color: var(--text-muted);
}

.defect-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.btn-camera {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.btn-camera:active {
  background: var(--blue-light);
}

.btn-camera svg {
  width: 18px;
  height: 18px;
}

.btn-camera input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.photo-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.photo-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ======================== FOOTER ======================== */

.inspection-footer {
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-primary {
  width: 100%;
  padding: 15px 24px;
  border: none;
  border-radius: var(--radius);
  background: var(--blue);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, opacity 0.2s, transform 0.1s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary svg {
  width: 20px;
  height: 20px;
}

.btn-submit {
  background: var(--green);
}

.btn-submit:active {
  background: #047857;
}

/* ======================== REVIEW ======================== */

#screen-review {
  background: var(--bg);
}

#screen-review .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.review-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(var(--footer-h) + var(--safe-bottom) + 16px);
}

.review-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.review-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.review-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.review-row:last-child {
  border-bottom: none;
}

.review-row span:first-child {
  color: var(--text-secondary);
}

.review-row span:last-child,
.review-row strong {
  font-weight: 500;
  color: var(--text);
}

.review-defect-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.review-defect-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--red);
  margin-bottom: 4px;
}

.review-defect-category {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.review-defect-notes {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.review-defect-photos {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.review-defect-photos img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.no-defects {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 0;
  text-align: center;
}

.no-defects p {
  font-size: 16px;
  font-weight: 600;
  color: var(--green);
}

.no-defects span {
  font-size: 13px;
  color: var(--text-muted);
}

.input-field {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--text);
  transition: border-color 0.2s;
  background: var(--surface);
}

.input-field:focus {
  outline: none;
  border-color: var(--blue);
}

.input-field::placeholder {
  color: var(--text-muted);
}

textarea.input-field {
  resize: none;
}

.cert-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

.signature-wrapper {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fafafa;
}

#signature-canvas {
  width: 100%;
  height: 150px;
  display: block;
  touch-action: none;
}

.sig-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
}

/* ======================== SUBMITTING ======================== */

#screen-submitting {
  background: var(--blue);
  justify-content: center;
  align-items: center;
  color: #fff;
}

.submit-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.submit-spinner {
  position: relative;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-ring {
  position: absolute;
  inset: 0;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.submit-icon {
  color: #fff;
}

.submit-content h2 {
  font-size: 20px;
  font-weight: 600;
}

.submit-status {
  font-size: 14px;
  opacity: 0.8;
}

/* ======================== CONFIRMED ======================== */

#screen-confirmed {
  background: var(--surface);
  justify-content: center;
  align-items: center;
}

.confirmed-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.confirmed-check {
  margin-bottom: 8px;
}

.confirmed-circle {
  stroke-dasharray: 226;
  stroke-dashoffset: 226;
  animation: circle-draw 0.6s ease-out 0.2s forwards;
}

.confirmed-tick {
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: tick-draw 0.4s ease-out 0.7s forwards;
}

@keyframes circle-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes tick-draw {
  to { stroke-dashoffset: 0; }
}

.confirmed-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  opacity: 0;
  animation: fade-up 0.4s ease-out 0.9s forwards;
}

.confirmed-card {
  width: 100%;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px;
  opacity: 0;
  animation: fade-up 0.4s ease-out 1.1s forwards;
}

.confirmed-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.confirmed-row:last-child {
  border-bottom: none;
}

.confirmed-row span {
  color: var(--text-secondary);
}

.confirmed-row strong {
  color: var(--blue);
  font-size: 13px;
  font-family: monospace;
}

.btn-done {
  margin-top: 16px;
  opacity: 0;
  animation: fade-up 0.4s ease-out 1.3s forwards;
}

/* ======================== PHOTO MODAL ======================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  animation: fade-in 0.2s;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  position: relative;
  max-width: 90%;
  max-height: 80%;
  z-index: 1;
  animation: modal-in 0.25s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: var(--radius);
}

.modal-close {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ======================== SEVERITY PILLS ======================== */

.severity-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.severity-pill {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: none;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.severity-pill.selected-minor {
  border-color: var(--amber);
  background: var(--amber-light);
  color: var(--amber);
}

.severity-pill.selected-major {
  border-color: var(--red);
  background: var(--red-light);
  color: var(--red);
}

/* ======================== UTILITIES ======================== */

@media (min-width: 480px) {
  .inspection-body, .review-body {
    max-width: 480px;
    margin: 0 auto;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --text: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border: #374151;
  }
  .signature-wrapper { background: #111827; }
  .type-select { color: #fff; }
}
