/* Bloco de coroamento sobre estacas — dimensionamento estrutural */
:root {
  --azul: #1d4e89;
  --azul-claro: #eaf1f9;
  --cinza: #555;
  --borda: #d7dce3;
  --ok: #1a7f37;
  --nok: #c62828;
  --aten: #9a6700;
  --fundo: #f5f6f8;
  --bg: #fff;
  --texto: #222;
  --topo-bg: #1d4e89;
  --input-bg: #fff;
  --input-border: #d7dce3;
}
[data-tema="escuro"] {
  --azul-claro: #1a2940;
  --cinza: #99a;
  --borda: #3a4050;
  --fundo: #111111;
  --bg: #1a1a1a;
  --texto: #dde;
  --topo-bg: #0d0d0d;
  --input-bg: #232a38;
  --input-border: #3a4050;
  --ok: #3dbe5a;
  --nok: #f06060;
  --aten: #d9a73e;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; font-size: 14px; color: var(--texto); background: var(--fundo); }

/* cabeçalho */
.topo { background: var(--topo-bg); color: #fff; padding: 10px 22px; position: relative; }
.tema-btn {
  position: absolute; top: 10px; right: 16px;
  background: none; border: 1px solid rgba(255,255,255,.3);
  color: #fff; border-radius: 20px; padding: 3px 10px;
  cursor: pointer; font-size: 13px; opacity: .8;
}
.tema-btn:hover { opacity: 1; }
.topo-save-area { position: absolute; top: 10px; right: 80px; display: flex; gap: 6px; }
.btn-save { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 6px; padding: 4px 12px; cursor: pointer; font-size: 12px; transition: background .2s; white-space: nowrap; }
.btn-save:hover { background: rgba(255,255,255,.28); }
input#file-open { display: none; }
.topo-content { display: flex; align-items: center; gap: 16px; }
.topo-logo { height: 36px; width: auto; flex-shrink: 0; }
.topo h1 { margin: 0; font-size: 18px; }
.topo .sub { margin: 2px 0 0; font-size: 11.5px; opacity: .88; }
.volta-portal { display: inline-block; color: rgba(255,255,255,.7); font-size: 11.5px; text-decoration: none; margin-bottom: 4px; }
.volta-portal:hover { color: #fff; text-decoration: underline; }

/* projeto */
.projeto { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 22px; background: var(--bg); border-bottom: 1px solid var(--borda); }
.projeto label { display: flex; flex-direction: column; font-size: 11px; color: var(--cinza); flex: 1 1 160px; }
.projeto input { margin-top: 2px; padding: 4px 7px; border: 1px solid var(--input-border); border-radius: 4px; font-size: 13px; background: var(--input-bg); color: var(--texto); }

.oculta { display: none !important; }

/* layout em faixas: entradas | desenhos | resultados | memória */
main { padding: 14px 22px 40px; display: flex; flex-direction: column; gap: 14px; }
.faixa { background: var(--bg); border: 1px solid var(--borda); border-radius: 8px; padding: 14px 16px; }
.faixa-titulo { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--azul); border-bottom: 2px solid var(--azul); padding-bottom: 6px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }

/* faixa 1 — entradas em 2×2 + (verificações | isométrica) ao lado, no topo */
.entrada-layout { display: flex; gap: 12px; align-items: flex-start; }
/* coluna esquerda: campos de edição em cima + tabela de ferros logo abaixo */
.entrada-esq { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
/* duas colunas independentes: esq = Pilar · Materiais · Tabela · dir = Estacas · Bloco */
.inputs-cols { display: flex; gap: 12px; align-items: flex-start; }
.col-in { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
/* campos numéricos estreitos (valores curtos); seletores um pouco maiores */
.col-in .campo input { max-width: 96px; }
.col-in .campo select { max-width: 160px; }
.painel-tabela { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.painel-tabela h2 { margin-bottom: 8px; }
/* coluna direita: verificações em cima, isométrica logo abaixo */
.topo-result { display: flex; flex-direction: column; gap: 12px; flex: 0 0 360px; width: 360px; align-items: stretch; }
.painel-verif { width: auto; }
.painel-iso { width: auto; max-width: none; }
#verif-topo .vt { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11.5px; padding: 3px 0; border-bottom: 1px solid var(--borda); }
#verif-topo .vt:last-child { border-bottom: none; }
#verif-topo .vt .lab { color: var(--texto); }
.vazio-verif { color: var(--cinza); font-size: 11.5px; font-style: italic; }
@media (max-width: 1200px) {
  .entrada-layout { flex-direction: column; }
  .topo-result { width: 100%; flex: 1 1 auto; flex-direction: row; flex-wrap: wrap; }
  .painel-iso { width: auto; max-width: 480px; flex: 1 1 340px; }
  .painel-verif { width: auto; flex: 1 1 230px; }
}

.painel { background: var(--fundo); border: 1px solid var(--borda); border-radius: 8px; padding: 12px 14px; }
.painel h2 { margin: 0 0 10px; font-size: 13.5px; color: var(--azul); }

/* campos */
.campo { display: flex; flex-direction: column; font-size: 11.5px; color: var(--cinza); margin-bottom: 8px; gap: 3px; }
.campo input, .campo select { padding: 5px 8px; border: 1px solid var(--input-border); border-radius: 5px; font-size: 13px; background: var(--input-bg); color: var(--texto); width: 100%; }
.campo input:focus, .campo select:focus { outline: none; border-color: var(--azul); }
.campo-check { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: 11.5px; color: var(--cinza); margin-bottom: 8px; }
.campo-check input { width: auto; }
.campo-desc { font-size: 10px; line-height: 1.3; color: var(--cinza); opacity: .8; font-weight: 400; margin-top: 1px; }
.campo-desc b { color: var(--azul); font-weight: 600; }
.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.nota-tipo { font-size: 11px; color: var(--cinza); background: var(--azul-claro); border-radius: 5px; padding: 6px 9px; line-height: 1.5; }

/* faixa 2 — planta + cortes lado a lado */
.desenhos-row { display: flex; gap: 14px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }
.painel-desenho { flex: 1 1 340px; max-width: 480px; }
.painel-desenho svg { display: block; width: 100%; margin: 0 auto; }
.desenho-info { font-size: 11.5px; color: var(--cinza); text-align: center; margin-top: 4px; line-height: 1.5; }

/* tabela de ferros */
.tabela-ferros { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.tabela-ferros th, .tabela-ferros td { border: 1px solid var(--borda); padding: 5px 8px; text-align: center; }
.tabela-ferros th { background: var(--azul-claro); color: var(--azul); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.tabela-ferros td:nth-child(2) { text-align: left; color: var(--cinza); }
.tabela-ferros .tf-marca { font-weight: 700; color: var(--azul); }
.tabela-ferros .tf-total td { font-weight: 700; background: var(--fundo); text-align: right; }
.tf-nota { font-size: 11px; color: var(--cinza); margin: 8px 2px 0; line-height: 1.5; }
/* permite rolagem horizontal da tabela larga no celular sem alargar a página */
#tabela-ferros { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* resultados (faixa 3 — grupos em colunas) */
#resultados { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 0 24px; }
#resultados .res-destaque { grid-column: 1 / -1; }
.res-grupo { margin-bottom: 10px; min-width: 0; overflow-wrap: anywhere; }
.res-titulo { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--cinza); border-bottom: 1px solid var(--borda); padding-bottom: 3px; margin-bottom: 5px; }
.res-linha { display: flex; justify-content: space-between; align-items: baseline; font-size: 12.5px; padding: 2px 0; gap: 8px; overflow-wrap: anywhere; }
.res-linha .rotulo { color: var(--cinza); }
.res-linha .valor { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; min-width: 0; text-align: right; }
.res-destaque { background: var(--azul-claro); border: 1px solid var(--azul); border-radius: 6px; padding: 8px 10px; margin-bottom: 10px; }
.res-destaque .res-linha { font-size: 13px; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; border-radius: 9px; padding: 1px 8px; }
.badge-ok   { background: #e2f3e6; color: #1a7f37; }
.badge-nok  { background: #fde3e3; color: #c62828; }
.badge-aten { background: #fff7e0; color: #9a6700; }
[data-tema="escuro"] .badge-ok   { background: #13301a; color: #5fca76; }
[data-tema="escuro"] .badge-nok  { background: #3a1015; color: #f4a3a8; }
[data-tema="escuro"] .badge-aten { background: #2a2510; color: #d9a73e; }
.ok  { color: var(--ok); }
.nok { color: var(--nok); }

/* barra de resumo fixa no topo: veredito + dimensões sempre visíveis ao editar */
.resumo-topo { position: sticky; top: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px 14px; background: var(--bg); border-bottom: 2px solid var(--azul); padding: 8px 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.14); font-size: 12.5px; }
.resumo-topo:empty { display: none; }
.resumo-topo .rt-verdict { font-size: 14px; font-weight: 800; padding: 3px 12px; border-radius: 8px; letter-spacing: .02em; }
.resumo-topo .rt-verdict.ok  { background: #e2f3e6; color: #1a7f37; }
.resumo-topo .rt-verdict.nok { background: #fde3e3; color: #c62828; }
[data-tema="escuro"] .resumo-topo .rt-verdict.ok  { background: #13301a; color: #5fca76; }
[data-tema="escuro"] .resumo-topo .rt-verdict.nok { background: #3a1015; color: #f4a3a8; }
.resumo-topo .rt-chip { color: var(--texto); white-space: nowrap; }
.resumo-topo .rt-chip b { color: var(--azul); }
.resumo-topo .rt-link { margin-left: auto; color: var(--azul); cursor: pointer; font-weight: 600; white-space: nowrap; }
.resumo-topo .rt-link:hover { text-decoration: underline; }

#avisos .aviso { font-size: 11.5px; background: #fff7e0; border-left: 3px solid #e0b400; color: #6a5500; border-radius: 0 5px 5px 0; padding: 6px 9px; margin-top: 6px; line-height: 1.45; }
[data-tema="escuro"] #avisos .aviso { background: #2a2510; color: #d9c27a; }
#avisos .aviso.erro { background: #fde3e3; border-left-color: var(--nok); color: #8a1c1c; }
[data-tema="escuro"] #avisos .aviso.erro { background: #3a1015; color: #f4a3a8; }

.btn-print { padding: 7px 16px; border: none; border-radius: 6px; background: var(--azul); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.btn-print:hover { filter: brightness(1.12); }

/* memória de cálculo */
.memoria { max-width: 880px; }
.memoria h2 { font-size: 15px; color: var(--azul); border-bottom: 2px solid var(--azul); padding-bottom: 4px; margin: 22px 0 10px; }
.memoria h2:first-child { margin-top: 0; }
.passo { border-left: 3px solid var(--azul); padding: 7px 12px; margin-bottom: 7px; background: var(--fundo); border-radius: 0 6px 6px 0; }
.passo .p-label { font-size: 12px; font-weight: 600; }
.passo .p-calc { font-size: 12px; color: var(--cinza); font-family: Consolas, monospace; margin: 2px 0; }
.passo .p-res { font-size: 12.5px; font-weight: 600; }
.passo.ok   { border-left-color: var(--ok); }
.passo.nok  { border-left-color: var(--nok); }
.passo.aten { border-left-color: #e0b400; }

/* resumo dos dados de entrada (topo da memória) */
.resumo-tab { border-collapse: collapse; margin: 4px 0 12px; font-size: 12.5px; width: 100%; max-width: 620px; }
.resumo-tab th, .resumo-tab td { border: 1px solid var(--borda, #d0d5dd); padding: 4px 9px; text-align: left; vertical-align: top; }
.resumo-tab .rt-grp { background: var(--fundo); color: var(--azul); font-weight: 700; width: 90px; }
.resumo-tab .rt-cmp { color: var(--cinza); width: 150px; }
.rt-id { font-size: 12px; color: var(--cinza); margin: 0 0 6px; }
.resumo-fig { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 10px; }
.resumo-fig .fig { flex: 0 1 360px; }
.resumo-fig .fig svg { width: 100%; height: auto; border: 1px solid var(--borda, #d0d5dd); border-radius: 6px; background: #fff; }
.resumo-fig .fig-cap { font-size: 11.5px; color: var(--cinza); text-align: center; margin-top: 3px; }

@media (max-width: 700px) {
  .inputs-cols { flex-direction: column; }
  .desenhos-row { flex-direction: column; align-items: stretch; }
  .painel-desenho { flex: 1 1 auto; max-width: none; }
}
@media (max-width: 600px) {
  main { padding: 12px 12px 32px; }
  .faixa { padding: 12px 12px; }
  #resultados { grid-template-columns: 1fr; gap: 0; }
  .tabela-ferros { font-size: 11px; }
  .tabela-ferros th, .tabela-ferros td { padding: 4px 5px; }
  /* memória/resultados não podem ultrapassar a largura do celular */
  .res-linha { flex-wrap: wrap; }
  .res-linha .valor { white-space: normal; word-break: break-word; overflow-wrap: anywhere; text-align: right; }
  .memoria { max-width: 100%; overflow-wrap: anywhere; }
  .passo .p-calc, .passo .p-label, .passo .p-res { white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
  .memoria table, .resumo-tab { width: 100%; max-width: 100%; table-layout: fixed; }
  .memoria th, .memoria td { word-break: break-word; overflow-wrap: anywhere; }
  .memoria svg, .memoria figure, .memoria img { max-width: 100%; height: auto; }
  /* empilha o painel de entradas para não passar da largura do celular */
  .entrada-layout, .inputs-cols { align-items: stretch; }
  .inputs-cols { flex-direction: column; }
  .col-in, .painel { width: 100%; max-width: 100%; min-width: 0; }
  .grade-2 { grid-template-columns: 1fr; }
  .painel { padding: 12px 12px; }
  .col-in .campo input, .col-in .campo select { max-width: none; }
}
/* campo obrigatório faltando (marcação em vermelho) */
.campo input.faltando, .campo select.faltando { border-color: var(--nok) !important; box-shadow: 0 0 0 2px rgba(220,53,69,.22); }

/* ---------- modal de otimização (sugestões de arranjo) ---------- */
.otim-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.otim-box { background: var(--bg); border: 1px solid var(--borda); border-radius: 10px; max-width: 700px; width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.4); }
.otim-topo { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 2px solid var(--azul); }
.otim-topo b { color: var(--azul); font-size: 14px; }
.otim-topo button { background: var(--azul); color: #fff; border: none; border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.otim-conteudo { overflow: auto; padding: 14px 16px; }
.otim-tab { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.otim-tab th, .otim-tab td { border: 1px solid var(--borda); padding: 6px 8px; text-align: center; white-space: nowrap; }
.otim-tab th { background: var(--azul-claro); color: var(--azul); }
.otim-tab td:first-child { text-align: left; white-space: normal; }
.otim-tab tr.rec td { background: var(--azul-claro); font-weight: 600; }
.otim-aplicar { background: var(--azul); color: #fff; border: none; border-radius: 5px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
.otim-nota { font-size: 11px; color: var(--cinza); margin-top: 10px; line-height: 1.5; }
/* no celular: cada sugestão vira um card empilhado (sem rolagem horizontal larga) */
@media (max-width: 560px) {
  .otim-overlay { padding: 8px; }
  .otim-conteudo { padding: 12px; }
  .otim-tab { font-size: 12px; display: block; }
  .otim-tab thead { display: none; }
  .otim-tab tbody, .otim-tab tr, .otim-tab td { display: block; width: 100%; }
  .otim-tab tr { border: 1px solid var(--borda); border-radius: 8px; margin-bottom: 10px; padding: 4px 2px; }
  .otim-tab tr.rec { border-color: var(--azul); background: var(--azul-claro); }
  .otim-tab td { border: none; white-space: normal; text-align: right; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 10px; }
  .otim-tab td::before { content: attr(data-l); color: var(--cinza); font-weight: 600; text-align: left; }
  .otim-tab td:first-child { font-size: 13.5px; font-weight: 700; color: var(--azul); justify-content: flex-start; border-bottom: 1px solid var(--borda); padding-bottom: 7px; margin-bottom: 3px; }
  .otim-tab td:first-child::before { content: ''; }
  .otim-tab td:last-child { justify-content: center; padding-top: 8px; }
  .otim-tab td:last-child::before { content: ''; }
  .otim-aplicar { width: 100%; padding: 9px; font-size: 13px; }
}
/* ── ABAS ── */
.tabs-bar{display:flex;align-items:stretch;border-bottom:2px solid var(--azul);background:var(--fundo);overflow-x:auto;flex-shrink:0;min-height:36px}
.tab-btn{display:inline-flex;align-items:center;gap:5px;padding:6px 11px 6px 13px;border:none;border-right:1px solid var(--borda);background:transparent;color:var(--cinza);cursor:pointer;font-size:12px;font-weight:500;white-space:nowrap;flex-shrink:0;transition:background .15s,color .15s;line-height:1.2}
.tab-btn:hover{background:var(--azul-claro);color:var(--texto)}
.tab-btn.ativo{background:var(--azul-claro);color:var(--azul);font-weight:700;box-shadow:inset 0 -3px 0 var(--azul)}
.tab-fechar{background:none;border:none;cursor:pointer;color:var(--cinza);font-size:15px;padding:0 1px;line-height:1;vertical-align:middle}
.tab-fechar:hover{color:#e74c3c}
.tab-add{padding:6px 12px;background:none;border:none;color:var(--azul);font-size:20px;cursor:pointer;flex-shrink:0;line-height:1}
.tab-add:hover{color:var(--azul-esc)}

@media print {
  .no-print, .tabs-bar { display: none !important; }
  body { background: #fff; }
  main { padding: 0; gap: 10px; }
  .faixa { border: none; padding: 0; }
  /* planta ao lado da isométrica · corte A ao lado do corte B */
  .desenhos-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; justify-content: stretch; }
  .painel-desenho { flex: none; max-width: none; break-inside: avoid; }
  /* na impressão a isométrica (que ficou no topo) ocupa a largura disponível */
  .entrada-layout, .entrada-esq, .inputs-cols, .col-in, .topo-result { display: block; }
  .painel-iso { width: auto; max-width: none; }
  .faixa-memoria { page-break-before: always; }
}

/* ---- seletor de memória entre os dois métodos de biela (não vai p/ Word) ---- */
.mem-metodos { margin: 0 0 16px; padding: 10px 12px; border: 1px dashed var(--azul); border-radius: 8px; background: var(--azul-claro); }
.mm-tit { font-size: 12.5px; font-weight: 700; color: var(--azul); margin-bottom: 8px; }
.mm-row { display: flex; gap: 10px; flex-wrap: wrap; }
.mm-btn { flex: 1 1 240px; display: flex; flex-direction: column; gap: 5px; align-items: flex-start; padding: 9px 11px; border: 1px solid var(--borda); background: var(--bg); color: var(--texto); border-radius: 7px; cursor: pointer; text-align: left; font-size: 12.5px; }
.mm-btn:hover { border-color: var(--azul); }
.mm-btn.sel { border-color: var(--azul); box-shadow: 0 0 0 2px var(--azul) inset; background: var(--azul-claro); }
.mm-lab { font-weight: 600; }
.mm-st { font-weight: 700; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.mm-st.ok { color: #fff; background: var(--ok); }
.mm-st.no { color: #fff; background: #c0392b; }
.mm-dim { font-size: 11.5px; color: var(--cinza); }
.mm-note { font-size: 11px; color: var(--cinza); margin-top: 7px; }
