/* ==========================================================================
   Object Sorting — estilo
   Paleta e tipografia herdadas do restante do site (Garet, vinho/petróleo).
   Regra visual: mesa do participante quase branca e sem nenhum ornamento.
   ========================================================================== */

:root {
    --wine: #800020;
    --teal: #004e5d;
    --paper: #fbfaf8;
    --surface: #ffffff;
    --mesa: #fafafa;
    --text: #243033;
    --muted: #6d787c;
    --line: #dde3e4;
    --shadow-soft: 0 8px 22px rgba(36, 48, 51, 0.08);

    /* tamanho das peças na mesa: hitbox nunca abaixo de ~76px */
    /* O limite por altura (14vh) existe porque a distribuição inicial usa 5 linhas:
       objetos maiores que isso começariam sobrepostos. */
    --peca: clamp(80px, min(7.4vw, 14vh), 128px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: 'Garet', Arial, sans-serif;
    color: var(--text);
    background: var(--paper);
    overflow: hidden;
}

.tela { display: none; height: 100%; }
.tela.ativa { display: flex; }

/* ---------------------------------------------------------------- botões */
button {
    font-family: 'Garet', Arial, sans-serif;
    font-size: 15px;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 9px 14px;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
button:hover { border-color: var(--teal); color: var(--teal); }
button.primario {
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
}
button.primario:hover { background: #063f4a; color: #fff; }
button.vinho {
    background: var(--wine);
    border-color: var(--wine);
    color: #fff;
}
button.vinho:hover { background: #64001a; color: #fff; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ------------------------------------------- campos (usados no painel)  */
.campo { margin-bottom: 15px; }
.campo label {
    display: block;
    font-size: 13px;
    color: var(--teal);
    margin-bottom: 6px;
}
.campo input, .campo textarea, .campo select {
    width: 100%;
    padding: 10px 11px;
    font-family: 'Garet', Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
}
.campo input:focus, .campo textarea:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(0, 78, 93, .12);
}
.campo textarea { min-height: 74px; resize: vertical; }

/* ======================================================= A) PARTICIPANTE */
#telaParticipante { flex-direction: column; background: var(--mesa); }

.mesa {
    position: relative;
    flex: 1;
    margin: 0;
    background: var(--mesa);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.peca {
    position: absolute;
    width: var(--peca);
    height: var(--peca);
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    padding: 3px;
}
.peca.arrastando { cursor: grabbing; }
.peca.ajustando { transition: left .18s ease, top .18s ease; }
.peca img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    -webkit-user-drag: none;
}

/* placeholder de protótipo — só existe enquanto o PNG real não estiver na pasta */
.placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px;
    text-align: center;
    background: #f2f2f0;
    border: 1px dashed #b9c1c3;
    border-radius: 6px;
    font-size: 10.5px;
    line-height: 1.15;
    color: #5d686b;
}
.placeholder .tag {
    font-size: 8px;
    letter-spacing: 1px;
    color: #a2acaf;
}

.barra-inferior {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    padding: 14px 0 18px;
    background: var(--mesa);
}
#btnTerminei {
    padding: 15px 56px;
    font-size: 20px;
    letter-spacing: 3px;
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
    border-radius: 10px;
}
#btnTerminei:hover { background: #063f4a; color: #fff; }

/* ============================================================ C) ESPERA */
#telaCarregando, #telaEspera {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--mesa);
}
#telaCarregando p {
    font-size: 26px;
    letter-spacing: 5px;
    color: #c3cacc;
    font-weight: 300;
}
#telaEspera p {
    font-size: 40px;
    letter-spacing: 6px;
    color: var(--muted);
    font-weight: 300;
}
#btnAbrirPainel {
    margin-top: 34px;
    padding: 14px 34px;
    font-size: 15px;
    letter-spacing: 2px;
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
    border-radius: 9px;
}
#btnAbrirPainel:hover { background: #063f4a; color: #fff; }

.lembrete-avaliador {
    margin-top: 12px;
    font-size: 11.5px;
    letter-spacing: 1px;
    color: #b9c1c3;
}

/* canto invisível de acesso ao painel — fica sobre a barra do botão, nunca sobre a mesa */
#cantoPainel {
    display: none;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 62px;
    height: 62px;
    z-index: 1500;
    touch-action: none;
}
#cantoPainel.disponivel { display: block; }

/* ======================================================== D) RESULTADOS */
#telaResultados {
    flex-direction: column;
    overflow-y: auto;
    background: var(--paper);
}
.res-wrap {
    width: min(94%, 1120px);
    margin: 0 auto;
    padding: 34px 0 60px;
}
.res-wrap h1 {
    font-size: 26px;
    font-weight: 500;
    color: var(--wine);
    letter-spacing: 3px;
    margin-bottom: 4px;
}
.res-wrap h2 {
    font-size: 17px;
    font-weight: 500;
    color: var(--teal);
    letter-spacing: 2px;
    margin: 34px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line);
}
.res-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

.cabecalho-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.dado {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px 15px;
}
.dado .rot { display: block; font-size: 11.5px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.dado .val { display: block; font-size: 21px; color: var(--teal); margin-top: 4px; }
.dado .val.txt { font-size: 15px; line-height: 1.35; }

.org-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    gap: 18px;
}
.org-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px;
}
.org-card h3 {
    font-size: 15px;
    font-weight: 500;
    color: var(--wine);
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.org-card img.foto {
    width: 100%;
    display: block;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--mesa);
}
.org-card dl { margin-top: 12px; font-size: 13.5px; line-height: 1.5; }
.org-card dt { color: var(--muted); font-size: 11.5px; letter-spacing: .8px; text-transform: uppercase; margin-top: 9px; }
.org-card dd { color: var(--text); }
.org-card dd.citacao { font-style: italic; color: #3c4a4d; }

.sequencia {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 15px 18px;
    font-size: 15px;
    line-height: 1.7;
}
.sequencia .seta { color: var(--muted); margin: 0 8px; }

.dimensoes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 8px;
}
.dim {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13.5px;
}
.dim .marca {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #e2e6e7;
    flex: 0 0 auto;
}
.dim.apareceu .marca { background: var(--teal); }
.dim.apareceu { color: var(--text); }
.dim:not(.apareceu) { color: #9aa4a7; }
.dim .qtd { margin-left: auto; font-size: 12px; color: var(--muted); }

details.avancado {
    margin-top: 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 16px;
}
details.avancado summary {
    cursor: pointer;
    font-size: 14px;
    color: var(--teal);
    letter-spacing: 1px;
}
details.avancado .conteudo { margin-top: 14px; }

table.tab {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 16px;
}
table.tab th, table.tab td {
    border: 1px solid var(--line);
    padding: 6px 9px;
    text-align: left;
}
table.tab th { background: #f4f6f6; color: var(--teal); font-weight: 500; }
table.tab td.num { text-align: right; font-variant-numeric: tabular-nums; }

pre.bruto {
    max-height: 300px;
    overflow: auto;
    background: #f6f7f7;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    font-size: 11.5px;
    line-height: 1.4;
}

.status-banco {
    margin-top: 26px;
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 13.5px;
    line-height: 1.5;
    border: 1px solid var(--line);
}
.status-banco.aguardando { background: #f4f6f6; color: var(--muted); }
.status-banco.ok { background: #eef7f0; border-color: #bfdcc7; color: #23663a; }
.status-banco.erro { background: #fdf0f0; border-color: #eec5c5; color: #8c2323; }

.barra-export {
    position: sticky;
    bottom: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    padding: 14px;
    margin-top: 18px;
    background: rgba(251, 250, 248, .95);
    border-top: 1px solid var(--line);
}
.barra-export button { padding: 12px 26px; letter-spacing: 1px; }

/* ================================================== IMPRESSÃO / PDF ==== */
/* O PDF é literalmente esta página de resultados. */
@media print {
    body { overflow: visible; background: #fff; }

    .tela { display: none !important; }
    #telaResultados.ativa {
        display: block !important;
        height: auto;
        overflow: visible;
        background: #fff;
    }

    #painel, #cantoPainel, .salvo-flash, .barra-export { display: none !important; }

    .res-wrap { width: 100%; padding: 0; }
    .res-wrap h1 { font-size: 20px; }
    .res-wrap h2 { font-size: 14px; margin-top: 20px; }

    .cabecalho-grid { grid-template-columns: repeat(4, 1fr); }
    .org-grid { grid-template-columns: 1fr 1fr; }
    .org-card, .dim, .sequencia, .status-banco { break-inside: avoid; }
    .dimensoes { grid-template-columns: repeat(3, 1fr); }

    details.avancado { break-before: page; }
    details.avancado summary { list-style: none; font-weight: 600; }

    .dado, .org-card, .sequencia, .dim, details.avancado {
        box-shadow: none;
        border-color: #ccc;
    }

    @page { margin: 12mm; }
}

/* =============================================== PAINEL DO AVALIADOR ==== */
#painel {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--surface);
    z-index: 2000;
    overflow-y: auto;
}
#painel.aberto { display: block; }

.painel-topo {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 26px;
    background: var(--surface);
    border-bottom: 2px solid var(--teal);
}
.painel-topo button { padding: 10px 18px; }

.painel-corpo { padding: 20px 26px 46px; }

/* durante a tarefa e na tela final o painel tem pouco conteúdo: coluna única */
.painel-estreito { max-width: 560px; margin: 0 auto; }

/* após TERMINEI: mesa grande à esquerda, campos de registro à direita */
#painelRegistro {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(330px, 1fr);
    gap: 28px;
    align-items: start;
}
@media (max-width: 980px) {
    #painelRegistro { grid-template-columns: 1fr; }
}
.painel-topo h2 {
    font-size: 15px;
    font-weight: 500;
    color: var(--wine);
    letter-spacing: 2px;
}
.painel-topo .meta { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: 4px; }

.bloco { margin-bottom: 20px; }
.bloco > h3 {
    font-size: 12.5px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--teal);
    margin-bottom: 8px;
}
.bloco .dica-uso { font-size: 12px; color: var(--muted); margin-bottom: 8px; line-height: 1.45; }

/* mini-mesa de marcação de grupos */
#miniMesa {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--mesa);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}
#miniMesa .mini-peca {
    position: absolute;
    transform: translate(-50%, -50%);
    border: 2px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
#miniMesa .mini-peca img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
#miniMesa .mini-peca .mini-ph {
    width: 100%; height: 100%;
    background: #f2f2f0;
    border: 1px dashed #c3caCC;
    border-radius: 4px;
}
#miniMesa .mini-peca.selecionada {
    border-color: var(--wine);
    border-width: 3px;
    background: rgba(128, 0, 32, .12);
}
#miniMesa .mini-peca.atribuida { opacity: .38; }
#miniMesa .mini-peca .num-grupo {
    position: absolute;
    top: 0; right: 0;
    background: var(--teal);
    color: #fff;
    font-size: 11px;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 0 0 0 5px;
}

.botoes-linha {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.botoes-linha button { flex: 1 1 auto; padding: 11px 12px; }

.lista-grupos { font-size: 12.5px; line-height: 1.55; color: var(--text); }
.lista-grupos li { margin-bottom: 3px; margin-left: 16px; }
.lista-grupos .vazio { color: var(--muted); font-style: italic; }

.sugestao {
    background: #f2f7f8;
    border: 1px solid #cfe0e3;
    border-radius: 7px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.5;
}
.sugestao strong { color: var(--teal); }
.sugestao .evid { display: block; margin-top: 6px; font-size: 11.5px; color: var(--muted); }

.criterios {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
    font-size: 12.5px;
}
.criterios label { display: flex; align-items: center; gap: 6px; cursor: pointer; line-height: 1.3; }

.radios { display: flex; gap: 16px; font-size: 13px; }
.radios label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.botoes-painel { display: flex; flex-direction: column; gap: 8px; }
.botoes-painel button { width: 100%; padding: 11px; }

/* instruções, agora dentro do painel */
details.instrucoes {
    max-width: 720px;
    margin: 0 auto 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
}
details.instrucoes summary {
    cursor: pointer;
    font-size: 13px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--teal);
}
.instrucoes-conteudo { margin-top: 12px; }
.instrucoes-conteudo p, .instrucoes-conteudo li { font-size: 13.5px; line-height: 1.5; }
.instrucoes-conteudo ul { margin: 8px 0 10px 20px; }
.instrucoes-conteudo .fala { font-style: italic; color: var(--teal); margin: 6px 0 10px; }

.painel-topo .alerta { color: var(--wine); }

.salvo-flash {
    position: fixed;
    bottom: 14px; right: 14px;
    background: var(--teal);
    color: #fff;
    font-size: 12px;
    letter-spacing: 1px;
    padding: 7px 13px;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    z-index: 2100;
}
.salvo-flash.visivel { opacity: .92; }
