:root{
  --red:#d10a11; --red2:#e11b22; --ink:#15181d; --muted:#6b7280;
  --bg:#f4f6f9; --card:#ffffff; --line:#eceef2; --ok:#16a34a; --warn:#d97706;
  --radius:18px; --nav-h:64px;
  --safe-b:env(safe-area-inset-bottom,0px);
}
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
[hidden]{display:none!important}
html,body{height:100%}
body{font-family:'Prompt',system-ui,sans-serif;background:var(--bg);color:var(--ink);
  -webkit-font-smoothing:antialiased;overscroll-behavior-y:none}

/* app bar */
.appbar{position:sticky;top:0;z-index:30;display:flex;align-items:center;justify-content:space-between;
  gap:10px;padding:10px 16px;padding-top:calc(10px + env(safe-area-inset-top,0px));
  background:#fff;border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.logo{width:34px;height:34px;flex:0 0 34px}
.brandtxt{display:flex;flex-direction:column;line-height:1.1;min-width:0}
.brandtxt b{font-size:15px;font-weight:700}
.brandtxt span{font-size:12px;color:var(--muted)}
.connpill{flex:0 0 auto;font-size:12px;font-weight:600;padding:6px 12px;border-radius:30px;white-space:nowrap}
.connpill.off{background:#f1f3f6;color:var(--muted)}
.connpill.on{background:#e7f7ec;color:var(--ok)}
.connpill.busy{background:#fdeede;color:var(--warn)}

/* screens */
#main{padding:14px 14px calc(var(--nav-h) + var(--safe-b) + 18px);max-width:560px;margin:0 auto}
.screen{display:none;flex-direction:column;gap:14px}
.screen.active{display:flex}

/* cards */
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:16px;
  box-shadow:0 6px 18px rgba(21,24,33,.04)}
.card-h{font-size:15px;font-weight:700;margin-bottom:12px;display:flex;align-items:center;justify-content:space-between;gap:8px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.stat{padding:14px 16px}
.stat .s-lbl{font-size:12px;color:var(--muted)}
.stat b{display:block;font-size:22px;font-weight:800;margin-top:4px}
.kv{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:8px 0;border-bottom:1px solid var(--line);font-size:14px}
.kv:last-child{border-bottom:0}
.kv span{color:var(--muted)}
.kv b{font-weight:700;text-align:right}

/* connect card */
.connect-card{background:linear-gradient(160deg,#fff,#fbfcfe)}
.cc-top{display:flex;gap:16px;align-items:center;margin-bottom:16px}
.cc-chip{flex:0 0 84px}.cc-chip svg{width:84px;height:84px}
.cc-info{display:flex;flex-direction:column;gap:2px;min-width:0}
.cc-lbl{font-size:12px;color:var(--muted)}
.cc-info b{font-size:18px;font-weight:800}
.cc-info small{font-size:12px;color:var(--muted);line-height:1.35}

/* buttons */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;width:100%;border:0;cursor:pointer;
  font-family:inherit;font-weight:700;font-size:15px;padding:13px 18px;border-radius:14px;transition:.15s;color:#fff}
.btn:active{transform:scale(.98)}
.btn-lg{padding:16px;font-size:16px}
.btn-sm{width:auto;padding:7px 14px;font-size:13px}
.btn-primary{background:var(--red);box-shadow:0 8px 20px rgba(209,10,17,.25)}
.btn-primary:disabled{background:#f0b9bc;box-shadow:none}
.btn-danger{background:#b0060c}
.btn-outline{background:#fff;color:var(--red);border:1.5px solid var(--red)}
.btn-ghost{background:#f1f3f6;color:var(--ink)}
.btnrow{display:flex;gap:10px;margin-top:4px}
.btnrow .btn{flex:1}

/* dropzone / select */
.dropzone{display:flex;flex-direction:column;align-items:center;gap:6px;padding:26px 16px;border:2px dashed #e4b9bb;
  border-radius:16px;text-align:center;cursor:pointer;background:#fffafa}
.dz-ic{width:40px;height:40px;margin-bottom:4px}
.dropzone b{font-size:15px}.dropzone small{color:var(--muted);font-size:12px}
.select{width:100%;font-family:inherit;font-size:14px;padding:12px;border:1px solid var(--line);border-radius:12px;background:#fff;color:var(--ink)}
.select-sm{width:auto;padding:8px 10px;font-size:13px}

/* mini gauges */
.mini-gauges{display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:8px}
.mg{background:#f8fafc;border:1px solid var(--line);border-radius:12px;padding:10px 6px;text-align:center}
.mg span{display:block;font-size:11px;color:var(--muted)}
.mg b{display:block;font-size:20px;font-weight:800;color:var(--ink);line-height:1.1;margin-top:2px;font-family:'Rajdhani'}
.mg small{font-size:10px;color:var(--muted)}

/* full gauges */
.gauges{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.gauge{background:#f8fafc;border:1px solid var(--line);border-radius:14px;padding:12px}
.gauge .g-top{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:8px}
.gauge .g-name{font-size:12px;color:var(--muted);font-weight:600}
.gauge .g-val{font-size:20px;font-weight:800;font-family:'Rajdhani'}
.gauge .g-val small{font-size:11px;color:var(--muted);font-weight:600}
.gbar{height:7px;background:#e8ebf0;border-radius:5px;overflow:hidden}
.gbar i{display:block;height:100%;width:0;background:linear-gradient(90deg,var(--red2),var(--red));border-radius:5px;transition:width .15s}
.gauge.analog .g-dialwrap{display:flex;justify-content:center}
.gauge.analog svg{width:100%;max-width:150px;height:84px}
.gauge .g-bar-wrap{margin-top:2px}

/* steps */
.steps{display:flex;gap:6px}
.step{flex:1;display:flex;flex-direction:column;align-items:center;gap:4px;font-size:11px;color:var(--muted)}
.step i{width:30px;height:30px;border-radius:50%;display:grid;place-items:center;background:#eceef2;color:var(--muted);font-weight:800;font-style:normal;font-size:14px}
.step.done i,.step.active i{background:var(--red);color:#fff}
.step.active span,.step.done span{color:var(--ink);font-weight:600}

/* progress */
.progwrap{margin-bottom:10px}
.progbar{height:16px;background:#e8ebf0;border-radius:10px;overflow:hidden}
.progfill{height:100%;width:0;background:linear-gradient(90deg,var(--red2),var(--red));border-radius:10px;transition:width .2s}
.progmeta{display:flex;justify-content:space-between;font-size:13px;font-weight:700;margin-top:6px}
.progmeta span:last-child{color:var(--muted);font-weight:500}
.statusline{font-size:13px;color:var(--ink);background:#f8fafc;border-radius:10px;padding:10px;margin-bottom:12px;min-height:20px}
.log{font-family:'Rajdhani',monospace;font-size:12px;color:#4b5563;max-height:160px;overflow:auto;line-height:1.5}
.log div{padding:1px 0;border-bottom:1px dashed #f0f2f5}

/* joblist */
.joblist{display:flex;flex-direction:column;gap:8px}
.joblist .empty{color:var(--muted);font-size:13px;text-align:center;padding:14px 0}
.jobrow{display:flex;align-items:center;gap:10px;padding:10px 12px;background:#f8fafc;border:1px solid var(--line);border-radius:12px}
.jobrow .ji{flex:0 0 auto;font-size:18px}
.jobrow .jb{min-width:0;flex:1}
.jobrow .jb b{display:block;font-size:13px;font-weight:700}
.jobrow .jb small{display:block;font-size:11px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.jobrow .jt{font-size:11px;color:var(--muted);white-space:nowrap}
.jobrow.ok{border-left:3px solid var(--ok)}
.jobrow.bad{border-left:3px solid var(--red)}

/* dtc */
.dtcrow{padding:10px 12px;background:#fff7f7;border:1px solid #f3d6d7;border-radius:12px;font-size:13px}
.dtcrow b{color:var(--red)}

/* hub */
.hub{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:8px}
.hubitem{padding:14px;background:#f8fafc;border:1px solid var(--line);border-radius:12px;text-align:center;font-weight:600;font-size:14px;cursor:pointer}
.hubitem:active{background:#eef1f5}
.note{display:block;font-size:11.5px;color:var(--muted);line-height:1.4;margin-top:4px}

/* warn */
.warn{background:#fff7ed;border-color:#fed7aa;color:#9a3412;font-size:13px;line-height:1.45}
.warn-soft{background:#fff7ed;border:1px solid #fed7aa;color:#9a3412;font-size:12.5px;line-height:1.5;border-radius:var(--radius);padding:14px}

/* segmented */
.seg{display:inline-flex;background:#f1f3f6;border-radius:10px;padding:3px}
.seg .tbtn{border:0;background:transparent;font-family:inherit;font-size:12px;font-weight:600;color:var(--muted);padding:6px 12px;border-radius:8px;cursor:pointer}
.seg .tbtn.active{background:#fff;color:var(--red);box-shadow:0 1px 4px rgba(0,0,0,.08)}

/* bottom nav */
.bottomnav{position:fixed;left:0;right:0;bottom:0;z-index:40;display:flex;justify-content:space-around;
  background:#fff;border-top:1px solid var(--line);height:calc(var(--nav-h) + var(--safe-b));
  padding-bottom:var(--safe-b)}
.navbtn{flex:1;border:0;background:transparent;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
  color:var(--muted);font-family:inherit;font-size:10.5px;font-weight:600;cursor:pointer}
.navbtn svg{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
.navbtn.active{color:var(--red)}
.navbtn.flashnav svg{fill:currentColor;stroke:currentColor}
.navbtn.flashnav{position:relative}

/* more sheet */
.sheet{position:fixed;inset:0;z-index:60}
.sheet-bg{position:absolute;inset:0;background:rgba(21,24,33,.4)}
.sheet-body{position:absolute;left:0;right:0;bottom:0;background:#fff;border-radius:22px 22px 0 0;padding:10px 16px calc(20px + var(--safe-b));
  animation:up .2s ease}
@keyframes up{from{transform:translateY(100%)}to{transform:translateY(0)}}
.sheet-grab{width:40px;height:4px;background:#d7dbe0;border-radius:3px;margin:6px auto 14px}
.sheetitem{width:100%;text-align:left;border:0;background:#f8fafc;border-radius:12px;padding:15px 16px;font-family:inherit;font-size:15px;font-weight:600;margin-bottom:10px;cursor:pointer}

/* map tune */
.tagfile{font-size:12px;font-weight:600;color:var(--muted);background:#f1f3f6;padding:4px 10px;border-radius:20px;max-width:55%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.src-row{display:grid;grid-template-columns:auto 1fr;gap:10px;align-items:center;margin-bottom:10px}
.src-row .btn{width:auto;white-space:nowrap}
.src-status{margin-top:4px}
.src-status .kv b{max-width:62%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.mt-ctrl{display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px}
.mt-ctrl label{display:flex;flex-direction:column;gap:4px;font-size:11px;color:var(--muted);font-weight:600}
.inp{font-family:inherit;font-size:14px;padding:9px 10px;border:1px solid var(--line);border-radius:10px;background:#fff;color:var(--ink);width:100%}
.inp-sm{width:72px;padding:7px 8px;font-size:13px}
.mt-presets{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
.chip{border:1px solid var(--line);background:#f8fafc;border-radius:20px;padding:7px 13px;font-family:inherit;font-size:12.5px;font-weight:600;color:var(--ink);cursor:pointer}
.chip:active{background:#eef1f5}
.mt-stat{font-size:12px;color:var(--muted);font-weight:600;margin-bottom:10px}
.mt-axis{display:grid;grid-template-columns:1fr 1fr 1fr 1fr;gap:8px;margin-bottom:12px}
.mt-axis label{display:flex;flex-direction:column;gap:3px;font-size:10.5px;color:var(--muted);font-weight:600}
.mt-axis .inp-sm{width:100%}
.mt-3d{width:100%;height:340px;background:linear-gradient(180deg,#0f1115,#1a1e25);border-radius:12px;touch-action:none;display:block}
.mt-3dhint{text-align:center;font-size:11px;color:var(--muted);margin-top:6px}
.mt-legend{display:flex;align-items:center;gap:8px;justify-content:center;margin-top:6px;font-size:11px;color:var(--muted)}
.mt-legend .lg-bar{width:140px;height:8px;border-radius:5px;background:linear-gradient(90deg,#1e63d0,#19b36b,#f4d03f,#e8631a,#d61f1f)}
.mt-tools,.mt-tools2{display:flex;gap:10px;flex-wrap:wrap;align-items:center;margin-bottom:12px}
.mt-tools2{margin-top:12px;margin-bottom:0}
.mt-tool{display:flex;gap:6px;align-items:center}
.mt-gridwrap{overflow:auto;-webkit-overflow-scrolling:touch;border:1px solid var(--line);border-radius:10px;max-height:60vh}
.mt-grid{border-collapse:collapse;font-family:'Rajdhani',monospace;font-size:12px}
.mt-grid th{position:sticky;top:0;background:#15181d;color:#fff;font-weight:700;padding:5px 4px;font-size:10px;z-index:2}
.mt-grid th.corner{left:0;z-index:3}
.mt-grid td.rowh{position:sticky;left:0;background:#2a2f37;color:#fff;font-weight:700;font-size:10px;padding:4px 6px;z-index:1}
.mt-grid td.cell{padding:0;border:1px solid #eef0f3;min-width:44px;position:relative;cursor:cell}
.mt-grid td.cell .cv{display:block;min-width:46px;text-align:center;font-family:inherit;font-size:12px;font-weight:600;padding:7px 3px;color:#15181d;pointer-events:none}
.mt-grid td.cell.sel{box-shadow:inset 0 0 0 2px var(--red);filter:saturate(1.35) brightness(.97)}
.mt-grid td.cell.anchor{box-shadow:inset 0 0 0 3px #b0060c}
.mt-grid{user-select:none;-webkit-user-select:none}
.mt-gridwrap{touch-action:pan-x pan-y;overscroll-behavior:contain}
.mt-gridwrap.selecting{touch-action:none}
/* selection toolbar */
.mt-selbar{position:sticky;top:0;z-index:4;background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px 12px;margin-bottom:10px;box-shadow:0 6px 18px rgba(21,24,33,.06)}
.mt-selbar .sel-info{display:flex;flex-direction:column;gap:2px;margin-bottom:8px}
.mt-selbar .sel-info b{font-size:13px;color:var(--red)}
.mt-selbar .sel-info small{font-size:11px;color:var(--muted);line-height:1.35}
.mt-selbar .sel-tools{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
.mt-selbar .inp-sm{width:78px}
.fullbtn{border:1px solid var(--line);background:#fff;color:var(--ink);font-family:inherit;font-size:12px;font-weight:700;padding:7px 10px;border-radius:10px;cursor:pointer;white-space:nowrap}
.fullbtn.on{background:var(--red);color:#fff;border-color:var(--red)}
/* fullscreen landscape tuning mode */
body.tune-full .appbar,body.tune-full .bottomnav,body.tune-full #moreSheet{display:none!important}
body.tune-full #main{max-width:none;padding:8px 10px 10px}
body.tune-full .screen[data-screen="maptune"]>.card:not(#mtEditor){display:none}
body.tune-full #mtEditor{padding:10px 12px;border-radius:12px}
body.tune-full #mtEditor .card-h{margin-bottom:8px;font-size:14px}
body.tune-full #mtTableSel{margin-bottom:6px;padding:8px 10px;font-size:13px}
body.tune-full .mt-stat{margin-bottom:6px;font-size:11px}
body.tune-full .mt-selbar .sel-info small{display:none}
body.tune-full .mt-selbar{padding:6px 10px;margin-bottom:6px}
body.tune-full .mt-selbar .sel-info{flex-direction:row;align-items:center;gap:10px;margin-bottom:4px}
body.tune-full .mt-gridwrap{max-height:calc(100vh - 215px)}
body.tune-full .mt-3d{height:calc(100vh - 230px)}
body.tune-full .mt-tools2{margin-top:8px}
body.tune-full .mt-tools2 .btn{padding:9px 12px;font-size:13px}
body.tune-full #mtMsg{margin-top:6px}
/* maximised table: nothing but the grid + floating pills */
body.tune-max #mtEditor{padding:4px 6px;border:0;box-shadow:none;border-radius:0;background:transparent}
body.tune-max #main{padding:4px 4px 0}
body.tune-max #mtEditor .card-h,body.tune-max #mtTableSel,body.tune-max .mt-stat,body.tune-max .mt-tools2,body.tune-max #mtMsg,body.tune-max .mt-3dhint,body.tune-max .mt-legend{display:none!important}
body.tune-max .mt-selbar{display:none;position:fixed;left:8px;right:8px;top:6px;z-index:70;margin:0;box-shadow:0 12px 30px rgba(21,24,33,.25)}
body.tune-max.tools-open .mt-selbar{display:block}
body.tune-max .mt-gridwrap{max-height:calc(100vh - 12px);border-radius:8px}
body.tune-max .mt-3d{height:calc(100vh - 14px)}
.mt-float{position:fixed;right:10px;bottom:10px;z-index:80;display:flex;gap:8px}
.mt-float button{width:46px;height:46px;border-radius:50%;border:0;background:rgba(21,24,33,.88);color:#fff;font-size:18px;font-weight:800;cursor:pointer;box-shadow:0 8px 20px rgba(0,0,0,.3);font-family:inherit}
.mt-float button.exit{background:var(--red)}
.mt-float button.on{background:var(--red)}
/* general landscape: let the table use the width */
@media (orientation:landscape) and (max-height:520px){
  #main{max-width:none}
  .mt-gridwrap{max-height:62vh}
}

/* license */
.lic-card{border-color:#f3d0d2;background:linear-gradient(160deg,#fff,#fff6f6)}
.lic-badge{font-size:12px;font-weight:700;padding:4px 10px;border-radius:20px}
.lic-badge.lock{background:#fdecec;color:#b0060c}
.lic-badge.ok{background:#e7f7ec;color:#16a34a}
.lic-state{font-size:13px;line-height:1.5;color:#6b7280;margin-bottom:12px}
.lic-state.ok{color:#16a34a}
.mono{font-family:'Rajdhani',monospace;letter-spacing:1px}
#licInput{resize:vertical;font-family:'Rajdhani',monospace;font-size:12px}
.lockicon{font-size:13px}
.btn-buy{margin-top:10px;background:#1877f2;color:#fff;text-decoration:none;box-shadow:0 8px 20px rgba(24,119,242,.22)}
.btn-buy svg{vertical-align:middle}

/* popup */
.popup{position:fixed;inset:0;z-index:80;display:grid;place-items:center;padding:28px;background:rgba(21,24,33,.45)}
.popup-card{background:#fff;border-radius:22px;padding:28px 24px;text-align:center;max-width:340px;width:100%;animation:pop .2s ease}
@keyframes pop{from{transform:scale(.9);opacity:0}to{transform:scale(1);opacity:1}}
.popup-ic{width:64px;height:64px;border-radius:50%;background:#e7f7ec;color:var(--ok);display:grid;place-items:center;font-size:34px;margin:0 auto 14px}
.popup-ic.bad{background:#fdecec;color:var(--red)}
.popup-card b{font-size:20px;font-weight:800}
.popup-card p{color:var(--muted);font-size:14px;line-height:1.5;margin:8px 0 20px}
