:root{
  --bg:#0a1020; --bg2:#0f1830; --line:#22304f; --text:#e8edf8; --muted:#93a1c0;
  --accent:#7c4dff; --accent2:#6d3df0; --good:#34d399; --mid:#fbbf24; --bad:#f87171;
  --top:60px; --rail:60px; --gap:14px; --r:12px;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{background:radial-gradient(1200px 600px at 80% -10%,#16224a 0,transparent 60%),var(--bg);color:var(--text);
  font:14px/1.45 Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
body.has-max{overflow:hidden}
button{font:inherit;color:inherit;cursor:pointer}
a{color:#a78bfa}
:focus-visible{outline:2px solid #a78bfa;outline-offset:2px}

/* top bar */
.topbar{position:fixed;inset:0 0 auto 0;height:var(--top);z-index:40;display:flex;align-items:center;gap:20px;padding:0 18px;
  background:rgba(10,16,32,.92);backdrop-filter:blur(10px);border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:10px;color:var(--text);text-decoration:none;font-weight:700;letter-spacing:.06em;font-size:17px;white-space:nowrap}
.brand b{color:#a78bfa}
.topnav{display:flex;gap:4px;flex:1;min-width:0;overflow-x:auto;scrollbar-width:none}
.topnav button,.topnav a{background:none;border:0;color:var(--muted);padding:8px 12px;border-radius:8px;text-decoration:none;white-space:nowrap;font-weight:500}
.topnav button:hover,.topnav a:hover{background:#18233f;color:var(--text)}
.topnav .active{color:#fff;background:#1a2748}
.pill{background:#26365f;color:#cdd7ef;border-radius:99px;padding:1px 8px;font-size:11px;margin-left:4px}

/* buttons */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;border:1px solid var(--line);background:#16213d;color:var(--text);
  padding:8px 14px;border-radius:9px;text-decoration:none;font-weight:600;font-size:13px}
.btn:hover{background:#1d2b50}
.btn.primary{background:linear-gradient(135deg,#7c4dff,#6338e6);border-color:#7c4dff;color:#fff}
.btn.primary:hover{filter:brightness(1.1)}
.btn.ghost{background:transparent}
.open-all{white-space:nowrap}

/* rail */
.rail{position:fixed;top:var(--top);left:0;bottom:0;width:var(--rail);z-index:30;display:flex;flex-direction:column;align-items:center;gap:6px;padding:14px 0;
  background:#0c1428;border-right:1px solid var(--line)}
.rail button{width:40px;height:40px;border:0;border-radius:10px;background:none;display:grid;place-items:center;color:var(--muted)}
.rail button:hover{background:#18233f;color:#fff}
.rail button.active{background:#1f2c52;color:#c4b5fd}
.rail svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}

/* stage + grid */
.stage{padding:calc(var(--top) + var(--gap)) var(--gap) var(--gap) calc(var(--rail) + var(--gap));min-height:100%}
.workspace{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));grid-auto-flow:dense;gap:var(--gap);align-items:start}
.notice-bar{margin:0 0 var(--gap);padding:10px 14px;border-radius:10px;background:#3a2a0a;border:1px solid #6b4e10;color:#fcd34d}

/* panel */
.panel{grid-column:span var(--span,1);height:var(--h,520px);display:flex;flex-direction:column;min-width:0;
  background:#fff;color:#0f172a;border-radius:var(--r);overflow:hidden;border:1px solid var(--line);box-shadow:0 10px 30px rgba(0,0,0,.35)}
.panel.is-min{height:auto}
.panel.is-min .panel-body,.panel.is-min .panel-foot{display:none}
.panel-head{display:flex;align-items:center;gap:8px;padding:8px 8px 8px 10px;cursor:grab;user-select:none;flex:none;color:#fff;background:#1b2a4e}
.panel-head:active{cursor:grabbing}
.panel-title{margin:0;font-size:14px;font-weight:700;flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.panel-ctl{display:flex;gap:2px;flex:none}
.ctl{width:26px;height:26px;border:0;border-radius:7px;background:rgba(255,255,255,.14);color:inherit;font-size:13px;line-height:1;display:grid;place-items:center;padding:0}
.ctl:hover{background:rgba(255,255,255,.3)}
.badge{width:26px;height:26px;border-radius:8px;display:grid;place-items:center;font-size:11px;font-weight:800;flex:none;background:#fff;color:#111}
.panel-body{position:relative;flex:1;min-height:0;overflow:auto;background:#fff}
.panel-foot{flex:none;display:flex;gap:10px;justify-content:space-between;align-items:center;padding:6px 10px;font-size:11px;color:#475569;background:#f1f5f9;border-top:1px solid #e2e8f0}
.panel-foot a{white-space:nowrap;font-weight:600;color:#5b32d6}
.embed{display:block;width:100%;height:100%;border:0;background:#fff;position:relative;z-index:1}
.panel-body.direct{display:flex;flex-direction:column}
.panel-body.direct .embed{flex:1}
.spinner{position:absolute;top:50%;left:50%;width:28px;height:28px;margin:-14px;border:3px solid #e2e8f0;border-top-color:#7c4dff;border-radius:50%;animation:spin .8s linear infinite}
.panel.loaded .spinner{display:none}
@keyframes spin{to{transform:rotate(360deg)}}
body.dragging .embed{pointer-events:none}
.panel.drag-src{opacity:.45}
.panel.drop-target{outline:2px dashed #a78bfa;outline-offset:-3px}

/* maximize */
.panel.is-max{position:fixed;z-index:60;top:calc(var(--top) + 10px);left:calc(var(--rail) + 10px);right:10px;bottom:10px;height:auto;grid-column:auto}
.panel.is-max .panel-head{cursor:default}
body.has-max::after{content:"";position:fixed;inset:0;background:rgba(3,6,14,.7);z-index:55}

/* platform header themes (modelled on the reference screenshot) */
.theme-ig .panel-head{background:#fff;color:#262626;border-bottom:1px solid #eee}
.theme-ig .badge{background:linear-gradient(45deg,#f9ce34,#ee2a7b 55%,#6228d7);color:#fff}
.theme-ig .ctl{background:#f1f1f1}.theme-ig .ctl:hover{background:#e3e3e3}
.theme-fb .panel-head{background:#3b5998}
.theme-fb .badge{background:#fff;color:#3b5998;font-size:16px}
.theme-x .panel-head{background:#1d9bf0}
.theme-x .badge{background:#000;color:#fff;font-size:14px}
.theme-yt .panel-head{background:#fff;color:#0f0f0f;border-bottom:1px solid #eee}
.theme-yt .badge{background:#f00;color:#fff}
.theme-yt .ctl{background:#f1f1f1}.theme-yt .ctl:hover{background:#e3e3e3}
.theme-wa .panel-head{background:#25a244}
.theme-wa .badge{background:#fff;color:#25a244}
.theme-li .panel-head{background:#fff;color:#0a66c2;border-bottom:1px solid #eee}
.theme-li .badge{background:#0a66c2;color:#fff}
.theme-li .ctl{background:#eef3f8}.theme-li .ctl:hover{background:#dce6f1}
.theme-rd .panel-head{background:#ff4500}
.theme-rd .badge{background:#fff;color:#ff4500}
.theme-pi .panel-head{background:#fff;color:#bd081c;border-bottom:1px solid #eee}
.theme-pi .badge{background:#e60023;color:#fff}
.theme-pi .ctl{background:#f5f0f0}.theme-pi .ctl:hover{background:#eadede}
.theme-tt .panel-head{background:#111}
.theme-tt .badge{background:#fff;color:#111}

/* in-panel states */
.notice,.cfg{padding:20px 18px;display:flex;flex-direction:column;gap:10px;align-items:stretch}
.notice{align-items:center;text-align:center}
.notice-icon{font-size:30px}
.notice h3,.cfg h3{margin:0;font-size:16px}
.notice p{margin:0;color:#475569}
.tiny{font-size:12px;color:#64748b;margin:0}
.cfg label{display:flex;flex-direction:column;gap:6px;font-weight:600;font-size:13px}
.cfg input,.wa-form input{width:100%;padding:9px 11px;border:1px solid #cbd5e1;border-radius:8px;font:inherit;color:#0f172a;background:#fff}
.err{color:#b91c1c;min-height:1em}
.row{display:flex;flex-wrap:wrap;gap:8px}
.panel .btn{color:#0f172a;background:#eef2f8;border-color:#d5dcea}
.panel .btn.primary{color:#fff;background:linear-gradient(135deg,#7c4dff,#6338e6);border-color:#7c4dff}
.panel .btn.ghost{background:transparent}
.wa-form{display:flex;flex-direction:column;gap:8px;width:100%;text-align:left;padding:12px;border:1px solid #e2e8f0;border-radius:10px;background:#f8fafc}
.wa-form label{font-weight:600;font-size:12px;color:#334155}

.empty{margin:12vh auto;text-align:center;max-width:380px;color:var(--muted)}
.empty h2{color:var(--text)}

/* dialog */
dialog{border:1px solid var(--line);border-radius:14px;background:#0f1830;color:var(--text);padding:0;width:min(720px,calc(100vw - 24px));max-height:calc(100vh - 40px)}
dialog::backdrop{background:rgba(3,6,14,.75)}
.dlg-head{display:flex;justify-content:space-between;align-items:center;padding:14px 18px;border-bottom:1px solid var(--line)}
.dlg-head h2{margin:0;font-size:17px}
.dlg-body{padding:16px 18px 20px;overflow:auto;max-height:calc(100vh - 140px);display:flex;flex-direction:column;gap:14px}
.dlg-body .tiny,.dlg-body p{color:var(--muted)}
.picker-list{display:grid;gap:8px}
.pick{display:flex;align-items:center;gap:12px;padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:#131f3d;cursor:pointer}
.pick:hover{background:#18284d}
.pick input{width:18px;height:18px;accent-color:#7c4dff}
.pick-name{font-weight:600;flex:1}
.pick-status{font-size:12px;color:var(--muted)}
.theme-ig.pick .badge{background:linear-gradient(45deg,#f9ce34,#ee2a7b 55%,#6228d7);color:#fff}
.theme-fb.pick .badge{background:#3b5998;color:#fff}.theme-x.pick .badge{background:#000;color:#fff}
.theme-yt.pick .badge{background:#f00;color:#fff}.theme-wa.pick .badge{background:#25a244;color:#fff}
.theme-li.pick .badge{background:#0a66c2;color:#fff}.theme-rd.pick .badge{background:#ff4500;color:#fff}
.theme-pi.pick .badge{background:#e60023;color:#fff}.theme-tt.pick .badge{background:#fff;color:#000}
.table-scroll{overflow:auto;border:1px solid var(--line);border-radius:10px}
table{border-collapse:collapse;width:100%;min-width:560px}
th,td{text-align:left;padding:9px 12px;border-bottom:1px solid var(--line);vertical-align:top;font-size:13px}
th{background:#131f3d;color:var(--muted);font-weight:600}
tr:last-child td{border-bottom:0}
.tag{display:inline-block;padding:2px 9px;border-radius:99px;font-size:12px;font-weight:600;white-space:nowrap}
.tag.good{background:#0d3b2c;color:var(--good)}.tag.mid{background:#44350c;color:var(--mid)}.tag.bad{background:#46181b;color:var(--bad)}
.links{display:flex;flex-wrap:wrap;gap:8px}
.popup-help ol{margin:0 0 12px;padding-left:20px;color:var(--text)}
.popup-help li{margin:6px 0}

/* tablet / mobile */
@media (max-width:900px){
  .topbar{gap:10px;padding:0 10px}
  .topnav a{display:none}
  .brand span{font-size:15px}
}
@media (max-width:700px){
  :root{--rail:0px;--gap:10px;--top:56px}
  .topnav{display:none}
  .topbar{justify-content:space-between}
  .open-all{padding:8px 11px;font-size:12px}
  .rail{top:auto;left:0;right:0;bottom:0;width:auto;height:56px;flex-direction:row;justify-content:space-around;padding:0;border-right:0;border-top:1px solid var(--line)}
  .stage{padding:calc(var(--top) + var(--gap)) var(--gap) 70px}
  .workspace{grid-template-columns:1fr}
  .panel{grid-column:auto;height:min(var(--h,520px),78vh)}
  .panel.is-min{height:auto}
  .panel.is-max{left:6px;right:6px;top:calc(var(--top) + 6px);bottom:62px}
  .panel-head{cursor:default}
  .panel-ctl .ctl{width:30px;height:30px}
  .panel-ctl [data-act=size]{display:none}
}
@media (prefers-reduced-motion:reduce){.spinner{animation-duration:2s}}
