:root {
  --bg: #0d0a12;
  --panel: #15111c;
  --panel-2: #1f1829;
  --line: #2b2338;
  --text: #ece6f3;
  --muted: #9a8fab;
  --cyan: #b98cff;
  --green: #2fd17a;
  --red: #f05454;
  --yellow: #f5b83d;
  --gray: #5c6b7a;
  --lime: #d4f27a;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Inter", system-ui, sans-serif; font-size: 14px; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }

/* Barra lateral */
.side { background: #08060c; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.logo span { display: flex; flex-direction: column; line-height: 1.05; }
.logo b { font-size: 20px; letter-spacing: -.03em; }
.logo small { font-size: 10px; letter-spacing: .3em; color: var(--cyan); font-weight: 700; }
.menu { display: flex; flex-direction: column; gap: 4px; }
.menu a { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.menu a span { width: 18px; text-align: center; }
.menu a:hover { background: var(--panel); color: var(--text); }
.menu a.on { background: rgba(185,140,255,.12); color: var(--cyan); box-shadow: inset 3px 0 0 var(--cyan); }
.side-foot { margin-top: auto; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; font-size: 12px; color: var(--muted); }
.side-foot p { margin: 8px 0 12px; }
.demo-tag { background: var(--lime); color: #1f1430; font-weight: 800; font-size: 10px; letter-spacing: .12em; padding: 3px 8px; border-radius: 99px; }
.back { color: var(--cyan); font-weight: 600; }

/* Topo */
.top { display: flex; align-items: center; gap: 16px; padding: 14px 26px; border-bottom: 1px solid var(--line); background: rgba(13,10,18,.92); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.top-title { display: flex; flex-direction: column; }
.top-title b { font-size: 15px; }
.top-title span { font-size: 12px; color: var(--muted); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.online { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.online i, .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.clock { font-family: var(--mono); font-size: 18px; color: var(--cyan); }
.burger { display: none; background: none; border: 0; font-size: 22px; }
.view { padding: 24px 26px 60px; }

/* Blocos comuns */
h1.pg { font-size: 22px; margin: 0 0 4px; }
.pg-sub { color: var(--muted); margin: 0 0 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.kpi span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.kpi b { display: block; font-family: var(--mono); font-size: 26px; margin-top: 4px; }
.kpi small { color: var(--muted); font-size: 12px; }
.c-green { color: var(--green); } .c-red { color: var(--red); } .c-yellow { color: var(--yellow); } .c-cyan { color: var(--cyan); } .c-muted { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-side { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: var(--panel); border: 1px solid var(--line); padding: 6px 14px; border-radius: 99px; font-size: 13px; color: var(--muted); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(185,140,255,.1); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 4px 10px; border-radius: 6px; text-transform: uppercase; }
.b-run { background: rgba(47,209,122,.15); color: var(--green); }
.b-stop { background: rgba(240,84,84,.15); color: var(--red); }
.b-setup { background: rgba(245,184,61,.15); color: var(--yellow); }

/* Cartões de máquina */
.mgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: block; transition: transform .15s, border-color .15s; }
.mcard:hover { transform: translateY(-3px); border-color: var(--cyan); }
.mcard .bar { height: 5px; }
.bg-run { background: var(--green); } .bg-stop { background: var(--red); } .bg-setup { background: var(--yellow); }
.mcard .in { padding: 14px 16px; }
.mhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mhead b { font-family: var(--mono); font-size: 17px; }
.mhead small { display: block; color: var(--muted); font-size: 12px; }
.mbody { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-top: 12px; }
.big { font-family: var(--mono); font-size: 28px; font-weight: 700; line-height: 1; }
.big small { font-size: 13px; color: var(--muted); font-weight: 500; }
.prod { color: var(--muted); font-size: 12px; margin-top: 4px; }
.meta { position: relative; height: 7px; background: var(--panel-2); border-radius: 9px; margin-top: 12px; }
.meta i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 9px; background: var(--cyan); }
.meta em { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; opacity: .7; }
.mfoot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 10px; font-family: var(--mono); }
.stop-why { margin-top: 10px; font-size: 12px; padding: 6px 10px; border-radius: 8px; background: rgba(240,84,84,.08); color: #ffb3b3; }
.stop-why.setup { background: rgba(245,184,61,.08); color: #ffd98a; }

/* Anel de OEE */
.ring { --p: 50; --c: var(--cyan); width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--panel-2) 0); }
.ring span { width: 46px; height: 46px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-family: var(--mono); font-size: 13px; font-weight: 700; }
.ring.lg { width: 150px; height: 150px; }
.ring.lg span { width: 120px; height: 120px; font-size: 32px; flex-direction: column; }
.ring.lg span small { font-size: 11px; color: var(--muted); font-family: "Inter"; font-weight: 500; }

/* Eventos */
.feed { list-style: none; margin: 0; padding: 0; max-height: 640px; overflow: auto; }
.feed li { display: grid; grid-template-columns: 50px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.feed li:first-child { border-top: 0; }
.feed time { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.feed b { font-family: var(--mono); }
.feed .ev-stop { color: #ffb3b3; } .feed .ev-run { color: #a6f0c6; } .feed .ev-setup { color: #ffd98a; } .feed .ev-info { color: var(--text); }

/* Gráficos */
svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; font-family: "Inter"; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Linha do tempo */
.timeline { position: relative; height: 34px; border-radius: 8px; overflow: hidden; background: var(--panel-2); display: flex; }
.timeline span { height: 100%; }
.tl-ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Detalhe da máquina */
.mtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.mtabs a { font-family: var(--mono); font-size: 12px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.mtabs a i { width: 7px; height: 7px; border-radius: 50%; }
.mtabs a.on { border-color: var(--cyan); color: var(--cyan); }
.dhead { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.dhead h1 { font-family: var(--mono); font-size: 30px; margin: 0; }
.dinfo { display: grid; grid-template-columns: repeat(4, auto); gap: 6px 26px; font-size: 13px; color: var(--muted); }
.dinfo b { color: var(--text); font-weight: 600; }
.oee-box { display: flex; gap: 22px; align-items: center; }
.apq { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.apq div { font-size: 12px; color: var(--muted); }
.apq div b { float: right; color: var(--text); font-family: var(--mono); }
.apq .tr { height: 8px; background: var(--panel-2); border-radius: 9px; margin-top: 5px; overflow: hidden; }
.apq .tr i { display: block; height: 100%; border-radius: 9px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

/* Tabelas */
table.tb { width: 100%; border-collapse: collapse; font-size: 13px; }
.tb th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: default; white-space: nowrap; }
.tb th[data-sort] { cursor: pointer; }
.tb th[data-sort]:hover { color: var(--cyan); }
.tb td { padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tb td.n { font-family: var(--mono); text-align: right; }
.tb th.n { text-align: right; }
.tb tr:hover td { background: rgba(255,255,255,.02); }
.cell { display: inline-block; min-width: 52px; text-align: center; padding: 3px 8px; border-radius: 6px; font-weight: 700; }
.good { background: rgba(47,209,122,.15); color: var(--green); }
.mid { background: rgba(245,184,61,.15); color: var(--yellow); }
.low { background: rgba(240,84,84,.15); color: var(--red); }
.tbl-wrap { overflow-x: auto; }
.btn { background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; }
.btn:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-row { display: flex; gap: 8px; }

/* Modo TV */
body.tv .side, body.tv .top { display: none; }
body.tv .app { grid-template-columns: 1fr; }
body.tv .view { padding: 18px; }
.tv-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 20px; }
.tv-head h1 { margin: 0; font-size: clamp(22px, 2.6vw, 36px); }
.tv-head .clock { font-size: clamp(26px, 3vw, 44px); }
.tv-stats { display: flex; gap: 28px; font-family: var(--mono); font-size: clamp(14px, 1.5vw, 20px); color: var(--muted); }
.tv-stats b { color: var(--text); }
.tv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { border-radius: 16px; padding: clamp(14px, 1.6vw, 24px); color: #fff; min-height: 22vh; display: flex; flex-direction: column; justify-content: space-between; }
.tile.run { background: linear-gradient(160deg, #1f9d55, #157a40); }
.tile.stop { background: linear-gradient(160deg, #d63c3c, #9f2424); animation: blink 2s infinite; }
.tile.setup { background: linear-gradient(160deg, #e0a526, #b07b0e); }
@keyframes blink { 50% { filter: brightness(1.25); } }
.tile h2 { margin: 0; font-family: var(--mono); font-size: clamp(22px, 2.6vw, 40px); display: flex; justify-content: space-between; gap: 12px; white-space: nowrap; }
.tile h2 small { white-space: normal; text-align: right; max-width: 60%; }
.tile h2 small { font-family: "Inter"; font-size: clamp(11px, 1vw, 15px); font-weight: 800; letter-spacing: .08em; opacity: .9; }
.tile .num { font-family: var(--mono); font-size: clamp(30px, 4vw, 62px); font-weight: 700; line-height: 1; }
.tile .num small { font-size: .4em; opacity: .8; }
.tile .tl { height: 10px; background: rgba(0,0,0,.25); border-radius: 9px; overflow: hidden; }
.tile .tl i { display: block; height: 100%; background: #fff; }
.tile p { margin: 0; font-size: clamp(12px, 1.1vw, 16px); opacity: .92; display: flex; justify-content: space-between; }
.tv-exit { position: fixed; right: 16px; bottom: 16px; opacity: .3; }
.tv-exit:hover { opacity: 1; }

/* Display do operador (tela touch 320x240) */
.disp-wrap { display: grid; grid-template-columns: auto 1fr; gap: 30px; align-items: start; }
.device { background: #1b1b1b; padding: 26px 22px 34px; border-radius: 22px; box-shadow: 0 30px 60px -20px #000, inset 0 0 0 2px #2c2c2c; width: max-content; }
.device-label { text-align: center; font-size: 10px; color: #666; letter-spacing: .3em; margin-top: 14px; }
.screen { width: 480px; height: 360px; background: #000; border-radius: 4px; overflow: hidden; font-family: var(--mono); display: flex; flex-direction: column; color: #fff; user-select: none; }
.scr-top { display: flex; justify-content: space-between; padding: 8px 12px; background: #1a1424; font-size: 14px; color: #b4a8c6; }
.scr-status { margin: 10px 12px 0; padding: 14px; border-radius: 6px; text-align: center; font-weight: 700; font-size: 30px; letter-spacing: .06em; }
.scr-status.run { background: #1f9d55; } .scr-status.stop { background: #d63c3c; } .scr-status.setup { background: #e0a526; }
.scr-status small { display: block; font-size: 13px; font-weight: 500; letter-spacing: 0; margin-top: 2px; }
.scr-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 12px; }
.scr-counts div { background: #17121f; border-radius: 6px; padding: 8px; text-align: center; font-size: 12px; color: #b4a8c6; }
.scr-counts b { display: block; font-size: 26px; color: #fff; }
.scr-btns { margin: auto 12px 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scr-btns button { border: 0; border-radius: 6px; padding: 14px 4px; font-family: var(--mono); font-weight: 700; font-size: 14px; color: #fff; background: #2e2440; }
.scr-btns button:active { transform: scale(.96); }
.scr-btns .red { background: #b33030; } .scr-btns .green { background: #1f9d55; } .scr-btns .yel { background: #b07b0e; }
.scr-motivos { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.scr-motivos button { border: 0; border-radius: 6px; background: #2e2440; color: #fff; font-family: var(--mono); font-size: 13px; font-weight: 700; padding: 6px; }
.scr-title { padding: 10px 12px 0; font-size: 15px; color: #b4a8c6; }
.disp-help h3 { margin-top: 0; }
.disp-help ol { padding-left: 18px; color: var(--muted); line-height: 1.7; }

/* Responsivo */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-side { grid-template-columns: 1fr; }
  .tv-grid { grid-template-columns: repeat(3, 1fr); }
  .disp-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .burger { display: block; }
  .online { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .tv-grid { grid-template-columns: repeat(2, 1fr); }
  .dinfo { grid-template-columns: repeat(2, auto); }
  .view { padding: 18px 14px 50px; }
  .top { padding: 12px 14px; }
}
@media (max-width: 540px) {
  .screen { width: 320px; height: 240px; }
  .scr-status { font-size: 20px; padding: 8px; margin-top: 6px; }
  .scr-counts { margin: 6px 8px; } .scr-counts b { font-size: 18px; }
  .scr-btns { margin: auto 8px 8px; } .scr-btns button { padding: 9px 2px; font-size: 11px; }
  .scr-top { font-size: 11px; padding: 5px 8px; }
  .device { padding: 16px 12px 22px; }
  .tv-head { flex-direction: column; align-items: flex-start; }
}
