/* ─── Calibration Page ───────────────────────────────────── */

/* Page shell */
.calib-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ── Navigation ─────────────────────────────────────────── */
.calib-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.calib-nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.calib-nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}

.calib-nav-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
  line-height: 1;
}

.calib-nav-skip {
  background: none;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.2s;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.calib-nav-skip:hover { color: var(--text-muted); }

/* ── Body layout ─────────────────────────────────────────── */
.calib-body {
  display: flex;
  gap: 32px;
  padding: 32px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  align-items: flex-start;
}

/* ── Camera column (left) ────────────────────────────────── */
.calib-camera-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calib-camera-frame {
  position: relative;
  background: #1c1917;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  max-height: 480px;
  border: 2px solid var(--border);
}

#calib-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Mirror so user sees natural reflection */
  transform: scaleX(-1);
}

/* Camera loading/error overlay */
.calib-cam-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #78716c;
  background: #1c1917;
  font-size: 13px;
}

/* Spinner */
.calib-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Angle HUD (bottom of camera frame) ─────────────────── */
.calib-angle-hud {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.calib-angle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #ffffff;
}

.calib-angle-label {
  width: 32px;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.calib-angle-bar-wrap {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  position: relative;
  overflow: visible;
}

/* Center tick mark */
.calib-angle-center {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: rgba(255, 255, 255, 0.5);
  transform: translateX(-50%);
  border-radius: 1px;
}

/* Fill bar — JS sets left/width to show deviation from center */
.calib-angle-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--primary);
  border-radius: 3px;
  transition: left 0.1s linear, width 0.1s linear;
  left: 50%;
  width: 0;
}

.calib-angle-val {
  width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 600;
}

/* ── Control column (right) ──────────────────────────────── */
.calib-control-col {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}

/* ── Loading step panel ──────────────────────────────────── */
.calib-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 32px 24px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex: 1;
  justify-content: center;
  min-height: 360px;
}

.calib-step h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.3px;
}

.calib-step > p {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

/* Inline loader (loading step) */
.calib-loader {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Main calibration panel ──────────────────────────────── */
.calib-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px 20px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex: 1;
}

.calib-main-header { margin-bottom: 4px; }
.calib-main-header h2 {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 4px;
  letter-spacing: -0.3px;
}
.calib-main-header p {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* ── Calibration cards ───────────────────────────────────── */
.calib-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s;
}
.calib-card:has(.status-measuring) { border-color: var(--primary); }

.calib-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.calib-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.calib-card-icon { font-size: 22px; flex-shrink: 0; line-height: 1; }
.calib-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.calib-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.calib-card-desc { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }

.calib-card-action { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ── Status badge ────────────────────────────────────────── */
.calib-status-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
  background: #f3f4f6;
  color: var(--text-muted);
}
.calib-status-badge.status-measuring { background: #fef3c7; color: #d97706; }
.calib-status-badge.status-done      { background: #dcfce7; color: #16a34a; }
.calib-status-badge.status-failed    { background: #fee2e2; color: #dc2626; }

/* ── Tags ────────────────────────────────────────────────── */
.calib-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
}
.calib-tag-required { background: #fee2e2; color: #dc2626; }
.calib-tag-optional { background: #f3f4f6; color: var(--text-muted); }

/* ── Card action button ──────────────────────────────────── */
.btn-calib-do {
  padding: 6px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  font-family: inherit;
  white-space: nowrap;
}
.btn-calib-do:hover:not(:disabled) { background: var(--primary-dark); }
.btn-calib-do:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Progress bar at bottom of card ─────────────────────── */
.calib-card-progress { height: 4px; background: #f3f4f6; }
.calib-card-progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* ── Buttons ─────────────────────────────────────────────── */
.calib-start-btn {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(232, 93, 4, 0.3);
  font-family: inherit;
  margin-top: 4px;
}
.calib-start-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(232, 93, 4, 0.38);
}
.calib-start-btn:active:not(:disabled) { transform: translateY(0); }
.calib-start-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none;
}

.calib-skip-link {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--text-light);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-family: inherit;
  transition: color 0.2s;
  text-align: center;
}
.calib-skip-link:hover { color: var(--text-muted); }

/* ── Responsive: stack on mobile ─────────────────────────── */
@media (max-width: 780px) {
  .calib-body {
    flex-direction: column;
    padding: 16px;
    gap: 16px;
  }

  .calib-control-col {
    width: 100%;
    align-self: auto;
  }

  .calib-step {
    min-height: 0;
    padding: 24px 20px;
  }
}

@media (max-width: 480px) {
  .calib-nav { padding: 0 16px; }
  .calib-nav-title { display: none; }
}
