/* ============================================================
   QOP 07 — Plano de Empenhamento de Meios Aéreos
   Estilos principais — fiéis ao impresso original (v09ABR25)
   ============================================================ */

:root {
    --cor-cabecalho-cinza: #595959;  /* fundo cinza cabeçalho principal */
    --cor-titulo-vermelho: #C00000;  /* título do plano */
    --cor-linha-amarela:   #FFC000;  /* linha de horas / legenda da grelha */
    --cor-azul-tabela:     #1F4E79;  /* cabeçalhos das tabelas de referência */
    --cor-azul-claro:      #BDD7EE;  /* linha alternada da tabela de aeronaves */
    --cor-verde-missao:    #92D050;  /* M — Em Missão */
    --cor-laranja-transito:#F4B942;  /* T — Em Trânsito */
    --cor-vermelho-inop:   #FF0000;  /* I — INOP */
    --cor-azul-reabast:    #00B0F0;  /* R — Reabastecimento */
    --cor-fundo-grelha:    #FFFFFF;
    --cor-borda:           #000000;
    --cor-borda-suave:     #b9b9b9;

    --fundo-pagina:  #e9eaed;
    --fundo-painel:  #ffffff;
    --texto:         #1a1a1a;
    --texto-suave:   #555;
    --barra-fundo:   #2b2f36;
    --barra-texto:   #f1f1f1;
}

* { box-sizing: border-box; }

/* O atributo HTML [hidden] tem de vencer regras display:flex (modais/menus) */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    color: var(--texto);
    background: var(--fundo-pagina);
}

button { font-family: inherit; cursor: pointer; }

/* ─── Barra de ações ─────────────────────────────────────── */
.barra-acoes {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: var(--barra-fundo);
    color: var(--barra-texto);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.barra-grupo { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.barra-acoes button {
    background: #3b4049;
    color: #fff;
    border: 1px solid #555b66;
    border-radius: 5px;
    padding: 6px 11px;
    font-size: 12.5px;
    transition: background .15s;
}
.barra-acoes button:hover { background: #4b5159; }
.barra-acoes .btn-tema { padding: 6px 9px; }
.pin-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: #14502a;
    color: #cdeccf;
    border: 1px solid #2e7d46;
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.pin-badge strong { color: #fff; font-size: 13px; letter-spacing: 1px; }
.pin-badge:hover { background: #1b6537; }
.estado-guardado {
    font-size: 11.5px;
    color: #c9ccd1;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, .07);
    white-space: nowrap;
}
.estado-guardado.sujo  { color: #ffd479; }
.estado-guardado.ok    { color: #9ee493; }
.estado-guardado.erro  { color: #ff8a8a; }

/* ─── Aviso mobile ───────────────────────────────────────── */
.aviso-mobile {
    display: none;
    background: #fff3cd;
    color: #664d03;
    border-bottom: 1px solid #ffe69c;
    padding: 8px 12px;
    text-align: center;
    font-size: 12px;
}

/* ─── Contentor do documento ─────────────────────────────── */
.container-qop07 {
    background: var(--fundo-painel);
    margin: 12px auto;
    padding: 10px 12px 16px;
    max-width: 1700px;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .15);
}

/* ─── Cabeçalho do plano (banner vermelho) ───────────────── */
.qop-header {
    display: grid;
    grid-template-columns: 70px 1fr auto;
    align-items: center;
    gap: 12px;
    background: var(--cor-titulo-vermelho);
    padding: 4px 14px;
    border: 1px solid var(--cor-borda);
}
.qop-logo {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qop-logo svg { display: block; }
.qop-titulo {
    margin: 0;
    text-align: center;
    color: #fff;
    font-size: 26px;
    font-weight: bold;
    letter-spacing: .3px;
}
.qop-ref {
    color: #fff;
    font-size: 9.5px;
    line-height: 1.3;
    text-transform: uppercase;
    font-weight: bold;
    display: flex;
    gap: 14px;
    align-items: center;
    white-space: nowrap;
}
.qop-ref-cod { text-align: center; }

/* ─── Faixa de campos (rótulo azul + valor) ──────────────── */
.qop-fields {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    border: 1px solid var(--cor-borda);
    border-top: none;
    overflow-x: auto;
}
.qop-fields .ff {
    display: flex;
    align-items: stretch;
    flex: 1 1 0;
    min-width: 0;
    min-height: 58px;
    border-right: 1px solid var(--cor-borda);
}
.qop-fields .ff:last-child { border-right: none; }
.qop-fields .lbl {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: var(--cor-azul-tabela);
    color: #fff;
    font-weight: bold;
    font-size: 9.5px;
    padding: 4px 6px;
    line-height: 1.15;
    flex: 0 0 auto;
    width: 104px;
    overflow: visible;
    word-break: normal;
    overflow-wrap: anywhere;
}
.qop-fields .ff input {
    border: none;
    background: #fff;
    font-size: 13px;
    text-align: center;
    padding: 4px 6px;
    min-width: 0;
    width: 100%;
    color: var(--texto);
}
.qop-fields .ff input:focus { outline: 2px solid var(--cor-azul-reabast); background: #eef8ff; }
/* Nº Ocorrência + Data empilhados */
.ff-stacked { flex-direction: column; flex: 1.4 1 0; }
.ff-stacked .frow { display: flex; align-items: stretch; flex: 1; min-height: 28px; }
.ff-stacked .frow:first-child { border-bottom: 1px solid var(--cor-borda); }
/* Lat / Long */
.ff-latlong { flex-direction: column; flex: 0 0 auto; justify-content: center; padding: 4px 10px; gap: 6px; min-width: 200px; }
.ff-latlong .frow { display: flex; align-items: center; gap: 6px; }
.ff-latlong .ll { font-weight: bold; min-width: 34px; }
.ff-latlong input { border: none; border-bottom: 1px solid #999; font-size: 12px; padding: 2px 4px; width: 100%; text-align: left; }

/* ─── Grelha temporal ────────────────────────────────────── */
.grelha-wrap {
    margin-top: 10px;
    overflow-x: auto;
    border: 1px solid var(--cor-borda);
}
.grelha {
    border-collapse: collapse;
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
}
.grelha th, .grelha td {
    border: 1px solid var(--cor-borda-suave);
    padding: 0;
}
.grelha thead th {
    background: var(--cor-linha-amarela);
    color: #000;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    height: 22px;
}
.grelha .hora-grupo {
    border-left: 2px solid var(--cor-borda);
    border-right: 2px solid var(--cor-borda);
    font-size: 10.5px;
}
.grelha .min-cell { width: 19px; font-size: 8.5px; font-weight: normal; }

/* Cabeçalhos verticais (Hora Descolagem / Autonomia / 21:00) */
.grelha th.rot { vertical-align: bottom; padding: 2px 0; }
.grelha th.rot span {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    display: inline-block;
    font-size: 10px;
}

/* Colunas fixas à esquerda */
.col-meio  { width: 150px; min-width: 150px; }
.col-desc  { width: 60px; }
.col-aut   { width: 56px; }
.col-aplicar { width: 26px; background: var(--cor-linha-amarela); }
.col-fim   { width: 24px; background: var(--cor-linha-amarela); border-left: 2px solid var(--cor-borda); }
.col-obs   { width: 160px; min-width: 160px; }

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--cor-linha-amarela);
}
.grelha tbody .sticky-col { background: #fff; }

.grelha tbody td input {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 11px;
    padding: 4px 4px;
    color: inherit;
}
.grelha tbody td input:focus { outline: 2px solid var(--cor-azul-reabast); background: #eef8ff; }
.in-meio { font-weight: bold; }
.in-descolagem, .in-autonomia { text-align: center; }

.btn-aplicar {
    width: 100%;
    height: 26px;
    border: none;
    background: transparent;
    font-size: 13px;
    line-height: 1;
}
.btn-aplicar:hover { background: rgba(0, 0, 0, .08); }

/* Slots */
.slot {
    width: 19px;
    height: 28px;
    cursor: pointer;
    background: var(--cor-fundo-grelha);
    touch-action: none;   /* permite arrastar para pintar em tablet */
}
.grelha .hora-grupo,
.slot[data-hora$=":00"] { border-left: 2px solid var(--cor-borda) !important; }
.slot.transito { background: var(--cor-laranja-transito); }
.slot.missao   { background: var(--cor-verde-missao); }
.slot.reabast  { background: var(--cor-azul-reabast); }
.slot.inop     { background: var(--cor-vermelho-inop); }
.slot:hover    { outline: 2px solid #333; outline-offset: -2px; opacity: .8; }
.slot:focus    { outline: 2px solid #000; outline-offset: -2px; }
.slot.selecionado { box-shadow: inset 0 0 0 2px #000; }

/* ─── Legenda + contadores ───────────────────────────────── */
.barra-legenda {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 6px 4px;
}
.legenda { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.legenda-titulo { font-weight: bold; font-size: 12px; }
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
    border: 1px solid rgba(0, 0, 0, .35);
    color: #000;
}
.badge-transito { background: var(--cor-laranja-transito); }
.badge-missao   { background: var(--cor-verde-missao); }
.badge-reabast  { background: var(--cor-azul-reabast); }
.badge-inop     { background: var(--cor-vermelho-inop); color: #fff; }

.contadores { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; }
.contadores b { font-size: 12.5px; }

/* ─── Painel inferior (FOMA + Pontos) ────────────────────── */
.painel-inferior {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 12px;
}
.bloco-titulo {
    margin: 0 0 4px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    color: #fff;
    background: var(--cor-azul-tabela);
    padding: 4px 8px;
    letter-spacing: .3px;
}

/* ─── Tabelas de referência ──────────────────────────────── */
.tabela-ref {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.tabela-ref th, .tabela-ref td {
    border: 1px solid var(--cor-borda);
    padding: 3px 5px;
    font-size: 11px;
    text-align: center;
    vertical-align: middle;
}
.tabela-ref thead th {
    background: var(--cor-azul-tabela);
    color: #fff;
    font-size: 10px;
}
.tabela-aeronaves thead th { font-size: 9px; padding: 2px 3px; line-height: 1.1; }
.tabela-ref .th-verde { background: var(--cor-verde-missao); color: #000; }
.tabela-ref tbody input,
.tabela-ref tbody select {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 11px;
    text-align: center;
    padding: 2px;
    color: inherit;
}
.tabela-ref tbody input:focus { outline: 2px solid var(--cor-azul-reabast); background: #eef8ff; }

/* FOMA */
.tabela-foma .f-meio { text-align: left; font-weight: bold; }
.tabela-foma th:first-child, .tabela-foma td:first-child { width: 30%; text-align: left; }

/* Pontos de abastecimento */
.tabela-pontos .td-num { width: 26px; font-weight: bold; background: #f3f6fb; }
.tabela-pontos .p-local { text-align: left; }
.td-coord { padding: 1px 2px !important; }
.coord-grupo {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    flex-wrap: nowrap;
    font-size: 10px;
}
.coord-grupo input { width: 34px !important; text-align: center; }
.coord-grupo input.p-lat-g, .coord-grupo input.p-long-g { width: 30px !important; }
.coord-grupo select { width: 34px !important; }
.coord-grupo span { color: var(--texto-suave); }
.td-mapa { width: 34px; }
.btn-mapa { border: none; background: transparent; font-size: 15px; }
.btn-mapa:hover { transform: scale(1.15); }

/* Tabela de aeronaves (estática) */
.tabela-aeronaves { margin-top: 2px; }
.tabela-aeronaves td { background: #fff; }
.tabela-aeronaves tbody tr:nth-child(even) td { background: var(--cor-azul-claro); }
.tabela-aeronaves .td-modelo { text-align: left; font-weight: bold; }
/* Linhas HEM (a preencher) destacadas a amarelo, como no original */
.tabela-aeronaves tbody tr.linha-hem td,
.tabela-aeronaves tbody tr.linha-hem:nth-child(even) td { background: var(--cor-linha-amarela); }
.tabela-aeronaves tbody tr.linha-hem .td-modelo { background: #fff; }
.bloco-aeronaves { margin-top: 14px; }

/* ─── Mini-selector de estado ────────────────────────────── */
.slot-menu {
    position: absolute;
    z-index: 200;
    display: flex;
    gap: 2px;
    padding: 3px;
    background: #fff;
    border: 1px solid #333;
    border-radius: 5px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
.slot-menu button {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(0, 0, 0, .35);
    border-radius: 3px;
    font-weight: bold;
    font-size: 12px;
}
.slot-menu .sm-transito { background: var(--cor-laranja-transito); }
.slot-menu .sm-missao   { background: var(--cor-verde-missao); }
.slot-menu .sm-reabast  { background: var(--cor-azul-reabast); }
.slot-menu .sm-inop     { background: var(--cor-vermelho-inop); color: #fff; }
.slot-menu .sm-limpar   { background: #eee; }

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}
.modal {
    background: var(--fundo-painel);
    width: min(620px, 92vw);
    max-height: 86vh;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}
.modal-cabecalho {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--cor-azul-tabela);
    color: #fff;
    padding: 10px 14px;
}
.modal-cabecalho h2 { margin: 0; font-size: 15px; }
.modal-fechar { background: transparent; border: none; color: #fff; font-size: 18px; }
.modal-filtros { display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid #ddd; }
.modal-filtros input { flex: 1; padding: 6px 8px; border: 1px solid #bbb; border-radius: 4px; font-size: 12px; }
.modal-filtros button { padding: 6px 12px; border: 1px solid var(--cor-azul-tabela); background: var(--cor-azul-tabela); color: #fff; border-radius: 4px; }
.modal-lista { overflow-y: auto; padding: 6px 10px 12px; }
.modal-vazio { color: var(--texto-suave); text-align: center; padding: 18px; }

/* Modal de acesso por PIN (porta de entrada) */
.modal-acesso-box { width: min(420px, 92vw); }
.acesso-corpo { padding: 16px 18px 20px; }
.acesso-corpo p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }
.acesso-linha { display: flex; gap: 8px; align-items: stretch; }
.acesso-linha input {
    flex: 1;
    padding: 10px 12px;
    font-size: 20px;
    text-align: center;
    letter-spacing: 4px;
    border: 1px solid #aaa;
    border-radius: 6px;
    background: #fff;
    color: #111;
}
.acesso-linha input:focus { outline: 2px solid var(--cor-azul-reabast); border-color: var(--cor-azul-reabast); }
.acesso-linha button {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    background: var(--cor-azul-tabela);
    border: none;
    border-radius: 6px;
    white-space: nowrap;
}
.acesso-linha button:hover { opacity: .9; }
.acesso-dica { margin: 12px 0 0 !important; font-size: 11.5px; color: var(--texto-suave); }
.item-plano {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border: 1px solid #e1e1e1;
    border-radius: 6px;
    margin-bottom: 7px;
    background: #fafafa;
}
.item-plano:hover { background: #eef4fb; border-color: #bcd4ef; }
.item-plano .ip-info { display: flex; flex-direction: column; gap: 2px; }
.item-plano .ip-titulo { font-weight: bold; font-size: 13px; }
.item-plano .ip-meta { font-size: 11px; color: var(--texto-suave); }
.item-plano .ip-acoes { display: flex; gap: 6px; }
.item-plano button { padding: 5px 10px; border-radius: 4px; border: 1px solid #bbb; background: #fff; font-size: 12px; }
.item-plano .btn-abrir { background: var(--cor-azul-tabela); color: #fff; border-color: var(--cor-azul-tabela); }
.item-plano .btn-dup { background: #fff; }

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 400;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
    opacity: 0;
    transition: opacity .25s, transform .25s;
}
.toast.mostrar { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.erro { background: #b22; }
.toast.ok   { background: #1b7a35; }

/* ─── Modo escuro (uso noturno) ──────────────────────────── */
body.tema-escuro {
    --fundo-pagina: #14161a;
    --fundo-painel: #1d2026;
    --texto: #e6e6e6;
    --texto-suave: #aaa;
    --cor-borda-suave: #4a4f57;
    background: var(--fundo-pagina);
}
body.tema-escuro .container-qop07 { box-shadow: 0 1px 6px rgba(0, 0, 0, .6); }

/* Cabeçalho (vermelho) e rótulos (azul) mantêm-se — são cores de identidade.
   Corrigem-se sim os campos editáveis, que tinham fundo branco fixo. */
body.tema-escuro .qop-fields { background: var(--fundo-painel); }
body.tema-escuro .qop-fields .ff input {
    background: #23262d;
    color: var(--texto);
}
body.tema-escuro .qop-fields .ff input::placeholder,
body.tema-escuro input::placeholder { color: #7f868f; }

/* Células e inputs das tabelas / grelha */
body.tema-escuro .grelha tbody .sticky-col,
body.tema-escuro .tabela-ref tbody td,
body.tema-escuro .tabela-pontos .td-num,
body.tema-escuro .tabela-aeronaves td { background: #23262d; }
body.tema-escuro .tabela-aeronaves tbody tr:nth-child(even) td { background: #2b3340; }
/* Linhas HEM (amarelo) e célula do modelo (branca) → texto preto legível */
body.tema-escuro .tabela-aeronaves tbody tr.linha-hem td { color: #111; }
body.tema-escuro .grelha tbody td input,
body.tema-escuro .tabela-ref tbody input,
body.tema-escuro .tabela-ref tbody select { color: var(--texto); }
body.tema-escuro .slot { background: #23262d; }
/* Slots com estado mantêm a sua cor em modo escuro (especificidade superior ao genérico acima) */
body.tema-escuro .slot.transito { background: var(--cor-laranja-transito); }
body.tema-escuro .slot.missao   { background: var(--cor-verde-missao); }
body.tema-escuro .slot.reabast  { background: var(--cor-azul-reabast); }
body.tema-escuro .slot.inop     { background: var(--cor-vermelho-inop); }

/* Modais, listas e slot-menu */
body.tema-escuro .item-plano { background: #23262d; border-color: #3a3f47; }
body.tema-escuro .modal { background: #1d2026; }
body.tema-escuro .slot-menu { background: #2a2d34; border-color: #555b66; }
body.tema-escuro .slot-menu .sm-limpar { background: #3a3f47; color: var(--texto); }
body.tema-escuro .modal-filtros input { background: #23262d; color: var(--texto); border-color: #4a4f57; }
body.tema-escuro .acesso-linha input  { background: #23262d; color: var(--texto); border-color: #5a5f66; }

body.tema-escuro input:focus,
body.tema-escuro select:focus,
body.tema-escuro .grelha tbody td input:focus { background: #15324a !important; color: #fff; }

/* Contagem decrescente — cores mais vivas para fundo escuro */
body.tema-escuro .aut-countdown.ok       { color: #5fd07a; }
body.tema-escuro .aut-countdown.aviso    { color: #f0b94a; }
body.tema-escuro .aut-countdown.critico  { color: #ff6b6b; }
body.tema-escuro .aut-countdown.esgotada { color: #8a8f96; }

/* ─── Autonomia: wrapper + countdown ────────────────────── */
.aut-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}
.aut-countdown {
    display: block;
    font-size: 7.5px;
    font-weight: bold;
    text-align: center;
    line-height: 1.15;
    min-height: 11px;
    padding: 0 1px;
    white-space: nowrap;
}
.aut-countdown.ok       { color: #1a7a35; }
.aut-countdown.aviso    { color: #8a4e00; }
.aut-countdown.critico  { color: #c00000; }
.aut-countdown.partida  { color: var(--texto-suave); }
.aut-countdown.esgotada { color: #999; font-style: italic; }

/* Botão GPS ─────────────────────────────────────────────── */
.btn-gps {
    align-self: center;
    margin-top: 3px;
    padding: 3px 8px;
    font-size: 10px;
    border: 1px solid var(--cor-azul-tabela);
    border-radius: 4px;
    background: var(--cor-azul-tabela);
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
}
.btn-gps:hover { opacity: .85; }

/* ─── Responsivo ─────────────────────────────────────────── */
@media (max-width: 1100px) {
    .painel-inferior { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
    .aviso-mobile { display: block; }
}
