/* Painel mobile-first. Escuro por padrão (carro à noite); claro via prefers-color-scheme. */
:root {
  --bg: #0d1117; --panel: #151b24; --panel2: #1c2430; --line: #263041;
  --fg: #e8edf4; --muted: #8592a6;
  --rpm: #ff6b3d; --speed: #2ec8ff; --temp: #ffb020; --volt: #8b7bff; --pedal: #ff4fa3; --tps: #2ee59d;
  --ok: #2ee59d; --warn: #ffb020; --bad: #ff4d5e;
  --f-display: "Sora", "Segoe UI", system-ui, sans-serif;
  --f-body: "Inter", system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) { :root[data-theme="auto"] {
  --bg: #eef2f7; --panel: #ffffff; --panel2: #f4f7fb; --line: #dbe2ec; --fg: #121826; --muted: #5d6b80;
  --rpm: #e8521f; --speed: #0596d6; --temp: #d98a00; --volt: #6a58f0; --pedal: #e0287f; --tps: #10a86c;
  --ok: #10a86c; --warn: #d98a00; --bad: #e02d3f; color-scheme: light } }
:root[data-theme="light"] {
  --bg: #eef2f7; --panel: #ffffff; --panel2: #f4f7fb; --line: #dbe2ec; --fg: #121826; --muted: #5d6b80;
  --rpm: #e8521f; --speed: #0596d6; --temp: #d98a00; --volt: #6a58f0; --pedal: #e0287f; --tps: #10a86c;
  --ok: #10a86c; --warn: #d98a00; --bad: #e02d3f; color-scheme: light }

* { box-sizing: border-box }
html, body { margin: 0 }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--f-body); padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) }
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance }
h2 { font-size: 15px; font-weight: 600 }
a { color: var(--speed) }
.lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600 }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums }
.muted { color: var(--muted) }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-width: 0 }
.wrap { max-width: 1180px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 16px }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap }
.grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px }
.grid2e { display: grid; grid-template-columns: 1fr 1fr; gap: 16px }
.view { display: grid; gap: 16px }
.view[hidden] { display: none }

/* topo */
.top { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top, 0px) }
.top .in { max-width: 1180px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between }
.brand { display: flex; align-items: center; gap: 10px }
.logo { width: 34px; height: 34px; border-radius: 10px; background: conic-gradient(from 200deg, var(--rpm), var(--temp), var(--tps), var(--speed), var(--volt), var(--pedal), var(--rpm)); display: grid; place-items: center }
.logo i { width: 22px; height: 22px; border-radius: 7px; background: var(--panel) }
.brand h1 { font-size: 17px } .brand small { color: var(--muted); display: block; font-size: 12px }
.chips { display: flex; flex-wrap: wrap; gap: 6px }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ok)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--ok)) 25%, transparent) }

/* abas inferiores (celular) / superiores (desktop) */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--panel); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); overflow-x: auto; scrollbar-width: none }
.tabs a { flex: 1 0 auto; min-width: 60px; text-align: center; text-decoration: none; color: var(--muted); font: 600 11px var(--f-body); padding: 6px 4px; border-radius: 10px; display: grid; gap: 2px; justify-items: center }
.tabs a svg { width: 20px; height: 20px }
.tabs a[aria-current="page"] { color: var(--fg); background: var(--panel2) }
.tabs a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--speed); outline-offset: 2px }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; margin-left: 2px }

/* banner de alerta */
.banner { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--s) 45%, transparent); background: color-mix(in srgb, var(--s) 12%, var(--panel)) }
.banner b { font-family: var(--f-display) } .banner .ic { grid-row: span 2; align-self: center }

/* medidores */
.gauges { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px }
.gauge { display: grid; justify-items: center; gap: 2px; padding: 14px 10px 12px }
.gauge svg { width: 100%; max-width: 150px; height: auto }
.gauge .v { font-size: 26px; font-weight: 700; margin-top: -42px }
.gauge .u { font-size: 11px; color: var(--muted); margin-bottom: 8px }
.gauge .sub { font-size: 12px; color: var(--muted); text-align: center }

/* gráficos */
.chart { width: 100%; height: 190px; display: block }
.chart.sm { height: 140px }
.chart text { fill: var(--muted); font: 10px var(--f-mono) }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap }
.legend span::before { content: ""; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--c) }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px }
.stats div { background: var(--panel2); border-radius: 12px; padding: 10px 12px; min-width: 0 }
.stats b { display: block; font: 700 18px var(--f-mono); overflow-wrap: anywhere }

/* saúde */
.ring { display: flex; align-items: center; gap: 16px }
.ring svg { width: 112px; height: 112px; flex: none }
.ring .score { font: 700 30px var(--f-display) }
.checks { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none }
.checks li, .alert { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; background: var(--panel2); border-radius: 12px; border-left: 3px solid var(--s) }
.checks .t, .alert .t { font-weight: 600; font-size: 13px } .checks .d, .alert .d { font-size: 12px; color: var(--muted) }
.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; color: var(--s); background: color-mix(in srgb, var(--s) 16%, transparent); white-space: nowrap }
.ic { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: color-mix(in srgb, var(--s) 18%, transparent); color: var(--s); font-weight: 800; font-size: 12px }
.list { display: grid; gap: 8px }

/* sensores */
.sensors { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px }
.sensor { background: var(--panel2); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; border-top: 3px solid var(--s, var(--line)); cursor: pointer; text-align: left; color: inherit; font: inherit; border-left: 0; border-right: 0; border-bottom: 0 }
.sensor .n { font-size: 12px; color: var(--muted) } .sensor .pid { font: 500 10px var(--f-mono); color: var(--muted) }
.sensor .val { font: 700 18px var(--f-mono) } .sensor .val small { font: 500 11px var(--f-body); color: var(--muted); margin-left: 3px }

/* tabelas */
.tbl { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: 13px }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 8px; white-space: nowrap }
td { padding: 10px 8px; border-top: 1px solid var(--line) } td.num { white-space: nowrap }
tr.click { cursor: pointer } tr.click:hover td { background: var(--panel2) }
.bar { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; width: 80px } .bar i { display: block; height: 100%; background: var(--s) }

.btn, select, input[type=text], input[type=datetime-local] { font: 600 13px var(--f-body); color: var(--fg); background: var(--panel2); border: 1px solid var(--line); padding: 8px 12px; border-radius: 10px }
.btn { cursor: pointer; text-decoration: none; display: inline-block }
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 12px }
code.k { font: 600 12px var(--f-mono); background: var(--panel2); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere }

@media (min-width: 901px) {
  body { padding-bottom: 0 }
  .tabs { position: static; border: 0; background: none; padding: 0; justify-content: flex-start; flex: 1 1 100%; order: 3 }
  .tabs a { flex: 0 0 auto; display: inline-flex; gap: 6px; font-size: 13px; padding: 8px 12px }
  .tabs a svg { width: 16px; height: 16px }
}
@media (max-width: 900px) { .grid2, .grid2e { grid-template-columns: 1fr } .gauges { grid-template-columns: repeat(2, minmax(0, 1fr)) } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important } }

/* motor / consumo */
.engine { display: grid; grid-template-columns: minmax(0, 1.2fr) repeat(4, minmax(0, 1fr)); gap: 12px; align-items: center }
.engine .st { display: flex; align-items: center; gap: 12px }
.engine .st .big { font: 700 20px var(--f-display) }
.engine .pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 22%, transparent); flex: none }
.engine .pulse.on { animation: pulse 1.6s ease-in-out infinite }
@keyframes pulse { 50% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--c) 8%, transparent) } }
.engine .kv { background: var(--panel2); border-radius: 12px; padding: 10px 12px; min-width: 0 }
.engine .kv b { display: block; font: 700 18px var(--f-mono) }
.btn.big { font-size: 15px; padding: 12px 18px; background: var(--ok); color: #06140d; border: 0 }
.seg { display: flex; gap: 8px } .seg label { flex: 1 } .seg input { position: absolute; opacity: 0 }
.seg span { display: block; text-align: center; padding: 12px; border-radius: 12px; background: var(--panel2); border: 2px solid var(--line); font-weight: 700; cursor: pointer }
.seg input:checked + span { border-color: var(--ok); color: var(--ok) } .seg input:focus-visible + span { outline: 2px solid var(--speed) }
input[type=number] { font: 600 15px var(--f-body); color: var(--fg); background: var(--panel2); border: 1px solid var(--line); padding: 12px; border-radius: 10px }
.timeline { display: grid; gap: 6px } .timeline .d { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center; font: 11px var(--f-mono); color: var(--muted) }
.timeline .tr { position: relative; height: 14px; background: var(--panel2); border-radius: 4px; overflow: hidden }
.timeline .tr i { position: absolute; top: 0; bottom: 0; background: var(--rpm); border-radius: 3px; min-width: 2px }
@media (max-width: 900px) { .engine { grid-template-columns: repeat(2, minmax(0, 1fr)) } .engine .st { grid-column: 1 / -1 } }

/* gráfico individual (modal) */
.modal { position: fixed; inset: 0; z-index: 20; background: color-mix(in srgb, #000 55%, transparent); display: grid; place-items: end center; padding: 0 max(0px, env(safe-area-inset-right, 0px)) 0 max(0px, env(safe-area-inset-left, 0px)) }
.modal[hidden] { display: none }
.modal .sheet { width: min(760px, 100%); max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; display: grid; gap: 12px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)) }
@media (min-width: 901px) { .modal { place-items: center } .modal .sheet { border-radius: 20px } }
.mval { display: flex; align-items: baseline; gap: 12px } .mval b { font-size: 40px; font-weight: 700 }
.seg.small span { padding: 8px; font-size: 13px }
.rbtn { font: 600 12px var(--f-body); padding: 6px 10px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--fg); cursor: pointer }
.rbtn[aria-pressed="true"] { border-color: var(--speed); color: var(--speed) }
.sensor.bad { background: color-mix(in srgb, var(--s) 14%, var(--panel2)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--s) 55%, transparent) }
.sensor.bad .val { color: var(--s) }

/* recomendações nos alertas */
details.alert { display: block; padding: 0 } details.alert > summary { list-style: none; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; cursor: pointer }
details.alert > summary::-webkit-details-marker { display: none }
details.alert[open] > summary { border-bottom: 1px solid var(--line) }
.adv { padding: 12px 14px 14px; display: grid; gap: 10px; font-size: 13px }
.adv h4 { margin: 0 0 4px; font: 700 12px var(--f-body); text-transform: uppercase; letter-spacing: .06em; color: var(--muted) }
.adv ul { margin: 0; padding-left: 18px; display: grid; gap: 3px } .adv .urg { font-weight: 700; color: var(--s) }
.more { font-size: 11px; color: var(--speed); font-weight: 600; white-space: nowrap }
.theme { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden } .theme button { font: 600 11px var(--f-body); background: none; border: 0; color: var(--muted); padding: 6px 9px; cursor: pointer }
.theme button[aria-pressed="true"] { background: var(--panel2); color: var(--fg) }

/* sensores: verde = normal, vermelho = fora do normal */
.sensor .rng { font-size: 11px; color: var(--muted); line-height: 1.3 }
.sensor.good .val { color: var(--ok) } .sensor.good { border-top-color: var(--ok) }
.sensor.bad .val { color: var(--bad) } .sensor.bad .rng { color: var(--bad) }

.big2 { font-size: 28px; font-weight: 700 }

/* laudo da IA */
.md { font-size: 14px; line-height: 1.6; max-width: 75ch } .md h2 { font-size: 17px; margin: 18px 0 6px } .md h3 { font-size: 15px; margin: 14px 0 4px }
.md ul, .md ol { padding-left: 20px; margin: 6px 0 } .md li { margin: 3px 0 } .md p { margin: 8px 0 } .md code { font: 12px var(--f-mono); background: var(--panel2); padding: 1px 5px; border-radius: 5px }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--volt); border-radius: 50%; animation: sp 1s linear infinite; vertical-align: -2px; margin-right: 6px } @keyframes sp { to { transform: rotate(360deg) } }

.cloudbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line) }
.cloudbar[hidden] { display: none }
