/* ============================================================================
 * SiderConnect · Design System Global Industrial Dark + Laranja (#ff8945)
 * ============================================================================ */

:root {
    color-scheme: dark;
    --bg: #15181b;
    --header: #1b1e21;
    --panel: #202428;
    --card: #22262a;
    --field: #1a1d20;
    --edge: #383e43;
    --text: #f1f2f3;
    --muted: #b1b8bf;
    --hot: #ff8945;
    --hot-hover: #ffa264;
    --mono: 'Geist Mono', Consolas, monospace;
    --sans: 'Geist', Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar dark industrial */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #1b1f22; }
::-webkit-scrollbar-thumb { background: #464e54; border-radius: 4px; border: 2px solid #1b1f22; }
::-webkit-scrollbar-thumb:hover { background: #5e6870; }

/* ============================================================================
 * 1. BARRA SUPERIOR (HEADER #1b1e21 · 6 MENUS EM LINHA ÚNICA)
 * ============================================================================ */
.top-navbar {
    background: var(--header);
    color: var(--text);
    border-bottom: 1px solid var(--edge);
    min-height: 60px;
    padding: 0 2.5vw;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sc-nav-left {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    align-self: stretch;
    gap: 22px;
    min-width: 0;
}

.sc-navbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-size: 20px;
    font-weight: 760;
    letter-spacing: -1px;
    color: var(--text);
    text-decoration: none;
    flex-shrink: 0;
    white-space: nowrap;
}
.sc-navbar-brand svg {
    width: 32px;
    height: 32px;
    mix-blend-mode: lighten;
    flex-shrink: 0;
    display: block;
}

.sc-nav-menus {
    display: flex;
    align-self: stretch;
    align-items: stretch;
    gap: 16px;
    white-space: nowrap;
    overflow: visible;
}

/* Menus dropdown superiores */
.menu-dd {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: stretch;
}
.menu-dd.hidden,
.menu-dd[hidden] {
    display: none !important;
}
.menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: none;
    color: var(--muted);
    font-family: var(--sans);
    font-weight: 500;
    font-size: 12px;
    padding: 0 4px;
    min-height: 60px;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.25;
    transition: color 0.15s ease, box-shadow 0.15s ease;
}
.menu-btn:hover,
.menu-dd:focus-within .menu-btn,
.menu-dd.is-open > .menu-btn {
    color: var(--text);
}
.menu-dd.active > .menu-btn,
.menu-btn.active {
    color: var(--hot);
    box-shadow: inset 0 -2px var(--hot);
    font-weight: 600;
}
.menu-btn .sc-ico {
    opacity: 0.72;
}
.menu-dd.active > .menu-btn .sc-ico,
.menu-btn.active .sc-ico {
    color: var(--hot);
    opacity: 1;
}

.menu-panel {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    min-width: 256px;
    max-width: calc(100vw - 16px);
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--edge);
    border-radius: 5px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.58);
    padding: 5px 0;
    z-index: 60;
    white-space: normal;
}
.menu-dd:hover .menu-panel,
.menu-dd:focus-within .menu-panel,
.menu-dd.is-open > .menu-panel {
    display: block;
}
.menu-dd[data-nav-group="suporte"] .menu-panel,
.menu-dd[data-nav-group="importar-exportar"] .menu-panel,
.menu-panel.sc-flip-right {
    left: auto;
    right: 0;
}
.menu-panel a {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 7px 13px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    color: #dbe0e4;
    transition: background 0.12s ease, color 0.12s ease;
}
.menu-panel a .sc-ico {
    color: var(--muted);
    opacity: 0.9;
}
.menu-panel a.hidden {
    display: none;
}
.menu-panel a:hover {
    background: #2a2f34;
    color: #ffffff;
}
.menu-panel a:hover .sc-ico {
    color: var(--hot);
}
.menu-sep {
    height: 1px;
    background: var(--edge);
    margin: 5px 10px;
}
.menu-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: #ffac78;
    background: #362920;
    border: 1px solid #65412b;
    border-radius: 3px;
    padding: 1px 6px;
    margin-left: auto;
    white-space: nowrap;
}

/* Conta / Usuário à direita da barra */
.sc-account-area {
    margin-left: auto;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    color: #d6dbdf;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.sc-account-area > #sc-user-session-chip {
    display: contents;
}
.sc-account-btn {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 3px 10px 3px 3px;
    color: #d6dbdf;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    max-width: 240px;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.sc-account-btn > span:not(.sc-avatar) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sc-account-btn:hover {
    background: #24292e;
    border-color: var(--edge);
    color: #ffffff;
}
.sc-avatar {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #555b60;
    border-radius: 50%;
    font: 600 10px var(--mono);
    letter-spacing: 0.5px;
    color: #f1f2f3;
    background: #22262a;
    flex-shrink: 0;
}
.sc-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: 1px solid var(--edge);
    border-radius: 4px;
    padding: 5px 10px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.sc-logout-btn:hover {
    border-color: var(--hot);
    color: #ffffff;
    background: rgba(255, 137, 69, 0.12);
}

/* ============================================================================
 * 2. CABEÇALHO DE CONTEXTO + FILTROS (FIDELIDADE AO TEMPLATE PLANILHA)
 * ============================================================================ */
.sc-main-planilha {
    padding: 24px 1.6vw 48px;
    max-width: 100%;
    margin: 0 auto;
}

.sc-eyebrow {
    font: 500 10px var(--mono);
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sc-eyebrow::before {
    content: '';
    width: 20px;
    height: 2px;
    background: var(--hot);
    display: inline-block;
}

.sc-title-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}
.sc-title-line h1 {
    margin: 8px 0 0;
    font-weight: 580;
    font-size: clamp(27px, 3vw, 43px);
    letter-spacing: -0.055em;
    line-height: 1.08;
    color: var(--text);
}

.sc-unit-tag {
    font: 600 10px var(--mono);
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #ffac78;
    background: #362920;
    border: 1px solid #65412b;
    padding: 7px 11px;
    border-radius: 3px;
    white-space: nowrap;
}

.sc-filters {
    display: grid;
    grid-template-columns: 1fr 2fr 1.25fr 0.8fr;
    gap: 1px;
    background: var(--edge);
    border: 1px solid var(--edge);
    border-radius: 5px;
    overflow: hidden;
    margin: 20px 0 22px;
}
.sc-filter {
    background: var(--panel);
    padding: 13px 17px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.sc-filter-name {
    display: block;
    font: 500 9px var(--mono);
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}
.sc-filter-ctl {
    width: 100%;
    min-width: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text);
    font-family: var(--sans);
    font-weight: 560;
    font-size: 14px;
    padding: 2px 4px;
    margin-left: -4px;
    outline: none;
    color-scheme: dark;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.sc-filter-ctl:hover {
    background: #262b30;
    border-color: #454d54;
}
.sc-filter-ctl:focus {
    background: var(--field);
    border-color: var(--hot);
}
.sc-filter-ctl option {
    background: var(--panel);
    color: var(--text);
}
.sc-filter-val {
    font-weight: 560;
    font-size: 14px;
    color: var(--text);
    font-family: var(--mono);
    padding: 2px 0;
}

/* ============================================================================
 * 3. COMPONENTE .sheet (PLANILHA 24H E TODOS OS QUADROS OPERACIONAIS)
 * ============================================================================ */
.sc-sheet {
    border: 1px solid var(--edge);
    border-radius: 5px;
    overflow: hidden;
    background: #191c20;
    margin-bottom: 22px;
}

.sc-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    padding: 13px 15px;
    background: var(--panel);
    border-bottom: 1px solid var(--edge);
}
.sc-toolbar h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.015em;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.sc-toolbar-right {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.sc-legend {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    color: #bfc6cb;
    font-size: 11px;
}
.sc-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.sc-legend i {
    width: 10px;
    height: 10px;
    display: inline-block;
    border: 1px solid #959ea6;
    border-radius: 1px;
}
.sc-legend i.ed {
    border-color: var(--hot);
    background: #543620;
}
.sc-legend i.calc {
    background: #495159;
}
.sc-legend i.locked {
    background: repeating-linear-gradient(45deg, #24282d 0 2px, #697279 2px 3px);
}
.sc-legend i.auto {
    background: #8a949c;
}
.sc-legend i.escoria {
    border-color: #22c55e;
    background: #166534;
}

.sc-scroller,
.table-container {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    max-height: none;
    height: auto;
    background: #191c20;
    scrollbar-width: thin;
    scrollbar-color: #464f57 #191c20;
}
.sc-scroller::-webkit-scrollbar,
.table-container::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}
.sc-scroller::-webkit-scrollbar-track,
.table-container::-webkit-scrollbar-track {
    background: #191c20;
}
.sc-scroller::-webkit-scrollbar-thumb,
.table-container::-webkit-scrollbar-thumb {
    background: #464f57;
    border-radius: 999px;
    border: 1px solid #191c20;
}
.sc-scroller::-webkit-scrollbar-thumb:hover,
.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--hot);
}
.sc-scroller:focus-visible {
    outline: 2px solid var(--hot);
    outline-offset: -2px;
}

.sc-sheetfoot {
    padding: 10px 15px;
    background: #191c20;
    color: var(--muted);
    font-size: 11px;
    border-top: 1px solid var(--edge);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

/* Status real de gravação no rodapé da planilha */
#status-save-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 11px;
    color: #4ade80;
}
#status-save-badge.text-emerald-700 { color: #4ade80 !important; }
#status-save-badge.text-amber-700,
#status-save-badge.text-amber-600 { color: #fbbf24 !important; }
#status-save-badge.text-red-700,
#status-save-badge.text-red-600 { color: #f87171 !important; }

/* Selectores de toolbar dark */
.sc-toolbar-sel {
    background: var(--field);
    color: var(--text);
    border: 1px solid #464b50;
    border-radius: 4px;
    padding: 4px 9px;
    font-size: 11px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}
.sc-toolbar-sel:focus {
    border-color: var(--hot);
}

/* Banner legado caso algum módulo ainda utilize */
.section-banner {
    background: var(--panel);
    color: var(--text);
    font-weight: 600;
    font-size: 15px;
    padding: 10px 15px;
    border-bottom: 1px solid var(--edge);
}

/* ============================================================================
 * 4. TABELAS OPERACIONAIS (SUPERFÍCIE CLARA DE ALTA LEGIBILIDADE)
 * ============================================================================ */
table.op-grid {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    text-align: right;
    font: 11px var(--mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

table.op-grid thead {
    position: sticky;
    top: 0;
    z-index: 12;
}
table.op-grid thead th {
    background: #2a2f34;
    color: #dbe0e4;
    font: 600 10px var(--sans);
    letter-spacing: 0.25px;
    text-align: center;
    text-transform: uppercase;
    border-right: 1px solid #383e44;
    border-bottom: 1px solid #363b40;
    padding: 6px 5px;
    white-space: nowrap;
}
table.op-grid thead tr + tr th {
    background: #252a2f;
    color: #b5bdc5;
    font-size: 9px;
    padding: 5px 4px;
}

table.op-grid tbody tr {
    background: #ffffff;
}
table.op-grid tbody tr:nth-child(even) {
    background: #f1f3f5;
}
table.op-grid tbody td {
    color: #242a30;
    border-right: 1px solid #cbd1d6;
    border-bottom: 1px solid #cbd1d6;
    padding: 5px 5px;
    height: 24px;
    color-scheme: light;
}

/* Colunas congeladas (Sticky) à esquerda */
.sticky-col-1 {
    position: sticky;
    left: 0;
    z-index: 6;
    background-color: #e6eaed !important;
    color: #242a30;
    font-weight: 700;
    text-align: center !important;
    min-width: 46px;
    width: 46px;
}
.sticky-first {
    position: sticky;
    left: 0;
    z-index: 6;
    white-space: nowrap;
    background-color: #e6eaed !important;
    color: #242a30;
}

/* Painel Congelado Estilo Excel — Planilha 24h (HORA, G, A, C/H, ACUM) */
#tabela-24h {
    --p24-w1: 46px;
    --p24-w2: 28px;
    --p24-w3: 28px;
    --p24-w4: 40px;
    --p24-w5: 44px;
    --p24-l1: 0px;
    --p24-l2: 46px;
    --p24-l3: 74px;
    --p24-l4: 102px;
    --p24-l5: 142px;
    --p24-frozen-w: 186px;
    min-width: 1480px;
}
#tabela-24h thead th {
    font-size: 9.5px;
    padding: 5px 3px;
    letter-spacing: 0.15px;
}
#tabela-24h thead tr + tr th {
    font-size: 8.5px;
    padding: 4px 3px;
}
#tabela-24h tbody td {
    padding: 3px 4px;
    height: 23px;
    font-size: 10.5px;
}
#tabela-24h tbody td.cell-edit,
#tabela-24h tbody td.cell-lock:has(> input) {
    padding: 0 1px;
}
#tabela-24h td input.grid-input {
    padding: 2px 2px;
    font-size: 10.5px;
}
#tabela-24h th.sticky-col-1,
#tabela-24h td.sticky-col-1 {
    position: sticky;
    left: var(--p24-l1, 0px);
    z-index: 6;
    min-width: var(--p24-w1, 46px);
    width: var(--p24-w1, 46px);
    max-width: var(--p24-w1, 46px);
}
#tabela-24h th.sticky-col-2,
#tabela-24h td.sticky-col-2 {
    position: sticky;
    left: var(--p24-l2, 46px);
    z-index: 6;
    min-width: var(--p24-w2, 28px);
    width: var(--p24-w2, 28px);
    max-width: var(--p24-w2, 28px);
}
#tabela-24h th.sticky-col-3,
#tabela-24h td.sticky-col-3 {
    position: sticky;
    left: var(--p24-l3, 74px);
    z-index: 6;
    min-width: var(--p24-w3, 28px);
    width: var(--p24-w3, 28px);
    max-width: var(--p24-w3, 28px);
}
#tabela-24h th.sticky-col-4,
#tabela-24h td.sticky-col-4 {
    position: sticky;
    left: var(--p24-l4, 102px);
    z-index: 6;
    min-width: var(--p24-w4, 40px);
    width: var(--p24-w4, 40px);
    max-width: var(--p24-w4, 40px);
}
#tabela-24h th.sticky-col-5,
#tabela-24h td.sticky-col-5 {
    position: sticky;
    left: var(--p24-l5, 142px);
    z-index: 6;
    min-width: var(--p24-w5, 44px);
    width: var(--p24-w5, 44px);
    max-width: var(--p24-w5, 44px);
    font-weight: 700;
}
#tabela-24h tbody td.sticky-col-5 {
    background-color: #ffffff;
}
#tabela-24h tr.row-mt td.sticky-mt-span {
    position: sticky;
    left: var(--p24-l2, 46px);
    z-index: 6;
    padding: 0 !important;
    vertical-align: middle;
}
.mt-sel-box {
    position: relative;
    width: 100%;
    height: 22px;
    overflow: hidden;
}
#tabela-24h tr.row-mt td.sticky-mt-span select.mt-sel {
    position: absolute;
    left: 3px;
    top: 2px;
    width: calc(100% - 6px);
    height: 18px;
    font-size: 10px;
    line-height: 1;
    padding: 0 3px;
    margin: 0;
}

/* Linha divisória e sombra sutil à direita da coluna ACUM (painel congelado Excel) */
#tabela-24h .sticky-freeze-end {
    border-right: 2px solid #8a95a2 !important;
    box-shadow: 3px 0 6px -2px rgba(15, 23, 42, 0.16);
}
#tabela-24h thead th.sticky-freeze-end,
#tabela-24h tr.row-md td.sticky-freeze-end {
    border-right: 2px solid #5c6670 !important;
    box-shadow: 3px 0 7px -2px rgba(0, 0, 0, 0.42);
}
.sc-scroller.is-scrolled-x #tabela-24h .sticky-freeze-end {
    box-shadow: 6px 0 12px -3px rgba(15, 23, 42, 0.34);
}
.sc-scroller.is-scrolled-x #tabela-24h thead th.sticky-freeze-end,
.sc-scroller.is-scrolled-x #tabela-24h tr.row-md td.sticky-freeze-end {
    box-shadow: 6px 0 12px -3px rgba(0, 0, 0, 0.58);
}
.sc-scroller.is-scrolled-x #tabela-corridas .sticky-col-1,
.sc-scroller.is-scrolled-x .sticky-first {
    box-shadow: 5px 0 10px -3px rgba(15, 23, 42, 0.26);
}

table.op-grid thead th.sticky-col-1,
table.op-grid thead th.sticky-col-2,
table.op-grid thead th.sticky-col-3,
table.op-grid thead th.sticky-col-4,
table.op-grid thead th.sticky-col-5,
table.op-grid thead th.sticky-first {
    z-index: 16;
    background: #282d32 !important;
    color: #ffffff !important;
}

/* ============================================================================
 * 5. CONVENÇÃO DE CÉLULAS DO TEMPLATE + ALERTAS CRÍTICOS PRESERVADOS
 * ============================================================================ */

/* Editável: #fff5ec, texto #743916, detalhe pontilhado #a16d4b, foco #ff8945 */
.cell-edit {
    background-color: #fff5ec !important;
    color: #743916 !important;
    font-weight: 600;
}
.cell-edit:focus-within {
    background-color: #ffedd5 !important;
    outline: 2px solid var(--hot);
    outline-offset: -2px;
    position: relative;
    z-index: 2;
}
#tabela-24h td.sticky-col-2.cell-edit:focus-within,
#tabela-24h td.sticky-col-3.cell-edit:focus-within,
#tabela-24h td.sticky-col-4.cell-edit:focus-within {
    position: sticky;
    z-index: 7;
}
td.cell-edit input.grid-input,
textarea.cell-edit {
    color: #743916 !important;
}
td.cell-edit input.grid-input {
    text-decoration: underline dotted #a16d4b;
    text-underline-offset: 3px;
}

/* Calculado */
.cell-calc {
    color: #242a30;
    font-weight: 500;
}
table.op-grid tbody tr:nth-child(odd) td.cell-calc {
    background-color: #ffffff;
}
table.op-grid tbody tr:nth-child(even) td.cell-calc {
    background-color: #f1f3f5;
}
td.cell-min-acum {
    background-color: #e6eaed !important;
    color: #242a30;
    font-weight: 700;
}

/* Bloqueado: padrão hachurado/cinza discreto (.locked) para células de input/textarea travadas */
.cell-lock {
    background-color: #e6eaed !important;
    color: #5b6672;
}
table.op-grid td.cell-lock:has(> input),
table.op-grid td.cell-lock:has(> select),
textarea.cell-lock,
.cell-lock.locked {
    background: repeating-linear-gradient(
        45deg,
        #e6eaed 0 3px,
        #dce1e6 3px 6px
    ) !important;
    color: #5b6672 !important;
}
#tabela-leito td.sticky-first.cell-lock,
#tabela-materias td.sticky-first.cell-lock,
#tabela-fechamento td:nth-child(3n+1).cell-lock,
#tabela-fechamento td:nth-child(3n+2).cell-lock,
#tabela-esc td.sticky-first.cell-lock,
#tabela-gas td.sticky-first.cell-lock,
#tabela-vnt td:first-child.cell-lock {
    background: #e6eaed !important;
    color: #242a30 !important;
}

/* Automático (CLP / Modbus) */
.cell-auto {
    background-color: #e2e8f0 !important;
    color: #1e293b;
    font-weight: 600;
}

/* Verde funcional: Correção de Escória */
.cell-escoria-verde {
    background-color: #bbf7d0 !important;
    color: #14532d !important;
    font-weight: 700 !important;
}

/* Linha de Total / M/T (#dbe0e5) */
tr.row-mt td,
#tabela-24h tr.row-mt td.sticky-col-1,
#tabela-24h tr.row-mt td.sticky-mt-span {
    background-color: #dbe0e5 !important;
    color: #20262b !important;
    font-weight: 700;
    border-top: 1px solid #9aa4ae;
    border-bottom: 1px solid #9aa4ae;
}
tr.row-mt select.mt-sel {
    font-family: var(--sans);
    font-size: 10.5px;
    padding: 1px 4px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    background: #eef1f4;
    border: 1px solid #aeb7c0;
    border-radius: 3px;
    color: #30383e;
    font-weight: 600;
}

/* Linha M/D e Média Corridas (#2a2f34 com texto branco) */
tr.row-md td,
#tabela-24h tr.row-md td.sticky-col-1,
#tabela-24h tr.row-md td.sticky-col-2,
#tabela-24h tr.row-md td.sticky-col-3,
#tabela-24h tr.row-md td.sticky-col-4,
#tabela-24h tr.row-md td.sticky-col-5,
#tabela-leito tr.row-md td,
#tabela-leito tr.row-md td.sticky-first,
#tabela-corridas tr.row-media td,
#tabela-corridas tr.row-media td.sticky-col-1 {
    background-color: #2a2f34 !important;
    color: #ffffff !important;
    font-weight: 700;
    border-color: #383e44;
}

/* Remover spinners nativos em TODOS os input[type="number"] dentro das tabelas */
table input[type="number"]::-webkit-inner-spin-button,
table input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
table input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Células com inputs/selects: padding enxuto */
table.op-grid td.cell-edit,
table.op-grid td.cell-lock:has(> input) {
    padding: 0 2px;
}

/* Inputs reais in-place embutidos nas células */
table td input,
td input.grid-input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 3px 3px;
    text-align: center;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    background: transparent;
    border: none;
    overflow: visible;
    height: 100%;
    font-weight: 600;
    font-size: 11px;
    color: #242a30;
    outline: none;
}
td input.grid-input-left { text-align: left; }
input.grid-input:disabled {
    cursor: not-allowed;
    color: #5b6672 !important;
    text-decoration: none !important;
}
.cell-lock input.grid-input {
    background: transparent;
}

/* Alertas críticos preservados (Sonda >= 90% máx, Temp Gusa fora de faixa, soma % != 100%) */
.warn-low-temp,
.warn-temp-fora,
.warn-sonda-max,
td.warn-low-temp,
td.warn-temp-fora,
td.warn-sonda-max {
    background-color: #fee2e2 !important;
    color: #b91c1c !important;
    font-weight: 800 !important;
}
td.warn-low-temp input.grid-input,
td.warn-temp-fora input.grid-input,
td.warn-sonda-max input.grid-input {
    color: #b91c1c !important;
    font-weight: 800 !important;
    text-decoration-color: #dc2626 !important;
}
.ok-temp,
td.ok-temp input.grid-input {
    color: #065f46 !important;
    font-weight: 700;
}

/* Quadro Observações (5 colunas) */
.sc-obs-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(220px, 1fr));
    width: 100%;
    background: #ffffff;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    scrollbar-width: thin;
    scrollbar-color: #464f57 #191c20;
}
.sc-obs-grid::-webkit-scrollbar { height: 6px; }
.sc-obs-grid::-webkit-scrollbar-track { background: #191c20; }
.sc-obs-grid::-webkit-scrollbar-thumb { background: #464f57; border-radius: 999px; }
.sc-obs-grid::-webkit-scrollbar-thumb:hover { background: var(--hot); }
.sc-obs-col {
    border-right: 1px solid #cbd1d6;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.sc-obs-col:last-child { border-right: none; }
.sc-obs-hdr {
    background: #2a2f34;
    color: #dbe0e4;
    font-family: var(--sans);
    font-weight: 600;
    font-size: 10px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    text-align: center;
    padding: 8px 6px;
    border-bottom: 1px solid #363b40;
}
.sc-obs-col textarea {
    width: 100%;
    padding: 10px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.55;
    border: none;
    outline: none;
    resize: vertical;
    color-scheme: light;
}
.sc-obs-col textarea.cell-edit:focus {
    outline: 2px solid var(--hot);
    outline-offset: -2px;
}

/* ============================================================================
 * 6. LARGURAS MÍNIMAS DAS COLUNAS (COMPACTAÇÃO HORIZONTAL DESKTOP)
 * ============================================================================ */
#tabela-24h td.col-ga { min-width: 28px; width: 28px; }
#tabela-24h td.col-ch { min-width: 40px; width: 40px; }
#tabela-24h td.col-vazao { min-width: 58px; width: 58px; }
#tabela-24h td.col-pcor,
#tabela-24h td.col-ptop { min-width: 46px; width: 46px; }
#tabela-24h td.col-tcor,
#tabela-24h td.col-ttop { min-width: 48px; width: 48px; }
#tabela-24h td.col-sonda { min-width: 42px; width: 42px; }
#tabela-24h td.col-dens { min-width: 48px; width: 48px; }
#tabela-24h td.col-umid { min-width: 44px; width: 44px; }
#tabela-24h td.col-enf { min-width: 54px; width: 54px; }
#tabela-24h td.col-pto { min-width: 42px; width: 42px; }
#tabela-24h td.col-gusac { min-width: 54px; width: 54px; }
#tabela-24h td.col-basecf { min-width: 48px; width: 48px; }
#tabela-24h td.col-cvtipo { min-width: 88px; width: 88px; }
#tabela-24h td.col-finos { min-width: 50px; width: 50px; }

#tabela-corridas td.col-hora { min-width: 52px; width: 52px; }
#tabela-corridas td.col-chem { min-width: 52px; width: 52px; }
#tabela-corridas td.col-tg { min-width: 56px; width: 56px; }
#tabela-corridas td.col-esc-sel { min-width: 112px; width: 112px; }
#tabela-corridas td.col-carga { min-width: 52px; width: 52px; }
#tabela-corridas td.col-num { min-width: 56px; width: 56px; }
#tabela-corridas td.col-real { min-width: 64px; width: 64px; }
#tabela-corridas td.col-est { min-width: 50px; width: 50px; }

#tabela-leito,
#tabela-materias {
    table-layout: fixed;
    width: 100%;
}
#tabela-leito { min-width: 1120px; }
#tabela-materias { min-width: 1160px; }

#tabela-leito th.sticky-first,
#tabela-leito td.sticky-first {
    width: 175px;
    min-width: 155px;
    max-width: 190px;
    text-align: left !important;
    padding: 4px 7px !important;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}
#tabela-leito th:not(.sticky-first),
#tabela-leito td:not(.sticky-first) {
    min-width: 66px;
}

#tabela-materias th.sticky-first,
#tabela-materias td.sticky-first {
    width: 170px;
    min-width: 155px;
    max-width: 190px;
    text-align: left !important;
    padding: 4px 7px !important;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}
#tabela-materias th:not(.sticky-first),
#tabela-materias td:not(.sticky-first) {
    min-width: 58px;
}
#tabela-materias th:nth-last-child(3),
#tabela-materias td:nth-last-child(3) { width: 78px; min-width: 74px; }
#tabela-materias th:nth-last-child(2),
#tabela-materias td:nth-last-child(2) { width: 90px; min-width: 84px; }
#tabela-materias th:nth-last-child(1),
#tabela-materias td:nth-last-child(1) { width: 84px; min-width: 78px; }

#tabela-materias tr.row-mt td:not(.sticky-first) {
    text-align: center !important;
}
#tabela-materias tr.row-mt td.mp-pct-erro {
    background-color: #fee2e2 !important;
    color: #b91c1c !important;
    font-weight: 800 !important;
    border: 2px solid #dc2626 !important;
}
#tabela-materias tr.row-mt td.mp-pct-ok {
    background-color: #dcfce7 !important;
    color: #166534 !important;
    font-weight: 700 !important;
}

#tabela-fechamento {
    table-layout: fixed;
    width: 100%;
    min-width: 960px;
}
#tabela-fechamento th:nth-child(3n+1),
#tabela-fechamento td:nth-child(3n+1) {
    width: 17.5%;
    min-width: 150px;
    text-align: left !important;
    padding: 4px 7px !important;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}
#tabela-fechamento th:nth-child(3n+2),
#tabela-fechamento td:nth-child(3n+2) {
    width: 5.5%;
    min-width: 48px;
    text-align: center !important;
    padding: 2px 4px;
    font-size: 10px;
}
#tabela-fechamento th:nth-child(3n),
#tabela-fechamento td:nth-child(3n) {
    width: 10.33%;
    min-width: 78px;
    padding: 2px 5px;
}
#tabela-fechamento th:nth-child(4),
#tabela-fechamento td:nth-child(4),
#tabela-fechamento th:nth-child(7),
#tabela-fechamento td:nth-child(7) {
    border-left: 2px solid #6b7680;
}
#tabela-fechamento td.cell-edit {
    padding: 0 2px;
}

#tabela-esc {
    table-layout: fixed;
    width: 100%;
    min-width: 1020px;
}
#tabela-esc th.sticky-first,
#tabela-esc td.sticky-first {
    width: 120px;
    min-width: 100px;
    max-width: 125px;
    text-align: left !important;
    padding: 4px 6px !important;
    font-size: 10.5px;
    white-space: normal;
    line-height: 1.15;
}
#tabela-esc th:not(.sticky-first),
#tabela-esc td:not(.sticky-first) {
    min-width: 96px;
}
#tabela-esc td[id^="esc-btn-"] {
    text-align: center !important;
    padding: 2px 3px;
}

#tabela-esc-log td {
    text-align: center;
    padding: 4px 6px;
    font-size: 11px;
}
#tabela-esc-log th:nth-child(2),
#tabela-esc-log td:nth-child(2) {
    text-align: left;
}

#tabela-gas {
    table-layout: fixed;
    width: 100%;
    min-width: 580px;
}
#tabela-gas th.sticky-first,
#tabela-gas td.sticky-first {
    width: 95px;
    min-width: 90px;
    max-width: 115px;
    text-align: left !important;
    padding: 4px 6px !important;
    font-size: 11px;
}
#tabela-gas th:not(.sticky-first),
#tabela-gas td:not(.sticky-first) {
    min-width: 52px;
}

#tabela-gus td,
#tabela-gus th { min-width: 58px; width: 58px; }

#tabela-vnt td:first-child { text-align: center; }
#tabela-vnt td.cell-edit,
#tabela-vnt th { min-width: 48px; width: 48px; }
#tabela-vnt td:nth-child(2),
#tabela-vnt th:nth-child(2) { min-width: 56px; width: 56px; }

/* ============================================================================
 * 7. ÍCONES, BOTÕES GLOBAIS E MODAIS DARK INDUSTRIAL
 * ============================================================================ */
:where(.sc-ico) { width: 1em; height: 1em; }
.sc-ico { display: inline-block; vertical-align: -0.15em; flex-shrink: 0; }

.sc-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: #362920;
    border: 1px solid #65412b;
    color: var(--hot);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    margin-right: 6px;
    flex-shrink: 0;
}

/* Botões padrão Design System */
.sc-btn-pri,
.sc-btn-hot {
    background: var(--hot);
    color: #20160e;
    font-family: var(--sans);
    font-weight: 700;
    font-size: 12px;
    padding: 7px 14px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease;
    white-space: nowrap;
}
.sc-btn-pri:hover,
.sc-btn-hot:hover {
    background: var(--hot-hover);
}
.sc-btn-pri:disabled,
.sc-btn-hot:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sc-btn-sec {
    background: #2a2f34;
    color: var(--text);
    font-family: var(--sans);
    font-weight: 600;
    font-size: 12px;
    padding: 7px 14px;
    border-radius: 4px;
    border: 1px solid var(--edge);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}
.sc-btn-sec:hover {
    background: #353b42;
    border-color: #555e66;
}

/* Modais (Pre-load, Parâmetros, Leito) */
.sc-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 15, 0.78);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.sc-modal.hidden { display: none; }

.sc-modal-box {
    position: relative;
    background: var(--card);
    color: var(--text);
    border-radius: 6px;
    border: 1px solid #43474a;
    width: 440px;
    max-width: 95vw;
    padding: 20px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.65);
}
.sc-modal-box::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 24px;
    width: 42px;
    border-top: 2px solid var(--hot);
}

.sc-modal-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 14px;
    border-bottom: 1px solid var(--edge);
    padding-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sc-modal-title .sc-ico {
    color: var(--hot);
}

.sc-modal-box label {
    display: block;
    font: 600 10px var(--mono);
    letter-spacing: 0.7px;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 11px;
}
.sc-modal-box select,
.sc-modal-box input[type=date],
.sc-modal-box input[type=number],
.sc-modal-box input[type=text],
.sc-modal-box input[type=password] {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 8px 10px;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #464b50;
    border-radius: 4px;
    background: var(--field);
    color: #ffffff;
    outline: none;
    color-scheme: dark;
}
.sc-modal-box select:focus,
.sc-modal-box input:focus {
    border-color: var(--hot);
    outline: 1px solid var(--hot-hover);
}
.sc-modal-box input:disabled {
    background: #25292e;
    color: #7c858e;
    cursor: not-allowed;
}

.sc-modal-subbox {
    margin-bottom: 12px;
    padding: 11px 12px;
    border-radius: 5px;
    border: 1px solid var(--edge);
    background: var(--panel);
}
.sc-modal-subbox code {
    background: #14171a;
    color: #ffac78;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 10px;
}

.sc-label {
    font: 600 10px var(--mono);
    letter-spacing: 0.7px;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 6px;
}
.sc-checks { display: grid; gap: 4px; margin-bottom: 10px; }
.sc-modal-box label.sc-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    color: #dbe0e4;
    margin-bottom: 5px;
    cursor: pointer;
}
.sc-modal-box label.sc-check input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--hot);
}

.sc-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--edge);
}

.sc-toast {
    position: fixed;
    bottom: 42px;
    right: 18px;
    z-index: 120000;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--edge);
    border-left: 3px solid var(--hot);
    padding: 10px 15px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.sc-toast.hidden { display: none; }

/* ============================================================================
 * 8. RESPONSIVIDADE
 * ============================================================================ */
@media (max-width: 1380px) {
    .top-navbar {
        padding: 0 14px;
        gap: 12px;
    }
    .sc-nav-left {
        gap: 12px;
    }
    .sc-navbar-brand {
        font-size: 16px;
        gap: 7px;
    }
    .sc-navbar-brand svg {
        width: 26px;
        height: 26px;
    }
    .sc-nav-menus {
        gap: 8px;
        overflow: visible;
    }
    .menu-btn {
        font-size: 11.5px;
        padding: 0 3px;
        gap: 3px;
    }
    .sc-account-area {
        gap: 6px;
    }
    .sc-account-btn {
        max-width: 165px;
        font-size: 11.5px;
        gap: 6px;
        padding: 2px 8px 2px 2px;
    }
    .sc-avatar {
        width: 26px;
        height: 26px;
    }
    .sc-logout-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
}

@media (max-width: 1120px) {
    .sc-filters {
        grid-template-columns: 1fr 1.8fr 1fr 0.7fr;
    }
    .sc-obs-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1060px) {
    .top-navbar {
        padding: 0 10px;
        gap: 8px;
    }
    .sc-nav-left {
        gap: 8px;
    }
    .sc-navbar-brand > span {
        display: none;
    }
    .sc-navbar-brand svg {
        width: 28px;
        height: 28px;
    }
    .sc-nav-menus {
        gap: 6px;
        overflow: visible;
    }
    .sc-account-btn {
        max-width: 120px;
    }
    .sc-logout-btn {
        padding: 5px 7px;
    }
    .sc-logout-btn > span:not(.sc-ico) {
        display: none;
    }
}

@media (max-width: 840px) {
    .top-navbar {
        flex-wrap: wrap;
        padding: 6px 12px 4px;
        gap: 4px 10px;
        min-height: auto;
    }
    .sc-nav-left {
        display: contents;
    }
    .sc-navbar-brand {
        order: 1;
    }
    #nav-right-controls {
        order: 2;
        margin-left: auto;
    }
    .sc-nav-menus {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        overflow: visible;
        gap: 2px 10px;
    }
    .menu-btn {
        min-height: 36px;
    }
}

@media (max-width: 680px) {
    .sc-main-planilha {
        padding: 18px 12px 46px;
    }
    .sc-filters {
        grid-template-columns: 1fr 1.4fr;
    }
    .sc-filter {
        padding: 10px 12px;
    }
    .sc-legend {
        font-size: 10px;
        gap: 8px;
    }
    .sc-toolbar {
        padding: 11px 12px;
    }
    .sc-unit-tag {
        font-size: 9px;
    }
    .sc-obs-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================================================
 * 9. AUTH GATE FAIL-CLOSED (3 ESTADOS EXCLUSIVOS: pending / guest / ready)
 * ============================================================================ */
body.sc-auth-pending,
body.sc-auth-guest {
    background-color: #111315;
    overflow: hidden;
}

/* Fail-closed: em pending ou guest, TODO o shell autenticado, planilha, abas de
   módulos, painéis operacionais, modais e rodapés internos ficam ocultos */
body.sc-auth-pending > *:not(#scAuthGate):not(script):not(style):not(link),
body.sc-auth-guest > *:not(#sc-login-overlay):not(script):not(style):not(link) {
    display: none !important;
    visibility: hidden !important;
}

body.sc-auth-pending .top-navbar,
body.sc-auth-pending #planilha-main,
body.sc-auth-pending .sc-main-planilha,
body.sc-auth-pending #sc-statusbar,
body.sc-auth-pending #sc-login-overlay,
body.sc-auth-pending #sc-preload-view,
body.sc-auth-pending #sc-leito-view,
body.sc-auth-pending #sc-materiais-view,
body.sc-auth-pending #sc-gestao-view,
body.sc-auth-pending #sc-importacao-view,
body.sc-auth-pending #sc-pci-view,
body.sc-auth-pending #sc-ute-view,
body.sc-auth-pending #sc-estoque-view,
body.sc-auth-pending #sc-simulacao-view,
body.sc-auth-pending #sc-otimizacao-view,
body.sc-auth-guest .top-navbar,
body.sc-auth-guest #planilha-main,
body.sc-auth-guest .sc-main-planilha,
body.sc-auth-guest #sc-statusbar,
body.sc-auth-guest #sc-preload-view,
body.sc-auth-guest #sc-leito-view,
body.sc-auth-guest #sc-materiais-view,
body.sc-auth-guest #sc-gestao-view,
body.sc-auth-guest #sc-importacao-view,
body.sc-auth-guest #sc-pci-view,
body.sc-auth-guest #sc-ute-view,
body.sc-auth-guest #sc-estoque-view,
body.sc-auth-guest #sc-simulacao-view,
body.sc-auth-guest #sc-otimizacao-view {
    display: none !important;
    visibility: hidden !important;
}

/* Overlay inicial leve de verificação de sessão (#scAuthGate) */
#scAuthGate {
    display: none;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100010;
    background-color: #111315;
    color: #f1f2f3;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 18px;
    font-family: var(--sans);
}

.sc-auth-gate-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.sc-auth-gate-logo {
    width: 44px;
    height: 44px;
    display: block;
    flex-shrink: 0;
    mix-blend-mode: lighten;
}

.sc-auth-gate-title {
    font-size: 26px;
    font-weight: 760;
    letter-spacing: -0.8px;
    color: #f1f2f3;
    line-height: 1;
}

.sc-auth-gate-status {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.8px;
    color: #9ba3ab;
}

.sc-auth-gate-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 137, 69, 0.24);
    border-top-color: var(--hot);
    border-radius: 9999px;
    animation: sc-auth-spin 0.8s linear infinite;
}

@keyframes sc-auth-spin {
    to { transform: rotate(360deg); }
}

/* Estado 1: PENDING — exibe APENAS #scAuthGate (mantém tela de login oculta) */
body.sc-auth-pending > #scAuthGate {
    display: flex !important;
    visibility: visible !important;
}

/* Estado 2: GUEST — oculta #scAuthGate e exibe EXCLUSIVAMENTE a tela de login */
body.sc-auth-guest > #scAuthGate,
body.sc-auth-guest #scAuthGate {
    display: none !important;
    visibility: hidden !important;
}

body.sc-auth-guest > #sc-login-overlay,
body.sc-auth-guest #sc-login-overlay {
    display: flex !important;
    visibility: visible !important;
}

/* Estado 3: READY — oculta #scAuthGate e tela de login, liberando a aplicação */
body.sc-auth-ready > #scAuthGate,
body.sc-auth-ready #scAuthGate,
body.sc-auth-ready > #sc-login-overlay,
body.sc-auth-ready #sc-login-overlay {
    display: none !important;
    visibility: hidden !important;
}
