* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #f1f5f9; --panel: #ffffff; --line: #e2e8f0;
  --text: #0f172a; --muted: #64748b; --accent: #0284c7; --accent2: #0369a1;
}
html, body, #app { height: 100%; }
body { font: 13px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); }
/* a coluna direita é `auto`: com #patches/#results ocultos (display:none)
   ela colapsa a 0 e o viewer ocupa a largura toda — na Análise o painel de
   blocos só reserva espaço quando há resultados */
#app { display: grid; grid-template-columns: 320px 1fr auto; }
#patches, #results { width: 340px; }

/* seletor deslizante Mapeamento↔Análise: trilho em pílula + "polegar"
   absoluto que desliza (transform anima; posição dirigida por :has() no
   botão ativo — o setMode só troca a classe .active, como sempre) */
#mode-tabs { position: relative; display: flex; margin-bottom: 14px;
  background: #e2e8f0; border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; }
#mode-tabs .thumb { position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc(50% - 6px); background: var(--accent); border-radius: 999px;
  box-shadow: 0 1px 3px #0f172a33;
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1); }
#mode-tabs:has(button[data-mode="analysis"].active) .thumb {
  transform: translateX(calc(100% + 6px)); }
#mode-tabs button { flex: 1; position: relative; z-index: 1; padding: 8px;
  border: 0; border-radius: 999px; background: none; color: #334155;
  font-weight: 600; cursor: pointer; transition: color 0.28s; }
#mode-tabs button:hover:not(.active) { color: var(--accent2); }
#mode-tabs button.active { color: #fff; }

/* sub-abas da Análise: cada seção carrega uma classe atab-* e só aparece
   quando o #sidebar[data-atab] correspondente está ativo (compõe com o
   .hidden da troca Mapeamento/Análise sem conflito) */
#analysis-tabs { display: flex; gap: 4px; margin: -6px 0 14px; }
#analysis-tabs button { flex: 1; padding: 6px 2px; border: 1px solid var(--line);
  border-radius: 999px; background: #f8fafc; color: var(--muted);
  font-size: 11px; font-weight: 600; cursor: pointer; }
#analysis-tabs button:hover { border-color: var(--accent); }
#analysis-tabs button.active { background: #e0f2fe;
  border-color: var(--accent); color: var(--accent2); }
/* fluxo contínuo: etapa ainda não liberada */
#analysis-tabs button:disabled { opacity: 0.4; cursor: not-allowed; }
#analysis-tabs button:disabled:hover { border-color: var(--line); }
#sidebar:not([data-atab="geometry"]) .atab-geometry,
#sidebar:not([data-atab="joints"]) .atab-joints,
#sidebar:not([data-atab="blocks"]) .atab-blocks { display: none; }

#project-bar { display: flex; gap: 6px; margin-bottom: 12px; }
#project-bar button { flex: 1; width: auto; padding: 6px 4px;
  font-size: 11px; }

/* fonte das juntas: 2×2 pílulas; o que não participa do modo ativo é
   OCULTADO (.src-hidden — classe própria: o .hidden pertence ao setMode
   e é re-aplicado a cada troca Mapeamento↔Análise) */
#joint-source { display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin-bottom: 8px; }
#joint-source button { padding: 6px 2px; border: 1px solid var(--line);
  border-radius: 8px; background: #f8fafc; color: var(--muted);
  font-size: 11px; font-weight: 600; cursor: pointer; }
#joint-source button:hover { border-color: var(--accent); }
#joint-source button.active { background: #e0f2fe;
  border-color: var(--accent); color: var(--accent2); }
.src-hidden { display: none !important; }

/* mapping panel: patch list scrolls, the stereonet stays pinned at the
   bottom-right of the menu */
#patches { display: flex; flex-direction: column; }
#patch-list { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
#stereo-sec { flex: none; margin: 10px 0 0; padding-top: 10px;
  border-top: 1px solid var(--line); }
#stereonet { width: 100%; height: auto; display: block; }
#family-legend { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.fam-chip { display: inline-flex; align-items: center; gap: 5px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 8px; font-size: 10px; }
.fam-chip i { width: 9px; height: 9px; border-radius: 50%; display: block; }

.patch-row { display: flex; align-items: center; gap: 7px; padding: 7px 6px;
  border-bottom: 1px solid var(--line); font-size: 12px; cursor: pointer; }
.patch-row:hover { background: #f1f5f9; }
.patch-row.sel { background: #e0f2fe; outline: 1px solid var(--accent); }
.patch-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.patch-row .meta { flex: 1; min-width: 0; }
.patch-row .meta small { color: var(--muted); display: block; }
.patch-row .chip-cand { background: #fef3c7; color: #92400e; border-radius: 999px;
  padding: 1px 7px; font-size: 10px; }
.patch-row button { background: none; border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; padding: 2px 7px; font-size: 12px; }
.patch-row button:hover { border-color: var(--accent); }
#btn-seed.armed { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }

aside { background: var(--panel); overflow-y: auto; padding: 16px;
        border-right: 1px solid var(--line); }
#results { border-right: 0; border-left: 1px solid var(--line); }
header h1 { font-size: 22px; letter-spacing: -0.5px; }
header h1 span { color: var(--accent); }
/* logomarca RightSlope + "3D": a imagem já vem recortada na caixa útil
   (escada+check mais altos que o texto); o "3D" alinha pela base do
   wordmark e imita o peso do "RIGHT" */
.brand { display: flex; align-items: flex-end; gap: 4px; }
.brand img { height: 28.5px; display: block; }
/* fonte um passo acima da cap height do wordmark (pedido do usuário) e
   baseline nivelada empiricamente com a do wordmark */
.brand span { font-size: 25px; font-weight: 800; line-height: 0.78;
  letter-spacing: -0.5px; margin-bottom: 0; }
.tag { color: var(--muted); font-size: 11px; margin: 2px 0 14px;
  text-align: center; }

section { margin-bottom: 18px; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
     color: var(--muted); margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 11px;
        color: var(--muted); }
input, select { background: #f8fafc; border: 1px solid #cbd5e1;
  color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 13px; }
/* modo Análise: caixas numéricas compactas — os valores são curtos e as
   caixas em meia-coluna ficavam largas demais */
.mode-analysis input[type="number"] { max-width: 96px; padding: 5px 7px; }
/* nos cartões de família a grade já é estreita (3 colunas): a caixa
   preenche a própria coluna. min-width:0 é essencial — a largura
   intrínseca (~150px) de um input numérico impedia as colunas 1fr de
   encolher e o cartão SEMPRE estourou para fora da lateral */
.set-card .grid3 input[type="number"] { min-width: 0; width: 100%;
  max-width: 100%; }
.grid2 input, .grid2 select { min-width: 0; }
input:focus { outline: 1px solid #0ea5e9; }

.set-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  margin-bottom: 8px; }
.set-card .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.set-head { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; font-weight: 600; }
.set-head .fam-dot { display: inline-block; vertical-align: -1px;
  margin-right: 6px; }
.set-head small { color: var(--muted); font-weight: 400; font-size: 10px;
  margin-left: 5px; }
.set-head button { background: none; border: 0; color: var(--muted);
  cursor: pointer; font-size: 14px; }

button.primary { width: 100%; padding: 11px; background: var(--accent);
  color: #fff; font-weight: 700; font-size: 14px; border: 0; border-radius: 8px;
  cursor: pointer; }
button.primary:disabled { opacity: 0.5; cursor: wait; }
button.ghost { width: 100%; padding: 7px; background: none; color: var(--accent2);
  border: 1px dashed var(--line); border-radius: 8px; cursor: pointer; }
#status { margin-top: 10px; font-size: 12px; color: var(--muted);
  min-height: 18px; white-space: pre-line; }
#status.err { color: #b91c1c; }

#chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #f8fafc; border: 1px solid var(--line); padding: 5px 9px;
  border-radius: 999px; font-size: 11px; }
.chip b { color: var(--accent2); }
.chip.bad b { color: #b91c1c; }
.range { margin-top: 12px; }
.range input { width: 100%; }
#remote-src { margin-top: 8px; }
#remote-src summary { font-size: 11px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); cursor: pointer;
  user-select: none; }
#remote-src summary:hover { color: var(--accent2); }

#sg-advanced { margin-top: 14px; }
#sg-advanced summary { font-size: 11px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); cursor: pointer;
  user-select: none; }
#sg-advanced summary:hover { color: var(--accent2); }
input[type="range"] { accent-color: #0ea5e9; padding: 0; border: 0;
  background: none; }

/* the canvas is absolutely positioned so its intrinsic (attribute) size —
   which the renderer multiplies by devicePixelRatio — can never feed back
   into the grid layout (fractional-DPR growth loop) */
#viewer { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; }
#btn-center { position: absolute; top: 14px; right: 14px; background: #ffffffd9;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  font-size: 12px; color: var(--text); cursor: pointer; }
#btn-center:hover { background: #fff; border-color: var(--accent); }
#btn-grid { position: absolute; top: 52px; right: 14px; background: #ffffffd9;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  font-size: 12px; color: var(--text); cursor: pointer; }
#btn-grid:hover { background: #fff; border-color: var(--accent); }
#btn-grid.on { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }
#btn-points { position: absolute; top: 90px; right: 14px; background: #ffffffd9;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  font-size: 12px; color: var(--text); cursor: pointer; }
#btn-points:hover { background: #fff; border-color: var(--accent); }
#btn-points.on { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }
#btn-texture { position: absolute; top: 128px; right: 14px;
  background: #ffffffd9; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 12px; color: var(--text); cursor: pointer; }
#btn-texture:hover { background: #fff; border-color: var(--accent); }
#btn-texture.on { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }
#btn-sun { position: absolute; top: 166px; right: 14px;
  background: #ffffffd9; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 12px; color: var(--text); cursor: pointer; }
#btn-sun:hover { background: #fff; border-color: var(--accent); }
#btn-sun.on { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }
#btn-measure, #btn-measure-clear { position: absolute; right: 14px;
  background: #ffffffd9; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 12px; color: var(--text); cursor: pointer; }
#btn-measure { top: 204px; }
#btn-measure-clear { top: 242px; }
#btn-measure:hover, #btn-measure-clear:hover { background: #fff;
  border-color: var(--accent); }
#btn-measure.on { border-color: var(--accent); color: var(--accent);
  background: #e0f2fe; }
#legend { position: absolute; left: 14px; bottom: 14px; background: #ffffffd9;
  border: 1px solid var(--line);
  padding: 8px 10px; border-radius: 8px; font-size: 10px; width: 190px; }
#ramp { height: 10px; border-radius: 4px; margin: 4px 0 2px;
  background: linear-gradient(90deg,#a50026,#d73027,#f46d43,#fdae61,#fee08b,
    #d9ef8b,#a6d96a,#66bd63,#1a9850,#006837); }
.lg-ticks { display: flex; justify-content: space-between; color: var(--muted);
  font-style: normal; }
.lg-ticks i { font-style: normal; }

#results h2 small { color: var(--muted); font-weight: 400; }
table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 6px 6px; font-size: 12px;
  border-bottom: 1px solid var(--line); }
th { color: var(--muted); cursor: pointer; user-select: none;
  position: sticky; top: 0; background: var(--panel); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f1f5f9; }
tbody tr.sel { background: #e0f2fe; outline: 1px solid var(--accent); }
td.fs-bad { color: #ef4444; font-weight: 700; }
td.fs-warn { color: #d97706; font-weight: 600; }
td.fs-ok { color: #16a34a; }
/* successive-failure iteration column: only rendered when the run used it */
#blocks.no-iter .col-iter { display: none; }
td.col-iter b { color: var(--accent2); }
label.check { flex-direction: row; align-items: center; gap: 7px;
  margin-top: 10px; font-size: 12px; color: var(--text); cursor: pointer; }
label.check input { width: auto; }
#family-list { margin-top: 6px; }
.fam-row { display: flex; flex-direction: row; align-items: center; gap: 7px;
  padding: 3px 0 3px 20px; font-size: 12px; cursor: pointer; color: var(--text); }
.fam-row input { width: auto; }
.fam-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.fam-row small { color: var(--muted); margin-left: auto; }
.info { margin-top: 6px; font-size: 11px; color: var(--muted); white-space: pre-line; }
.info.warn { color: #b91c1c; }
input[type="file"] { padding: 5px; font-size: 11px; }
.hidden { display: none !important; }

/* ── progress modal ── */
#progress-overlay { position: fixed; inset: 0; background: #0f172a66;
  backdrop-filter: blur(2px); display: flex; align-items: center;
  justify-content: center; z-index: 100; }
#progress-card { background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px 26px; width: 380px;
  box-shadow: 0 18px 50px #0f172a33; }
#progress-card h3 { font-size: 15px; margin-bottom: 14px; }
#pbar-track { height: 10px; background: #e2e8f0; border-radius: 999px;
  overflow: hidden; }
#pbar-fill { height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #38bdf8);
  transition: width 0.35s ease; }
#pbar-row { display: flex; justify-content: space-between; margin-top: 6px;
  font-size: 12px; color: var(--muted); }
#pbar-pct { font-weight: 700; color: var(--accent2); }
#pbar-label { margin-top: 10px; font-size: 12px; color: var(--text);
  min-height: 30px; }
#pbar-cancel { margin-top: 8px; }
#progress-card.err #pbar-fill { background: #b91c1c; }
#progress-card.err #pbar-label { color: #b91c1c; }
