/* =====================================================================================
   EFICÁCIA CRM — mod-home.css · Home / Dashboard de Administração (MOD.home)
   -------------------------------------------------------------------------------------
   Só o que o design system (design-system.css) NÃO cobre. Prefixo mh-.
   Reutiliza os tokens de style.css/design-system.css (--primary-*, --neutral-*,
   --ds-control-h-*, --ds-touch, --radius-*, --shadow-*, --transition-*).
   Mobile-first; breakpoints 640/768/1024/1200 + paisagem (max-height: 520px).
   ===================================================================================== */

/* ---------- cabeçalho da página --------------------------------------------------- */

.mh-acoes {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Botões de ação do cabeçalho (refrescar, sino): alvo de toque >= 44px,
   alturas IGUAIS dentro do grupo. */
.mh-acao {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--ds-touch, 44px);
    height: var(--ds-touch, 44px);
    border: 1px solid var(--neutral-200);
    background: var(--neutral-0);
    border-radius: var(--radius-md);
    color: var(--neutral-600);
    cursor: pointer;
    transition: var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}
.mh-acao:hover { background: var(--neutral-50); border-color: var(--neutral-300); color: var(--neutral-800); }
.mh-acao:active { transform: scale(0.94); }
.mh-acao:focus-visible { outline: none; box-shadow: var(--ds-ring); border-color: var(--primary-300); }

/* ---------- sino + badge ---------------------------------------------------------- */

.mh-sino-wrap { position: relative; display: inline-flex; }

.mh-sino { position: relative; }

.mh-sino-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--primary-600);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    line-height: 19px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 2px var(--neutral-0);
    pointer-events: none;
}

/* ---------- grelha de KPIs (D12/I3: 1 tlm · 2 tablet · 5 desktop) ------------------ */

.mh-kpis {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    min-width: 0;
}
.mh-kpis > * { min-width: 0; }
@media (min-width: 768px) {
    .mh-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}
@media (min-width: 1200px) {
    .mh-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* Cartão KPI clicável (BUG-15: wrapper uniforme, cartão INTEIRO é o link) */
a.mh-kpi,
a.mh-kpi:hover,
a.mh-kpi:visited {
    display: block;
    text-decoration: none;
    color: inherit;
}
.mh-kpi--link { cursor: pointer; }
.mh-kpi--link:focus-visible {
    outline: none;
    box-shadow: var(--ds-ring), var(--shadow-md);
    border-color: var(--primary-300);
}

/* Barra de ocupação (ÚNICA barra com valor real — D8/D9) */
.mh-kpi-barra {
    margin-top: 12px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--neutral-100);
    overflow: hidden;
}
.mh-kpi-barra > span {
    display: block;
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--success-500);
    transition: width 0.6s ease;
    min-width: 0;
}
.mh-kpi-legenda {
    margin-top: 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--neutral-500);
    font-variant-numeric: tabular-nums;
}

/* ---------- widgets --------------------------------------------------------------- */

/* Tickets a meia largura em desktop (paridade §6.1: col-sm-6) */
.mh-linha2 { min-width: 0; }
@media (min-width: 1024px) {
    .mh-linha2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
}

.mh-results { margin-bottom: 12px; }
.mh-paginacao { margin-top: 14px; }

/* largura curta da coluna Id no widget de tickets (desktop) */
@media (min-width: 768px) {
    .mh-tabela-tickets .mh-col-id { width: 64px; }
}

/* Badge "Anulado" — escuro (§8; o design system não tem variante dark) */
.mh-badge--dark {
    background: var(--neutral-800, #1f2937);
    color: #fff;
    border-color: var(--neutral-800, #1f2937);
}

/* Referência de proposta ligeiramente atenuada face ao código do contrato */
.mh-ref-proposta { font-weight: 600; color: var(--neutral-600); }

/* ---------- estados de erro por cartão -------------------------------------------- */

.mh-erro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 28px 16px;
    text-align: center;
}
.mh-erro-ico {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--warning-50, #fef8e7);
    color: var(--warning-600, #b45309);
    display: flex;
    align-items: center;
    justify-content: center;
}
.mh-erro-msg {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--neutral-500);
    max-width: 340px;
    line-height: 1.5;
}

.mh-vazio { padding: 28px 16px; }

/* ---------- painel de notificações ------------------------------------------------
   Mobile (base): bottom sheet com backdrop — cabe em qualquer viewport (I8).
   >=768px: popover ancorado ao sino (dropdown alinhado à direita, A9).      ------- */

.mh-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--ds-z-modal, 950);
    background: rgba(15, 23, 42, 0.42);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
.mh-panel-backdrop[hidden] { display: none; }

.mh-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--ds-z-modal, 950) + 1);
    background: var(--neutral-0);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    max-height: min(82dvh, 560px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-width: 0;
    outline: none;
}
.mh-panel[hidden] { display: none; }

.mh-panel-pega {
    width: 44px;
    height: 5px;
    border-radius: var(--radius-full);
    background: var(--neutral-200);
    margin: 10px auto 0;
    flex-shrink: 0;
}

.mh-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--neutral-100);
    flex-shrink: 0;
    min-width: 0;
}
.mh-panel-titulo {
    margin: 0;
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--neutral-800);
    min-width: 0;
    overflow-wrap: anywhere;
}
.mh-panel-acoes {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.mh-panel-fechar {
    width: var(--ds-control-h-sm, 36px);
    height: var(--ds-control-h-sm, 36px);
    border: none;
}

.mh-panel-lista {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px;
    min-height: 96px;
}

.mh-notif-lista {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Item = UM único elemento interativo (BUG-06) */
.mh-notif {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    min-height: var(--ds-touch, 44px);
    padding: 10px 10px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    text-align: left;
    cursor: pointer;
    font-family: var(--font-family);
    transition: var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    min-width: 0;
}
.mh-notif:hover { background: var(--neutral-50); }
.mh-notif:active { background: var(--neutral-100); }
.mh-notif:focus-visible { outline: none; box-shadow: var(--ds-ring); }

.mh-notif-ico {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--neutral-100);
    color: var(--neutral-500);
    margin-top: 1px;
}
.mh-notif-ico--azul { background: var(--info-50, #eff6ff); color: var(--info-500, #3b82f6); }
.mh-notif-ico--ambar { background: var(--warning-50, #fffbeb); color: var(--warning-600, #b45309); }
.mh-notif-ico--vermelho { background: var(--error-50, #fef2f2); color: var(--error-500, #ef4444); }
.mh-notif-ico--cinza { background: var(--neutral-100); color: var(--neutral-500); }

.mh-notif-corpo {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    flex: 1 1 auto;
}
.mh-notif-texto {
    font-size: var(--text-sm);
    color: var(--neutral-600);
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.mh-notif-meta {
    font-size: var(--text-xs);
    color: var(--neutral-400);
    font-weight: 600;
}

/* distinção lida / não lida (peso + ponto de cor — melhoria §11) */
.mh-notif-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--primary-500);
    flex-shrink: 0;
    margin-top: 8px;
    opacity: 0;
}
.mh-notif.is-nova .mh-notif-texto { color: var(--neutral-900); font-weight: 600; }
.mh-notif.is-nova .mh-notif-dot { opacity: 1; }

/* Paisagem baixa (ex.: 844x390): a folha nunca ultrapassa o viewport */
@media (max-height: 520px) {
    .mh-panel { max-height: calc(100dvh - 16px); }
    .mh-panel-lista { min-height: 60px; }
}

/* Desktop/tablet: popover ancorado ao sino, alinhado à direita */
@media (min-width: 768px) {
    .mh-panel-backdrop { display: none !important; }
    .mh-panel {
        position: absolute;
        left: auto;
        right: 0;
        top: calc(100% + 8px);
        bottom: auto;
        width: min(400px, calc(100vw - 32px));
        border-radius: var(--radius-lg);
        border: 1px solid var(--neutral-200);
        box-shadow: var(--shadow-lg);
        max-height: min(480px, calc(100vh - 140px));
        z-index: var(--ds-z-dropdown, 80);
        padding-bottom: 0;
        animation: mhPanelIn 0.14s ease;
    }
    /* o popover ancora ao wrap do sino */
    .mh-sino-wrap { position: relative; }
    .mh-panel-pega { display: none; }
}
@keyframes mhPanelIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .mh-panel { animation: none; }
    .mh-kpi-barra > span { transition: none; }
}

/* =====================================================================================
   PONTE COM O SHELL (unidade shell-dashboard) — overrides aditivos à topbar/sidebar.
   O style.css não pode ser editado (agentes em paralelo); estas regras vencem por
   ordem de cascata (este ficheiro carrega DEPOIS do style.css) com a mesma
   especificidade, sem !important onde for possível.
   ===================================================================================== */

/* A17 — avatar da topbar com 40px (o shell tinha 34px; a spec pede 40px) */
.header-avatar {
    width: 40px;
    height: 40px;
}

/* I9 — alvos de toque >= 44px no sino e no avatar da topbar em mobile */
@media (max-width: 768px) {
    .header-notifications {
        min-width: 44px;
        min-height: 44px;
    }
    .header-user-menu {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}
/* anula o encolhimento para 30px do style.css em <=480px (fonte >= 12px) */
@media (max-width: 480px) {
    .header-avatar {
        width: 40px;
        height: 40px;
        font-size: 12px;
    }
}

/* A4 — o minimizador da sidebar só existe com a sidebar acoplada (>1024px);
   abaixo disso a sidebar é off-canvas e gere-se pelo toggler mobile/backdrop */
@media (max-width: 1024px) {
    #sidebarToggle { display: none; }
}

/* A5 — logótipo minimizado (monograma) no estado colapsado, em vez de desaparecer */
.sidebar.collapsed .sidebar-logo {
    display: flex;
    justify-content: center;
}
.sidebar.collapsed .sidebar-logo-img { display: none; }
.sidebar.collapsed .sidebar-logo::after {
    content: 'E';
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-400), #f87171);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    line-height: 1;
}
.sidebar.collapsed .sidebar-header {
    flex-direction: column;
    gap: 10px;
    padding: 14px 0;
}

/* A6 — foco visível no logótipo clicável */
.sidebar-logo:focus-visible {
    outline: none;
    box-shadow: var(--ds-ring, 0 0 0 3px rgba(59, 130, 246, 0.35));
    border-radius: var(--radius-sm);
}

/* A8 — estados vazio/carregar da lista real de notificações da topbar */
.mh-shell-notif-vazio {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 30px 16px;
    text-align: center;
    font-size: var(--text-sm, 13px);
    color: var(--neutral-400);
}

/* A18 — cabeçalho "Configurações" injetado no dropdown do avatar */
.mh-shell-dd-titulo {
    padding: 10px 16px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: var(--neutral-400);
}

/* =====================================================================================
   DASHBOARD DE GESTÃO (visão CEO de OOH) — secção aditiva, prefixo mh-g
   Mobile-first. Grelhas com minmax(0,1fr) para nunca gerar overflow horizontal;
   tabelas viram cartões <768px via o mecanismo data-label do design system.
   ===================================================================================== */

.mh-gestao {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}
.mh-gestao[hidden] { display: none; }

/* ---------- títulos de bloco ---------- */

.mh-g-titulo {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 12px;
    min-width: 0;
}
.mh-g-titulo--listas { margin-top: 4px; }
.mh-g-h2 {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: var(--text-lg, 17px);
    font-weight: 800;
    color: var(--neutral-900);
    min-width: 0;
}
.mh-g-h2 svg { color: var(--primary-500); flex-shrink: 0; }
.mh-g-h2--sec { font-size: var(--text-base, 15px); color: var(--neutral-700); margin-bottom: 12px; }
.mh-g-h2--sec svg { color: var(--neutral-400); }
.mh-g-sub {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--neutral-500);
    overflow-wrap: anywhere;
}
.mh-secao-paridade { min-width: 0; }

/* ---------- KPIs de gestão (1 tlm · 2 tablet · 5 desktop) ---------- */

.mh-g-kpis {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    min-width: 0;
}
.mh-g-kpis > * { min-width: 0; }
@media (min-width: 640px) {
    .mh-g-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
}
@media (min-width: 1200px) {
    .mh-g-kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.mh-gkpi { min-width: 0; }
.mh-gkpi-sub {
    margin-top: 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--neutral-500);
    line-height: 1.4;
    overflow-wrap: anywhere;
}
.mh-gkpi-flag {
    display: inline-flex;
    vertical-align: -1px;
    color: var(--warning-600, #b45309);
}

/* ---------- grelha de gráficos (1 col · 2 col >=1024px) ---------- */

.mh-g-charts {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}
.mh-g-charts > * { min-width: 0; }
@media (min-width: 1024px) {
    .mh-g-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mh-gcard--largo { grid-column: 1 / -1; }
}

.mh-gcard { min-width: 0; }
.mh-gcard .ds-card-title { font-size: var(--text-sm, 13px); }

/* Contentor de gráfico: altura FIXA, sem overflow, canvas nunca ultrapassa. */
.mh-chart {
    --mh-chart-h: 260px;
    position: relative;
    width: 100%;
    height: var(--mh-chart-h);
    min-width: 0;
    overflow: hidden;
}
.mh-chart-inner { position: relative; height: 100%; width: 100%; min-width: 0; }
.mh-chart canvas { max-width: 100%; }
.mh-gcard--largo .mh-chart { --mh-chart-h: 300px; }
@media (max-width: 768px) {
    .mh-chart { --mh-chart-h: 240px; }
    .mh-gcard--largo .mh-chart { --mh-chart-h: 260px; }
}

.mh-gnota {
    margin: 10px 0 0;
    font-size: var(--text-xs);
    color: var(--neutral-500);
    line-height: 1.45;
    overflow-wrap: anywhere;
}

/* ---------- grelha de listas acionáveis (1 col · 2 col >=768px) ---------- */

.mh-g-listas {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
}
.mh-g-listas > * { min-width: 0; }
@media (min-width: 768px) {
    .mh-g-listas { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mh-g-listas .ds-card-title { font-size: var(--text-sm, 13px); gap: 6px; }
.mh-g-listas .ds-card-title svg { color: var(--neutral-400); }

/* célula: subtítulo do suporte por baixo da referência */
.ds-cell-sub {
    display: block;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--neutral-500);
    line-height: 1.35;
    margin-top: 2px;
    overflow-wrap: anywhere;
}
.mh-val-neg { color: var(--error-600, #dc2626); font-weight: 700; }
.mh-dias {
    display: inline-block;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--warning-600, #b45309);
    font-variant-numeric: tabular-nums;
}

/* ---------- avisos honestos (lacunas de dados) ---------- */

.mh-gavisos {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    min-width: 0;
}
.mh-gavisos-ico { flex-shrink: 0; color: var(--warning-600, #b45309); margin-top: 1px; }
.mh-gavisos-lista {
    margin: 6px 0 0;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: var(--text-xs);
    color: var(--neutral-600);
    line-height: 1.5;
}
.mh-gavisos-lista li { overflow-wrap: anywhere; }

/* skeleton dos gráficos enquanto carrega */
.mh-gskel { height: 260px; border-radius: var(--radius-lg); }
@media (min-width: 1024px) {
    .mh-g-charts .mh-gskel:first-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
    .mh-chart canvas { /* animações já desligadas via JS */ }
}
