/* Calixto High Performance — painel (tema escuro) */
:root {
  --bg: #0b1016;
  --surface: #121821;
  --surface-2: #18202b;
  --chart-bg: #141a22;
  --border: #232d3a;
  --text: #e6ebf2;
  --muted: #93a0b2;
  --accent: #4c9bf5;
  --produtivo: #0aac23;
  --neutro: #338ced;
  --improdutivo: #e76624;
  --ocioso: #55606e;
  --danger: #e5484d;
  --radius: 10px;
  --sidebar: 220px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- controles */
.btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
.btn:hover { border-color: #3a4a5e; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.danger { border-color: var(--danger); color: #ff8589; }
.btn.link { background: none; border: none; padding: 4px 0; color: var(--muted); text-align: left; }
.btn.link:hover { color: var(--text); }
.input, select.input {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-width: 0;
}
.input:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form {
  width: 100%; max-width: 340px; display: grid; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px;
}
.login h1 { font-size: 20px; }
.form-error { color: #ff8589; min-height: 1.4em; font-size: 13px; }

/* ---------- estrutura */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 15px; line-height: 1.2; padding: 0 8px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { padding: 8px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.userbox { border-top: 1px solid var(--border); padding: 12px 8px 0; display: grid; gap: 2px; }
.userbox strong { font-size: 13px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.topbar .search { flex: 1 1 180px; max-width: 320px; }
.topbar .spacer { flex: 1; }
.rt { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.rt::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ocioso); }
.rt.on { color: var(--text); }
.rt.on::before { background: var(--produtivo); box-shadow: 0 0 0 3px rgba(10, 172, 35, .2); }
.content { padding: 20px; display: grid; gap: 20px; align-content: start; }
.page-title { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.page-title h1 { font-size: 20px; }

/* ---------- indicadores */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.kpi .value small { font-size: 13px; font-weight: 400; color: var(--muted); }

/* ---------- legenda e selos */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.c-produtivo { background: var(--produtivo); }
.c-neutro { background: var(--neutro); }
.c-improdutivo { background: var(--improdutivo); }
.c-ocioso { background: var(--ocioso); }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border); white-space: nowrap; flex: none;
}
.badge.produtivo { border-color: var(--produtivo); color: #5fdc72; }
.badge.neutro { border-color: var(--neutro); color: #8dbdf6; }
.badge.improdutivo { border-color: var(--improdutivo); color: #f3a074; }
.badge.ocioso { border-color: var(--ocioso); color: #aab4c2; }
.badge.st-online { background: rgba(10, 172, 35, .16); border-color: var(--produtivo); color: #5fdc72; }
.badge.st-ocioso { background: rgba(240, 180, 40, .12); border-color: #b98a1c; color: #f0c453; }
.badge.st-offline { background: rgba(229, 72, 77, .14); border-color: var(--danger); color: #ff8589; }
.badge.st-desativado, .badge.st-fora_expediente { background: rgba(85, 96, 110, .25); color: #aab4c2; }
.badge.warn { border-color: #b98a1c; color: #f0c453; }

/* ---------- grade ao vivo */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1500px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1880px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.card:hover { border-color: #3a4a5e; }
.card.offline .thumb img { filter: grayscale(1) brightness(.55); }
.card-head { display: flex; gap: 8px; align-items: flex-start; padding: 12px 12px 8px; }
.card-head .who { flex: 1; min-width: 0; }
.card-head .name { font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.thumb {
  aspect-ratio: 16 / 9; background: var(--chart-bg); display: grid; place-items: center;
  color: var(--muted); font-size: 12px; text-align: center; overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-body { padding: 10px 12px 12px; display: grid; gap: 8px; }
.now { display: flex; gap: 8px; align-items: center; min-width: 0; }
.now .app { font-weight: 600; flex: none; max-width: 45%; }
.now-title { font-size: 12px; color: var(--muted); }
.apps { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 12px; }
.apps div { display: flex; gap: 6px; align-items: center; min-width: 0; }
.apps .t { margin-left: auto; color: var(--muted); flex: none; }
.scoreline { display: flex; gap: 10px; align-items: center; }
.scoreline .pct { font-weight: 650; width: 44px; text-align: right; flex: none; }
.stack { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--chart-bg); flex: 1; gap: 1px; }
.stack i { display: block; height: 100%; }
.card-foot { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); }

.empty {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 28px; display: grid; gap: 10px; max-width: 720px;
}
.empty ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--muted); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

/* ---------- tela da máquina */
.machine-top { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel h2 { font-size: 14px; margin-bottom: 10px; }
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.panel-head h2 { margin: 0; flex: 1; }
.live { padding: 0; overflow: hidden; }
.live-screen {
  aspect-ratio: 16 / 9; background: #05080c; display: grid; place-items: center; cursor: zoom-in;
  color: var(--muted); border: 0; width: 100%; padding: 0;
}
.live-screen img { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-screen:fullscreen { cursor: zoom-out; }
.live-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; font-size: 12px; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ocioso); flex: none; }
.live-dot.on { background: var(--danger); }
.facts { display: grid; gap: 8px; }
.fact { display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
.fact .k { color: var(--muted); font-size: 12px; flex: none; }
.fact .v { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.meter { display: grid; grid-template-columns: 44px 1fr 44px; gap: 8px; align-items: center; font-size: 12px; }
.meter .track { height: 6px; background: var(--chart-bg); border-radius: 3px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); }
.meter .fill.high { background: var(--improdutivo); }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.chart { background: var(--chart-bg); border-radius: 8px; padding: 12px; }
.timeline-wrap { position: relative; }
.timeline-wrap canvas { width: 100%; height: 46px; display: block; border-radius: 4px; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.tip {
  position: absolute; bottom: 100%; margin-bottom: 6px; background: #000; border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; pointer-events: none; max-width: min(320px, 90%);
  z-index: 3; overflow-wrap: anywhere;
}
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; height: 120px; align-items: end; }
.hours .col { display: flex; flex-direction: column-reverse; height: 100%; gap: 1px; }
.hours .col i { display: block; width: 100%; border-radius: 1px; }
.hours-axis { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; font-size: 10px; color: var(--muted); text-align: center; margin-top: 4px; }
.rows { display: grid; gap: 6px; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; }
.row .lbl { min-width: 0; }
.row .lbl small { display: block; color: var(--muted); }
.row .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--chart-bg); overflow: hidden; margin-top: -2px; }
.row .bar i { display: block; height: 100%; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.strip button { flex: none; width: 160px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--chart-bg); cursor: zoom-in; overflow: hidden; }
.strip img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.strip span { display: block; font-size: 11px; color: var(--muted); padding: 3px 0; }
.event { display: grid; grid-template-columns: 70px auto minmax(0, 1fr); gap: 10px; align-items: baseline; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* ---------- modal, lightbox, aviso */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .72); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 420px; display: grid; gap: 12px; }
.modal h2 { font-size: 16px; }
.lightbox { display: grid; gap: 8px; width: 100%; max-width: 1400px; }
.lightbox img { width: 100%; max-height: 80vh; object-fit: contain; background: #000; border-radius: 6px; }
.lightbox .bar { display: flex; gap: 10px; align-items: center; justify-content: center; }
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #000; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; max-width: 90vw;
}
.toast.error { border-color: var(--danger); }

/* ---------- celular */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 10px; overflow-x: auto; }
  .brand small { display: none; }
  .nav { flex-direction: row; }
  .userbox { border: 0; padding: 0; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
  .userbox strong, .userbox .role { display: none; }
  .topbar { padding: 10px 12px; position: static; }
  .content { padding: 12px; }
  .machine-top { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .value { font-size: 20px; }
}
.spacer { flex: 1; }

/* ---------- fase 3: produtividade, aplicativos, insights */
.content.flush { padding: 0; }
.link { color: #8dbdf6; }
.link:hover { text-decoration: underline; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg-btn { background: none; border: 0; border-right: 1px solid var(--border); padding: 6px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn:disabled { cursor: default; }
.seg-btn.on { background: #263447; color: var(--text); font-weight: 600; }
.seg-btn.on.produtivo { background: rgba(10, 172, 35, .22); color: #5fdc72; }
.seg-btn.on.neutro { background: rgba(51, 140, 237, .22); color: #8dbdf6; }
.seg-btn.on.improdutivo { background: rgba(231, 102, 36, .22); color: #f3a074; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 500; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .stack { min-width: 110px; }
.th-btn { background: none; border: 0; padding: 0; color: inherit; cursor: pointer; font: inherit; }
.th-btn:hover { color: var(--text); }
th[aria-sort="ascending"] .th-btn, th[aria-sort="descending"] .th-btn { color: var(--text); font-weight: 600; }
.line-holder { min-height: 220px; }
.line-holder svg { display: block; }
.c-line { background: #4c9bf5; height: 3px !important; width: 16px !important; border-radius: 2px; }
.chart .legend { margin-top: 8px; }
.row .bar.thick { height: 8px; border-radius: 4px; }
.note { margin-bottom: 12px; font-size: 13px; }
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 20px; margin-top: 14px; }
.rule { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--border); }
.insights { display: grid; gap: 8px; }
.insight { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 10px 12px; background: var(--chart-bg); border-radius: 8px; border-left: 3px solid var(--ocioso); }
.insight.destaque { border-left-color: var(--produtivo); }
.insight.atencao { border-left-color: var(--improdutivo); }
.insight .badge { justify-content: center; }
.badge.lv-destaque { border-color: var(--produtivo); color: #5fdc72; }
.badge.lv-atencao { border-color: var(--improdutivo); color: #f3a074; }
.ai-out { margin-top: 12px; padding: 12px; background: var(--chart-bg); border-radius: 8px; white-space: pre-wrap; }
@media (max-width: 600px) { .insight { grid-template-columns: 1fr; gap: 4px; } }

/* ---------- eventos e configurações (Fase 4) */
.badge.crit { background: rgba(229, 72, 77, .14); border-color: var(--danger); color: #ff8589; }
.feed { display: grid; }
.feed-row { display: grid; grid-template-columns: 130px minmax(0, 200px) 130px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 13px; }
.feed-row:last-child { border-bottom: 0; }
.feed-row .badge { justify-self: start; }
.feed-row .detail { overflow-wrap: anywhere; }
.feed-row.fresh { animation: fresh 2.5s ease-out; }
@keyframes fresh { from { background: rgba(51, 140, 237, .22); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .feed-row.fresh { animation: none; } }
@media (max-width: 760px) {
  .feed-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; }
  .feed-row .detail { grid-column: 1 / -1; }
}
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--neutro); }
.gap { margin-top: 12px; }
.narrow { max-width: 320px; }
.field-group { display: grid; gap: 6px; }
textarea.input { width: 100%; resize: vertical; font: inherit; }
.input.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; width: 100%; }
.panel h3 { font-size: 13px; margin: 14px 0 8px; }
.table td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 220px; }
.form-grid.top { align-items: start; }
