/* ==========================================================================
   Lista de Materiais — Rei Sol Infraestrutura
   Direção "Meridiano+": warm minimal de precisão · creme + dourado + bronze
   Motivo único: "luz na aresta" (linha do meridiano · passo ativo · conferência dos campos · linha ativa)
   Sem fonte embutida (PWA offline · 0 KB). Refino = ritmo, numerais tabulares e arestas nítidas.
   ========================================================================== */

/* ===== Tokens ===== */
:root {
    /* Superfícies quentes */
    --bg: #f4f1ea;
    --card: #ffffff;
    --card-alt: #fbf7ee;

    /* Tinta */
    --text: #2a2520;
    --muted: #6f6250;
    --muted-strong: #5f5647;      /* micro-rótulos uppercase */

    /* Marca */
    --primary: #855b22;
    --primary-hover: #6b481f;
    --ink-brown: #6b481f;
    --primary-soft: #f5ead0;
    --gold: #dec078;
    --gold-mark: #9a7420;         /* âmbar de marcação — >=3:1 sobre branco (confiança média) */

    /* Estrutura */
    --border-contour: #e0d2ad;    /* borda firme de cards/inputs */
    --line: #e7ddc9;              /* hairline quente: zebra, separadores */
    --rule: #ece5d5;              /* column-rule / separador de célula */

    /* Estado */
    --success: #2e7d32;
    --danger: #b23b1a;
    --danger-bg: #fdece7;
    --locked: #b9ab8e;

    /* Fundos derivados (tema-aware) */
    --zebra: rgba(133, 91, 34, .035);
    --row-active-bg: rgba(133, 91, 34, .09);
    --hover-soft: rgba(133, 91, 34, .05);
    --focus-ring: rgba(133, 91, 34, .32);
    --lit-edge: rgba(255, 255, 255, .7);

    /* Rampa de elevação (tint bronze quente) */
    --shadow-1: 0 1px 2px rgba(107, 72, 31, .06), 0 1px 3px -1px rgba(107, 72, 31, .05);
    --shadow-2: 0 2px 4px -1px rgba(107, 72, 31, .08), 0 6px 14px -4px rgba(107, 72, 31, .07);
    --shadow-3: 0 12px 32px -8px rgba(107, 72, 31, .20);
    --shadow-modal: 0 24px 60px -16px rgba(42, 37, 32, .30);

    /* Geometria */
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-w: 236px;

    /* Grade de espaçamento (4px) */
    --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
}

/* ===== Dark quente (opt-in): segue o SO, mas o toggle vence nos dois sentidos ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1c1712;
        --card: #241d16;
        --card-alt: #2a2219;
        --text: #efe6d4;
        --muted: #b6a488;
        --muted-strong: #c8b593;
        --primary: #c79a52;
        --primary-hover: #d9ac60;
        --ink-brown: #ecdfc6;
        --primary-soft: #34291a;
        --gold: #dec078;
        --gold-mark: #d3ad5a;
        --border-contour: #4a3c28;
        --line: #342a1d;
        --rule: #3b3022;
        --success: #6bbf6f;
        --danger: #e0674a;
        --danger-bg: #331b16;
        --locked: #7a6d55;
        --zebra: rgba(255, 255, 255, .028);
        --row-active-bg: rgba(230, 195, 116, .10);
        --hover-soft: rgba(230, 195, 116, .07);
        --focus-ring: rgba(230, 195, 116, .45);
        --lit-edge: rgba(255, 255, 255, .06);
        --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px -1px rgba(0, 0, 0, .35);
        --shadow-2: 0 2px 6px -1px rgba(0, 0, 0, .45), 0 8px 20px -6px rgba(0, 0, 0, .40);
        --shadow-3: 0 14px 36px -10px rgba(0, 0, 0, .58);
        --shadow-modal: 0 26px 64px -16px rgba(0, 0, 0, .66);
    }
}
:root[data-theme="dark"] {
    --bg: #1c1712;
    --card: #241d16;
    --card-alt: #2a2219;
    --text: #efe6d4;
    --muted: #b6a488;
    --muted-strong: #c8b593;
    --primary: #c79a52;
    --primary-hover: #d9ac60;
    --ink-brown: #ecdfc6;
    --primary-soft: #34291a;
    --gold: #dec078;
    --gold-mark: #d3ad5a;
    --border-contour: #4a3c28;
    --line: #342a1d;
    --rule: #3b3022;
    --success: #6bbf6f;
    --danger: #e0674a;
    --danger-bg: #331b16;
    --locked: #7a6d55;
    --zebra: rgba(255, 255, 255, .028);
    --row-active-bg: rgba(230, 195, 116, .10);
    --hover-soft: rgba(230, 195, 116, .07);
    --focus-ring: rgba(230, 195, 116, .45);
    --lit-edge: rgba(255, 255, 255, .06);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px -1px rgba(0, 0, 0, .35);
    --shadow-2: 0 2px 6px -1px rgba(0, 0, 0, .45), 0 8px 20px -6px rgba(0, 0, 0, .40);
    --shadow-3: 0 14px 36px -10px rgba(0, 0, 0, .58);
    --shadow-modal: 0 26px 64px -16px rgba(0, 0, 0, .66);
}

/* ===== Reset ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-feature-settings: "tnum" 1, "lnum" 1;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color .2s ease, color .2s ease;
}
input, textarea, select, button { font-family: inherit; }
.tnum { font-variant-numeric: tabular-nums; }

.sr-only {
    position: absolute; width: 1px; height: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link {
    position: absolute; left: 8px; top: -48px; z-index: 2000;
    background: var(--primary); color: #fff; padding: 10px 16px;
    border-radius: var(--radius); text-decoration: none; font-weight: 600;
    transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

/* ===== Estrutura ===== */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh; height: 100dvh;
}

/* ===== Barra lateral ===== */
.sidebar {
    background: var(--card-alt);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    min-height: 0;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: var(--sp-4) var(--sp-4) var(--sp-3);
    border-bottom: 1px solid var(--line);
}
.brand-crest {
    width: 40px; height: 40px; object-fit: contain; flex-shrink: 0;
    border-radius: 50%; padding: 2px;
    box-shadow: inset 0 0 0 1px var(--border-contour);
}
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-weight: 600; color: var(--ink-brown); font-size: 15px; line-height: 1.15; letter-spacing: -.1px; }
.brand-sub {
    font-size: 11px; color: var(--muted-strong); text-transform: uppercase;
    letter-spacing: .09em; font-weight: 600; margin-top: 2px;
}
.sidebar-toggle {
    flex-shrink: 0; width: 26px; height: 26px; border-radius: 6px; border: none;
    background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center; transition: background-color .12s ease, color .12s ease;
}
.sidebar-toggle:hover { background: var(--primary-soft); color: var(--ink-brown); }

.steps { padding: var(--sp-3) 10px; display: flex; flex-direction: column; gap: var(--sp-1); }
.step {
    position: relative;
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 11px var(--sp-3); border: none; border-radius: 10px;
    background: transparent; color: var(--ink-brown);
    font-size: 14px; text-align: left;
    width: 100%; cursor: pointer; transition: background-color .12s ease, color .12s ease;
}
.step[hidden] { display: none; }
.step-ico { flex-shrink: 0; display: flex; align-items: center; color: var(--muted); transition: color .12s ease; }
.step-ico svg { width: 20px; height: 20px; }
.step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step:hover:not([aria-disabled="true"]):not([aria-current="step"]) { background: var(--hover-soft); }
.step.done .step-ico { color: var(--primary); }
.step[aria-current="step"] {
    background: var(--primary-soft); color: var(--ink-brown); font-weight: 500;
}
.step[aria-current="step"] .step-ico { color: var(--primary); }
/* Luz na aresta — barra-raio do passo ativo */
.step[aria-current="step"]::before {
    content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(180deg, var(--gold), var(--primary));
}
.step[aria-disabled="true"] { color: var(--locked); cursor: not-allowed; }
.step[aria-disabled="true"] .step-ico { color: var(--locked); }

/* Recolhida */
.app.collapsed { grid-template-columns: 68px 1fr; }
.collapsed .brand { flex-direction: column; gap: 8px; padding: 14px 0 12px; }
.collapsed .brand-text { display: none; }
/* mantém o botão de expandir visível quando recolhido (senão o usuário fica preso) */
.collapsed .sidebar-toggle { margin: 0 auto; }
.collapsed .steps { padding: var(--sp-3) 8px; }
.collapsed .step { justify-content: center; padding: 11px 0; gap: 0; }
.collapsed .step-label { display: none; }
.collapsed .step[aria-current="step"]::before { top: 6px; bottom: 6px; }
.collapsed .save-state { justify-content: center; }
.collapsed #saveStateText, .collapsed .theme-toggle span:last-child { display: none; }

.side-foot {
    margin-top: auto; padding: var(--sp-3) var(--sp-4) var(--sp-4);
    border-top: 1px solid var(--line);
    display: flex; flex-direction: column; gap: 10px;
}
.save-state {
    display: flex; align-items: center; gap: 7px;
    font-size: 12px; color: var(--primary); cursor: pointer;
    border-radius: 6px; padding: 2px 4px;
}
.save-dot { color: var(--primary); font-size: 10px; }
.theme-toggle {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: var(--radius);
    border: 1px solid var(--border-contour); background: var(--card);
    color: var(--ink-brown); font-size: 12px; font-weight: 500; cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease;
}
.theme-toggle:hover { background: var(--primary-soft); border-color: var(--gold); }
.theme-toggle .ic { width: 15px; height: 15px; display: inline-flex; }
.theme-toggle .ic svg { width: 15px; height: 15px; }

/* ===== Área principal ===== */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
    position: relative;
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
    padding: 14px var(--sp-6); background: var(--card);
    border-bottom: 1px solid var(--line);
}
/* Linha do Meridiano — o ÚNICO gradiente do produto */
.topbar::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--gold) 45%, transparent 100%);
}
.topbar-info { min-width: 0; }
.eyebrow {
    font-size: 11px; font-weight: 600; color: var(--muted-strong);
    text-transform: uppercase; letter-spacing: .12em; margin-bottom: 3px;
    font-variant-numeric: tabular-nums;
}
.eyebrow:empty { display: none; }
.topbar h1 { font-size: 19px; font-weight: 600; color: var(--ink-brown); letter-spacing: -.2px; line-height: 1.1; }
.ctx { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ctx.hidden { display: none; }
.ctx strong { color: var(--ink-brown); font-weight: 600; }
.ctx span { color: var(--text); }
.ctx-sep { margin: 0 5px; color: var(--gold-mark); }

.btn-primary {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 22px; border-radius: var(--radius); border: none;
    background: var(--primary); color: #fff;
    font-size: 14px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    box-shadow: var(--shadow-1);
    transition: background-color .15s ease, box-shadow .15s ease;
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-2); }

.work { flex: 1; overflow-y: auto; padding: var(--sp-6); min-height: 0; }
.work-inner { max-width: 980px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: panelIn .16s ease-out; }
@keyframes panelIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* ===== Formulário (Etapa 1) ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4) var(--sp-5); }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 12px; font-weight: 600; color: var(--muted-strong);
    text-transform: uppercase; letter-spacing: .05em;
}
.form-group input, .form-group select {
    width: 100%; height: 42px; padding: 0 13px;
    font-size: 15px; background-color: var(--card);
    border: 1.5px solid var(--border-contour); border-radius: var(--radius); color: var(--text);
    caret-color: var(--primary);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}
.form-group input:hover, .form-group select:hover { border-color: var(--gold); }
.form-group input::placeholder { color: var(--muted); opacity: 1; }
.form-group select {
    appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23855b22' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 19px;
}
:root[data-theme="dark"] .form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23c79a52' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
.form-group select:required:invalid { color: var(--muted); }

.cond-block { grid-column: span 2; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4) var(--sp-5); }

.field-err { font-size: 12px; color: var(--danger); display: none; font-weight: 500; text-transform: none; letter-spacing: 0; }
.form-group.invalid input, .form-group.invalid select { border-color: var(--danger); }
.form-group.invalid .field-err { display: block; }

.kbd-hint { font-size: 12px; color: var(--muted); margin-top: var(--sp-4); display: flex; align-items: center; gap: 7px; }

/* ===== Etapa Fundação ===== */
.fund-aviso {
    background: var(--primary-soft); border: 1px solid var(--gold);
    border-radius: var(--radius-lg); padding: 12px 14px; margin-bottom: var(--sp-5);
    font-size: 14px; color: var(--ink-brown); line-height: 1.4;
}
.fund-bloco { margin-top: var(--sp-4); }
.fund-h {
    font-size: 12px; font-weight: 600; color: var(--muted-strong); margin-bottom: 10px;
    text-transform: uppercase; letter-spacing: .06em;
    display: flex; align-items: center; gap: 8px;
}
.fund-h::before { content: ""; width: 3px; height: 13px; border-radius: 2px; background: var(--gold-mark); }
.fund-nota { font-weight: 500; font-size: 11px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.fund-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.fund-extras { margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
@media (max-width: 640px) { .fund-fields { grid-template-columns: 1fr; } }

/* ===== Tabela de Resultados (Etapa 3) ===== */
.table-wrap {
    border: 1px solid var(--border-contour); border-radius: var(--radius-lg);
    background: var(--card); box-shadow: var(--shadow-1);
    overflow-x: auto;        /* rola a tabela quando exceder a largura (celular) */
    overflow-y: hidden;      /* preserva o recorte dos cantos arredondados */
    -webkit-overflow-scrolling: touch;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
    position: sticky; top: 0; z-index: 1; background: var(--card-alt);
    text-align: left; padding: 12px 16px;
    font-size: 12px; font-weight: 600; color: var(--ink-brown);
    text-transform: uppercase; letter-spacing: .05em;
    border-bottom: 1px solid var(--border-contour);
}
.data-table thead th + th { border-left: 1px solid var(--rule); }
.data-table thead th.th-num { width: 62px; }
.data-table thead th.th-unit { width: 88px; }
.data-table thead th.th-qty { text-align: center; width: 150px; }

.data-table tbody td { padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.data-table tbody td + td { border-left: 1px solid var(--rule); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:nth-child(even) { background: var(--zebra); }
.data-table tbody tr.row-active { background: var(--row-active-bg); }
.data-table tbody tr.row-active td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
.data-table tbody tr.row-active td.item-name { color: var(--ink-brown); font-weight: 600; }

/* Linhas com quantidade 0 recuam (o olho vai para o que tem quantidade) */
.data-table tbody tr.row-zero td.item-name { color: var(--muted); }
.data-table tbody tr.row-zero .item-num { opacity: .6; }
.data-table tbody tr.row-zero .qty-input { background-color: transparent; color: var(--muted); border-color: var(--line); font-weight: 500; }
.data-table tbody tr.row-zero.row-active td.item-name { color: var(--ink-brown); }

.item-num { width: 62px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.item-name { color: var(--text); }
.item-unit { width: 88px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.item-qty-cell { width: 150px; text-align: center; padding: 5px 16px; }

/* Input de quantidade — idêntico nas Etapas 2 e 3 */
.qty-input {
    width: 112px; height: 36px; text-align: center;
    font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums;
    background-color: var(--primary-soft); border: 1.5px solid var(--border-contour);
    border-radius: var(--radius); color: var(--ink-brown); caret-color: var(--primary);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}
.qty-input:hover { border-color: var(--gold); }

/* ===== Etapa 2: busca + contador ===== */
.items-search { position: relative; margin-bottom: 14px; display: flex; align-items: center; gap: 12px; }
.items-search-ico {
    position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
    font-size: 15px; opacity: .6; pointer-events: none;
}
#filtroItens {
    flex: 1; height: 46px; padding: 0 14px 0 40px;
    font-size: 15px; color: var(--text); caret-color: var(--primary);
    background-color: var(--card); border: 1.5px solid var(--border-contour); border-radius: var(--radius);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}
#filtroItens:hover { border-color: var(--gold); }
#filtroItens::placeholder { color: var(--muted); opacity: 1; }
.items-count {
    flex-shrink: 0; font-size: 12px; font-weight: 600; color: var(--muted-strong);
    font-variant-numeric: tabular-nums; text-transform: uppercase; letter-spacing: .06em;
    white-space: nowrap;
}
.items-count b { color: var(--primary); font-weight: 700; }
.items-empty { padding: 30px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ===== Etapa 2: itens manuais em 2 colunas ===== */
.items-wrap {
    background: var(--card); border: 1px solid var(--border-contour);
    border-radius: var(--radius-lg); padding: 6px 8px; box-shadow: var(--shadow-1);
}
.items-cols { column-count: 2; column-gap: 0; }
.item-line {
    break-inside: avoid; display: flex; align-items: center; gap: 10px;
    min-height: 44px; padding: 6px 12px; border-radius: var(--radius);
    line-height: 1.35;
}
.items-cols > .item-line.zebra { background: var(--zebra); }
.item-line.row-active { background: var(--row-active-bg); box-shadow: inset 3px 0 0 var(--primary); }
.item-line.row-active .il-name { color: var(--ink-brown); font-weight: 600; }
.il-idx {
    flex-shrink: 0; width: 30px; text-align: right; font-size: 11px; color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.il-name { flex: 1; min-width: 0; font-size: 14px; }
.il-unit { flex-shrink: 0; width: 36px; text-align: right; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.item-line .qty-input { width: 72px; height: 34px; flex-shrink: 0; }
/* Fio-guia entre as duas colunas */
.items-cols { position: relative; }
.items-cols::before {
    content: ""; position: absolute; top: 8px; bottom: 8px; left: 50%; width: 1px;
    background: var(--rule); pointer-events: none;
}
@media (max-width: 640px) {
    .items-cols { column-count: 1; }
    .items-cols::before { display: none; }
}

/* ===== Conferência dos campos — "luz na aresta" (faixa esquerda via box-shadow: preserva a seta do select) ===== */
.ia-alta  { box-shadow: inset 3px 0 0 var(--success); }
.ia-media { box-shadow: inset 3px 0 0 var(--gold-mark); }
.ia-baixa { box-shadow: inset 3px 0 0 var(--danger); border-color: var(--danger) !important; background-color: var(--danger-bg) !important; }

/* ===== Banner "Retomar sessão" ===== */
.resume-banner {
    display: flex; align-items: center; gap: 14px;
    background: var(--primary-soft); border: 1px solid var(--gold);
    border-radius: var(--radius-lg); padding: 14px 16px; margin-bottom: var(--sp-6);
    box-shadow: var(--shadow-1);
}
.resume-banner[hidden] { display: none; }
.resume-icon {
    width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; line-height: 1;
}
.resume-body { flex: 1; min-width: 0; }
.resume-title { font-size: 14px; font-weight: 600; color: var(--ink-brown); }
.resume-text { font-size: 13px; color: var(--muted); margin-top: 2px; }
.resume-text strong { font-weight: 600; color: var(--ink-brown); }
.resume-actions { display: flex; gap: 10px; flex-shrink: 0; }
.btn-sm { padding: 9px 18px; font-size: 13px; border-radius: var(--radius); font-weight: 600; cursor: pointer; border: none; }
.btn-ghost { background: var(--card); color: var(--ink-brown); border: 1.5px solid var(--border-contour); }
.btn-ghost:hover { background: var(--card-alt); border-color: var(--gold); }
@media (max-width: 620px) {
    .resume-banner { flex-wrap: wrap; }
    .resume-actions { width: 100%; justify-content: flex-end; }
}

/* ===== Foco visível — anel de 2 camadas (corte nítido no branco e no creme) ===== */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, .step:focus-visible, .save-state:focus-visible, .theme-toggle:focus-visible {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--focus-ring);
}
.qty-input:focus-visible, #filtroItens:focus-visible {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--focus-ring);
}
/* Elementos sem borda: o anel translúcido some sobre o creme — usar outline sólido (>=3:1 nos 2 temas) */
.sidebar-toggle:focus-visible, .step:focus-visible, .save-state:focus-visible,
.import-x:focus-visible, .theme-toggle:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: none;
}
/* Foco nas linhas com quantidade 0 (a regra de de-ênfase vencia a borda de foco) */
.data-table tbody tr.row-zero .qty-input:focus-visible { border-color: var(--primary); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(42, 37, 32, .55);
    display: flex; align-items: center; justify-content: center;
    z-index: 1600; padding: 20px; animation: fadeIn .15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
    background: var(--card); border: 1px solid var(--border-contour);
    border-radius: 14px; padding: 30px; max-width: 420px; width: 100%;
    text-align: center; box-shadow: var(--shadow-modal);
    animation: popIn .16s ease-out;
}
@keyframes popIn { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-icon { font-size: 42px; }
.modal-title { font-size: 21px; font-weight: 700; color: var(--ink-brown); margin: 12px 0 8px; }
.modal-message { color: var(--muted); font-size: 14px; margin-bottom: 22px; line-height: 1.5; white-space: pre-line; }
.modal-actions { display: flex; gap: 12px; }
.modal-btn { flex: 1; padding: 13px 20px; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; border: none; }
.modal-btn-cancel { background: var(--card); color: var(--ink-brown); border: 1.5px solid var(--gold); }
.modal-btn-cancel:hover { background: var(--primary-soft); }
.modal-btn-confirm { background: var(--primary); color: #fff; }
.modal-btn-confirm:hover { background: var(--primary-hover); }

/* ===== Status de exportação (toast) ===== */
.upload-status { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1500; animation: slideDown .18s ease-out; }
@keyframes slideDown { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translateX(-50%); } }
.upload-status-content {
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border: 1px solid var(--border-contour);
    padding: 13px 22px; border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
}
.upload-spinner {
    width: 18px; height: 18px; border: 3px solid var(--primary-soft);
    border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.upload-text { color: var(--text); font-weight: 500; font-size: 14px; }
.upload-status.success .upload-spinner { display: none; }
.upload-status.success .upload-status-content::before { content: '✓'; color: var(--primary); font-size: 1.2rem; font-weight: 700; }
.upload-status.error .upload-spinner { display: none; }
.upload-status.error .upload-status-content::before { content: '✕'; color: var(--danger); font-size: 1.2rem; font-weight: 700; }
.upload-status.error .upload-status-content { border-color: rgba(178, 59, 26, .4); }

/* ===== Erro / shake ===== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}
.input-error { border-color: var(--danger) !important; animation: shake 0.4s ease; }

/* ===== Importar projeto (HERO) ===== */
.import-bar {
    display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap;
    background: var(--card-alt); border: 1px solid var(--border-contour); border-radius: var(--radius-lg);
    padding: 15px 16px; margin-bottom: var(--sp-5);
    box-shadow: var(--shadow-1), inset 0 1px 0 var(--lit-edge);
}
.import-bar-txt { flex: 1 1 260px; min-width: 200px; }
.import-bar-txt strong { display: block; color: var(--primary); font-size: 15px; }
.import-bar-txt span { color: var(--muted); font-size: 13px; }
.import-bar .btn-primary { white-space: nowrap; }

.import-result {
    margin-bottom: var(--sp-5); border-radius: var(--radius-lg);
    border: 1px solid var(--border-contour); padding: 14px 16px; font-size: 13px;
    background: var(--card); box-shadow: var(--shadow-1);
}
.import-result[hidden] { display: none; }
.import-result.load { background: var(--primary-soft); border-color: var(--gold); color: var(--ink-brown); }
.import-result.erro { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.import-msg { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.import-spin {
    width: 16px; height: 16px; border: 2px solid var(--gold); border-top-color: transparent;
    border-radius: 50%; display: inline-block; animation: spin .8s linear infinite;
}
.import-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--text); font-weight: 600; }
.import-head b { color: var(--primary); }
.import-x { margin-left: auto; background: none; border: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); border-radius: 6px; width: 26px; height: 26px; }
.import-x:hover { background: var(--hover-soft); color: var(--ink-brown); }
.ia-legenda { font-weight: 600; color: var(--muted-strong); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; display: inline-flex; align-items: center; }
.ia-legenda .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin: 0 3px 0 9px; }
.dot.alta { background: var(--success); } .dot.media { background: var(--gold-mark); } .dot.baixa { background: var(--danger); }
.import-obs { margin-top: 10px; color: var(--text); }
.import-obs ul { margin: 4px 0 0 18px; color: var(--muted); }
.import-obs li { margin: 2px 0; }
.import-check { margin-top: 10px; color: var(--text); line-height: 1.5; }
.import-check b { color: var(--ink-brown); }
.import-chip {
    display: inline-block; background: var(--primary-soft); border: 1px solid var(--gold);
    color: var(--ink-brown); border-radius: 999px; padding: 2px 10px; margin: 3px 3px 0 0; font-size: 12px;
}
.import-warn {
    margin-top: 10px; padding: 9px 12px; border-radius: var(--radius);
    background: var(--danger-bg); border: 1px solid var(--danger); color: var(--danger); line-height: 1.4;
}
.import-rac { margin-top: 8px; }
.import-rac summary {
    cursor: pointer; color: var(--ink-brown); font-size: 13px; font-weight: 600;
    padding: 4px 0; user-select: none;
}
.import-rac summary:hover { color: var(--gold-mark); }
.import-rac ul { margin: 6px 0 2px 18px; color: var(--muted); line-height: 1.45; }
.import-rac li { margin: 3px 0; }

/* ===== Importar por DWG (serviço próprio) ===== */
.import-bar .btn-primary:disabled { opacity: .6; cursor: progress; }
.import-tempo { margin-left: 4px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.import-meta { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.import-obs li, .import-check { overflow-wrap: anywhere; }
.dwg-fig { margin: 12px 0 0; }
.dwg-fig figcaption { font-weight: 600; color: var(--ink-brown); margin-bottom: 6px; }
.dwg-fig-dica { font-weight: 400; color: var(--muted); }
.dwg-fig-btn {
    display: block; max-width: 100%; padding: 0; overflow: hidden; cursor: zoom-in;
    border: 1px solid var(--border-contour); border-radius: var(--radius); background: #fff;
}
.dwg-fig-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.dwg-fig-btn img { display: block; max-width: 100%; max-height: 260px; height: auto; }
.dwg-zoom {
    margin: auto; padding: 0; border: none; border-radius: var(--radius-lg); background: #fff;
    max-width: 96vw; max-height: 94vh; overflow: auto; box-shadow: var(--shadow-modal);
}
.dwg-zoom::backdrop { background: rgba(42, 37, 32, .75); }
/* abre inteira na tela; clique na imagem alterna para o tamanho real (com rolagem) */
.dwg-zoom img { display: block; max-width: 94vw; max-height: 90vh; width: auto; height: auto; cursor: zoom-in; }
.dwg-zoom.dwg-zoom-real img { max-width: none; max-height: none; cursor: zoom-out; }
.dwg-zoom-x {
    position: sticky; top: 8px; float: right; margin: 8px; width: 34px; height: 34px;
    border: none; border-radius: 50%; background: rgba(42, 37, 32, .8); color: #fff;
    font-size: 22px; line-height: 1; cursor: pointer;
}
.dwg-zoom-x:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }


/* ===== Responsivo — colapsa a lateral em telas estreitas ===== */
@media (max-width: 720px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: none; border-bottom: 1px solid var(--line); }
    .brand { border-bottom: none; padding: 12px 16px; }
    .steps { flex-direction: row; padding: 10px; flex: 1; gap: 4px; }
    .step { padding: 10px 12px; }
    .step[aria-current="step"]::before { top: auto; left: 8px; right: 8px; bottom: 0; width: auto; height: 3px; border-radius: 3px 3px 0 0; background: linear-gradient(90deg, var(--gold), var(--primary)); }
    .step .step-label { display: none; }
    .side-foot { flex-direction: row; border-top: none; padding: 10px 16px; margin-left: auto; }
    .form-grid, .cond-block { grid-template-columns: 1fr; }
    .work { padding: var(--sp-4); }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ===== Croqui do fechamento (metade da tela ao lado de perímetro / lados / formato) ===== */
.perim-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
}
.perim-campos { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.croqui {
    margin: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--border-contour);
    border-radius: var(--radius);
    background: var(--card-alt);
}
.croqui-titulo {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted-strong);
}
.croqui-vazio {
    flex: 1;
    display: grid;
    place-items: center;
    min-height: 140px;
    padding: 8px;
    text-align: center;
    font-size: .85rem;
    color: var(--muted);
    border: 1px dashed var(--border-contour);
    border-radius: var(--radius);
}
.croqui-svg { flex: 1; min-height: 140px; display: flex; }
.croqui-svg svg { width: 100%; height: 100%; max-height: 320px; display: block; }
.croqui-svg .lado-obra { stroke: var(--danger); stroke-width: 3.2; fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.croqui-svg .lado-adequar { stroke: var(--gold-mark); stroke-width: 3.2; fill: none; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.croqui-svg .lado-pronto { stroke: var(--muted); stroke-width: 1.8; fill: none; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; }
.croqui-svg .area { fill: var(--primary-soft); stroke: none; }
.croqui-svg .vert { fill: var(--text); }
.croqui-svg .med { fill: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.croqui-svg .med-pronto { fill: var(--muted); font-weight: 600; font-style: italic; }
.croqui-svg .med-fundo { fill: var(--card-alt); stroke: var(--card-alt); stroke-linejoin: round; }
.croqui-legenda {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: .78rem;
    color: var(--muted);
}
.croqui-legenda li { display: flex; align-items: center; gap: 6px; }
.croqui-legenda i { display: inline-block; width: 22px; height: 0; border-top: 3px solid var(--danger); }
.croqui-legenda i.adequar { border-top-color: var(--gold-mark); }
.croqui-legenda i.pronto { border-top: 2px dashed var(--muted); }
.croqui.conferir { border-color: var(--danger); }
.croqui-aviso { font-size: .78rem; color: var(--danger); font-weight: 600; }
@media (max-width: 420px) {
    .perim-split { gap: 10px; }
    .croqui { padding: 8px; }
}.croqui-vazio[hidden], .croqui-svg[hidden], .croqui-legenda[hidden] { display: none; }
.croqui-svg { min-height: 200px; }