:root {
  --navy: #0b3b75;
  --navy-2: #134f96;
  --accent: #f28c00;
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1b2433;
  --muted: #667085;
  --line: #dde3ec;
  --radius: 14px;
  --g-A: #1f9d55;
  --g-B: #5fa83a;
  --g-C: #d99a00;
  --g-D: #e8590c;
  --g-E: #d62828;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Pretendard', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

/* ---------- 헤더 · 탭 ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: #fff;
  box-shadow: 0 2px 10px rgba(11, 59, 117, 0.25);
}
.app-header .logo { width: 40px; height: 40px; border-radius: 10px; }
.app-header h1 { margin: 0; font-size: 18px; letter-spacing: -0.3px; }
.app-header p { margin: 0; font-size: 12.5px; opacity: 0.85; }

main { max-width: 640px; margin: 0 auto; padding: 14px 14px 0; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar button {
  flex: 1;
  border: 0;
  background: none;
  padding: 8px 0 10px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: 0.6; }
.tabbar button.on { color: var(--navy); font-weight: 700; }
.tabbar button.on span { filter: none; opacity: 1; }

/* ---------- 카드 · 폼 ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 16px;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 12px;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; min-width: 0; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field small { font-weight: 400; }
input, select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px; /* iOS 확대 방지 */
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--navy-2); outline-offset: -1px; }

.gps-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13.5px; }
.muted { color: var(--muted); }
.btn-link { border: 0; background: none; color: var(--navy-2); font: inherit; font-weight: 700; padding: 6px 0; white-space: nowrap; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button {
  flex: 1;
  border: 0;
  background: #fff;
  padding: 10px 0;
  font: inherit;
  color: var(--muted);
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.on { background: var(--navy); color: #fff; font-weight: 700; }

.settings { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* ---------- 버튼 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-lg { min-height: 58px; font-size: 17px; width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { filter: brightness(0.93); }
.btn-secondary { background: #fff; color: var(--navy); border-color: #c7d3e3; }
.btn-danger { background: #fff; color: var(--g-E); border-color: #f1b8b8; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 13px; background: #fff; color: var(--navy); border-color: #c7d3e3; }
.btn-icon { border: 0; background: none; font-size: 20px; padding: 4px 8px; color: var(--muted); }

.capture { display: grid; gap: 10px; }

/* ---------- 결과 ---------- */

.viewer { position: relative; border-radius: 10px; overflow: hidden; background: #1b2433; }
.viewer canvas { display: block; width: 100%; height: auto; }
#overlayCanvas { position: absolute; inset: 0; }
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(11, 30, 60, 0.55);
  color: #fff;
  font-weight: 700;
}
.spinner {
  width: 38px; height: 38px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; }
.chip.off { opacity: 0.4; text-decoration: line-through; }
.legend-hint { font-size: 12px; color: var(--muted); }

.grade {
  --g: var(--g-A);
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 12px 0;
  padding: 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--g) 9%, #fff);
  border: 1.5px solid color-mix(in srgb, var(--g) 45%, #fff);
}
.grade-A { --g: var(--g-A); }
.grade-B { --g: var(--g-B); }
.grade-C { --g: var(--g-C); }
.grade-D { --g: var(--g-D); }
.grade-E { --g: var(--g-E); }
.grade-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 64px; height: 64px;
  border-radius: 14px;
  background: var(--g);
  color: #fff;
  font-size: 36px;
  font-weight: 800;
}
.grade-info { flex: 1; min-width: 0; }
.grade-title { font-size: 17px; font-weight: 800; }
.grade-title small { font-weight: 600; color: var(--muted); }
.grade-desc { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.meter { height: 8px; border-radius: 99px; background: rgba(0, 0, 0, 0.08); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--g); border-radius: 99px; }
.grade-score { font-size: 13px; margin-top: 4px; }
.grade-score b { color: var(--g); font-size: 15px; }

.defect-list { list-style: none; margin: 0; padding: 0; }
.defect-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}
.sev { font-size: 18px; }
.d-main { flex: 1; min-width: 0; }
.d-head { font-size: 15px; }
.conf { font-size: 12px; color: var(--muted); margin-left: 4px; background: #f1f4f8; padding: 1px 7px; border-radius: 99px; }
.d-sum { font-size: 13px; color: #475467; margin: 2px 0 6px; }
.bar { height: 6px; border-radius: 99px; background: #edf0f4; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.s-high { background: var(--g-E); }
.s-mid { background: var(--g-C); }
.s-low { background: var(--g-A); }
.d-score { text-align: right; min-width: 52px; }
.d-score b { display: block; font-size: 18px; }
.d-score small { font-size: 11px; color: var(--muted); }

.none-found { padding: 10px 0; font-weight: 600; }
.missing { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

.recos { margin-top: 12px; padding: 12px 14px; background: #f5f8fc; border-radius: 10px; }
.recos h4 { margin: 0 0 6px; font-size: 14px; }
.recos ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.recos li + li { margin-top: 3px; }

.meta-line { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions .btn { flex: 1; }
.disclaimer { font-size: 12.5px; color: var(--muted); margin: 0 4px 18px; }

/* ---------- 이력 ---------- */

.history-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 2px 10px; }
.history-head h2 { margin: 0; font-size: 18px; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
  cursor: pointer;
}
.history-list img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.h-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.h-main b, .h-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-main span { font-size: 13px; color: #475467; }
.h-main small { font-size: 12px; color: var(--muted); }
.h-grade { flex: none; text-align: center; width: 48px; padding: 4px 0; border-radius: 10px; background: var(--g); color: #fff; }
.h-grade b { display: block; font-size: 20px; line-height: 1.1; }
.h-grade small { font-size: 11px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

dialog {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  border: 0;
  border-radius: 16px;
  padding: 16px;
}
dialog::backdrop { background: rgba(11, 20, 40, 0.5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h3 { margin: 0; font-size: 17px; }
.detail-img { width: 100%; border-radius: 10px; margin-top: 8px; }
.detail-meta { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 28, 45, 0.92);
  color: #fff;
  font-size: 14px;
}

/* ---------- 보고서(인쇄 전용) ---------- */

.report { display: none; }

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; padding: 0; font-size: 11pt; }
  body > *:not(.report) { display: none !important; }
  .report { display: block; }
  .report h1 { font-size: 20pt; margin: 0; text-align: center; }
  .r-sub { text-align: center; color: #555; margin: 2px 0 12px; font-size: 9pt; }
  .report table { width: 100%; border-collapse: collapse; }
  .report th, .report td { border: 1px solid #999; padding: 5px 8px; font-size: 10pt; text-align: left; }
  .report th { background: #eef2f7; width: 13%; white-space: nowrap; }
  .r-body { display: grid; grid-template-columns: 45% 1fr; gap: 14px; margin-top: 12px; align-items: start; }
  .r-body img { width: 100%; border: 1px solid #ccc; }
  .r-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 9pt; margin-top: 8px; }
  .r-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
  .report .grade, .report .defect-list li, .report .recos { break-inside: avoid; }
  .report * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .r-foot { font-size: 9pt; color: #555; margin-top: 14px; }
  .sign { margin-top: 10px; }
  .sign td { height: 36px; }
}
