/* ==========================================================================
   Metodo REI v0.1 - estilos
   Paleta derivada do selo dourado do metodo (assets/img/rei/image33.png).
   Ordem: tokens > base > layout > secao > campos/grades > resultado > responsivo > impressao
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
    --ouro: #b8862b;
    --ouro-escuro: #7a5410;
    --ouro-claro: #f5e7c4;
    --vinho: #8a4b5a;          /* tom da assinatura */
    --texto: #2b2420;
    --texto-suave: #6b6058;
    --fundo: #faf6ee;
    --cartao: rgba(255, 255, 255, .8); /* deixa o selo de fundo visivel sem prejudicar leitura */
    --borda: #e3d6bb;
    --ok: #2f7d4f;
    --alerta: #b3412f;
    --raio: 14px;
    --sombra: 0 6px 24px rgba(90, 60, 10, .08);
    --fonte: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    --fonte-titulo: Georgia, "Times New Roman", serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 16px/1.5 var(--fonte);
    color: var(--texto);
    background: var(--fundo);
}
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { font-family: var(--fonte-titulo); line-height: 1.2; margin: 0; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; color: var(--ouro-escuro); }

/* ---------- Topo / rodape ---------- */
.topo {
    display: flex; align-items: center; gap: 1rem;
    padding: 1rem clamp(1rem, 4vw, 2.5rem);
    background: linear-gradient(90deg, #fff, var(--ouro-claro));
    border-bottom: 3px solid var(--ouro);
}
.topo__selo { width: 64px; height: 64px; object-fit: contain; flex: none; }
.topo h1 { font-size: clamp(1.1rem, 3vw, 1.6rem); color: var(--ouro-escuro); }
.topo p { margin: .15rem 0 0; color: var(--texto-suave); }

.rodape { text-align: center; padding: 2rem 1rem; color: var(--texto-suave); font-size: .85rem; }
.rodape img { width: min(260px, 70%); margin: 0 auto .5rem; }

.conteudo { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem; }

/* ---------- Secao com imagem de fundo (selo do metodo como marca d'agua) ---------- */
.secao {
    position: relative;
    margin-bottom: 1.5rem;
    padding: clamp(1rem, 3vw, 1.75rem);
    border: 1px solid var(--borda);
    border-radius: var(--raio);
    box-shadow: var(--sombra);
    background:
        linear-gradient(var(--cartao), var(--cartao)),
        url("../img/rei/image33.png") right -60px center / 340px auto no-repeat,
        #fff;
    overflow: hidden;
}
.secao__topo { border-left: 4px solid var(--ouro); padding-left: .75rem; margin-bottom: 1rem; }
.secao__topo h2 { font-size: clamp(1.05rem, 2.5vw, 1.35rem); color: var(--ouro-escuro); text-transform: uppercase; letter-spacing: .02em; }
.secao__topo p { margin: .35rem 0 0; color: var(--texto-suave); font-size: .92rem; }

.secao__grade { display: grid; gap: 1.25rem; }
.secao--img .secao__grade { grid-template-columns: minmax(160px, 260px) 1fr; align-items: start; }
.secao__figura { margin: 0; position: sticky; top: 1rem; }
.secao__figura img { width: 100%; max-height: 420px; object-fit: contain; border-radius: 10px; }
.secao__corpo { min-width: 0; } /* evita estouro horizontal em grid */

/* ---------- Campos ---------- */
.campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem 1rem; }
.campo { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--texto-suave); }
.campo--largo { grid-column: 1 / -1; }
input, select, textarea {
    width: 100%; min-width: 0;
    font: inherit; font-size: 1rem; color: var(--texto);
    padding: .55rem .7rem;
    border: 1px solid var(--borda); border-radius: 8px;
    background: #fff;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ouro); outline-offset: 1px; border-color: var(--ouro); }

/* Grade item + antes + depois (reutilizada em todas as secoes) */
.grade { display: grid; gap: .45rem; }
.grade__cab, .grade__linha { display: grid; grid-template-columns: 1fr 6.5rem 6.5rem; gap: .5rem; align-items: center; }
.grade__cab { font-size: .78rem; font-weight: 600; text-transform: uppercase; color: var(--ouro-escuro); }
.grade__rotulo { font-weight: 600; font-size: .92rem; }
.grade--trat .grade__cab, .grade--trat .grade__linha { grid-template-columns: 1fr 1.3fr; }
.num { text-align: center; }

/* Validacao */
.campo__erro { min-height: 1em; font-size: .78rem; color: var(--alerta); }
.campo__erro:empty { display: none; }
input.invalido, input:user-invalid { border-color: var(--alerta); background: #fff6f4; }
.avisos { border: 1px solid var(--alerta); background: #fff6f4; border-radius: var(--raio); padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.avisos ul { margin: .5rem 0 0; padding-left: 1.1rem; }

/* Prompt do mapa terapeutico */
.prompt { font: .85rem/1.45 Consolas, "Courier New", monospace; background: #fffdf7; white-space: pre-wrap; }

.nota { font-size: .85rem; color: var(--texto-suave); font-style: italic; margin: .9rem 0 0; }

/* ---------- Botoes ---------- */
.acoes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; margin: 1rem 0 2rem; }
.acoes--topo { justify-content: space-between; margin-top: 0; }
.btn {
    font: inherit; font-weight: 600; cursor: pointer;
    padding: .75rem 1.4rem; border-radius: 999px;
    border: 1px solid var(--ouro-escuro);
    background: linear-gradient(180deg, var(--ouro), var(--ouro-escuro)); color: #fff;
}
.btn--sec { background: #fff; color: var(--ouro-escuro); }
.btn:hover { filter: brightness(1.07); }

/* ---------- Resultado ---------- */
.dados { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem 1rem; margin: 0; }
.dados dt { font-size: .78rem; text-transform: uppercase; color: var(--texto-suave); }
.dados dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.tabela { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--borda); text-align: left; }
th { font-size: .78rem; text-transform: uppercase; color: var(--ouro-escuro); background: var(--ouro-claro); }
td:not(:first-child), th:not(:first-child) { text-align: center; white-space: nowrap; }

.livre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .25rem 0; }
.vazio { color: var(--texto-suave); font-style: italic; }
.texto-ref { background: #fff; border-left: 3px solid var(--vinho); padding: .6rem .8rem; border-radius: 6px; margin: .6rem 0; }

.freq { display: flex; flex-wrap: wrap; align-items: baseline; gap: .75rem; margin-top: .75rem; }
.freq__rot { font-size: .78rem; text-transform: uppercase; color: var(--texto-suave); min-width: 4rem; }
.freq__nivel { font-family: var(--fonte-titulo); font-size: 1.3rem; color: var(--ouro-escuro); }

.escala { margin-top: 1rem; }
.escala summary { cursor: pointer; color: var(--ouro-escuro); font-weight: 600; }
.escala ul { list-style: none; padding: 0; margin: .5rem 0 0; max-width: 320px; }
.escala li { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--borda); padding: .2rem 0; }

.selo { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 700; color: #fff; }
.selo--ok { background: var(--ok); }
.selo--alerta { background: var(--alerta); }
.selo--neutro { background: var(--ouro); }

.trat { padding-left: 1.1rem; margin: 0; }
.trat li { margin: .3rem 0; }

/* ---------- Graficos SVG (src/graficos.php) ---------- */
.grafico { width: 100%; height: auto; display: block; margin: .75rem 0 1rem; max-width: 760px; }
.grafico text { font-family: var(--fonte); fill: var(--texto); }
.g-antes { fill: #b9ada0; }
.g-depois { fill: var(--ouro); }
.g-leg, .g-val { font-size: 11px; fill: var(--texto-suave); }
.g-rot { font-size: 12px; font-weight: 600; }
.g-eixo { stroke: var(--texto-suave); stroke-width: 1; }
.g-div { stroke: rgba(255, 255, 255, .7); stroke-width: 1; }
.g-nivel { font-size: 12px; }
.g-marca-antes, .g-marca-depois { stroke-width: 2; }
.g-marca-antes { stroke: #8a7f74; }
.g-marca-depois { stroke: var(--ouro-escuro); }
.g-marca-txt { font-size: 13px; font-weight: 700; }
.regua { max-width: none; }

/* ---------- Painel resumo e evolucao ---------- */
.cartoes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.cartao { border-radius: var(--raio); padding: 1rem; text-align: center; border: 1px solid var(--borda); background: #fff; }
.cartao strong { display: block; font: 700 2.2rem/1 var(--fonte-titulo); }
.cartao span { font-size: .85rem; text-transform: uppercase; color: var(--texto-suave); }
.cartao--melhorou strong { color: var(--ok); }
.cartao--manteve strong { color: var(--ouro); }
.cartao--piorou strong { color: var(--alerta); }
.detalhe { margin: .4rem 0; }
.detalhe summary { cursor: pointer; font-weight: 600; color: var(--ouro-escuro); }
.detalhe ul { margin: .4rem 0; padding-left: 1.1rem; }
.etq { display: inline-block; font-size: .72rem; text-transform: uppercase; padding: 0 .4rem; border-radius: 4px; background: var(--ouro-claro); color: var(--ouro-escuro); }
.tend { font-weight: 700; font-size: .85rem; }
.tend--melhorou { color: var(--ok); }
.tend--manteve { color: var(--ouro); }
.tend--piorou { color: var(--alerta); }
table.evolucao small { font-weight: 400; text-transform: none; }

/* ---------- Historico no formulario ---------- */
.ultima-sessao { margin-top: 1rem; padding: .75rem 1rem; border-left: 3px solid var(--vinho); background: #fff; border-radius: 6px; }
.ultima-sessao p { margin: .25rem 0; }
.acoes__dir { display: flex; gap: .75rem; flex-wrap: wrap; }

/* ---------- Aviso de versao desktop (mobile ainda nao homologado) ---------- */
.aviso-desktop { display: none; padding: .6rem 1rem; text-align: center; font-weight: 600; background: var(--alerta); color: #fff; }
@media (max-width: 1023px) { .aviso-desktop { display: block; } }

/* ---------- Responsivo ---------- */
@media (max-width: 760px) {
    .secao--img .secao__grade { grid-template-columns: 1fr; }
    .secao__figura { position: static; }
    .secao__figura img { max-height: 220px; margin: 0 auto; }
    .secao { background-size: auto, 220px auto, auto; background-position: 0 0, right -50px top 10px, 0 0; }
}
@media (max-width: 480px) {
    .grade__cab, .grade__linha { grid-template-columns: 1fr 4.6rem 4.6rem; gap: .35rem; }
    .grade--trat .grade__cab { display: none; }
    .grade--trat .grade__linha { grid-template-columns: 1fr; padding-bottom: .5rem; border-bottom: 1px dashed var(--borda); }
    input, select { padding: .5rem; }
    .acoes .btn { flex: 1; }
}

/* ---------- Impressao / PDF ---------- */
@media print {
    @page { margin: 14mm; }
    body { background: #fff; font-size: 11pt; }
    .nao-imprimir, .acoes, .aviso-desktop, .detalhe:not([open]) { display: none !important; }
    .grafico { break-inside: avoid; }
    .conteudo { padding: 0; max-width: none; }
    .secao { box-shadow: none; break-inside: avoid; page-break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .secao__figura { position: static; }
    .secao__figura img { max-height: 200px; }
    .escala[open] summary, .escala summary { list-style: none; }
}
