/* Layout: painel de TV 16:9 — faixa de indicadores no topo, três colunas de fila (abertas → em campo → finalizadas), faixa de técnicos no rodapé. Paleta escura do Nuunes CRM (roxo); alertas em amarelo (O.S. nova) e vermelho (atrasada) para saltar do roxo. */
:root {
  --bg: #131116;
  --panel: #19161d;
  --panel-2: #201c25;
  --line: #2f2a37;
  --fg: #efecf4;
  --muted: #aca5b8;
  --accent: #a38bfa;
  --accent-forte: #7c5ce8;
  --ok: #7fe090;
  --warn: #ff9f43;
  --crit: #ff4d5e;
  --novo: #ffd23f;
  --exec: #ffd23f;
  --novo-fg: #1c1433;
  --agenda: #5cc8ff;
  --display: "Poppins", "Segoe UI", Arial, sans-serif;
  --body: "Mona Sans", "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: dark;
}
html { font-size: clamp(14px, 0.95vw, 24px); height: 100%; }
body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: 1rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
}
*, *::before, *::after { box-sizing: border-box; }
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  padding-block: 1rem;
}

/* Topo */
.top {
  display: grid;
  /* laterais com a mesma largura: os contadores ficam parados no centro, mesmo com o texto do relógio mudando */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 1.5rem;
  align-items: center;
}
.brand h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1;
}
.brand p { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.95rem; display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.tag {
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid var(--warn); color: var(--warn); padding: 0.1rem 0.45rem; border-radius: 4px;
}
.kpis { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.45rem 0.9rem; min-width: 7.5rem;
}
.kpi span { display: block; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.kpi strong { font-family: var(--display); font-size: 2.1rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi.is-accent strong { color: var(--accent); }
.kpi.is-ok strong { color: var(--ok); }
.kpi.is-agenda strong { color: var(--agenda); }
.kpi.is-crit strong { color: var(--crit); }
.kpi.is-crit { border-color: color-mix(in srgb, var(--crit) 55%, var(--line)); }
.kpi.is-crit.tem { background: color-mix(in srgb, var(--crit) 14%, var(--panel)); animation: alertaKpi 1.6s ease-in-out infinite; }
@keyframes alertaKpi { 50% { border-color: var(--crit); } }
.clock { text-align: right; }
.clock strong { font-family: var(--display); font-size: 2.6rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; display: block; }
.clock small { color: var(--muted); font-size: 0.9rem; display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
#sync { display: inline-block; min-width: 11.5em; text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--ok); display: inline-block; box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 70%, transparent); } 100% { box-shadow: 0 0 0 0.6rem transparent; } }
.controls { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.45rem; }
button {
  font: inherit; font-size: 0.8rem; color: var(--fg); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.3rem 0.7rem; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* Colunas */
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 0.85fr);
  gap: 1rem;
  min-height: 0;
}
.col {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); min-height: 0; min-width: 0;
}
.col-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0.8rem 1rem 0.6rem; border-bottom: 1px solid var(--line);
}
.col-head h2 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 1.25rem; letter-spacing: 0.06em; text-transform: uppercase; display: flex; align-items: center; gap: 0.55rem; }
.col-head h2::before { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--c, var(--accent)); }
#h-abertas { --c: var(--novo); }
#h-tecnico { --c: var(--ok); }
#h-agenda { --c: var(--agenda); }
#h-final { --c: var(--accent); }
.col-head .count { font-family: var(--display); font-size: 1.4rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.list { padding: 0.75rem; display: flex; flex-direction: column; gap: 0.6rem; overflow-x: hidden; overflow-y: auto; min-height: 0; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.list > * { flex-shrink: 0; }
.list::-webkit-scrollbar { width: 6px; }
.list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.more { padding: 0.5rem 1rem 0.75rem; color: var(--muted); font-size: 0.9rem; }
.more:empty { display: none; }

.card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.7rem 0.85rem 0.75rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.3rem; min-width: 0;
}
.card.late { border: 2px solid var(--crit); background: color-mix(in srgb, var(--crit) 12%, var(--panel-2)); animation: atrasada 1.6s ease-in-out infinite; }
@keyframes atrasada { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--crit) 35%, transparent); } }
.card.nova { border: 2px solid var(--novo); background: color-mix(in srgb, var(--novo) 12%, var(--panel-2)); animation: chegou 0.9s ease-in-out infinite; }
@keyframes chegou {
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--novo) 45%, transparent); }
}
.card-row { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.num { font-family: var(--display); font-weight: 600; font-size: 0.95rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.contrato { margin: -0.3rem 0 0; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.contrato b { color: var(--warn); font-weight: 600; }
.badge-new { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; background: var(--novo); color: var(--novo-fg); border-radius: 4px; padding: 0.05rem 0.45rem; margin-left: 0.4rem; }
.card h3 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 1.25rem; line-height: 1.2; }
.meta { margin: 0; color: var(--muted); font-size: 0.95rem; overflow-wrap: anywhere; }
.meta b { color: var(--fg); font-weight: 500; }
.meta.end { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
.chip {
  font-family: var(--display); font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums;
  padding: 0.05rem 0.55rem; border-radius: 5px; white-space: nowrap;
  background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok);
}
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.crit { background: var(--crit); color: #fff; }
.chip.exec { background: color-mix(in srgb, var(--exec) 18%, transparent); color: var(--exec); }
.card.exec { border-color: color-mix(in srgb, var(--exec) 55%, transparent); }
.sla.exec i { background: var(--exec); }
.sla { height: 0.35rem; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 0.15rem; }
.sla i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width 0.6s; }
.sla.warn i { background: var(--warn); }
.sla.crit i { background: var(--crit); }
.sla-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); }

.done {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center;
  padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); min-width: 0;
}
.done:last-child { border-bottom: 0; }
.done .check { width: 1.4rem; height: 1.4rem; border-radius: 50%; background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); display: grid; place-items: center; font-size: 0.85rem; font-weight: 700; }
.done .t { min-width: 0; }
.done .t strong { display: block; font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.done .t span { color: var(--muted); font-size: 0.85rem; }
.done time { font-family: var(--display); font-size: 1rem; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.list.done-list { gap: 0; }

/* Técnicos */
.techs { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.techs > .tech { flex: 1 1 13rem; }
.techs > .tech.sem-tec { flex: 0 0 auto; grid-template-columns: auto auto; padding: 0.4rem 0.75rem; opacity: 0.8; border-style: dashed; }
.tech.sem-tec .info strong { font-size: 0.85rem; color: var(--muted); }
.tech.sem-tec .info span { font-size: 0.72rem; }
.tech.sem-tec .score b { font-size: 1.05rem; color: var(--muted); }
.techs:empty { display: none; }
.tech {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.55rem 0.85rem; display: grid; grid-template-columns: auto 1fr auto; gap: 0.65rem; align-items: center; min-width: 0;
}
.avatar { width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1rem; background: var(--line); color: var(--fg); }
.tech.busy .avatar { background: var(--ok); color: var(--bg); }
.tech .info { min-width: 0; }
.tech .info strong { display: block; font-size: 1rem; }
.tech .info span { display: block; font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tech.busy .info span { color: var(--ok); }
.tech .score { text-align: right; }
.tech .score b { display: block; font-family: var(--display); font-size: 1.35rem; line-height: 1; font-variant-numeric: tabular-nums; }
.tech .score small { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Aviso de nova O.S. */
.toast {
  position: fixed; left: 50%; top: calc(1.2rem + env(safe-area-inset-top, 0px)); transform: translate(-50%, -180%);
  background: var(--novo); color: var(--novo-fg); padding: 1rem 2rem 1.1rem; border-radius: 14px;
  font-family: var(--display); z-index: 20; text-align: center;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--novo) 35%, transparent), 0 20px 60px rgba(0,0,0,0.6);
  transition: transform 0.5s cubic-bezier(.2,.9,.3,1.2);
  max-width: calc(100% - 32px); width: max-content;
}
.toast small { display: block; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.toast strong { display: block; font-size: 2rem; font-weight: 800; line-height: 1.15; }
.toast span { display: block; font-size: 1.1rem; font-weight: 600; }
.toast.show { transform: translate(-50%, 0); animation: toastPulse 0.9s ease-in-out infinite; }
@keyframes toastPulse { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--novo) 10%, transparent), 0 20px 60px rgba(0,0,0,0.6); } }

@media (max-width: 1000px) {
  html { font-size: 15px; }
  body, .app { height: auto; }
  .top { grid-template-columns: 1fr; }
  .clock { text-align: left; }
  .clock small, .controls { justify-content: flex-start; }
  .kpis { justify-content: flex-start; }
  .kpi { min-width: 0; flex: 1 1 7rem; }
  .board { grid-template-columns: 1fr; }
  .techs > .tech { flex-basis: 12rem; }
}
@media (prefers-reduced-motion: reduce) {
  .card.nova, .card.late, .dot, .toast.show, .kpi.is-crit.tem { animation: none; }
  .toast, .sla i { transition: none; }
}

/* Faixa de erro: sem conexão com o SGP (mostra os últimos dados) */
.falha {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--crit); color: #fff; text-align: center;
  font-family: var(--display); font-weight: 700; font-size: 1.15rem;
  padding: 0.6rem max(16px, env(safe-area-inset-right, 0px)) calc(0.6rem + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.falha small { font-family: var(--body); font-weight: 500; font-size: 0.85rem; opacity: 0.9; margin-left: 0.6rem; }
.dot.off { background: var(--crit); animation: none; }
#btn-som.precisa { background: var(--novo); color: var(--novo-fg); border-color: var(--novo); font-weight: 700; }
.vazio { color: var(--muted); padding: 1rem 0.5rem; text-align: center; font-size: 0.95rem; }

/* Etiquetas dentro do cartão */
.pill { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 4px; padding: 0.05rem 0.4rem; margin-left: 0.4rem; border: 1px solid var(--warn); color: var(--warn); }
.meta .agenda { color: var(--agenda); font-weight: 600; }
.meta .agenda.passou { color: var(--warn); }

/* botão para trocar de tela */
.trocar { font-size: 0.8rem; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--panel-2)); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 6px; padding: 0.3rem 0.7rem; text-decoration: none; white-space: nowrap; }
.trocar:hover { border-color: var(--accent); }
.trocar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* marca d'água do autor */
.marca {
  position: fixed; z-index: 5; pointer-events: none; user-select: none;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(0.2rem + env(safe-area-inset-bottom, 0px));
  font-family: var(--display); font-size: 0.68rem; font-weight: 600; letter-spacing: 0.08em;
  color: var(--fg); opacity: 0.28;
}
.app { padding-bottom: 1.3rem; }
#btn-som.som-on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); border-color: var(--ok); font-weight: 700; }
#btn-som.som-off { background: color-mix(in srgb, var(--crit) 18%, transparent); color: var(--crit); border-color: var(--crit); font-weight: 700; }

/* Impressão / PDF: mantém o fundo escuro da TV */
@media print { html, body, * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; } }
