/* ============ SOS Monitor ============ */
:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --ink: #142019;
  --ink-2: #4a5a51;
  --ink-3: #7a8880;
  --line: #e1e8e4;
  --line-2: #cfd9d3;
  --brand: #0f9d58;
  --brand-ink: #0b7a44;
  --brand-soft: #e3f4ea;
  --code-bg: #10231a; --code-ink: #d6f5e3;

  --ok: #12925a;   --ok-bg: #e2f4e9;
  --warn: #b26a00; --warn-bg: #fff2d9;
  --err: #cf3030;  --err-bg: #fde7e5;
  --late: #7a3fc4; --late-bg: #f1e8fb;
  --gray: #6b7680; --gray-bg: #edf0f2;
  --miss: #f3c2bd;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 28, .05), 0 2px 8px rgba(16, 40, 28, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1512;
    --surface: #151e1a;
    --surface-2: #1a2520;
    --ink: #e5eee9;
    --ink-2: #a9b8b0;
    --ink-3: #7d8c84;
    --line: #25322c;
    --line-2: #33433b;
    --brand: #22b26a;
    --brand-ink: #4fd08c;
    --brand-soft: #173326;
    --code-bg: #0a120e; --code-ink: #bff0d4;
    --ok: #3ccf86;   --ok-bg: #143223;
    --warn: #f0b03f; --warn-bg: #352a12;
    --err: #ff6b62;  --err-bg: #3a1a18;
    --late: #b58cf2; --late-bg: #2a1f3d;
    --gray: #8f9aa3; --gray-bg: #232c29;
    --miss: #5a2b28;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "tnum" 1;
}
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 23px; margin: 0 0 2px; letter-spacing: -.015em; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ico { width: 16px; height: 16px; vertical-align: -3px; }

/* ---------- topo ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-inner { max-width: 1360px; margin: 0 auto; padding: 0 24px; height: 58px; display: flex; align-items: center; gap: 26px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 16.5px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--brand); }
.top nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.top nav a { display: flex; align-items: center; gap: 7px; color: var(--ink-2); padding: 7px 11px; border-radius: 8px; font-weight: 550; white-space: nowrap; }
.top nav a svg { width: 17px; height: 17px; }
.top nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.top nav a.on { color: var(--brand-ink); background: var(--brand-soft); }
.top .link { display: flex; gap: 6px; align-items: center; }

.wrap { max-width: 1360px; margin: 0 auto; padding: 26px 24px 64px; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-2); margin: 0; }
.sub { color: var(--ink-3); font-size: 12px; }
.small { font-size: 12.5px; }
.crumb { margin: 0 0 6px; color: var(--ink-3); font-size: 13px; }
.t-err { color: var(--err); font-weight: 600; }
.t-warn { color: var(--warn); font-weight: 600; }

/* ---------- cartões ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.table-card { padding: 0; overflow-x: auto; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.cards.four { margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 15px 18px; display: flex; flex-direction: column; gap: 2px; color: var(--ink); position: relative; overflow: hidden;
}
a.stat:hover { text-decoration: none; border-color: var(--line-2); transform: translateY(-1px); }
a.stat, .ccard, .btn { transition: transform .12s ease, border-color .12s ease, background .12s ease; }
.stat:not(.plain)::after { content: ""; position: absolute; right: -18px; top: -18px; width: 70px; height: 70px; border-radius: 50%; background: var(--cb); opacity: .9; }
.stat.sel { outline: 2px solid var(--c); outline-offset: -1px; }
.stat-n { font-size: 32px; font-weight: 700; line-height: 1.1; position: relative; z-index: 1; }
.stat-l { display: flex; align-items: center; gap: 7px; color: var(--ink-2); font-weight: 550; position: relative; z-index: 1; }
.stat-l i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.stat.plain .stat-l { font-size: 12.5px; }
.stat-v { font-size: 20px; font-weight: 650; }
.stat-v.sm { font-size: 16px; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.kpi { padding: 12px 18px; display: flex; flex-direction: column; border-left: 1px solid var(--line); color: var(--ink); }
.kpi:first-child { border-left: 0; }
a.kpi:hover { text-decoration: none; background: var(--surface-2); }
.kpi-v { font-size: 19px; font-weight: 650; }
.kpi-l { color: var(--ink-3); font-size: 12.5px; }
.kpi.warn .kpi-v { color: var(--warn); }
.meter { display: block; height: 5px; border-radius: 9px; background: var(--gray-bg); margin-top: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); border-radius: 9px; }

/* status */
.s-success { --c: var(--ok); --cb: var(--ok-bg); }
.s-warning { --c: var(--warn); --cb: var(--warn-bg); }
.s-error { --c: var(--err); --cb: var(--err-bg); }
.s-overdue { --c: var(--late); --cb: var(--late-bg); }
.s-unknown, .s-pending, .s-ignored { --c: var(--gray); --cb: var(--gray-bg); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 99px; background: var(--cb); color: var(--c); font-weight: 650; font-size: 12px; white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.mini-badge { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--cb); color: var(--c); white-space: nowrap; }
.dot-st { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px var(--cb); flex: none; }
.chip { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--gray-bg); color: var(--ink-2); margin-left: 6px; white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.pill-alert, .pill-ok { display: inline-flex; align-items: center; gap: 8px; padding: 7px 15px; border-radius: 99px; font-weight: 650; white-space: nowrap; }
.pill-alert i, .pill-ok i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-alert { background: var(--err-bg); color: var(--err); }
.pill-alert i { animation: pulse 1.6s infinite; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
@keyframes pulse { 50% { opacity: .3; } }

/* mini histórico (pontos) */
.dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.d { display: inline-block; width: 11px; height: 18px; border-radius: 3px; background: var(--c); }
a.d:hover { transform: scaleY(1.15); }
.d.s-missed, .sq.s-missed { --c: var(--miss); background: repeating-linear-gradient(135deg, var(--miss) 0 3px, transparent 3px 6px); box-shadow: inset 0 0 0 1px var(--miss); }
.d.s-none, .sq.s-none { background: transparent; box-shadow: inset 0 0 0 1px var(--line-2); }

/* ---------- tabelas ---------- */
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.grid td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr[onclick] { cursor: pointer; }
.grid tbody tr[onclick]:hover td { background: var(--surface-2); }
.grid .r { text-align: right; }
.grid .nw { white-space: nowrap; }
.grid .msg { color: var(--ink-2); max-width: 420px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.grid td .sub { display: block; }

/* ---------- filtros ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg a, .seg button { font: inherit; border: 0; background: none; color: var(--ink-2); padding: 5px 12px; border-radius: 6px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.seg a:hover { text-decoration: none; color: var(--ink); background: var(--surface-2); }
.seg .on { background: var(--brand); color: #fff; }
.seg .on:hover { background: var(--brand); color: #fff; }
.dates { display: inline-flex; align-items: center; gap: 6px; }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 11px; outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip-f { display: inline-flex; align-items: center; gap: 7px; padding: 6px 13px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line-2); color: var(--ink-2); font-weight: 550; }
.chip-f i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip-f b { color: var(--ink); }
.chip-f:hover { text-decoration: none; border-color: var(--ink-3); }
.chip-f.on { border-color: var(--c, var(--brand)); background: var(--cb, var(--brand-soft)); color: var(--c, var(--brand-ink)); }

.form label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-weight: 550; color: var(--ink-2); }
label.check { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.row-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-top: 14px; }
.row-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 550; color: var(--ink-2); flex: 1; min-width: 200px; margin: 0; }
.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(.94); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.full { width: 100%; }
.link { font: inherit; background: none; border: 0; padding: 0; color: var(--ink-2); cursor: pointer; }
.link:hover { color: var(--ink); }
.link.danger { color: var(--err); }

.split { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.split.even { grid-template-columns: 1fr 1fr; }
.flash { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; font-weight: 550; }
.flash.ok { background: var(--ok-bg); color: var(--brand-ink); }
.flash.err { background: var(--err-bg); color: var(--err); }
.empty { text-align: center; padding: 44px 20px; color: var(--ink-2); }
.empty h2 { color: var(--ink); font-size: 17px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; width: 16px; color: var(--ink-3); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
details.card > summary { font-weight: 600; }

.code-row { display: flex; gap: 8px; align-items: stretch; margin: 10px 0; }
pre.code { flex: 1; margin: 0; background: var(--code-bg); color: var(--code-ink); padding: 12px 14px; border-radius: 9px; font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.token { word-break: break-all; }

/* ---------- grupos (painel por cliente / máquinas) ---------- */
.group { margin-bottom: 14px; }
.group-head, .machine-head, .day-head { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.group-title { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; color: var(--ink); }
.group-counts { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.machine { margin-bottom: 14px; }
.machine-head { justify-content: space-between; }
.mh-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card:not(.table-card) > .machine-head { padding: 0 0 10px; margin-bottom: 10px; }
.machine-head h2, .day-head h2 { margin: 0; }
.day { margin-bottom: 14px; }
.day-head { justify-content: space-between; background: var(--surface-2); }
.day-head h2 { font-size: 14px; }
.hist .c-when b { font-size: 13.5px; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

/* ---------- linha do tempo ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 12px; color: var(--ink-2); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .d { width: 12px; height: 12px; }
.tl-card { overflow-x: auto; }
table.tl { border-collapse: separate; border-spacing: 0; width: 100%; }
.tl th, .tl td { border-bottom: 1px solid var(--line); }
.tl thead th { background: var(--surface-2); position: sticky; top: 0; z-index: 2; font-weight: 600; }
.tl-job { text-align: left; padding: 9px 14px; min-width: 210px; max-width: 280px; position: sticky; left: 0; background: var(--surface); z-index: 1; border-right: 1px solid var(--line); }
.tl thead .tl-job { background: var(--surface-2); z-index: 3; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.tl-job .sub { display: block; }
.tl-day { padding: 6px 2px; text-align: center; min-width: 34px; color: var(--ink-2); line-height: 1.15; }
.tl-day span { display: block; font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; }
.tl-day b { font-size: 13px; }
.tl-day em { font-style: normal; font-size: 10px; color: var(--ink-3); }
.tl-day.today { color: var(--brand-ink); }
.tl-day.today b { background: var(--brand); color: #fff; border-radius: 6px; padding: 0 5px; }
.tl-cell { text-align: center; padding: 6px 2px; }
.tl-cell.we, .tl-day.we { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.tl-cell.today { background: color-mix(in srgb, var(--brand-soft) 55%, transparent); }
.sq { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 6px; background: var(--c); vertical-align: middle; }
a.sq:hover { transform: scale(1.12); text-decoration: none; }
.sq small { color: #fff; font-size: 10px; font-weight: 700; }
.tl-30 .sq { width: 18px; height: 22px; border-radius: 4px; }
.tl-30 .tl-day { min-width: 24px; }
.tl-7 .sq { width: 36px; height: 26px; }
.tl-group td { background: var(--surface-2); padding: 8px 14px; font-weight: 650; position: sticky; left: 0; }
.tl-group a { color: var(--ink); }
.tl-rate { padding: 6px 14px; min-width: 80px; }
.rate { font-weight: 650; color: var(--ok); }
.rate.mid { color: var(--warn); }
.rate.bad { color: var(--err); }

/* ---------- clientes ---------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ccard { display: flex; flex-direction: column; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; color: var(--ink); }
.ccard:hover { text-decoration: none; border-color: var(--line-2); transform: translateY(-2px); }
.ccard-top { display: flex; align-items: center; gap: 10px; }
.ccard-name { flex: 1; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccard-notes { margin: -4px 0 0; }
.sbar { display: flex; height: 8px; border-radius: 9px; overflow: hidden; gap: 2px; background: var(--gray-bg); }
.sbar span { background: var(--c); }
.ccard-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); }
.ccard-legend span { display: inline-flex; align-items: center; gap: 5px; }
.ccard-legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.ccard-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 10px; flex-wrap: wrap; }
.form-inline { padding: 14px 18px; }

/* ---------- job / execução ---------- */
.strip { display: flex; gap: 3px; height: 30px; }
.strip a { flex: 1; max-width: 22px; border-radius: 4px; background: var(--c); opacity: .9; }
.strip a:hover { opacity: 1; }
.strip-box { display: inline-block; min-width: 200px; }
.strip-legend { display: flex; justify-content: space-between; margin-top: 4px; }
pre.log { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; font: 12px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; word-break: break-word; max-height: 70vh; overflow: auto; margin: 0; color: var(--ink); }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 12px; margin: 0 0 16px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

/* ---------- login ---------- */
.login { max-width: 370px; margin: 11vh auto 0; text-align: center; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-brand h1 { font-size: 27px; font-weight: 500; }
.login-brand b { color: var(--brand); }
.login .card { text-align: left; margin-top: 22px; padding: 24px; }
.login label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-weight: 550; color: var(--ink-2); }

/* ---------- celular ---------- */
@media (max-width: 1000px) {
  .top nav a span { display: none; }
  .top nav a { padding: 8px 10px; }
}
@media (max-width: 760px) {
  .cards, .cards.four, .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
  .split, .split.even { grid-template-columns: 1fr; }
  .top-inner { gap: 10px; padding: 0 12px; }
  .brand span, .hide-sm { display: none; }
  .wrap { padding: 18px 16px 40px; }
  .head { flex-direction: column; gap: 10px; }
  .kv { grid-template-columns: 1fr; }
  .code-row { flex-direction: column; }
  .toolbar select { flex: 1; }
  .dates { width: 100%; }
  .dates input { flex: 1; min-width: 0; }
  /* tabelas viram lista de cartões */
  .grid.stack thead { display: none; }
  .grid.stack, .grid.stack tbody { display: block; }
  .grid.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .grid.stack td { display: block; padding: 0; border: 0; }
  .grid.stack .c-job { grid-column: 1; grid-row: 1; font-size: 15px; }
  .grid.stack .c-status { grid-column: 2; grid-row: 1; text-align: right; }
  .grid.stack .c-client, .grid.stack .c-host, .grid.stack .c-msg, .grid.stack .c-dots { grid-column: 1 / 3; }
  .grid.stack .c-host { color: var(--ink-2); }
  .grid.stack .c-when { grid-column: 1; }
  .grid.stack .c-when .sub { display: none; }
  .grid.stack .c-size { grid-column: 2; text-align: right; }
  .grid.stack .c-dur { display: none; }
  .grid.stack.hist .c-when { grid-row: 1; grid-column: 1; }
  .grid.stack.hist .c-job { grid-row: 2; }
  .tl-job { min-width: 150px; }
}

/* histórico: colunas alinhadas entre os dias */
@media (min-width: 761px) {
  table.hist { table-layout: fixed; }
  .hist th:nth-child(1) { width: 70px; }
  .hist th:nth-child(2) { width: 110px; }
  .hist th:nth-child(3) { width: 17%; }
  .hist th:nth-child(4) { width: 13%; }
  .hist th:nth-child(5) { width: 17%; }
  .hist th:nth-child(6) { width: 105px; }
  .hist th:nth-child(7) { width: 95px; }
  .hist td { overflow: hidden; text-overflow: ellipsis; }
}
