/* Manager Dashboard — identidade CIANO/TEAL sobre GRAFITE AZULADO.
   Deliberadamente distinta do edge-dash (índigo) e do boost-dash (âmbar/grafite quente):
   o operador mantém os três abertos lado a lado e precisa diferenciar de relance. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c2430;
  --surface-3: #232d3b;
  --border: rgba(34, 211, 238, .14);
  --border-soft: rgba(148, 163, 184, .14);
  --text: #e6edf3;
  --text-muted: #8b98a9;
  --text-dim: #64748b;

  --accent: #22d3ee;
  --accent-2: #2dd4bf;
  --accent-ink: #06232b;      /* texto sobre fundo de acento — contraste alto */

  /* estados operacionais */
  --online: #34d399;
  --atrasado: #fbbf24;
  --semdados: #64748b;
  --alerta: #f87171;
  --manut: #c4b5fd;
  --reserva: #94a3b8;
  --drenando: #fb923c;

  /* camadas — mesma linguagem do painel XUI (PLAYBOOK) */
  --cam-main: #22d3ee;
  --cam-lb: #b8860b;
  --cam-px: #2e7d32;
  --cam-vod: #0b5394;
  --cam-nov: #5a6268;
  --cam-evento: #7c3aed;
  --cam-especial: #2dd4bf;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.25);

  /* escala de empilhamento — declarada para não virar z-index:9999 por tentativa */
  --z-topbar: 40;
  --z-topbar-open: 95;
  --z-scrim: 80;
  --z-drawer: 90;
  --z-modal: 100;
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Fira Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-text-size-adjust: 100%;
}
/* Números em fonte tabular: coluna de dados não pode "dançar" a cada refresh. */
.num, .stat-v, td.num, .card-metrics b, .bar-label {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.25; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 16px; position: sticky; top: 0; z-index: var(--z-topbar);
  padding-top: calc(10px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand svg { color: var(--accent); flex: none; }
.brand .sub { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.nav-toggle {
  display: none; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  width: 44px; height: 44px; align-items: center; justify-content: center; cursor: pointer;
}
.mainnav { display: flex; gap: 3px; flex-wrap: wrap; }
.mainnav a {
  color: var(--text-muted); text-decoration: none; padding: 7px 12px;
  border-radius: var(--radius-sm); font-size: 14px; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.mainnav a:hover { color: var(--text); background: var(--surface-2); }
.mainnav a.active { color: var(--accent-ink); background: var(--accent); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-chip {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-muted);
  padding: 6px 11px; border-radius: 999px; font-size: 13px; text-decoration: none; white-space: nowrap;
}
.user-chip:hover { color: var(--text); border-color: var(--accent); }

.wrap { max-width: 1580px; margin: 0 auto; padding: 18px 16px 48px; }

/* ------------------------------------------------------------------ banners */
.banner {
  display: flex; gap: 11px; align-items: flex-start;
  border-radius: var(--radius); padding: 11px 14px; margin-bottom: 14px;
  border: 1px solid var(--border-soft); background: var(--surface);
}
.banner svg { flex: none; margin-top: 2px; }
.banner-warn { border-color: rgba(251,191,36,.4); background: rgba(251,191,36,.08); color: #fde68a; }
.banner-crit { border-color: rgba(248,113,113,.45); background: rgba(248,113,113,.09); color: #fecaca; }
.banner-info { border-color: rgba(34,211,238,.35); background: rgba(34,211,238,.07); }
.banner b { color: inherit; }
.banner-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ------------------------------------------------------------------ contadores */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 11px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 12px 14px; position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent); opacity: .8; }
.stat.s-alt::before { background: var(--accent-2); }
.stat.s-warn::before { background: var(--atrasado); }
.stat-k { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .55px; }
.stat-v { font-size: 24px; font-weight: 700; margin-top: 3px; line-height: 1.15; }
.stat-sub { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.stat-v.nd { color: var(--semdados); font-size: 17px; font-weight: 500; }

/* ------------------------------------------------------------------ painéis */
.panel { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 15px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-head .spacer { margin-left: auto; }

/* ------------------------------------------------------------------ filtros */
.filterbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.btn-group { display: flex; gap: 5px; flex-wrap: wrap; }
.btn-f {
  background: var(--surface-2); color: var(--text-muted); cursor: pointer;
  border: 1px solid var(--border-soft); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; min-height: 36px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn-f:hover { color: var(--text); border-color: var(--accent); }
.btn-f[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-f .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.btn, .btn-ghost {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border-radius: var(--radius-sm); padding: 8px 14px; font-size: 14px; cursor: pointer;
  text-decoration: none; min-height: 38px; border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
.btn { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:hover { background: var(--accent-2); }
.btn-ghost { background: var(--surface-2); color: var(--text-muted); border-color: var(--border-soft); }
.btn-ghost:hover { color: var(--text); border-color: var(--accent); }
.btn:disabled, .btn-ghost:disabled, .btn-f:disabled {
  opacity: .42; cursor: not-allowed; pointer-events: none;
}

/* ------------------------------------------------------------------ cards de nó */
#nodecards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
body.compact #nodecards { grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 9px; }

.ncard {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
}
.ncard-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px;
  border-bottom: 1px solid var(--border-soft);
  border-left: 3px solid var(--cam-especial);
}
.ncard-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ncard-name a { color: inherit; text-decoration: none; }
.ncard-name a:hover { color: var(--accent); }
.ncard-meta { color: var(--text-dim); font-size: 11.5px; white-space: nowrap; }
.led { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-left: auto; }
.led-online { background: var(--online); box-shadow: 0 0 7px rgba(52,211,153,.55); }
.led-atrasado { background: var(--atrasado); box-shadow: 0 0 7px rgba(251,191,36,.5); }
.led-sem_dados { background: var(--semdados); }
.ncard-body { padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 8px; }

.card-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cm { background: var(--surface-2); border-radius: var(--radius-sm); padding: 5px 7px; min-width: 0; }
.cm-k { color: var(--text-dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; }
.cm-v { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-v.nd { color: var(--semdados); font-weight: 400; }

/* Barras: rótulo DENTRO do preenchimento, thresholds 60/80 — paridade com o XUI.
   O fill estreito deixa o texto transbordar (overflow visível) e, abaixo de 16%,
   o texto vira escuro sobre o trilho — mesma solução da [3.26] do painel nativo. */
.bar { position: relative; height: 17px; background: var(--surface-3); border-radius: 5px; overflow: visible; }
.bar-fill {
  height: 100%; border-radius: 5px; overflow: visible; white-space: nowrap;
  display: flex; align-items: center; padding-left: 6px;
  font-size: 11px; font-weight: 600; color: #06201a;
  transition: width .3s ease;
}
.bar-fill.ok { background: var(--online); }
.bar-fill.warn { background: var(--atrasado); }
.bar-fill.crit { background: var(--alerta); color: #2a0b0b; }
.bar-fill.nd { background: transparent; color: var(--semdados); font-weight: 400; }
.bar-fill.lowbar { color: var(--text-muted); }
.bar-row { display: flex; align-items: center; gap: 7px; }
.bar-row .bl { color: var(--text-dim); font-size: 11px; width: 34px; flex: none; }
.bar-row .bar { flex: 1; min-width: 0; }

.badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge {
  font-size: 10.5px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border-soft); color: var(--text-muted); background: var(--surface-2);
  white-space: nowrap;
}
.badge-aberta   { color: var(--online);   border-color: rgba(52,211,153,.4); }
.badge-fechada  { color: var(--text-dim); }
.badge-drenando { color: var(--drenando); border-color: rgba(251,146,60,.5); background: rgba(251,146,60,.1); font-weight: 600; }
.badge-reserva  { color: var(--reserva);  border-color: rgba(148,163,184,.4); }
.badge-manut    { color: var(--manut);    border-color: rgba(196,181,253,.4); }
.badge-boost    { color: var(--atrasado); border-color: rgba(251,191,36,.42); background: rgba(251,191,36,.09); }
.badge-mudo     { color: var(--alerta);   border-color: rgba(248,113,113,.45); background: rgba(248,113,113,.09); font-weight: 600; }
.badge-gone     { color: var(--alerta);   border-color: var(--alerta); background: rgba(248,113,113,.14); font-weight: 700; }
.badge-cam      { color: var(--text); font-weight: 600; }

.nodata { color: var(--semdados); font-size: 12.5px; font-style: italic; }

/* ------------------------------------------------------------------ tabelas */
/* TODA tabela vive num .tbl-wrap com rolagem PRÓPRIA. O min-width vai no <table>,
   nunca na página — senão o body inteiro rola na horizontal no celular. */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; color: var(--text-muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .5px; padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft); white-space: nowrap; background: var(--surface);
  position: sticky; top: 0;
}
tbody td { padding: 9px 10px; border-bottom: 1px solid rgba(148,163,184,.07); vertical-align: middle; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; }
.t-dim { color: var(--text-dim); }
.empty-state { text-align: center; padding: 34px 16px; color: var(--text-muted); }
.empty-state svg { color: var(--text-dim); margin-bottom: 8px; }

/* ------------------------------------------------------------------ gráfico */
.chart-box { position: relative; height: 260px; }
.chart-box canvas { max-width: 100%; }

/* ------------------------------------------------------------------ formulários */
label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border-soft);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 16px; /* 16px evita o zoom automático do iOS ao focar */
  min-height: 44px; font-family: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .btn-f:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-color: var(--accent);
}
.form-row { margin-bottom: 14px; }
.help { color: var(--text-dim); font-size: 12px; margin-top: 5px; }
.err {
  background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.4);
  color: #fecaca; padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px;
}

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 26px; width: 100%; max-width: 380px; }
.login-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; font-size: 19px; font-weight: 700; }
.login-brand svg { color: var(--accent); }

/* ------------------------------------------------------------------ rodapé */
.footer { color: var(--text-dim); font-size: 12px; margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.footer .src { display: inline-flex; gap: 6px; align-items: center; margin-right: 16px; white-space: nowrap; }
.footer .src b { color: var(--text-muted); font-weight: 600; }

.nav-scrim { display: none; }

/* ================================================================== MOBILE */
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .wrap { padding: 14px 12px 40px; }

  .mainnav {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(78vw, 300px);
    /* Superfície MAIS CLARA que o fundo + borda de acento: com --surface o drawer
       sumia dentro do escurecimento do scrim (aprendido no boost-dash). */
    background: var(--surface-3);
    border-right: 2px solid var(--accent);
    flex-direction: column; gap: 4px; padding: 16px 12px;
    padding-top: calc(16px + env(safe-area-inset-top));
    transform: translateX(-102%); transition: transform .22s ease;
    z-index: var(--z-drawer); overflow-y: auto; box-shadow: 6px 0 24px rgba(0,0,0,.5);
  }
  .mainnav::before {
    content: 'Navegação'; color: var(--text-dim); font-size: 11px;
    text-transform: uppercase; letter-spacing: .8px; padding: 0 8px 8px;
  }
  .mainnav.open { transform: translateX(0); }

  /* CAUSA-RAIZ do "drawer atrás do scrim": a .topbar é sticky com z-index e cria um
     CONTEXTO DE EMPILHAMENTO. O drawer é filho dela, então seu z-index só vale DENTRO
     da topbar e não sobe acima do .nav-scrim, que é irmão da topbar. Elevar a TOPBAR
     acima do scrim quando o menu abre resolve; backdrop-filter NÃO resolve (testado). */
  body:has(.mainnav.open) .topbar { z-index: var(--z-topbar-open); }
  body.nav-open .topbar { z-index: var(--z-topbar-open); }  /* fallback sem :has() */

  .mainnav a {
    padding: 12px 14px; min-height: 44px; display: flex; align-items: center;
    border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 15px;
  }
  .mainnav a:hover { background: rgba(34,211,238,.1); border-color: rgba(34,211,238,.3); }
  .mainnav a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

  .nav-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.72); z-index: var(--z-scrim); display: block; }
  .nav-scrim[hidden] { display: none; }

  /* Contadores 2 por linha */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-v { font-size: 20px; }

  /* Cards e formulários em 1 coluna */
  #nodecards, body.compact #nodecards { grid-template-columns: 1fr; }

  /* Tabelas: nenhuma célula quebra; linha de 44px; texto completo no title */
  .tbl-wrap table { min-width: 640px; }
  tbody td, thead th { white-space: nowrap; height: 44px; }
  tbody td { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
  .brand .sub { display: none; }
  .chart-box { height: 210px; }
}

@media (max-width: 420px) {
  .stat-v { font-size: 18px; }
  .card-metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .mainnav { transition: none; }
}
