/* Esconde a top bar e a nav quando está dentro do iframe do index.php */
html.in-iframe .top-meta {
    display: none !important;
}

/* ── Variáveis e base ───────────────────── */
:root {
    --bg:          #0d0f14;
    --bg2:         #13161e;
    --bg3:         #1a1e28;
    --border:      rgba(255,255,255,0.07);
    --text:        #e9d9d9;
    --muted:       #6b7194;
    --accent:      #4f7cff;

    --cor-aguarda:  #f0a500;
    --cor-prod:     #4f7cff;
    --cor-concluido:#22c97a;
    --cor-alerta:   #f04f55;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 13px;
    overflow-x: hidden;
}

/* ── Barra de progresso de refresh (topo) ── */
#refresh-strip {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: rgba(79,124,255,.18);
    z-index: 1000;
}
#refresh-fill {
    height: 100%;
    background: var(--accent);
    transform-origin: left;
    transition: transform 1s linear;
}

/* ── Top bar ─────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 20px;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
}

.top-bar h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .01em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.live-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--cor-concluido);
    animation: livepulse 2.4s ease-in-out infinite;
}

/* Logo central fixo */
#monitor-logo {
    position: fixed;             /* fixa na viewport */
    top: 5px;                    /* distância do topo */
    left: 50%;                   /* centraliza horizontal */
    transform: translateX(-50%); /* ajuste central exato */
    z-index: 9999;               /* acima de tudo */
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;        /* evita interferir em cliques */
}

/* Logo */
#logo {
    height: 32px;
    width: auto;
    opacity: 0.9;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#logo:hover {
    opacity: 1;
    transform: scale(1.05);
}

#logo:hover {
    opacity: 1;
    transform: scale(1.05);
}

@keyframes livepulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}

.top-meta {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--muted);
    font-size: 12px;
    margin-left: -20px;
}

.top-meta strong { color: var(--text); }

/* ── KPI cards ───────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    padding: 14px 20px;
}

.kpi-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 2px 8px rgba(0,0,0,0.25);
    transition: box-shadow .2s ease;
}

.kpi-box:hover {
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08),
                0 4px 16px rgba(0,0,0,0.35);
}

.kpi-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
}

.kpi-box.aguarda::before  { background: var(--cor-aguarda); }
.kpi-box.producao::before { background: var(--cor-prod); }
.kpi-box.concluido::before{ background: var(--cor-concluido); }
/* .kpi-box.alerta::before   { background: var(--cor-alerta); } */
.kpi-box.total::before    { background: var(--muted); }

/* ── Card de alertas detalhado ── */
.kpi-box.alerta .kpi-detalhes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.detalhe-linha {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: rgba(240, 79, 85, 0.08);
    border-radius: 6px;
    border-left: 2px solid var(--cor-alerta);
    transition: background .2s;
    letter-spacing: 0.2px;
    cursor: pointer;
}

.detalhe-linha:hover {
    background: rgba(240, 79, 85, 0.18);
    transform: translateX(2px);
}

.kpi-box.alerta-ativo .detalhe-icone {
    font-size: 14px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    transform: scale(1.1);
}

.detalhe-texto {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    letter-spacing: 0.2px;
}

/* Remove o número grande neste card específico */
#box-alertas .kpi-num {
    display: none;
}

/* Remove a barra de progresso antiga se existir */
.barra-alerta { display: none; }

.kpi-label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 6px;
}

.kpi-num {
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
}

.kpi-num.aguarda  { color: var(--cor-aguarda); }
.kpi-num.producao { color: var(--cor-prod); }
.kpi-num.concluido{ color: var(--cor-concluido); }
.kpi-num.alerta   { color: var(--cor-alerta); }
.kpi-num.total    { color: var(--text); }

.kpi-sub {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

/* ── Secção de gráficos ──────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    gap: 10px;
    padding: 0 20px 10px;
}


.section {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03);
    /* Importante: nunca cortar os gráficos */
    overflow: visible;
}

.section-title {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 12px;
}

/* ── Wrappers dos canvas (definidos inline no HTML) ── */
/* Garante que o canvas não ultrapassa o wrapper */
.chart-wrap {
    position: relative;
}

.chart-wrap canvas {
    display: block;
    max-width: 100%;
}

/* ── Filtros ─────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 0 20px 10px;
}

.filter-ctrl {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 5px 10px;
    font-size: 12px;
    outline: none;
    transition: border-color .2s;
}

.filter-ctrl:focus { border-color: var(--accent); }
.filter-ctrl::placeholder { color: var(--muted); }

#count-label {
    margin-left: auto;
    font-size: 11px;
    color: var(--muted);
}

/* ── Tabela ──────────────────────────────── */
.table-wrap {
    padding: 0 20px 20px;
}

.table-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.table-responsive { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    padding: 9px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--bg3);
}

tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
tbody tr.row-alerta { background: rgba(240, 79, 85, .06); }
tbody tr.row-alerta:hover { background: rgba(240, 79, 85, .11); }
tbody tr { transition: background .15s ease; }

/* ── Pills de estado ─────────────────────── */
.pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: .04em;
}

.pill-aguarda  { background: rgba(240,165,0,.14);   color: var(--cor-aguarda);  }
.pill-producao { background: rgba(79,124,255,.16);  color: var(--cor-prod);     }
.pill-concluido{ background: rgba(34,201,122,.14);  color: var(--cor-concluido);}
.pill-alerta   { background: rgba(240,79,85,.18);   color: var(--cor-alerta);   }

/* ── Legenda do donut ────────────────────── */
#leg-estado {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--muted);
}

#leg-estado span {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Estado vazio / erro ─────────────────── */
.empty-cell {
    text-align: center;
    padding: 40px !important;
    color: var(--muted);
}

.error-bar {
    margin: 0 20px 10px;
    padding: 10px 14px;
    background: rgba(240,79,85,.1);
    border: 1px solid rgba(240,79,85,.25);
    border-radius: 8px;
    color: #f9a8ab;
    font-size: 12px;
    display: none;
}


/* ════════════════════════════════════════════
   MOBILE  ≤ 640 px
   ════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* ── Top bar ── */
    .top-bar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px 14px;
    }

    .top-meta {
        margin-left: 0;
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
        font-size: 11px;
    }

    /* ── KPI: 2×2 + Total em linha inteira ── */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 10px 14px;
    }

    .kpi-box:last-child {
        grid-column: 1 / -1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
    }

    .kpi-num          { font-size: 26px; }
    .kpi-label        { font-size: 10px; }
    .kpi-sub          { font-size: 10px; }

    /* ── Gráficos: coluna única ── */
    .charts-row {
        grid-template-columns: 1fr;
        padding: 0 14px 10px;
        gap: 8px;
    }

    /* ── Gráfico de barras ──────────────────────
       O wrapper tem scroll horizontal para que
       com muitos comerciais as barras não fiquem
       espremidas nem cortadas                    */
    .section:first-child .chart-wrap {
        overflow-x: auto;
        overflow-y: visible;
        /* Esconde a scrollbar visualmente mas mantém funcionalidade */
        scrollbar-width: none;
    }
    .section:first-child .chart-wrap::-webkit-scrollbar { display: none; }

    /* O canvas cresce conforme o nº de comerciais;
       o JS define a largura real via data-min-width  */
    #chartComercial {
        height: 200px !important;
        /* largura mínima calculada pelo JS */
    }

    /* ── Donut: legenda à esquerda, gráfico à direita ── */
    .section:last-child {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 14px;
    }

    #leg-estado {
        flex: 1 1 auto;
        margin-bottom: 0;
        font-size: 11px;
    }

    /* Wrapper do donut com tamanho fixo */
    .section:last-child .chart-wrap {
        flex: 0 0 130px;
        width: 130px;
        height: 130px;
    }

    #chartEstado {
        width: 130px  !important;
        height: 130px !important;
    }

    /* ── Filtros ── */
    .filter-bar {
        padding: 0 14px 10px;
        gap: 6px;
    }

    .filter-ctrl {
        width: 100%;
        padding: 8px 10px;
        /* Evita zoom automático iOS (mínimo 16px) */
        font-size: max(16px, 13px);
    }

    #count-label {
        margin-left: 0;
        width: 100%;
        text-align: right;
    }

    /* ── Tabela ── */
    .table-wrap  { padding: 0 14px 20px; }
    .error-bar   { margin: 0 14px 10px; }

    thead th     { padding: 8px 10px; font-size: 10px; }
    tbody td     { padding: 7px 10px; font-size: 12px; max-width: 140px; }
}

/* ════════════════════════════════════════════
   EXTRA SMALL  ≤ 380 px  (iPhone SE, etc.)
   ════════════════════════════════════════════ */
@media (max-width: 380px) {

    .kpi-num { font-size: 22px; }
    .kpi-box { padding: 10px 12px; }

    /* Donut + legenda empilham em coluna */
    .section:last-child {
        flex-direction: column;
        align-items: flex-start;
    }

    .section:last-child .chart-wrap {
        flex: unset;
        width: 100%;
        height: 140px;
    }

    #chartEstado {
        width: 100% !important;
        height: 140px !important;
    }
}

.hint-esc {
    font-size: 11px;
    opacity: 0.6;
    margin-left: 10px;
}

/*=============================================================
   animação Retrato - Paisagem -modo Telemóvem
  ============================================================*/
  #rotate-hint {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(13,15,20,0.92);
    z-index: 9999;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    backdrop-filter: blur(4px);
}
#rotate-hint.visible { display: flex; }

.rh-phone-wrap {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.rh-phone {
    width: 44px;
    height: 72px;
    border: 3px solid #7F77DD;
    border-radius: 8px;
    position: relative;
    animation: doRotate 2s ease-in-out infinite;
    transform-origin: center center;
}
.rh-phone::before {
    content: '';
    position: absolute;
    top: 6px; left: 50%;
    transform: translateX(-50%);
    width: 10px; height: 2px;
    background: #7F77DD;
    border-radius: 2px;
}
.rh-phone::after {
    content: '';
    position: absolute;
    bottom: 5px; left: 50%;
    transform: translateX(-50%);
    width: 8px; height: 8px;
    border: 2px solid #7F77DD;
    border-radius: 50%;
}
@keyframes doRotate {
    0%   { transform: rotate(0deg);   opacity: 1; }
    40%  { transform: rotate(-90deg); opacity: 1; }
    70%  { transform: rotate(-90deg); opacity: 1; }
    85%  { transform: rotate(-90deg); opacity: 0; }
    86%  { transform: rotate(0deg);   opacity: 0; }
    100% { transform: rotate(0deg);   opacity: 1; }
}
.rh-arrow {
    position: absolute;
    left: -36px; top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    animation: showArrow 2s ease-in-out infinite;
}
@keyframes showArrow {
    0%,20%   { opacity: 0; transform: translateY(-50%) translateX(6px); }
    40%,70%  { opacity: 1; transform: translateY(-50%) translateX(0); }
    85%,100% { opacity: 0; }
}
.rh-text {
    font-size: 13px;
    color: #9ba3c0;
    text-align: center;
    line-height: 1.6;
}
.rh-text strong { color: #dfe2eb; font-weight: 500; }
.rh-skip {
    font-size: 11px;
    color: #4a4f6a;
    background: none;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    padding: 5px 14px;
    cursor: pointer;
    margin-top: 4px;
    transition: color .2s, border-color .2s;
}
.rh-skip:hover { color: #9ba3c0; border-color: rgba(255,255,255,0.18); }


/* ============================================================
   Oculta tudo exceto gráficos e expande-os a ecrã cheio
   ============================================================ */

/* Oculta elementos que não são gráficos */
/* body.tv-mode .top-bar, */
/*body.tv-mode .kpi-grid,*/
body.tv-mode .filter-bar,
body.tv-mode .error-bar,
body.tv-mode .table-wrap,
body.tv-mode #refresh-strip {
    display: none !important;
}

body.tv-mode {
    overflow: hidden;
}

/* Transforma o charts-row num ecrã cheio */
body.tv-mode .charts-row {
    display:        flex !important;
    flex-direction: row;
    gap:            20px;
    padding:        20px;
    width:          100vw;
    height:         100vh;
    box-sizing:     border-box;
    margin:         0;
    align-items:    stretch;
}

/* Cada secção de gráfico ocupa metade da largura e altura total */
body.tv-mode .charts-row .section {
    flex:           1;
    display:        flex;
    flex-direction: column;
    max-height: 80%;
    overflow:       hidden;
}

/* Título da secção maior em modo TV */
body.tv-mode .charts-row .section-title {
    font-size:     16px;
    margin-bottom: 12px;
    flex-shrink:   0;
}

/* Legenda do donut maior em modo TV */
body.tv-mode #leg-estado {
    font-size:     14px;
    margin-bottom: 10px;
    flex-shrink:   0;
}

/* O wrapper do canvas ocupa todo o espaço restante */
body.tv-mode .charts-row .chart-wrap {
    flex:       1;
    height:     auto !important;
    min-height: 0;
    position:   relative;
    overflow:   hidden;
}

/* Remove qualquer scroll horizontal forçado no modo TV */
body.tv-mode .charts-row canvas {
    width:  100% !important;
    height: 100% !important;
}

#kpi-detalhes {
    font-size: 12px;
    line-height: 1.4;
    margin-top: 6px;
    opacity: 0.9;
}