:root{
  --red:#da291c; --red-d:#b71f14; --ink:#14181d; --slate:#2b333e; --grey:#5b6470; --mute:#8b939e;
  --line:#e2e6eb; --bg:#f3f5f8; --card:#fff; --ok:#1e9e5a; --warn:#c98a00; --down:#d0442f; --unknown:#9aa3af; --blue:#1f6fc4; --teal:#0f8b8d;
  --shadow:0 1px 2px rgba(20,25,35,.06),0 8px 24px rgba(20,25,35,.07);
  --tabs-h:58px; --top-h:56px;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{font-family:"Hiragino Sans","Hiragino Kaku Gothic ProN","Meiryo",system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--ink);-webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent;overscroll-behavior-y:none}
[hidden]{display:none!important}
.muted{color:var(--mute)}.err{color:var(--red)}
button{font-family:inherit}

/* ---- login ---- */
.gate{position:fixed;inset:0;display:grid;place-items:center;background:radial-gradient(120% 80% at 50% 0%,#2a323c,#0f1216);padding:20px}
.gate-card{background:var(--card);border-radius:18px;padding:32px 28px;width:min(360px,92vw);text-align:center;box-shadow:var(--shadow)}
.gate-card h1{font-size:19px;margin:.5em 0 .1em}
.gate-card input{width:100%;padding:13px 14px;border:1px solid var(--line);border-radius:12px;font-size:16px;margin:14px 0}
.gate-card button{width:100%;padding:13px;border:0;border-radius:12px;background:var(--red);color:#fff;font-size:16px;font-weight:700;cursor:pointer}

/* ---- top bar ---- */
.topbar{position:sticky;top:0;z-index:20;height:var(--top-h);display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 14px;background:var(--ink);color:#fff;padding-top:env(safe-area-inset-top)}
.brand{display:flex;align-items:center;gap:10px;min-width:0}
.brand-title{font-size:15.5px;font-weight:800;line-height:1.15;white-space:nowrap}
.brand-sub{font-size:11px;color:#b9c0c9;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-actions{display:flex;align-items:center;gap:12px;flex-shrink:0}
.updated{text-align:right;line-height:1.15}
.updated-label{display:block;font-size:9.5px;color:#9aa3af}
.updated-val{font-size:12px;color:#e7eaee;font-variant-numeric:tabular-nums}
.btn-refresh{display:inline-flex;align-items:center;gap:6px;background:var(--red);color:#fff;border:0;border-radius:11px;padding:9px 14px;font-size:14px;font-weight:700;cursor:pointer}
.btn-refresh:active{background:var(--red-d)}
.btn-refresh:disabled{opacity:.7;cursor:default}
.btn-refresh.spinning .ref-ico{animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* ---- refresh progress ---- */
.refresh-bar{background:#fff7e6;border-bottom:1px solid #f0dfb0;color:#7a5800;padding:9px 14px;font-size:13px}
.refresh-head{display:flex;align-items:center;gap:9px}
.spinner{width:14px;height:14px;border:2px solid #e3c778;border-top-color:transparent;border-radius:50%;animation:spin .8s linear infinite;flex-shrink:0}
.chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:7px}
.chip{display:inline-flex;align-items:center;gap:5px;background:#fff;border:1px solid #eadfbf;border-radius:20px;padding:2px 9px;font-size:11.5px;color:var(--grey)}
.chip i{width:8px;height:8px;border-radius:50%;background:var(--unknown);display:inline-block}
.chip.ok i{background:var(--ok)}.chip.running i{background:var(--warn);animation:pulse 1s infinite}.chip.down i,.chip.auth i{background:var(--down)}
@keyframes pulse{50%{opacity:.3}}

/* ---- layout ---- */
.content{max-width:1280px;margin:0 auto;padding:12px 12px calc(var(--tabs-h) + 24px + env(safe-area-inset-bottom))}
.panel{display:none}.panel.active{display:block}
.dia-head{display:flex;align-items:flex-end;justify-content:space-between;gap:10px;margin:4px 2px 10px}
.dia-head h2{font-size:17px;margin:0}
.lead{margin:2px 0 0;font-size:12px;color:var(--mute)}
.dia-tools{display:flex;gap:4px;flex-shrink:0}
.dia-tools button{border:1px solid var(--line);background:#fff;border-radius:9px;min-width:36px;height:32px;padding:0 10px;font-size:14px;font-weight:700;color:var(--slate);cursor:pointer}
.dia{position:relative;background:#fff;border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow);height:calc(100vh - var(--top-h) - var(--tabs-h) - 128px);min-height:420px;overflow:hidden;touch-action:none;user-select:none}
.dia svg{width:100%;height:100%;display:block;cursor:grab}
.dia svg.dragging{cursor:grabbing}
.hint{font-size:11.5px;color:var(--mute);margin:8px 4px 0}

/* diagram elements */
.nd{cursor:pointer}
.nd .box{fill:#fff;stroke:#cfd5dc;stroke-width:1.3}
.nd.sel .box{stroke:var(--red);stroke-width:2.4}
.nd.dim{opacity:.32}
.ed{fill:none;stroke:#b8c0ca;stroke-width:2;stroke-linejoin:round;stroke-linecap:round}
.ed.dim{opacity:.18}
.ed-lbl{font-size:10.5px;fill:#5b6470;paint-order:stroke;stroke:#fff;stroke-width:3.5px;stroke-linejoin:round}
.grp{fill:rgba(31,111,196,.05);stroke:rgba(31,111,196,.35);stroke-width:1.2;stroke-dasharray:6 4;rx:14}
.grp-lbl{font-size:12px;font-weight:800;fill:var(--blue)}
.ov{fill:none;stroke-width:2.4;stroke-dasharray:7 5;stroke-linecap:round;stroke-linejoin:round}
.ov-lbl{font-size:11px;font-weight:700;paint-order:stroke;stroke:#fff;stroke-width:4px;stroke-linejoin:round}
text{font-family:inherit}

/* ---- cards ---- */
.cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:11px}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;box-shadow:var(--shadow);padding:13px 14px 12px 17px;position:relative;overflow:hidden}
.card .bar{position:absolute;left:0;top:0;bottom:0;width:5px}
.card .role{font-size:10.5px;color:var(--mute);font-weight:700;letter-spacing:.02em}
.card h4{margin:1px 0 0;font-size:15px;display:flex;align-items:center;gap:7px;flex-wrap:wrap}
.card .ver{font-size:11.5px;color:var(--grey);margin-top:2px}
.card .kv{font-size:12.5px;color:var(--grey);margin-top:9px;line-height:1.5;display:grid;grid-template-columns:auto 1fr;gap:1px 10px}
.card .kv b{color:var(--ink);font-weight:600;word-break:break-word}
.card .kv span{white-space:nowrap;color:var(--mute)}
.badge{display:inline-block;font-size:10.5px;font-weight:800;color:#fff;border-radius:20px;padding:2px 8px;line-height:1.4}
.b-ok{background:var(--ok)}.b-pending,.b-auth{background:var(--warn)}.b-down{background:var(--down)}.b-unknown{background:var(--unknown)}
.card .hl{margin-top:8px;font-size:11.5px;color:#8a5a00;background:#fff6e0;border-radius:8px;padding:6px 8px}
.card.seg .swatch{position:absolute;left:0;top:0;bottom:0;width:5px}
.sub{font-size:14px;color:var(--slate);margin:22px 4px 10px;border-left:4px solid var(--red);padding-left:9px}
.health{background:#fff6e0;border:1px solid #f1dfae;border-radius:12px;padding:10px 14px;margin-bottom:12px;font-size:12.5px;color:#7a5800}
.health div{padding:2px 0}

/* ---- detail ---- */
.det{background:var(--card);border:1px solid var(--line);border-radius:12px;box-shadow:var(--shadow);margin-bottom:10px}
.det summary{cursor:pointer;padding:12px 14px;font-weight:700;font-size:14px;display:flex;align-items:center;gap:9px;list-style:none}
.det summary::-webkit-details-marker{display:none}
.det summary .dot{width:10px;height:10px;border-radius:50%;flex-shrink:0}
.det .cmd{margin:0 14px 6px;font-size:11px;color:var(--blue);font-weight:700;font-family:ui-monospace,Consolas,monospace}
.det pre{margin:0 14px 14px;padding:10px;background:#f7f9fb;border-radius:8px;font-size:11px;color:#37414c;white-space:pre-wrap;word-break:break-word;font-family:ui-monospace,Consolas,monospace;max-height:340px;overflow:auto}
.det .empty{color:var(--mute);padding:0 14px 14px;font-size:12.5px}

/* ---- tabs (bottom on mobile) ---- */
.tabs{position:fixed;left:0;right:0;bottom:0;z-index:20;height:calc(var(--tabs-h) + env(safe-area-inset-bottom));padding-bottom:env(safe-area-inset-bottom);display:flex;background:#fff;border-top:1px solid var(--line)}
.tabs button{flex:1;border:0;background:none;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:11px;font-weight:700;color:var(--mute);cursor:pointer}
.tabs button .t-ico{font-size:18px;line-height:1}
.tabs button.active{color:var(--red)}

/* ---- bottom sheet ---- */
.sheet{position:fixed;inset:0;z-index:30}
.sheet-backdrop{position:absolute;inset:0;background:rgba(10,14,20,.45)}
.sheet-card{position:absolute;left:0;right:0;bottom:0;background:#fff;border-radius:18px 18px 0 0;max-height:78vh;display:flex;flex-direction:column;box-shadow:0 -10px 40px rgba(0,0,0,.25);padding-bottom:env(safe-area-inset-bottom);animation:up .22s ease-out}
@keyframes up{from{transform:translateY(30px);opacity:.6}to{transform:none;opacity:1}}
.sheet-grip{width:40px;height:4px;border-radius:2px;background:#d5dae0;margin:8px auto 2px}
.sheet-head{display:flex;align-items:center;justify-content:space-between;padding:6px 16px 4px}
.sheet-head h3{margin:0;font-size:17px}
.sheet-head .role{font-size:11px;color:var(--mute);font-weight:700}
.sheet-close{border:0;background:#f0f2f5;width:32px;height:32px;border-radius:50%;font-size:18px;cursor:pointer;color:var(--grey)}
.sheet-body{overflow:auto;padding:4px 16px 18px;font-size:13px}
.sheet-body .kv{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;margin-top:8px}
.sheet-body .kv span{color:var(--mute);white-space:nowrap}
.sheet-body .kv b{font-weight:600;word-break:break-word}
.sheet-body h5{margin:14px 0 4px;font-size:12px;color:var(--blue)}
.sheet-body .rel{display:flex;align-items:center;gap:8px;padding:5px 0;border-bottom:1px solid var(--line);font-size:12.5px}
.sheet-body .rel i{width:22px;height:0;border-top:2.5px dashed var(--blue);display:inline-block}
.sheet-body .hl{margin-top:8px;font-size:12px;color:#8a5a00;background:#fff6e0;border-radius:8px;padding:6px 9px}
.foot{max-width:1280px;margin:0 auto;padding:0 16px 10px;display:flex;justify-content:space-between;align-items:center;color:var(--mute);font-size:11.5px}
.linkbtn{background:none;border:0;color:var(--grey);cursor:pointer;font-size:11.5px;text-decoration:underline}

/* ---- desktop ---- */
@media (min-width:900px){
  :root{--tabs-h:0px}
  .tabs{position:sticky;top:var(--top-h);bottom:auto;height:46px;padding:0 10px;justify-content:flex-start;border-top:0;border-bottom:1px solid var(--line)}
  .tabs button{flex:0 0 auto;flex-direction:row;gap:7px;padding:0 16px;font-size:13.5px;border-bottom:3px solid transparent}
  .tabs button .t-ico{font-size:15px}
  .tabs button.active{border-bottom-color:var(--red)}
  .content{padding:16px 18px 30px}
  .dia{height:calc(100vh - var(--top-h) - 46px - 150px);min-height:520px}
  .sheet-card{left:auto;right:16px;bottom:16px;width:420px;max-height:80vh;border-radius:18px}
  .sheet-grip{display:none}
}
@media (max-width:560px){
  .brand-sub{display:none}
  .updated{display:none}
  .ref-txt{display:none}
  .btn-refresh{padding:9px 11px}
  .dia-head{align-items:center}
  .lead{display:none}
}
