:root {
  --bg1: #f6f4f0; --bg2: #e6e2db;
  --card: #ffffff; --card2: #f4f5f7; --line: #e4e6ea;
  --tx: #16181c; --tx2: #5d6470; --tx3: #8a919c;
  --brand: #f7a21b; --brand-d: #d9860a; --ink: #111214;
  --ok: #16a34a; --warn: #d97706;
  --sheet-h: 46vh; --tab-h: 64px; --top-h: 58px;
  --r: 16px;
  --shadow: 0 10px 30px rgba(20, 22, 28, .12), 0 2px 6px rgba(20, 22, 28, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
.dark {
  --bg1: #1a1c21; --bg2: #0f1013;
  --card: #1d2026; --card2: #252930; --line: #2e333b;
  --tx: #f1f2f4; --tx2: #a9b0bb; --tx3: #7a818c;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 14px/1.45 Inter, system-ui, sans-serif; color: var(--tx);
  background: radial-gradient(120% 90% at 50% 20%, var(--bg1), var(--bg2));
  transition: background .8s;
}
body.storm { background: radial-gradient(120% 90% at 50% 10%, #3b4656, #12161d); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* topo */
.top {
  position: fixed; inset: 0 0 auto 0; height: var(--top-h); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 36px; height: 36px; box-shadow: var(--shadow); border-radius: 10px; }
.brand b { font: 800 20px/1 "Baloo 2", sans-serif; letter-spacing: .5px; display: block; }
.brand span { font-size: 12px; color: var(--tx2); }
body.storm .brand span, body.storm .brand b { color: #fff; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); color: var(--tx);
}

/* 3D */
#view { position: fixed; left: 0; right: 0; top: 0; bottom: calc(var(--sheet-h) + var(--tab-h) + var(--safe-b)); transition: bottom .35s ease; }
#view canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.dim {
  font: 600 10.5px/1 Inter, sans-serif; color: #fff; background: #0284c7; padding: 3px 6px; border-radius: 6px;
  white-space: nowrap; box-shadow: 0 2px 6px rgba(0, 0, 0, .2);
}
.dim.rain { background: #c026d3; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--tx2); }
.loading i { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
body.ready .loading { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.cams {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--top-h) + 4px + env(safe-area-inset-top, 0px));
  display: flex; gap: 4px; padding: 4px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow); z-index: 5;
  max-width: calc(100vw - 20px); overflow-x: auto; scrollbar-width: none;
}
.cams button { padding: 7px 10px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--tx2); white-space: nowrap; display: grid; place-items: center; }
.cams button:hover { background: var(--card2); color: var(--tx); }
.cams button.on { background: var(--ink); color: var(--brand); }

/* card da peça */
.info {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 6; max-width: 380px;
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px;
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .25s;
  max-height: 60%; overflow: auto;
}
.info.show { transform: none; opacity: 1; pointer-events: auto; }
.info .close { position: absolute; right: 8px; top: 8px; width: 32px; height: 32px; box-shadow: none; background: var(--card2); }
.info h3 { margin: 8px 0 8px; font-size: 16px; padding-right: 30px; }
.info dl { margin: 0; display: grid; grid-template-columns: 76px 1fr; gap: 4px 10px; font-size: 13px; }
.info dt { color: var(--tx3); }
.info dd { margin: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--tx2); }
.chip::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.bom-mini { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 12.5px; }
.bom-mini div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.bom-mini span { color: var(--tx2); }

/* painel */
.sheet {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); height: var(--sheet-h); z-index: 10;
  background: var(--card); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column; transition: height .35s ease;
}
.sheet.min { height: 52px; }
body:has(.sheet.min) #view { bottom: calc(52px + var(--tab-h) + var(--safe-b)); }
.handle { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 6px; flex: none; }
.handle i { width: 40px; height: 4px; border-radius: 4px; background: var(--line); }
.handle b { font-size: 15px; }
.sheet-body { overflow-y: auto; padding: 6px 16px 22px; flex: 1; overscroll-behavior: contain; }
.sheet-body h4 { margin: 20px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--tx3); }

/* menu inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); z-index: 11;
  display: grid; grid-template-columns: repeat(5, 1fr); background: var(--card); border-top: 1px solid var(--line);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--tx3); position: relative; }
.tabbar button.on { color: var(--tx); }
.tabbar button.on svg { color: var(--brand); }
.tabbar button.on::before { content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand); }

/* controles */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--card2); padding: 4px; border-radius: 12px; }
.seg button { padding: 9px 6px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--tx2); }
.seg button.on { background: var(--card); color: var(--tx); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.row-ctl { display: block; margin: 16px 0 6px; font-weight: 600; font-size: 13px; }
.row-ctl span { display: flex; justify-content: space-between; }
input[type=range] { width: 100%; accent-color: var(--brand); margin-top: 8px; height: 22px; }
.switch { display: flex; align-items: center; gap: 12px; padding: 10px 0; cursor: pointer; }
.switch input { display: none; }
.switch i { width: 42px; height: 24px; border-radius: 20px; background: var(--line); position: relative; flex: none; transition: .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: .2s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { left: 21px; }
.switch span { font-weight: 600; font-size: 13.5px; }
.switch small { display: block; font-weight: 400; color: var(--tx3); font-size: 12px; }
.hint { font-size: 12.5px; color: var(--tx2); background: var(--card2); border-radius: 10px; padding: 9px 12px; margin: 8px 0 0; }

.legend { display: grid; gap: 4px; }
.leg { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--card2); text-align: left; font-size: 13px; font-weight: 500; }
.leg i { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.leg span { flex: 1; }
.leg svg { color: var(--tx3); }
.leg.off { opacity: .45; }
.ref { margin: 0; border-radius: 14px; overflow: hidden; background: var(--card2); }
.ref img { width: 100%; display: block; max-height: 320px; object-fit: cover; }
.ref figcaption { font-size: 12px; color: var(--tx3); padding: 8px 12px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td:last-child { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl small { display: block; color: var(--tx3); font-size: 11.5px; margin-top: 2px; }
.note { background: var(--card2); border-radius: 12px; padding: 12px 14px; margin-top: 16px; font-size: 13px; color: var(--tx2); }
.note b { color: var(--tx); }
.note ul { margin: 6px 0 0; padding-left: 18px; }
.note li { margin: 4px 0; }
.note.warn { background: rgba(217, 119, 6, .1); border: 1px solid rgba(217, 119, 6, .3); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.big { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 13px 10px; border-radius: 14px; background: var(--card2); font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.big.on { background: #1e3a5f; color: #cfe3ff; }
.big.primary { background: var(--ink); color: var(--brand); }
.dark .big.primary { background: var(--brand); color: var(--ink); }
.big svg { transition: transform .3s; flex: none; }
.big.flip svg { transform: rotate(180deg); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.kpis div { background: var(--card2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.kpis small { display: block; color: var(--tx3); font-size: 11.5px; }
.kpis b { font-size: clamp(15px, 4.4vw, 19px); font-variant-numeric: tabular-nums; white-space: nowrap; }
#gain { color: var(--ok); }
.steps { padding-left: 20px; margin: 0; }
.steps li { margin: 0 0 10px; font-size: 13px; color: var(--tx2); }
.steps b { color: var(--tx); }

.total-card { background: var(--ink); color: #fff; border-radius: 18px; padding: 16px 18px; position: relative; overflow: hidden; }
.total-card::after { content: ""; position: absolute; right: -70px; top: -70px; width: 170px; height: 170px; border-radius: 50%; border: 22px solid var(--brand); opacity: .14; }
.total-card small { color: #b9bec7; font-size: 12px; }
.total-card b { display: block; font: 800 clamp(28px, 9vw, 38px)/1.1 "Baloo 2", sans-serif; color: var(--brand); margin: 4px 0; }
.total-card span { font-size: 12.5px; color: #d7dbe1; }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12.5px; }
.bar i { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: var(--card2); overflow: hidden; order: 3; }
.bar em { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.bar b { font-variant-numeric: tabular-nums; }
.cat { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; overflow: hidden; }
.cat summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 11px 12px; cursor: pointer; font-weight: 600; font-size: 13.5px; }
.cat summary::-webkit-details-marker { display: none; }
.cat summary span { flex: 1; }
.cat summary svg { color: var(--tx3); transition: transform .2s; }
.cat[open] summary svg { transform: rotate(180deg); }
.cat .tbl { padding: 0 12px; display: block; }
.cat .tbl tbody { display: table; width: 100%; }
.cat .tbl tr:last-child td { border-bottom: 0; }
.btn-line { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: 12px; border: 1.5px solid var(--line); font-weight: 600; margin-top: 8px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; gap: 12px; padding-bottom: 12px; position: relative; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--line); }
.timeline li > i { width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--brand); font: 700 12px/28px Inter; text-align: center; font-style: normal; flex: none; }
.timeline b { font-size: 13.5px; }
.timeline .d { font-size: 11.5px; color: var(--brand-d); font-weight: 700; margin-left: 8px; }
.timeline p { margin: 2px 0 0; font-size: 12.5px; color: var(--tx2); }
.check { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.check li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; background: var(--card2); padding: 9px 12px; border-radius: 10px; }
.check svg { color: var(--ok); flex: none; margin-top: 1px; }

@media (max-width: 899px) {
  :root { --sheet-h: 42vh; }
  .cams { top: auto; bottom: 10px; }
  .info { top: calc(var(--top-h) + 6px); bottom: auto; max-height: calc(100% - var(--top-h) - 70px); padding: 12px 14px; }
  .info dl { font-size: 12.5px; }
}

/* desktop */
@media (min-width: 900px) {
  :root { --panel-w: 400px; }
  #view { right: calc(var(--panel-w) + 16px); bottom: 0; }
  body:has(.sheet.min) #view { bottom: 0; }
  .sheet { left: auto; right: 12px; top: 12px; bottom: calc(var(--tab-h) + 24px); width: var(--panel-w); height: auto; border-radius: 22px; box-shadow: var(--shadow); }
  .sheet.min { height: auto; }
  .handle { pointer-events: none; padding-top: 16px; }
  .handle i { display: none; }
  .tabbar { left: auto; right: 12px; bottom: 12px; width: var(--panel-w); height: var(--tab-h); border-radius: 18px; border: 0; box-shadow: var(--shadow); overflow: hidden; }
  .top { right: calc(var(--panel-w) + 16px); padding: 0 20px; }
  .info { left: 20px; bottom: 20px; }
}
