/* ControLab — estilo base (sem build step; CSS estático servido de public/) */

:root {
    --bg: #f3f5f7;
    --surface: #ffffff;
    --border: #d9dee3;
    --text: #1d2530;
    --text-muted: #6b7684;
    --primary: #0d5c8c;
    --primary-dark: #0a4a71;
    --ok-bg: #e2f4e2;
    --ok-fg: #1d6b2a;
    --off-bg: #fde4e1;
    --off-fg: #a3271c;
    --danger: #b3261e;
    --chart-opened: #d98a0b; /* âmbar p/ "abertos" (par azul+laranja: seguro p/ daltônicos) */
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { background: #eef1f4; padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--text-muted); }

/* Topbar — fixa no topo ao rolar (sticky), sempre acessível */
.topbar {
    background: #14293d; color: #fff;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
}
/* Topo na largura toda (11/11/2026): marca colada à esquerda, usuário à direita, e o menu
   ocupa o meio inteiro — com o perfil super_admin (17 itens) cabe em até 2 linhas. */
.topbar-inner {
    padding: .3rem 1.25rem;
    display: flex; align-items: center; gap: 1.25rem; min-height: 52px;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; flex-shrink: 0; }
.brand span { color: #6fc1ff; }
.mainnav { display: flex; gap: .1rem .15rem; flex: 1; flex-wrap: wrap; min-width: 0; }
.mainnav a {
    color: #c9d6e2; text-decoration: none; padding: .38rem .55rem; border-radius: 6px; font-size: .9rem;
    white-space: nowrap;
}
.mainnav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.mainnav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
.userbox { display: flex; align-items: center; gap: .75rem; margin-left: auto; flex-shrink: 0; white-space: nowrap; }
.username { font-size: .88rem; color: #c9d6e2; }
@media (max-width: 1280px) {
    .topbar-inner { gap: .9rem; padding: .3rem .9rem; }
    .mainnav a { padding: .34rem .42rem; font-size: .86rem; }
    .username small { display: none; } /* o perfil cede espaço ao menu em tela menor */
}

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; width: 100%; flex: 1; }
.footer {
    text-align: center; color: var(--text-muted); font-size: .8rem;
    padding: 1rem; border-top: 1px solid var(--border);
}

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem;
}

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.table th a.th-sort { color: inherit; text-decoration: none; }
.table th a.th-sort:hover { color: var(--text); text-decoration: underline; }

/* Dashboard de produtividade — gráficos em CSS puro (sem build/CDN) */
.chart-legend { display: flex; gap: 1.25rem; margin-bottom: .5rem; font-size: .8rem; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: .4rem; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.vchart { display: flex; align-items: flex-end; gap: 3px; height: 200px; padding-bottom: 1.2rem; position: relative; }
.vchart-col {
    flex: 1 1 0; min-width: 0; height: 100%; position: relative;
    display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
}
/* Duas barras lado a lado (abertos x finalizados) por dia */
.vchart-bars { display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 100%; height: 100%; }
.vchart-stack {
    flex: 1 1 0; min-width: 0; max-width: 16px; height: 100%;
    display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px;
}
.vchart-val { font-size: .62rem; color: var(--text-muted); line-height: 1; }
.vchart-bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-opened { background: var(--chart-opened); }
.bar-finished { background: var(--primary); }
.vchart-col:hover .vchart-bar { filter: brightness(.9); }
.vchart-label {
    position: absolute; bottom: -1.2rem; font-size: .66rem; color: var(--text-muted);
    white-space: nowrap; height: 1rem;
}
.hbar { background: #e8edf3; border-radius: 4px; height: 12px; width: 100%; min-width: 90px; margin-top: .2rem; }
.hbar > i { display: block; height: 100%; border-radius: 4px; background: var(--primary); min-width: 2px; }
.hbar.hbar-danger > i { background: var(--danger); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.table tbody tr:hover { background: #f8fafb; }
.actions { white-space: nowrap; }
.actions a { margin-right: .5rem; }
.table-audit { font-size: .85rem; }
.diff-cell pre {
    margin: 0; font-size: .75rem; max-width: 320px; max-height: 130px;
    overflow: auto; background: #f6f8fa; padding: .35rem; border-radius: 4px;
}

/* Badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-off { background: var(--off-bg); color: var(--off-fg); }
.badge-unknown { background: #e5e8ec; color: #4a5665; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field-wide { grid-column: 1 / -1; }
.field label.checkbox { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 600; }
.field label.checkbox input { width: auto; padding: 0; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select {
    padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
    font-size: .95rem; background: #fff; color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.form-actions { margin-top: 1.25rem; display: flex; gap: .6rem; }

/* Buttons */
.btn {
    display: inline-block; padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); font-size: .92rem; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f2f4f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(0, 0, 0, .07); }
.topbar .btn-ghost { color: #c9d6e2; }
.btn-block { width: 100%; }
.link-button {
    background: none; border: none; padding: 0; cursor: pointer;
    color: var(--primary); font-size: inherit; text-decoration: underline;
}
.link-button.danger { color: var(--danger); }
.inline { display: inline; }

/* Alerts */
.alert { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: .92rem; }
.alert-success { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid #bfe3bf; }
.alert-error { background: var(--off-bg); color: var(--off-fg); border: 1px solid #f2c4be; }
.alert-info { background: #eaf2fb; color: #1d4f7a; border: 1px solid #c3d8ee; }
.alert-warning { background: #fdf5e3; color: #7a5410; border: 1px solid #ecd9a8; }
.error-list { margin: 0; padding-left: 1.1rem; }

/* Search bar */
.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.searchbar input, .searchbar select {
    padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; font-size: .92rem;
}
.searchbar input[type="text"] { min-width: 280px; }

/* Login */
.login-wrap { display: flex; justify-content: center; padding: 8vh 1rem 0; }
.login-card { width: 100%; max-width: 380px; padding: 2rem; }
.login-brand { text-align: center; font-size: 1.7rem; margin-bottom: .25rem; color: #14293d; }
.login-brand span { color: var(--primary); }
.login-subtitle { text-align: center; color: var(--text-muted); margin: 0 0 1.5rem; font-size: .9rem; }
.login-card .field { margin-bottom: 1rem; }
.login-help { color: var(--text-muted); font-size: .9rem; margin: 0 0 1rem; }
.login-links { text-align: center; margin: 1rem 0 0; font-size: .9rem; }
.login-suggest { margin: 1rem 0 0; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 1.25rem; text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: .88rem; margin-top: .25rem; }

/* Catalogs */
.catalog-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px) { .catalog-grid { grid-template-columns: 1fr 1fr; } .catalog-grid .card:last-child { grid-column: 1 / -1; } }

/* Pagination (view pagination::default) */
.pagination { display: flex; gap: .25rem; list-style: none; padding: 0; margin: 1rem 0; flex-wrap: wrap; }
.pagination li a, .pagination li span {
    display: inline-block; padding: .35rem .7rem; border: 1px solid var(--border);
    border-radius: 6px; text-decoration: none; color: var(--text); background: #fff; font-size: .88rem;
}
.pagination li.active span { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination li.disabled span { color: var(--text-muted); background: transparent; }

/* ==== Fase 2: Reparos ==== */

/* Badges de estado (cores portadas do legado: lbBotRepair.BackColor) */
.badge.status-0 { background: #e5e8ec; color: #4a5665; }           /* Cadastrado (cinza) */
.badge.status-1 { background: #e2f4d3; color: #3d6b12; }           /* Em andamento (verde) */
.badge.status-2 { background: #ffe8cc; color: #9a5a00; }           /* Pausado (laranja) */
.badge.status-3 { background: #ffdfd6; color: #b03a12; }           /* Aguardando peça (laranja-vermelho) */
.badge.status-4 { background: #f3dcf5; color: #862e8e; }           /* Em teste (magenta) */
.badge.status-5 { background: #d9ecf0; color: #2a6b7c; }           /* Finalizado (azul cadet) */
.badge.status-6 { background: #14293d; color: #ffffff; }           /* Congelado (azul escuro) */
.badge.status-7 { background: #eef0f2; color: #6b7480; border: 1px dashed #b8c0c8; } /* Encerrado (cinza claro, arquivado) */

/* Barra de botões de transição (legado: bts0..bts4) */
.statebar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.btn-state { font-weight: 600; border-width: 2px; }
.btn-state.state-1 { border-color: #6fae2e; color: #3d6b12; }
.btn-state.state-2 { border-color: #e09a3a; color: #9a5a00; }
.btn-state.state-3 { border-color: #d96442; color: #b03a12; }
.btn-state.state-4 { border-color: #b45cbb; color: #862e8e; }
.btn-state.state-6 { border-color: #14293d; color: #14293d; }
.btn-state:hover { background: #f2f4f6; }

.repair-statusbox { display: flex; align-items: center; gap: .75rem; }
.timer {
    font-family: Consolas, "Cascadia Code", monospace; font-size: 1.05rem;
    font-weight: 700; color: var(--primary);
}

/* Bancada: dados à esquerda, peças/laudo/histórico à direita */
.repair-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; align-items: start; }
@media (min-width: 1000px) { .repair-grid { grid-template-columns: 5fr 7fr; } }

.table-kv th { width: 40%; font-size: .82rem; text-transform: none; letter-spacing: 0; }

.qty-input { width: 5.5rem; padding: .3rem .4rem; border: 1px solid var(--border); border-radius: 5px; }
.row-missing td { background: #fff4f2; }

.part-add {
    display: flex; gap: .75rem; align-items: end; flex-wrap: wrap;
    margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border);
}
.part-add .field { min-width: 130px; }
.part-add .field:first-child { flex: 1; min-width: 260px; }

textarea {
    padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
    font-size: .95rem; font-family: inherit; background: #fff; color: var(--text);
    width: 100%; box-sizing: border-box;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }

/* ==== Fase 3: Fila de impressão ==== */
.badge.print-0 { background: #e5e8ec; color: #4a5665; }  /* Na fila */
.badge.print-1 { background: #fff3c8; color: #8a6d00; }  /* Processando */
.badge.print-2 { background: #fde4e1; color: #a3271c; }  /* Falha */
.badge.print-3 { background: #fde4e1; color: #a3271c; }  /* Timeout */
.badge.print-4 { background: #e2f4e2; color: #1d6b2a; }  /* Impresso */

/* ==== Módulos x Máquinas (seletor no cadastro de componente) ==== */
.equip-picker { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-top: 1rem; }
.equip-picker legend { font-weight: 600; color: var(--text-muted); font-size: .85rem; padding: 0 .4rem; }
.equip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .35rem .9rem; }
.equip-option { display: flex; align-items: center; gap: .45rem; font-size: .9rem; cursor: pointer; }
.equip-option input { width: auto; }

/* ==== Card de impressao da bancada ==== */
.print-actions { display: flex; flex-wrap: wrap; gap: 1.5rem; }
.print-group { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.print-group-label { font-size: .85rem; font-weight: 600; color: var(--text-muted); }

/* ==== Catalogos editaveis ==== */
.cat-input {
    width: 100%; padding: .35rem .5rem; font-size: .9rem;
    border: 1px solid var(--border); border-radius: 5px; background: #fff; color: var(--text);
}
.cat-input:disabled { background: #f0f2f4; color: var(--text-muted); }

/* ==== Saude do agente de impressao (Administracao) ==== */
.agent-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }

/* ==== Monitor de uso (Administracao > Monitor de uso) ==== */
.usage-chart { display: flex; align-items: flex-end; gap: 1px; height: 90px; margin-top: 1rem; padding: .4rem; background: #f4f6f8; border-radius: 6px; overflow-x: auto; }
.usage-bar { flex: 1 0 3px; min-width: 3px; background: var(--primary); border-radius: 1px 1px 0 0; }
.usage-bar:hover { background: var(--danger); }
/* Eixo de tempo fixo (24h): barras posicionadas pelo horário da amostra */
.usage-chart-timed { position: relative; display: block; padding: 0; }
.usage-chart-timed .usage-bar { position: absolute; bottom: 0; min-width: 2px; }
.usage-chart-timed .usage-bar:hover { background: #163f6b; }
.usage-axis { position: relative; height: 16px; margin-top: 2px; }
.usage-axis span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--text-muted); }

/* Monitor de uso — Agenda do dia (linhas por pessoa, estilo calendário) */
.agenda { margin-top: 1rem; overflow-x: auto; }
.agenda-row { display: flex; align-items: center; gap: .6rem; min-width: 640px; border-bottom: 1px solid #eef1f4; }
.agenda-label { flex: 0 0 210px; padding: .35rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-track { position: relative; flex: 1; height: 26px; background: #f4f6f8; border-radius: 4px; }
.agenda-total { flex: 0 0 60px; text-align: right; font-variant-numeric: tabular-nums; }
.agenda-head .agenda-track { background: none; height: 20px; }
.agenda-hour { position: absolute; top: 2px; transform: translateX(-50%); font-size: 11px; color: var(--text-muted); }
.agenda-grid { position: absolute; top: 0; bottom: 0; width: 1px; background: #e2e7ec; }
.agenda-bar { position: absolute; top: 5px; bottom: 5px; min-width: 3px; background: var(--primary); border-radius: 3px; }
.agenda-bar:hover { background: var(--danger); }
.agenda-load { display: block; height: 34px; }
.agenda-load-bar { position: absolute; bottom: 0; background: #7aa7d6; border-radius: 1px 1px 0 0; }

/* Card recolhível (<details>): título clicável com seta */
.collapsible > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .5rem; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before { content: "▸"; color: var(--text-muted); transition: transform .15s; }
.collapsible[open] > summary::before { transform: rotate(90deg); }
.collapsible > summary h2 { margin: 0; }
.collapsible[open] > summary { margin-bottom: .75rem; }

/* Histórico do item (selo na tela do reparo + modal) */
.item-history-link { margin-top: .35rem; display: flex; flex-wrap: wrap; gap: .35rem; }
button.badge { border: 0; cursor: pointer; font-family: inherit; }
button.badge:hover { filter: brightness(.95); text-decoration: underline; }
.badge-info { background: #eaf2fb; color: #1d4f7a; }
.badge-warn { background: #fdf5e3; color: #7a5410; }
.modal { border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; width: min(960px, calc(100vw - 2rem)); max-height: calc(100vh - 4rem); }
.modal::backdrop { background: rgba(20, 41, 61, .45); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.modal-head h2 { margin: 0 0 .5rem; }
.table-scroll { overflow-x: auto; }
.current-row td { background: #f3f7fb; }

/* Painel de histórico do item na abertura do chamado */
#item-alert .alert { margin-bottom: .5rem; }
#item-alert .table-compact { margin-top: .5rem; background: rgba(255,255,255,.6); font-size: .85rem; }
#item-alert .table-compact th, #item-alert .table-compact td { padding: .3rem .45rem; }
#duplicate-box textarea { width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.modal-subtitle { color: var(--text-muted); font-size: .95rem; margin: -.25rem 0 .5rem; }

/* Seleção com busca (public/js/searchable-select.js) */
.ss-wrap { position: relative; }
.ss-native { position: absolute; left: 0; bottom: 0; width: 100%; height: 1px; opacity: 0; pointer-events: none; }
.ss-input {
    width: 100%; padding: .5rem 2rem .5rem .6rem; border: 1px solid var(--border); border-radius: 6px;
    font-size: .95rem; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%236b7684' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right .65rem center;
    color: var(--text); box-sizing: border-box;
}
.ss-input:disabled { background-color: #f2f4f6; color: var(--text-muted); cursor: not-allowed; }
.ss-list {
    position: absolute; z-index: 50; left: 0; top: calc(100% + 2px); margin: 0; padding: .25rem 0;
    min-width: 100%; width: max-content; max-width: min(560px, calc(100vw - 2rem));
    list-style: none; background: #fff; border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 6px 18px rgba(20, 41, 61, .12); max-height: 280px; overflow-y: auto;
}
.ss-list li { padding: .4rem .65rem; cursor: pointer; font-size: .92rem; }
.ss-list li.ss-active { background: #eaf2fb; }
.ss-list li.ss-current { font-weight: 600; }
.ss-list li.ss-empty { color: var(--text-muted); cursor: default; font-style: italic; }
.ss-input.ss-invalid { border-color: #d64545; box-shadow: 0 0 0 2px rgba(214, 69, 69, .15); }

/* Destino "Destruir" no laudo (CLAUDE.md §21.4 #3) */
.badge-danger { background: #fde4e1; color: #a3271c; font-weight: 700; }
.destination-field { border: 1px solid var(--border); border-radius: 8px; padding: .6rem 1rem; }
.destination-field legend { font-weight: 600; color: var(--text-muted); font-size: .85rem; padding: 0 .4rem; }
.destination-field .radio { display: flex; align-items: center; gap: .45rem; font-weight: 400; cursor: pointer; margin: .2rem 0; }
.destination-field .radio input { width: auto; }

/* Integração Power BI: token exibido uma única vez */
.bi-token-row { display: flex; gap: .5rem; margin: .6rem 0; }
.bi-token-row input { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }

/* Faixa do ambiente de testes (APP_ENV=staging) — nunca aparece na produção */
.env-banner { position: sticky; top: 0; z-index: 1000; background: #b3261e; color: #fff; text-align: center; font-weight: 700; letter-spacing: .03em; padding: .35rem 1rem; font-size: 13px; }

/* Card do Painel que abre uma lista (ex.: Aguardando peça) */
a.stat-card.stat-link { text-decoration: none; color: inherit; transition: box-shadow .15s, border-color .15s; }
a.stat-card.stat-link:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(16, 41, 61, .12); }
