:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-faixa: #172033;
    --border-color: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-blue: #38bdf8;
    --accent-blue-escuro: #0369a1;
    --accent-amber: #f59e0b;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
    --hover: rgba(56, 189, 248, 0.12);
    --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body { height: 100%; }

body {
    background: var(--bg-primary);
    color: var(--text-main);
    font: 13px/1.4 var(--font-sans);
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: minmax(0, 1fr); /* sem isso o conteúdo largo do ribbon alarga a página */
    overflow: hidden;
}

.ic {
    width: 24px;
    height: 24px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

select, input[type="number"], input[type="text"] {
    background: var(--bg-primary);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
    font: inherit;
}
input[type="number"] { width: 5.5rem; }
input[type="range"] { width: 90px; }

.muted { color: var(--text-muted); }
.chk { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }

/* ---------------------------------------------------------------- Topo */

.topo { background: var(--bg-secondary); border-bottom: 1px solid var(--border-color); }

.qat {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.3rem 0.75rem 0.1rem;
}
.marca { white-space: nowrap; }
.marca span { color: var(--accent-blue); }
.marca small { color: var(--text-muted); font-weight: normal; }

.qat-botoes { display: flex; align-items: center; gap: 0.1rem; }
.qat-btn {
    display: inline-flex;
    padding: 0.2rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-main);
    cursor: pointer;
}
.qat-btn .ic { width: 18px; height: 18px; }
.qat-btn:hover { background: var(--hover); }
.qat-btn.ativo { border-color: var(--accent-blue); color: var(--accent-blue); }
.qat-sep { width: 1px; height: 18px; background: var(--border-color); margin: 0 0.3rem; }

/* Guias */
.guias {
    display: flex;
    align-items: flex-end;
    gap: 0.1rem;
    padding: 0 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
}
.guia {
    position: relative;
    background: none;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    color: var(--text-main);
    font: inherit;
    padding: 0.35rem 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}
.guia:hover { background: var(--hover); }
.guia.ativa {
    background: var(--bg-faixa);
    border-color: var(--border-color);
    color: var(--accent-blue);
    margin-bottom: -1px;
    z-index: 1;
}
.guia-arquivo { background: var(--accent-blue-escuro); color: #fff; border-radius: 4px; margin: 0 0.4rem 0.25rem 0; padding: 0.25rem 0.9rem; }
.guia-arquivo:hover { background: var(--accent-blue); color: #0f172a; }
.guia.contextual { color: var(--accent-amber); border-top: 3px solid var(--accent-amber); padding-top: calc(0.35rem - 2px); }
.guia.contextual.ativa { color: var(--accent-amber); }
.selo { font-size: 0.75rem; margin-left: 0.2rem; }
.selo.ok { color: var(--accent-green); }
.selo.alerta { color: var(--accent-amber); }

.recolher {
    margin-left: auto;
    align-self: center;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
}
.recolher .ic { width: 18px; height: 18px; transition: transform 0.15s; }
.ribbon-recolhido .recolher .ic { transform: rotate(180deg); }

/* Faixa */
.faixa {
    background: var(--bg-faixa);
    border-top: 1px solid var(--border-color);
    height: 92px;
    overflow-x: auto;
    overflow-y: hidden;
}
.ribbon-recolhido .faixa { display: none; }

.painel-guia { display: none; height: 100%; align-items: stretch; }
.painel-guia.ativa { display: flex; }

.grupo-rb {
    display: flex;
    flex-direction: column;
    padding: 0.35rem 0.5rem 0.15rem;
    border-right: 1px solid var(--border-color);
    flex: none;
}
.grupo-itens { display: flex; align-items: flex-start; gap: 0.2rem; flex: 1; }
.grupo-titulo {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding-top: 0.15rem;
    white-space: nowrap;
}

.rb-grande {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    min-width: 60px;
    max-width: 84px;
    min-height: 58px;
    padding: 0.3rem 0.15rem;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-main);
    font: 11.5px/1.15 var(--font-sans);
    text-align: center;
    cursor: pointer;
}
.rb-grande:hover:not(:disabled) { background: var(--hover); border-color: var(--border-color); }
.rb-grande.ativo { background: rgba(56, 189, 248, 0.2); border-color: var(--accent-blue); color: var(--accent-blue); }
.rb-grande:disabled { opacity: 0.4; cursor: default; }

.rb-pilha {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.3rem;
    padding: 0 0.3rem;
    min-height: 58px;
    font-size: 12px;
}
.rb-pilha select { max-width: 13rem; }
.rb-campo { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; white-space: nowrap; }
.rb-campo input { width: 6.5rem; }
.rb-campo select { min-width: 6.5rem; max-width: 14rem; }
.rb-valor { font-variant-numeric: tabular-nums; }

.aviso-etapa { align-self: center; padding: 0 1rem; max-width: 22rem; font-size: 0.75rem; }

/* ---------------------------------------------------------------- Arquivo (bastidores) */

.bastidores {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: 200px 1fr;
    background: var(--bg-primary);
}
.bastidores[hidden] { display: none; }
.bastidores-menu {
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    background: var(--accent-blue-escuro);
}
.bs-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1.25rem;
    background: none;
    border: none;
    color: #fff;
    font: inherit;
    font-size: 0.95rem;
    text-align: left;
    cursor: pointer;
}
.bs-item .ic { width: 18px; height: 18px; }
.bs-item:hover, .bs-item.ativo { background: rgba(255, 255, 255, 0.15); }
.bs-voltar { margin-bottom: 0.75rem; }
.bastidores-conteudo { padding: 2rem 2.5rem; overflow-y: auto; }
.bastidores-conteudo h2 { font-size: 1.4rem; font-weight: 500; margin-bottom: 1.25rem; }
.bastidores-conteudo p { margin-top: 1.25rem; max-width: 40rem; }
.info-lista { display: grid; grid-template-columns: max-content auto; gap: 0.4rem 2rem; font-variant-numeric: tabular-nums; }
.info-lista dt { color: var(--text-muted); }
.form-linha { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 28rem; margin-bottom: 0.75rem; }

/* ---------------------------------------------------------------- Área de trabalho */

.area {
    display: grid;
    grid-template-columns: 1fr 340px;
    min-height: 0;
}
.area.sem-painel { grid-template-columns: 1fr; }
.area.sem-painel .painel { display: none; }

.viewport {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    outline: none;
    cursor: crosshair;
}
.viewport canvas { display: block; }

.painel {
    border-left: 1px solid var(--border-color);
    background: var(--bg-secondary);
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.painel h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 0.4rem; }

.tabela-wrap { max-height: 300px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 0.2rem 0.4rem; text-align: right; border-bottom: 1px solid var(--border-color); }
th:nth-child(2), td:nth-child(2) { text-align: left; }
th { position: sticky; top: 0; background: var(--bg-secondary); color: var(--text-muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
tbody tr.sel { background: rgba(245, 158, 11, 0.2); }

.ajuda { font-size: 0.75rem; line-height: 1.5; }

.status {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.3rem 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 800px) {
    .marca small { display: none; }
    .area { grid-template-columns: 1fr; grid-template-rows: 1fr 40%; }
    .painel { border-left: none; border-top: 1px solid var(--border-color); }
    .bastidores { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .bastidores-menu { flex-direction: row; flex-wrap: wrap; padding: 0.25rem; }
    .bs-voltar { margin-bottom: 0; }
    .bastidores-conteudo { padding: 1rem; }
}
