/* ═══════════════════════════════════════════════════════════════════════════
   PAINEL DE ADMINISTRAÇÃO (painel.js)
   ---------------------------------------------------------------------------
   Vive dentro de .workspace como uma tela irmã da Home e do Mapeamento — não é
   mais um modal. Reaproveita os tokens do app (--bg-*, --text-*, --accent,
   --emerald/--amber/--rose) e os estilos .admin-form-* / .admin-users-table de
   style.css para formulários e tabelas. O que é novo aqui: KPIs, gráficos SVG,
   alertas, cartões de empresa e o diálogo de formulário.

   Cores de série dos gráficos (validadas com o validador do skill de dataviz
   contra #ffffff e #1C2921): azul = receita / série única, laranja = custo de IA.
   Estado (bom/atenção/crítico) usa os tokens de status do app e nunca vira
   cor de série; toda marca de estado vem com ícone + texto.
   ═══════════════════════════════════════════════════════════════════════════ */

.pn {
    --pn-s1: #2a78d6;
    --pn-s2: #eb6834;
    --pn-s3: #1baf7a;
    --pn-s1-wash: rgba(42,120,214,0.10);
    --pn-grid: rgba(15,77,55,0.09);
    --pn-axis: rgba(15,77,55,0.22);
    --pn-surface: var(--bg-elevated);
    --pn-track: rgba(15,77,55,0.08);

    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 2px 2px 40px;
    color: var(--text-primary);
    font-size: 13.5px;
}
.pn[hidden] { display: none !important; }
:root[data-theme="dark"] .pn {
    --pn-s1: #3987e5;
    --pn-s2: #d95926;
    --pn-s3: #199e70;
    --pn-s1-wash: rgba(57,135,229,0.14);
    --pn-grid: rgba(255,255,255,0.08);
    --pn-axis: rgba(255,255,255,0.20);
    --pn-track: rgba(255,255,255,0.10);
}

/* ── cabeçalho + filtros (uma linha, acima de tudo que ela filtra) ────────── */
.pn-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.pn-titulo { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.01em; }
.pn-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-tertiary); }
.pn-filtros { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.pn-filtro { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.pn-filtro select, .pn-select {
    padding: 9px 34px 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-surface);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.pn-filtro select:focus, .pn-select:focus { border-color: var(--accent); }

/* ── botões ──────────────────────────────────────────────────────────────── */
.pn-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-default);
    background: var(--bg-surface);
    color: var(--text-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    line-height: 1.2;
}
.pn-btn:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.pn-btn:disabled { opacity: 0.55; cursor: default; }
.pn-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.pn-btn-primary:hover { background: var(--accent-light); border-color: var(--accent-light); }
.pn-btn-ghost { background: transparent; }
.pn-btn-danger { color: var(--rose); border-color: var(--rose-border); }
.pn-btn-danger:hover { background: var(--rose-muted); }
.pn-btn-sm { padding: 6px 11px; font-size: 12px; }
.pn-btn svg { flex-shrink: 0; }

/* ── abas do painel ──────────────────────────────────────────────────────── */
.pn-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 4px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    border: 1px solid var(--border-faint);
    width: fit-content;
    max-width: 100%;
}
.pn-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 15px;
    border-radius: var(--radius-full);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.pn-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.pn-tab.active { background: var(--accent); color: var(--on-accent); }
.pn-tab-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--rose);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pn-tab.active .pn-tab-badge { background: rgba(0,0,0,0.25); color: #fff; }

.pn-panel { display: flex; flex-direction: column; gap: 16px; }
.pn-panel[hidden] { display: none; }
.pn-carregando { opacity: 0.55; pointer-events: none; transition: opacity .2s; }

/* ── cartões genéricos ───────────────────────────────────────────────────── */
.pn-card {
    background: var(--pn-surface);
    border: 1px solid var(--border-faint);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
}
.pn-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.pn-card-title { margin: 0; font-size: 14.5px; font-weight: 700; }
.pn-card-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-tertiary); }
.pn-secao-titulo {
    margin: 6px 0 -6px;
    font-size: 11.5px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}
.pn-vazio { padding: 22px; text-align: center; color: var(--text-tertiary); font-size: 13px; }
.pn-nota { font-size: 12px; color: var(--text-tertiary); margin: 0; line-height: 1.5; }

/* ── KPIs ────────────────────────────────────────────────────────────────── */
.pn-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
@media (max-width: 1100px) { .pn-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 700px) { .pn-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pn-kpi {
    background: var(--pn-surface);
    border: 1px solid var(--border-faint);
    border-radius: var(--radius-lg);
    padding: 16px 18px 14px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.pn-kpi-hero { grid-column: span 2; }
.pn-kpi-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.pn-kpi-valor { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.pn-kpi-hero .pn-kpi-valor { font-size: 46px; }
.pn-kpi-linha { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pn-kpi-delta { font-size: 12px; font-weight: 700; color: var(--text-tertiary); white-space: nowrap; }
.pn-kpi-delta.up { color: var(--emerald); }
.pn-kpi-delta.down { color: var(--rose); }
.pn-kpi-sub { font-size: 12px; color: var(--text-tertiary); line-height: 1.4; }
.pn-kpi-spark { margin-top: 4px; width: 100%; height: 34px; display: block; }
.pn-kpi-spark path { fill: none; stroke: var(--pn-axis); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pn-kpi-spark circle { fill: var(--pn-s1); stroke: var(--pn-surface); stroke-width: 2; }

/* ── alertas ─────────────────────────────────────────────────────────────── */
.pn-alertas { display: flex; flex-direction: column; gap: 8px; }
.pn-alerta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-faint);
    background: var(--bg-surface);
}
.pn-alerta-icone {
    width: 30px; height: 30px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 13px; font-weight: 800;
}
.pn-alerta-critico .pn-alerta-icone { background: var(--rose-muted); color: var(--rose); }
.pn-alerta-atencao .pn-alerta-icone { background: var(--amber-muted); color: var(--amber); }
.pn-alerta-info .pn-alerta-icone { background: var(--sky-muted); color: var(--sky); }
.pn-alerta-texto { flex: 1; min-width: 0; font-size: 13px; line-height: 1.4; }
.pn-alerta-texto b { font-weight: 700; }
.pn-alerta-nivel {
    font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
    padding: 2px 8px; border-radius: var(--radius-full); white-space: nowrap;
}
.pn-alerta-critico .pn-alerta-nivel { background: var(--rose-muted); color: var(--rose); }
.pn-alerta-atencao .pn-alerta-nivel { background: var(--amber-muted); color: var(--amber); }
.pn-alerta-info .pn-alerta-nivel { background: var(--sky-muted); color: var(--sky); }
.pn-alerta-ok { display: flex; align-items: center; gap: 10px; color: var(--emerald); font-weight: 600; padding: 6px 2px; }

/* ── chips de estado ─────────────────────────────────────────────────────── */
.pn-chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
    padding: 3px 9px; border-radius: var(--radius-full); white-space: nowrap;
    background: var(--bg-surface); border: 1px solid var(--border-default); color: var(--text-primary);
}
.pn-chip-ok { background: var(--emerald-muted); border-color: transparent; color: var(--emerald); }
.pn-chip-atencao { background: var(--amber-muted); border-color: transparent; color: var(--amber); }
.pn-chip-critico { background: var(--rose-muted); border-color: transparent; color: var(--rose); }
.pn-chip-info { background: var(--sky-muted); border-color: transparent; color: var(--sky); }
.pn-chip-neutro { background: var(--neutral-muted); border-color: transparent; color: var(--text-secondary); }

/* ── gráficos ────────────────────────────────────────────────────────────── */
.pn-graficos {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.pn-grafico-largo { grid-column: 1 / -1; }
.pn-chart-body { position: relative; min-width: 0; }
.pn-chart-body svg { display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.pn-chart-table { display: none; }
.pn-chart.is-table .pn-chart-body { display: none; }
.pn-chart.is-table .pn-chart-table { display: block; }
.pn-legenda { display: flex; gap: 14px; flex-wrap: wrap; margin: 0 0 8px; font-size: 12px; color: var(--text-secondary); }
.pn-legenda span { display: inline-flex; align-items: center; gap: 6px; }
.pn-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.pn-swatch-linha { width: 14px; height: 2px; border-radius: 1px; }

.pn-grid-line { stroke: var(--pn-grid); stroke-width: 1; shape-rendering: crispEdges; }
.pn-axis-line { stroke: var(--pn-axis); stroke-width: 1; shape-rendering: crispEdges; }
.pn-tick { fill: var(--text-tertiary); font-size: 11px; font-variant-numeric: tabular-nums; }
.pn-lbl { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.pn-lbl-forte { fill: var(--text-primary); font-size: 11.5px; font-weight: 700; }
.pn-hit { fill: transparent; cursor: default; outline: none; }
.pn-grp:hover .pn-bar, .pn-grp:focus-within .pn-bar { filter: brightness(0.9); }
.pn-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pn-dot { stroke: var(--pn-surface); stroke-width: 2; }
.pn-area { opacity: 0.10; }

/* ── medidores (uso da cota) ─────────────────────────────────────────────── */
.pn-medidores { display: flex; flex-direction: column; gap: 9px; }
.pn-medidor { display: grid; grid-template-columns: minmax(120px, 1.2fr) minmax(0, 2fr) auto; gap: 12px; align-items: center; font-size: 12.5px; }
.pn-medidor-rotulo { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pn-medidor-rotulo small { display: block; font-size: 11px; color: var(--text-tertiary); }
.pn-medidor-trilho { height: 8px; border-radius: 4px; background: var(--pn-track); overflow: hidden; }
.pn-medidor-nivel { height: 100%; border-radius: 4px; background: var(--emerald); }
.pn-medidor-atencao .pn-medidor-nivel { background: var(--amber); }
.pn-medidor-critico .pn-medidor-nivel { background: var(--rose); }
.pn-medidor-valor { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; text-align: right; }
.pn-medidor-valor small { font-weight: 500; color: var(--text-tertiary); }

/* ── tabelas ─────────────────────────────────────────────────────────────── */
.pn-tabela-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-faint); }
.pn-tabela { width: 100%; border-collapse: collapse; font-size: 13px; }
.pn-tabela th {
    text-align: left;
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    color: var(--text-tertiary);
    padding: 9px 12px;
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-faint);
    white-space: nowrap;
}
.pn-tabela td { padding: 10px 12px; border-bottom: 1px solid var(--border-faint); vertical-align: middle; }
.pn-tabela tr:last-child td { border-bottom: none; }
.pn-tabela .n, .pn-tabela th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pn-tabela tfoot td { font-weight: 700; background: var(--bg-hover); }
.pn-tabela .pn-linha-total td { font-weight: 700; }
.pn-tabela .neg { color: var(--rose); }
.pn-tabela .pos { color: var(--emerald); }
.pn-tabela-nome { display: block; font-weight: 600; white-space: nowrap; }
.pn-tabela td.pn-col-nome { white-space: nowrap; }
.pn-tabela-sub { display: block; font-size: 11.5px; color: var(--text-tertiary); }
.pn-acoes { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ── empresas (clientes) ─────────────────────────────────────────────────── */
.pn-empresa-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pn-empresa-nome { margin: 0; font-size: 16px; font-weight: 800; }
.pn-empresa-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pn-empresa-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    margin: 14px 0;
}
.pn-stat { padding: 10px 12px; border-radius: var(--radius-md); background: var(--bg-surface); border: 1px solid var(--border-faint); }
.pn-stat-label { font-size: 11px; color: var(--text-tertiary); font-weight: 600; }
.pn-stat-valor { font-size: 16px; font-weight: 700; margin-top: 2px; }
.pn-stat-valor small { font-size: 11.5px; font-weight: 500; color: var(--text-tertiary); }
.pn-empresa .admin-users-table th { padding: 9px 12px; }
.pn-empresa .admin-users-table td { padding: 10px 12px; }
.pn-empresa .admin-table-wrap { max-height: none; border-radius: var(--radius-md); border: 1px solid var(--border-faint); }

/* ── formulário de configuração ──────────────────────────────────────────── */
.pn-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.pn-form-grid .admin-form-field label { display: block; }
.pn-form-grid input[type="number"], .pn-form-grid input[type="text"] {
    width: 100%; box-sizing: border-box; padding: 9px 12px;
    border-radius: var(--radius-sm); border: 1px solid var(--border-default);
    background: var(--bg-surface); color: var(--text-primary); font: inherit; font-size: 13.5px; outline: none;
}
.pn-form-grid input:focus { border-color: var(--accent); }
.pn-form-acoes { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; align-items: center; flex-wrap: wrap; }
.pn-form-msg { font-size: 12.5px; color: var(--text-tertiary); margin-right: auto; }
.pn-form-msg.ok { color: var(--emerald); font-weight: 600; }
.pn-form-msg.erro { color: var(--rose); font-weight: 600; }
.pn-planos-tabela input { width: 110px; padding: 7px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-default); background: var(--bg-surface); color: var(--text-primary); font: inherit; font-size: 13px; text-align: right; }

/* ── diálogo de formulário (substitui prompt()) ──────────────────────────── */
.pn-dialog-overlay {
    position: fixed; inset: 0; z-index: 1500;
    background: rgba(15,23,42,0.45); backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.pn-dialog {
    background: var(--bg-elevated);
    border-radius: 22px;
    padding: 26px 28px;
    width: min(560px, 100%);
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.pn-dialog h2 { margin: 0 0 4px; font-size: 17px; font-weight: 800; }
.pn-dialog .pn-dialog-desc { margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.pn-dialog .admin-form-row { margin-bottom: 12px; }
.pn-dialog textarea {
    width: 100%; box-sizing: border-box; padding: 10px 12px; min-height: 70px; resize: vertical;
    border-radius: var(--radius-sm); border: 1px solid var(--border-default);
    background: var(--bg-surface); color: var(--text-primary); font: inherit; font-size: 13.5px; outline: none;
}
.pn-dialog textarea:focus { border-color: var(--accent); }
.pn-dialog-acoes { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.pn-dialog-erro { color: var(--rose); font-size: 12.5px; margin: 8px 0 0; min-height: 1em; }
.pn-dialog-resumo { font-size: 13px; padding: 10px 12px; border-radius: var(--radius-md); background: var(--bg-hover); margin-bottom: 12px; line-height: 1.5; }

/* ── tooltip dos gráficos ────────────────────────────────────────────────── */
.pn-tip {
    position: fixed;
    z-index: 1600;
    pointer-events: none;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.45;
    box-shadow: var(--shadow-md);
    max-width: 260px;
}
.pn-tip[hidden] { display: none; }
.pn-tip b { display: block; font-weight: 700; margin-bottom: 2px; }
.pn-tip .pn-tip-linha { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ── toast ───────────────────────────────────────────────────────────────── */
.pn-toast {
    position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
    z-index: 1700; padding: 10px 18px; border-radius: var(--radius-full);
    background: var(--charcoal-bg); color: #fff; font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .2s; pointer-events: none;
}
.pn-toast.show { opacity: 1; }
.pn-toast.erro { background: var(--rose); }

/* ── responsivo ──────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
    .pn-graficos { grid-template-columns: 1fr; }
    .pn-kpi-hero { grid-column: span 2; }
}
@media (max-width: 560px) {
    .pn-titulo { font-size: 20px; }
    .pn-kpi-hero .pn-kpi-valor { font-size: 34px; }
    .pn-medidor { grid-template-columns: 1fr; gap: 4px; }
    .pn-medidor-valor { text-align: left; }
}

/* ranking de uso (09/10/2026) */
.pn-ranking .pn-rank-pos { font-weight: 700; width: 44px; }
.pn-ranking tr.pn-rank-top td { background: var(--bg-hover); }
.pn-ranking td .pn-tabela-sub { white-space: nowrap; }

/* Módulos marcáveis no cadastro (26/10/2026) */
.admin-modulos{display:flex;flex-wrap:wrap;gap:8px 18px;padding:10px 12px;border:1px solid var(--border-subtle,#dfe7e1);border-radius:10px}
.admin-modulos .admin-checkbox-label small{color:var(--text-tertiary)}
