:root {
  --bg: #0f1420;
  --surface: #182238;
  --surface-2: #1f2c48;
  --text: #f2f5fa;
  --text-dim: #a9b4c7;
  --primary: #2f7bff;
  --primary-dark: #1e5fd6;
  --danger: #ff4d5e;
  --warning: #ffb020;
  --info: #3bd6ff;
  --success: #3bd67a;
  --border: #2b3550;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

.app-root {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
  min-height: 100vh;
}

h1, h2, h3 { line-height: 1.25; margin: 1.2em 0 0.5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; color: var(--text-dim); }

p { margin: 0.5em 0; }

/* ---------- header / marca ---------- */
.app-header { text-align: center; padding: 8px 0 4px; }
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.6rem; font-weight: 700; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7a3bff);
  color: #fff; font-weight: 800;
}
.brand-tag { color: var(--text-dim); margin-top: 2px; font-size: 0.95rem; }

/* ---------- botoes ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 14px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  min-height: 48px; touch-action: manipulation;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-text { background: transparent; color: var(--text-dim); padding: 10px; }
.btn-lg { width: 100%; font-size: 1.08rem; padding: 16px; }
.btn-sm { padding: 9px 12px; font-size: 0.88rem; min-height: 38px; }
.btn-icon { background: transparent; border: none; color: var(--text-dim); font-size: 1.4rem; padding: 6px 10px; cursor: pointer; }
.hidden-input { display: none; }

.home-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }

/* ---------- inputs / formularios ---------- */
.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 12px 14px; font-size: 1rem;
  min-height: 46px;
}
.input:focus { outline: 2px solid var(--primary); }
.form { display: flex; flex-direction: column; gap: 14px; margin: 14px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.92rem; color: var(--text-dim); }
.field-inline { flex-direction: column; }
.field-checkbox { flex-direction: row; align-items: flex-start; gap: 10px; font-size: 0.95rem; }
.field-checkbox input { width: 22px; height: 22px; margin-top: 2px; flex-shrink: 0; }

/* ---------- avisos / caixas ---------- */
.notice-box {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--primary); border-radius: 10px;
  padding: 12px 14px; margin: 10px 0; font-size: 0.92rem; color: var(--text-dim);
}
.notice-privacy { border-left-color: var(--info); }
.notice-card { border-left-color: var(--warning); }
.disclaimer { font-size: 0.82rem; color: var(--text-dim); text-align: center; margin: 18px 0 6px; }
.error-box {
  background: #3a1420; border: 1px solid var(--danger); color: #ffd7db;
  border-radius: 10px; padding: 12px 14px; margin: 12px 0;
}

/* ---------- listagem de testes ---------- */
.search-wrap { display: flex; gap: 8px; margin: 12px 0; }
.search-wrap select { flex: 0 0 150px; }
.test-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.test-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer;
}
.test-card-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.test-card-sub { color: var(--text-dim); font-size: 0.85rem; margin-top: 4px; }
.badge { font-size: 0.72rem; padding: 3px 8px; border-radius: 20px; font-weight: 600; }
.badge-rascunho { background: #4a3a12; color: var(--warning); }
.badge-concluido { background: #123a24; color: var(--success); }
.empty-state { text-align: center; color: var(--text-dim); padding: 24px 0; }

.card-menu {
  position: absolute; z-index: 50; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.card-menu-item {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  background: none; border: none; color: var(--text); font-size: 0.95rem; cursor: pointer;
}
.card-menu-item:hover { background: rgba(255,255,255,0.06); }
.card-menu-item.danger { color: var(--danger); }

.backup-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 6px; }

/* ---------- progresso do wizard ---------- */
.progress-wrap { margin: 4px 0 18px; }
.progress-track { background: var(--surface); border-radius: 20px; height: 8px; overflow: hidden; }
.progress-bar { background: linear-gradient(90deg, var(--primary), #7a3bff); height: 100%; border-radius: 20px; transition: width 0.3s ease; }
.progress-label { font-size: 0.82rem; color: var(--text-dim); margin-top: 6px; }

.wizard-step { display: flex; flex-direction: column; }
.wizard-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.step-help { color: var(--text-dim); font-size: 0.9rem; }
.hint-text { color: var(--text-dim); font-size: 0.85rem; }

/* ---------- instrucoes / ilustracao ---------- */
.instructions { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.instructions summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.instructions ul { margin: 8px 0; padding-left: 20px; color: var(--text-dim); font-size: 0.9rem; }
.instructions li { margin: 4px 0; }
.positioning-illustration { width: 100%; height: auto; border-radius: 10px; margin-top: 8px; }

/* ---------- foto ---------- */
.photo-preview-wrap { display: flex; justify-content: center; margin: 12px 0; }
.photo-preview { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); }
.capture-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

/* ---------- editor de pontos (canvas) ---------- */
.editor-host {
  position: relative; width: 100%; height: 62vh; min-height: 340px;
  background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); margin: 10px 0;
  touch-action: none;
}
.point-editor { position: relative; width: 100%; height: 100%; }
.point-editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.point-editor-magnifier {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  width: 110px; height: 110px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  pointer-events: none;
}
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.nudge-pad {
  display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 46px);
  gap: 6px; justify-content: center; margin: 6px 0 12px;
}
.nudge-btn:nth-child(1) { grid-column: 2; grid-row: 1; }
.nudge-btn:nth-child(2) { grid-column: 1; grid-row: 2; }
.nudge-btn:nth-child(3) { grid-column: 3; grid-row: 2; }
.nudge-btn:nth-child(4) { grid-column: 2; grid-row: 2; }

/* ---------- alertas ---------- */
.alerts-host { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 0.88rem; border-left: 4px solid; }
.alert-info { background: #12293a; border-color: var(--info); color: #cdeeff; }
.alert-warning { background: #3a2f12; border-color: var(--warning); color: #ffe6b3; }
.alert-danger { background: #3a1420; border-color: var(--danger); color: #ffd7db; }

/* ---------- resultados ---------- */
.results-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.result-value { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.result-label { color: var(--text-dim); font-size: 0.82rem; margin-top: 4px; }

.comparison-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.88rem; }
.comparison-table th, .comparison-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.class-badge { padding: 2px 8px; border-radius: 20px; font-size: 0.76rem; font-weight: 600; }
.class-ate_0_5 { background: #123a24; color: var(--success); }
.class-0_6_a_1_0 { background: #3a2f12; color: var(--warning); }
.class-acima_1_0 { background: #3a1420; color: var(--danger); }

/* ---------- toasts ---------- */
.toast-container { position: fixed; bottom: calc(16px + var(--safe-bottom)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 200; pointer-events: none; }
.toast { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 10px 16px; border-radius: 30px; opacity: 0; transform: translateY(10px); transition: all 0.25s ease; font-size: 0.9rem; max-width: 90vw; }
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-warning { border-color: var(--warning); }
.toast-danger { border-color: var(--danger); }

/* ---------- modal de confirmacao ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px; }
.modal-box { background: var(--surface-2); border-radius: 14px; padding: 20px; max-width: 360px; width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- banner de atualizacao ---------- */
.update-banner {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface-2);
  border-top: 1px solid var(--border); padding: 12px 16px; display: flex;
  align-items: center; justify-content: space-between; gap: 10px; z-index: 250;
  padding-bottom: calc(12px + var(--safe-bottom));
}

/* ---------- relatorio ---------- */
.report-toolbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.report-page { background: #fff; color: #111; border-radius: 12px; padding: 24px; }
.report-page h1 { font-size: 1.3rem; }
.report-page .results-grid .result-card { background: #f2f5fa; border-color: #ddd; }
.report-page .result-value { color: #1e5fd6; }
.report-disclaimer { background: #fff4e0; border: 1px solid #e0b04a; color: #7a5a10; border-radius: 8px; padding: 10px 12px; font-size: 0.82rem; }
.report-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 12px 0; }
.report-info-item { display: flex; flex-direction: column; font-size: 0.9rem; }
.report-info-label { color: #777; font-size: 0.75rem; }
.report-photo { width: 100%; border-radius: 8px; margin: 10px 0; }
.report-alerts { font-size: 0.88rem; color: #444; }
.report-footer { font-size: 0.75rem; color: #888; text-align: center; margin-top: 20px; }
.report-page .comparison-table th, .report-page .comparison-table td { border-color: #ddd; }

@media print {
  body * { visibility: hidden; }
  .report-page, .report-page * { visibility: visible; }
  .report-page { position: absolute; top: 0; left: 0; width: 100%; padding: 0; }
  .no-print { display: none !important; }
}

@media (max-width: 380px) {
  .form-grid { grid-template-columns: 1fr; }
  .results-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- aviso de destaque: cartao de calibracao ---------- */
.card-callout {
  display: flex; gap: 14px; align-items: flex-start;
  background: linear-gradient(135deg, rgba(255,176,32,0.14), rgba(255,176,32,0.05));
  border: 1.5px solid var(--warning); border-radius: var(--radius);
  padding: 14px 16px; margin: 14px 0;
}
.card-callout-icon { font-size: 1.8rem; line-height: 1; flex-shrink: 0; }
.card-callout strong { display: block; color: var(--text); font-size: 0.98rem; margin-bottom: 4px; }
.card-callout p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }
.card-callout-link { color: var(--warning); font-weight: 600; text-decoration: underline; white-space: nowrap; }

/* ---------- ativação de licença ---------- */
.activation-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; padding-top: calc(24px + var(--safe-top));
}
.activation-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 22px; text-align: center;
}
.activation-card h1 { margin: 0 0 6px; font-size: 1.4rem; color: var(--primary); }
.activation-card p { color: var(--text-dim); font-size: 0.92rem; margin: 0 0 16px; }
.activation-card .input { text-align: center; letter-spacing: 1px; text-transform: uppercase; }
.activation-hint { margin-top: 18px !important; font-size: 0.8rem !important; }
