:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --fg: #16181d;
  --muted: #6b7280;
  --line: #e4e7ec;
  --accent: #0a66d8;
  --accent-soft: #e6f0fc;
  --ok: #18864b;
  --ok-soft: #e3f5ea;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --bad: #c62828;
  --bad-soft: #fde7e7;
  --track: #e9ecf1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --panel: #171a20;
    --panel-2: #1c2027;
    --fg: #e8eaed;
    --muted: #9aa1ac;
    --line: #2a2f38;
    --accent: #4c9bff;
    --accent-soft: #16263d;
    --ok: #3ec27a;
    --ok-soft: #12291d;
    --warn: #f0a833;
    --warn-soft: #2e2311;
    --bad: #ff6b6b;
    --bad-soft: #321718;
    --track: #262b33;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; font-weight: 650; margin: 0; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 650; margin: 0; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.navsec { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--fg); font-weight: 500;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .me { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.side .me .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .me small { color: var(--muted); display: block; }
.main { padding: 24px 28px 64px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 2px; }
.menu-btn { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .main { padding: 16px 16px 64px; }
  .menu-btn { display: inline-flex; }
}

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap { height: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 32px; padding: 0; }
.btn svg { width: 16px; height: 16px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--fg); font: inherit; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.field > input, label.field > select { color: var(--fg); font-size: 14px; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

/* toggle */
.switch { position: relative; width: 36px; height: 20px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--track); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* bars */
.bar { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: inherit; transition: width .3s; }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }

/* pool visual */
.pool { display: flex; height: 34px; border-radius: 8px; overflow: hidden; gap: 2px; background: var(--line); }
.pool .seg { position: relative; background: var(--track); min-width: 4px; cursor: pointer; transition: flex-grow .3s; }
.pool .seg > i { position: absolute; inset: 0 auto 0 0; transition: width .3s; opacity: .9; }
.pool .seg > span { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 8px; font-size: 12px; font-weight: 600; color: var(--fg); white-space: nowrap; overflow: hidden; text-shadow: 0 0 3px var(--panel); }
.pool .seg:hover { filter: brightness(1.08); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* nodes */
.region { margin-top: 20px; }
.region-h { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.nodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; }
.node { padding: 14px 16px; display: grid; gap: 12px; border-top: 3px solid var(--nc, var(--accent)); }
.node.pending { border-style: dashed; border-top-style: solid; }
.node .top { display: flex; align-items: flex-start; gap: 10px; }
.node .name { font-weight: 650; font-size: 15px; }
.node .meta { color: var(--muted); font-size: 12px; display: grid; gap: 1px; }
.node .meta .mono { font-size: 11.5px; }
.node .kv { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.node .kv b { color: var(--fg); font-weight: 600; }
.cap { display: grid; gap: 6px; }
.cap .ctl { display: flex; align-items: center; gap: 8px; }
.cap input[type=range] { flex: 1; accent-color: var(--nc, var(--accent)); }
.cap input[type=number] { width: 84px; text-align: right; }
.node .actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
.node .actions .sp { flex: 1; }
.over { color: var(--bad); font-weight: 600; }

/* ---------- tables / files ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.sel td { background: var(--accent-soft); }
.table tbody tr:hover td { background: var(--panel-2); }
.table tr.sel:hover td { background: var(--accent-soft); }
.tablewrap { overflow-x: auto; }
.fname { display: flex; align-items: center; gap: 10px; min-width: 0; }
.fname svg { width: 20px; height: 20px; flex: none; }
.fname a, .fname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.fname a:hover { color: var(--accent); }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 15px; }
.crumbs a { padding: 2px 6px; border-radius: 6px; color: var(--fg); font-weight: 600; }
.crumbs a:hover { background: var(--panel-2); text-decoration: none; }
.crumbs .sep { color: var(--muted); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.drop { position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 3px dashed var(--accent); display: none; place-items: center; font-size: 18px; font-weight: 650; color: var(--accent); pointer-events: none; }
.drop.on { display: grid; }

/* uploads panel */
.uploads { position: fixed; right: 16px; bottom: 16px; width: 340px; max-width: calc(100vw - 32px); z-index: 35; max-height: 50vh; display: flex; flex-direction: column; }
.uploads .uh { padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.uploads .ul { overflow: auto; padding: 6px 14px 12px; display: grid; gap: 8px; }
.uploads .ui { display: grid; gap: 3px; font-size: 12.5px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: 520px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; }
.modal h2 { font-size: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.urls { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.url { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.url .mono { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* toasts */
#toasts { position: fixed; top: 16px; right: 16px; z-index: 60; display: grid; gap: 8px; }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--fg); color: var(--bg); box-shadow: 0 6px 20px rgba(0,0,0,.2); font-weight: 500; max-width: 360px; animation: tin .15s ease-out; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes tin { from { transform: translateY(-6px); opacity: 0; } }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 360px; max-width: 100%; padding: 28px; display: grid; gap: 14px; }
.login .brand { padding: 0 0 6px; justify-content: center; font-size: 20px; }

/* events */
.events { display: grid; }
.ev { display: grid; grid-template-columns: 120px 1fr; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.ev.warn { background: var(--warn-soft); }

.codeblock { position: relative; }
.codeblock pre { margin: 0; padding: 12px 14px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
.codeblock .btn { position: absolute; top: 6px; right: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.kvs { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kvs dt { color: var(--muted); }
.kvs dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-all; }
