/* =============================================================================
   app.css — Controle de Frota (COMIPA)
   Layout: shell · sidebar · login · grids · componentes · responsivo
   Depende de: comipa-design-system.css (variáveis e base)
   ORGANIZAÇÃO
     1. Shell (header · sidebar · main)
     2. Status da API (rodapé da sidebar)
     3. Login
     4. Grids e layout
     5. Componentes (tabs, relatos, IDO, modais, badges, toasts)
     6. Telas específicas (formulário, DMT, dados brutos)
     7. Utilitários
     8. Responsivo (tablet · celular · celular pequeno)
   v3.9.0: Dados Brutos com linhas de altura fixa (.tabela-brutos).
   ========================================================================== */
/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
img, table, .tabela, .card { max-width: 100%; }
.js-plotly-plot, .plot-container { max-width: 100% !important; }
/* =============================================================================
   1. SHELL
   ========================================================================== */
.shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "header header" "sidebar main";
    height: 100vh;
    min-height: 100vh;
    overflow: hidden;              /* só o main rola */
}
/* ---- Header ---- */
.shell__header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--cor-header);
    color: #fff;
    padding: 12px var(--gap-lg);
    box-shadow: var(--sombra);
    position: sticky;
    top: 0;
    z-index: 20;
}
.shell__brand { display: flex; align-items: center; gap: 12px; }
.shell__brand small { color: var(--cor-neutra); font-weight: var(--peso-regular); }
.shell__logo { height: 30px; width: auto; display: block; filter: brightness(0) invert(1); }
.shell__header-actions { display: flex; align-items: center; gap: 10px; }
.shell__user { font-size: .9rem; color: #cfd2d4; }
.icon-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 7px 9px;
    border-radius: var(--raio);
    transition: background .15s, transform .12s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .14); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn--dark { color: var(--cor-erro); }
/* botão Sair: destaque avermelhado no hover */
.icon-btn--sair:hover { background: rgba(239, 78, 56, .22); }
/* ---- Sidebar ---- */
.shell__sidebar {
    grid-area: sidebar;
    background: var(--superficie);
    border-right: 1px solid var(--borda);
    padding: var(--gap);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.shell__nav {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.shell__sidebar-foot {
    flex: 0 0 auto;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--borda);
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--raio);
    color: var(--cor-texto);
    font-weight: var(--peso-bold);
    font-size: .92rem;
    cursor: pointer;
    position: relative;              /* p/ o badge de notificação */
    transition: background .15s;
}
.nav-link:hover { background: var(--bg-alt); text-decoration: none; }
.nav-link.ativo { background: var(--cor-primaria); color: #fff; }
.nav-link .ico { width: 18px; text-align: center; flex-shrink: 0; }
/* ---- Main ---- */
.shell__main {
    grid-area: main;
    padding: var(--gap-lg);
    overflow: auto;
    height: 100%;
}
.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--gap-lg);
    flex-wrap: wrap;
    gap: 8px;
}
.page-title h1 { font-size: 1.5rem; margin: 0; }
/* =============================================================================
   2. STATUS DA API (rodapé da sidebar)
   ========================================================================== */
.api-status {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: var(--raio);
    background: var(--bg-alt);              /* claro — a sidebar é branca */
    border: 1px solid var(--borda);
    cursor: pointer;
    user-select: none;
    transition: background .15s, border-color .15s;
}
.api-status:hover { background: var(--superficie); border-color: var(--cor-neutra); }
.api-status .api-ponto {
    flex: 0 0 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--cor-neutra);
}
.api-status .api-info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.api-status .api-rot {
    font-size: .66rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--cor-neutra);
    font-weight: var(--peso-bold);
}
.api-status .api-texto {
    font-size: .78rem;
    font-weight: var(--peso-bold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* estados */
.api-status--on { border-color: rgba(135, 196, 64, .45); }
.api-status--on .api-ponto { background: var(--cor-sucesso); box-shadow: 0 0 0 3px rgba(135, 196, 64, .22); }
.api-status--on .api-texto { color: var(--cor-sucesso); }
.api-status--off { border-color: rgba(239, 78, 56, .45); }
.api-status--off .api-ponto { background: var(--cor-erro); box-shadow: 0 0 0 3px rgba(239, 78, 56, .22); }
.api-status--off .api-texto { color: var(--cor-erro); }
.api-status--check .api-ponto { background: var(--cor-amarelo); animation: apiPulso 1.1s ease-in-out infinite; }
.api-status--check .api-texto { color: #b8791a; }
@keyframes apiPulso {
    0%, 100% { opacity: 1;   transform: scale(1); }
    50%      { opacity: .45; transform: scale(.8); }
}
/* =============================================================================
   3. LOGIN
   ========================================================================== */
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--cor-header) 0%, var(--cor-escura) 100%);
    padding: var(--gap);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--superficie);
    border-radius: var(--raio-lg);
    box-shadow: var(--sombra-lg);
    padding: 32px;
}
.login-logo { height: 54px; width: auto; display: block; margin: 0 auto; }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h2 { font-size: 1.25rem; }
.login-head p { color: var(--cor-neutra); margin: 4px 0 0; font-size: .9rem; }
.login-ou {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--cor-neutra);
    margin: 16px 0;
    font-size: .8rem;
}
.login-ou::before, .login-ou::after { content: ""; flex: 1; border-bottom: 1px solid var(--borda); }
.login-ou span { padding: 0 12px; }
.login-foot { text-align: center; margin-top: 20px; }
/* =============================================================================
   4. GRIDS E CAMPOS
   ========================================================================== */
.grid { display: grid; gap: var(--gap); }
.grid--kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-frente { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.field { margin-bottom: var(--gap); }
.field--sm { margin-bottom: 8px; }
.chk {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: var(--peso-regular);
    margin-left: 12px;
    cursor: pointer;
}
.chk input { width: auto; }
.linha-acao { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
/* =============================================================================
   5. COMPONENTES
   ========================================================================== */
/* ---- KPIs e deltas ---- */
.kpi--sm .valor { font-size: 1.4rem; }
.delta { font-size: .78rem; font-weight: var(--peso-bold); margin-top: 2px; }
.delta--up { color: var(--cor-sucesso); }
.delta--down { color: var(--cor-erro); }
.delta-mini { font-size: .72rem; font-weight: var(--peso-bold); margin-left: 4px; }
.delta-mini.delta--up { color: var(--cor-sucesso); }
.delta-mini.delta--down { color: var(--cor-erro); }
/* ---- Badges: complementa o design system (que já define a base) ---- */
/* badge sem modificador: fundo neutro claro (evita texto branco sobre branco) */
.badge:not([class*="badge--"]) {
    background: var(--bg-alt);
    color: var(--cor-texto);
    border: 1px solid var(--borda);
}
.badge--sucesso { background: var(--cor-sucesso); color: #fff; }
.badge--erro    { background: var(--cor-erro);    color: #fff; }
.badge--aviso   { background: var(--cor-amarelo); color: var(--cor-escura); }
.badge--info    { background: var(--cor-info);    color: #fff; }
.chip-inativo { opacity: .55; }
/* ---- Abas ---- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--borda); flex-wrap: wrap; }
.tab {
    background: transparent;
    border: none;
    padding: 10px 18px;
    cursor: pointer;
    font-family: var(--fonte-base);
    font-weight: var(--peso-bold);
    font-size: .92rem;
    color: var(--cor-neutra);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}
.tab:hover { color: var(--cor-texto); }
.tab--ativa { color: var(--cor-primaria); border-bottom-color: var(--cor-primaria); }
/* ---- Relatos (Atividades) ---- */
.relato { margin-bottom: 14px; }
.relato-tag {
    padding: 8px 14px;
    border-radius: var(--raio) var(--raio) 0 0;
    font-size: .85rem;
    border-left: 5px solid;
}
.relato-tag--pend { background: #fff3cd; border-left-color: #ffc107; color: #664d03; }
.relato-tag--done { background: #d4edda; border-left-color: var(--cor-sucesso); color: #0f5132; }
.relato .card { border-radius: 0 0 var(--raio-lg) var(--raio-lg); }
[data-tema="escuro"] .relato-tag--pend { background: #4a3f1a; color: #ffe08a; }
[data-tema="escuro"] .relato-tag--done { background: #1e3a24; color: #a3e0b0; }
blockquote {
    margin: 4px 0;
    padding: 8px 14px;
    border-left: 3px solid var(--borda);
    background: var(--bg-alt);
    border-radius: 0 var(--raio) var(--raio) 0;
    color: var(--cor-texto);
}
blockquote.resposta { border-left-color: var(--cor-sucesso); }
/* ---- Barra do IDO ---- */
.ido-bar { background: var(--bg-alt); border-radius: 999px; height: 28px; overflow: hidden; margin: 8px 0; }
.ido-fill {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 12px;
    color: #fff;
    font-weight: var(--peso-bold);
    font-size: .85rem;
    border-radius: 999px;
    transition: width .4s ease;
    min-width: 42px;
}
.ido-fill--sucesso { background: var(--cor-sucesso); }
.ido-fill--aviso { background: var(--cor-amarelo); color: var(--cor-escura); }
.ido-fill--erro { background: var(--cor-erro); }
/* ---- Justificativas ---- */
.just-item { padding: 10px 0; border-bottom: 1px solid var(--borda); }
.just-item:last-child { border-bottom: none; }
.just-item .badge { margin-right: 4px; }
/* ---- Modais ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 20, .55);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: modalFadeIn .18s ease;
}
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--superficie);
    border-radius: var(--raio-lg);
    box-shadow: var(--sombra-lg);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalUp .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes modalUp { from { transform: translateY(14px) scale(.98); } to { transform: none; } }
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--borda);
    background: var(--bg-alt);
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-head .icon-btn { color: var(--cor-texto); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1 1 auto; }
.modal-body .field:last-child { margin-bottom: 0; }
.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--borda);
    background: var(--bg-alt);
}
/* ---- Toasts (canto inferior esquerdo) ---- */
#toast-root {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 900;                    /* abaixo dos modais (1000) */
    display: flex;
    flex-direction: column-reverse;  /* mais recente embaixo */
    gap: 8px;
    align-items: flex-start;
    pointer-events: none;
    max-width: min(90vw, 380px);
}
#toast-root > * { pointer-events: auto; }
.toast {
    padding: 12px 16px;
    border-radius: var(--raio);
    color: #fff;
    box-shadow: var(--sombra-lg);
    font-weight: var(--peso-bold);
    font-size: .9rem;
    min-width: 240px;
    animation: toastEntra .22s cubic-bezier(.2, .8, .3, 1);
}
.toast--sucesso { background: var(--cor-sucesso); }
.toast--erro { background: var(--cor-erro); }
.toast--info { background: var(--cor-info); }
.toast--aviso { background: var(--cor-amarelo); color: var(--cor-escura); }
@keyframes toastEntra {
    from { opacity: 0; transform: translateX(-14px); }
    to   { opacity: 1; transform: none; }
}
/* =============================================================================
   6. TELAS ESPECÍFICAS
   ========================================================================== */
/* ---- Formulário: intervalos (accordion) ---- */
.intervalo {
    border: 1px solid var(--borda);
    border-radius: var(--raio);
    background: var(--superficie);
    margin-bottom: 10px;
    overflow: hidden;
}
.intervalo > summary {
    cursor: pointer;
    padding: 12px 16px;
    font-weight: var(--peso-bold);
    background: var(--bg-alt);
    list-style: none;
    transition: background .15s;
}
.intervalo > summary:hover { background: var(--borda); }
.intervalo > summary::-webkit-details-marker { display: none; }
.intervalo > summary::before { content: "▸ "; color: var(--cor-primaria); }
.intervalo[open] > summary::before { content: "▾ "; }
.intervalo > .stack { padding: 16px; }
/* ---- Cards de frente ---- */
.card--frente { border-left: 4px solid var(--cor-primaria); }
.card--frente input[readonly] { background: var(--bg-alt); cursor: not-allowed; }
.frente-head { display: flex; align-items: center; justify-content: space-between; }
/* ---- Multi-select de pilhas ---- */
.pilhas-box { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 8px 0; }
.pilhas-box .chk { margin: 0; }
/* ---- Tabelas com scroll ---- */
.tabela-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabela-edit { min-width: 720px; }
.tabela-edit input { min-width: 80px; }
/* ---- Tabela de Referências por DMT (larga, com grupos) ---- */
.tabela-dmt { min-width: 1600px; }
.tabela-dmt thead th { position: sticky; top: 0; background: var(--superficie); z-index: 2; }
.tabela-dmt thead tr:first-child th {
    background: var(--bg-alt);
    border-bottom: 2px solid var(--cor-primaria);
    font-size: .72rem;
}
.tabela-dmt input { min-width: 70px; }
/* ---- Dados Brutos: todas as linhas com a mesma altura (v3.9.0) ---- */
/* texto longo fica em 1 linha com "…"; o texto completo aparece ao passar o mouse */
.tabela-brutos th,
.tabela-brutos td { white-space: nowrap; vertical-align: middle; }
.tabela-brutos td { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.tabela-brutos tbody tr { height: 44px; }
/* =============================================================================
   7. UTILITÁRIOS
   ========================================================================== */
.muted { color: var(--cor-neutra); }
.stack > * + * { margin-top: var(--gap); }
hr { border: none; border-top: 1px solid var(--borda); margin: var(--gap) 0; }
textarea { resize: vertical; }
.spinner {
    width: 18px;
    height: 18px;
    border: 3px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 48px; color: var(--cor-neutra); }
/* =============================================================================
   8. RESPONSIVO
   ========================================================================== */
/* ---------- TABLET (<= 1024px) ---------- */
@media (max-width: 1024px) {
    .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr) !important; }
    .grid--ido { grid-template-columns: 1fr !important; }
}
/* ---------- CELULAR (<= 768px) — menu vira barra no topo ---------- */
@media (max-width: 768px) {
    /* Shell empilhado */
    .shell {
        display: block !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        grid-template-areas: none !important;
        height: auto !important;
        min-height: 100vh;
        overflow: visible !important;
    }
    .shell__header {
        grid-area: auto !important;
        position: static !important;
        width: 100% !important;
        padding: 8px 12px !important;
    }
    .shell__user { display: none; }
    /* Sidebar: barra horizontal rolável */
    .shell__sidebar {
        grid-area: auto !important;
        display: flex !important;
        visibility: visible !important;
        flex-direction: row !important;
        align-items: center;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        padding: 6px 8px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--borda);
        background: var(--superficie);
        gap: 8px;
    }
    .shell__nav {
        flex-direction: row !important;
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        white-space: nowrap;
        gap: 6px;
    }
    .shell__sidebar .nav-link {
        display: inline-flex !important;
        flex: 0 0 auto !important;
        width: auto !important;
        font-size: .82rem;
        padding: 8px 12px !important;
        white-space: nowrap;
    }
    /* status da API vira chip compacto ao lado do menu */
    .shell__sidebar-foot {
        border-top: none;
        border-left: 1px solid var(--borda);
        margin-top: 0;
        padding: 0 0 0 8px;
    }
    .api-status { padding: 6px 8px; gap: 6px; }
    .api-status .api-rot { display: none; }
    .api-status .api-texto { font-size: .7rem; max-width: 88px; }
    .shell__main {
        grid-area: auto !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        padding: 12px !important;
    }
    /* Grids em 1 coluna */
    .grid, .grid--2, .grid--3, .grid--4, .grid--ido { grid-template-columns: 1fr !important; }
    .grid--kpis { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .grid-frente { grid-template-columns: repeat(2, 1fr) !important; }
    /* Tipografia */
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.1rem; }
    h3 { font-size: 1rem; }
    .kpi .valor { font-size: 1.4rem; }
    .page-title { flex-wrap: wrap; gap: 6px; }
    /* Tabelas */
    .tabela th, .tabela td { white-space: nowrap; font-size: .8rem; padding: 6px 8px; }
    /* Toque: 16px evita zoom no iOS */
    input, select, textarea, .btn { min-height: 40px; font-size: 16px; }
    .linha-acao .btn { flex: 1 1 auto; }
    .pilhas-box { flex-direction: column; gap: 6px; }
    /* Toasts centralizados embaixo */
    #toast-root {
        left: 8px;
        right: 8px;
        bottom: 12px;
        max-width: none;
        align-items: center;
    }
    #toast-root > * { width: 100%; max-width: 460px; }
}
/* ---------- CELULAR PEQUENO (<= 640px) — modais ---------- */
@media (max-width: 640px) {
    .modal-backdrop { padding: 10px; align-items: flex-end; }
    .modal { max-width: 100%; max-height: 92vh; border-radius: var(--raio-lg) var(--raio-lg) 0 0; }
    .modal-foot { flex-direction: column-reverse; }
    .modal-foot .btn { width: 100%; }
}
/* ---------- CELULAR MUITO PEQUENO (<= 480px) ---------- */
@media (max-width: 480px) {
    .grid--kpis { grid-template-columns: 1fr !important; }
    .grid-frente { grid-template-columns: 1fr !important; }
    .shell__brand small { display: none; }
    .shell__sidebar .nav-link span:not(.ico) { display: none !important; }
    .api-status .api-texto { max-width: 60px; }
}
