/* Tema escuro fixo: a tela vive numa TV de parede, sem alternância de tema.
   Cores de status vêm da paleta validada (good/warning/serious/critical). */
:root {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #212120;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --line:        #2c2c2a;
  --border:      rgba(255, 255, 255, 0.10);

  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;
  --accent:      #3987e5;

  --gap: clamp(12px, 1.2vw, 22px);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- barra de progresso da rotação ---------- */
.rotate-bar {
  height: 4px;
  background: var(--line);
  flex: none;
}
.rotate-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}
body.paused .rotate-bar span { background: var(--muted); }

/* ---------- topo ---------- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: clamp(10px, 1vw, 18px) clamp(16px, 2vw, 34px);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

/* Altura fixa e largura livre: aceita logo quadrado ou faixa horizontal
   sem distorcer nem empurrar o título para fora da barra. */
.logo {
  height: clamp(28px, 3vw, 46px);
  width: auto;
  max-width: 220px;
  object-fit: contain;
  flex: none;
}

.brand-text { min-width: 0; }

.brand h1 {
  margin: 0;
  font-size: clamp(17px, 1.5vw, 26px);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sources {
  display: flex;
  gap: 14px;
  margin-top: 6px;
  font-size: clamp(11px, 0.75vw, 13px);
  color: var(--muted);
}
.sources .src { display: flex; align-items: center; gap: 6px; }
.sources .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: none;
}
.sources .dot.ok  { background: var(--good); }
.sources .dot.err { background: var(--critical); }

.tabs { display: flex; gap: 8px; }
.tab {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: clamp(12px, 0.9vw, 15px);
  cursor: pointer;
}
.tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--page);
  font-weight: 600;
}

.clockbox { display: flex; align-items: center; gap: 14px; }
.clock {
  font-size: clamp(22px, 2.2vw, 40px);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.date { font-size: clamp(11px, 0.75vw, 13px); color: var(--muted); margin-top: 4px; }
.pause {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 12px;
}
body.paused .pause { color: var(--warning); border-color: var(--warning); }

/* ---------- telas ---------- */
main {
  flex: 1;
  min-height: 0;
  padding: var(--gap) clamp(16px, 2vw, 34px);
}
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  gap: var(--gap);
}
.screen.active { display: flex; }

/* ---------- KPIs ---------- */
.kpis {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(12px, 1.1vw, 22px) clamp(14px, 1.3vw, 26px);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-label {
  font-size: clamp(11px, 0.85vw, 15px);
  color: var(--ink-2);
  font-weight: 500;
}
.kpi-value {
  font-size: clamp(38px, 4.6vw, 84px);
  font-weight: 600;
  line-height: 1.05;
  color: var(--critical);          /* padrão: contadores de problema */
}
/* KPI cujo valor é um nome, não um número: precisa caber sem estourar o card. */
.kpi-value.small {
  font-size: clamp(17px, 1.7vw, 30px);
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.kpi-value.good    { color: var(--good); }
.kpi-value.neutral { color: var(--ink); }
.kpi-value.warn    { color: var(--warning); }
.kpi-value.accent  { color: var(--accent); }
.kpi-value.zero    { color: var(--muted); }
.kpi-foot {
  font-size: clamp(10px, 0.72vw, 13px);
  color: var(--muted);
}

/* Na tela do GLPI a tabela é curta (5 linhas) e a faixa de entidades vem logo
   abaixo: o painel não deve esticar, senão empurra os cards para o rodapé da TV. */
[data-screen="glpi"] .panel { flex: none; }

/* Linhas mais baixas e fonte menor: "Chamados do dia" ocupa menos altura na TV
   e sobra respiro para a faixa de entidades. */
[data-screen="glpi"] .panel-head {
  padding-top: clamp(8px, 0.6vw, 12px);
  padding-bottom: clamp(8px, 0.6vw, 12px);
}
[data-screen="glpi"] table { font-size: clamp(11px, 0.82vw, 15px); }
[data-screen="glpi"] thead th { padding-top: 6px; padding-bottom: 6px; }
[data-screen="glpi"] tbody td { padding: clamp(4px, 0.35vw, 7px) clamp(14px, 1.3vw, 26px); }

/* ---------- chamados por entidade (abaixo da tabela do GLPI) ---------- */
.entity-strip {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.entity-strip-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.entity-strip-head h2 {
  margin: 0;
  font-size: clamp(11px, 0.8vw, 14px);
  font-weight: 600;
}
/* Mesmo grid dos KPIs: cada card fica do tamanho do "Chamados abertos hoje". */
.entity-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
/* Nome da entidade pode ser longo: cabe em até duas linhas sem estourar o card. */
.entity-cards .kpi-label {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- painéis e tabelas ---------- */
.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: var(--gap);
}
.panel {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: clamp(10px, 0.9vw, 18px) clamp(14px, 1.3vw, 26px);
  border-bottom: 1px solid var(--border);
}
.panel-head h2 {
  margin: 0;
  font-size: clamp(13px, 1vw, 18px);
  font-weight: 600;
}
.hint { font-size: clamp(10px, 0.72vw, 13px); color: var(--muted); }

.table-wrap { flex: 1; min-height: 0; overflow: auto; }

/* table-layout fixed + colgroup: garante que título longo vire reticências
   em vez de estourar a largura — ninguém rola a tela de uma TV. */
table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: clamp(12px, 1vw, 18px);
}
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
  font-size: clamp(10px, 0.75vw, 13px);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 10px clamp(14px, 1.3vw, 26px);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: clamp(8px, 0.75vw, 14px) clamp(14px, 1.3vw, 26px);
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
thead th { overflow: hidden; text-overflow: ellipsis; }
tbody td.name { color: var(--ink); font-weight: 500; }
th.num, tbody td.num { font-variant-numeric: tabular-nums; text-align: right; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.alert td { background: rgba(208, 59, 59, 0.09); }

/* pílula de status: cor + rótulo, nunca cor sozinha */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: var(--ink);
  font-size: 0.92em;
}
.pill::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.pill.ok::before       { background: var(--good); }
.pill.down::before     { background: var(--critical); }
.pill.warn::before     { background: var(--warning); }
.pill.serious::before  { background: var(--serious); }
.pill.unknown::before  { background: var(--muted); }
.pill.down    { color: var(--critical); }

/* ---------- rosca de uso do volume (servidor de arquivos) ----------
   SVG inline, sem biblioteca: a CSP é 'self' e a TV pode estar sem internet. */
.kpis.dois { grid-template-columns: repeat(2, 1fr); }

.donut-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5vw, 90px);
  padding: clamp(12px, 2vw, 32px);
}
.donut {
  height: 100%;
  max-height: 46vh;
  min-height: 180px;
  flex: none;
}
.donut-trilha {
  fill: none;
  stroke: var(--line);
  stroke-width: 5;
}
.donut-fatia {
  fill: none;
  stroke: var(--good);
  stroke-width: 5;
  stroke-linecap: round;
  /* a rosca cresce até o valor lido em vez de saltar a cada coleta */
  transition: stroke-dasharray .6s ease, stroke .6s ease;
}
.donut-fatia.warn    { stroke: var(--warning); }
.donut-fatia.serious { stroke: var(--serious); }
.donut-fatia.down    { stroke: var(--critical); }
.donut-pct {
  fill: var(--ink);
  font-size: 8px;
  font-weight: 700;
  text-anchor: middle;
  font-variant-numeric: tabular-nums;
}
.donut-sub {
  fill: var(--muted);
  font-size: 2.6px;
  text-anchor: middle;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.donut-legenda {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vw, 28px);
}
.legenda-item {
  display: grid;
  grid-template-columns: 16px auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  align-items: center;
}
.legenda-cor {
  width: 16px; height: 16px;
  border-radius: 5px;
  grid-row: 1 / 3;
}
.legenda-cor.usado { background: var(--good); }
.legenda-cor.livre { background: var(--line); }
.legenda-cor.vazio { background: transparent; border: 2px solid var(--border); }
.legenda-rotulo {
  color: var(--muted);
  font-size: clamp(12px, 1.1vw, 17px);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.legenda-valor {
  color: var(--ink);
  font-size: clamp(22px, 2.6vw, 42px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.legenda-item.total .legenda-valor { color: var(--ink-2); }

.fs-erro {
  margin: auto;
  padding: clamp(20px, 3vw, 48px);
  text-align: center;
  color: var(--critical);
  font-size: clamp(15px, 1.4vw, 22px);
}

.empty {
  padding: clamp(20px, 3vw, 48px);
  text-align: center;
  color: var(--muted);
  font-size: clamp(13px, 1vw, 17px);
}
.empty.err { color: var(--serious); }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .kpis, .entity-cards { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}
