:root {
  --bg: #07090a;
  --bg-2: #0c0f10;
  --panel: #0f1314;
  --panel-2: #131819;
  --line: #1c2122;
  --line-2: #2a3132;
  --ink: #e6efe9;
  --mute: #7a8482;
  --dim: #4a5452;
  --accent: #00ff9c;
  --accent-2: #2effb1;
  --accent-dim: #0e3a28;
  --warn: #ffb84d;
  --red: #ff5c5c;
  --serif: 'Instrument Serif', ui-serif, Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --sans: 'Inter', system-ui, sans-serif;

  --d-pad: 22px;
  --d-gap: 18px;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
::selection { background: var(--accent); color: #000; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 48px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
  background: var(--bg);
}
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px;
  background: rgba(7,9,10,0.7); backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.topbar .crumb { color: var(--mute); }
.topbar .crumb b { color: var(--ink); font-weight: 500; }
.topbar .crumb .sep { margin: 0 8px; color: var(--dim); }
.topbar .spacer { flex: 1; }
.topbar .pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px; border: 1px solid var(--line-2); border-radius: 2px;
  color: var(--mute); font-size: 11.5px;
}
.topbar .pill b { color: var(--accent); font-weight: 500; }
.topbar .live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }
.topbar .icon-btn {
  width: 30px; height: 30px; border: 1px solid var(--line-2); border-radius: 2px;
  display: flex; align-items: center; justify-content: center; color: var(--mute);
}
.topbar .icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.topbar .user {
  display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink);
  padding-left: 14px; border-left: 1px solid var(--line);
}
.topbar .user .av {
  width: 24px; height: 24px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #006b40); color: #00130a;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11px;
}

.sidebar {
  grid-area: sidebar;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 14px 12px;
  font-family: var(--mono); font-size: 12.5px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 14px; margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.sidebar .brand .mark { width: 18px; height: 18px; position: relative; }
.sidebar .brand .mark::before { content:''; position: absolute; inset: 0; border: 1.5px solid var(--accent); }
.sidebar .brand .mark::after { content:''; position: absolute; inset: 0; border: 1.5px solid var(--ink); opacity: 0.4; transform: rotate(45deg); }
.sidebar .brand b { font-weight: 700; }
.sidebar .brand .v { margin-left: auto; color: var(--dim); font-size: 10.5px; }

.sidebar .group { color: var(--dim); font-size: 10px; letter-spacing: 0.12em; margin: 14px 8px 6px; }
.sidebar .navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 2px; color: var(--mute); cursor: pointer;
  position: relative;
}
.sidebar .navitem .ico { width: 14px; height: 14px; opacity: 0.8; }
.sidebar .navitem:hover { color: var(--ink); }
.sidebar .navitem.active { color: var(--accent); background: rgba(0,255,156,0.06); }
.sidebar .navitem.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px; background: var(--accent);
}
.sidebar .navitem .badge { margin-left: auto; font-size: 10.5px; color: var(--accent); }

.sidebar .footer {
  margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--line);
  color: var(--dim); font-size: 11px; line-height: 1.5;
}
.sidebar .footer .row { display: flex; align-items: center; gap: 8px; }
.sidebar .footer .dot { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; box-shadow: 0 0 6px var(--accent); }

.main {
  grid-area: main;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--d-pad) 32px 64px;
}
.main::-webkit-scrollbar { width: 10px; }
.main::-webkit-scrollbar-track { background: var(--bg-2); }
.main::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 0; }
.main::-webkit-scrollbar-thumb:hover { background: #3a4243; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 24px; padding-bottom: 18px; border-bottom: 1px solid var(--line);
  gap: 16px;
}
.page-head h1 { margin: 0; font-weight: 300; font-size: 32px; letter-spacing: -0.02em; }
.page-head h1 em { font-family: var(--serif); font-style: italic; color: var(--accent); font-weight: 400; }
.page-head p { margin: 6px 0 0; color: var(--mute); font-size: 13.5px; font-family: var(--mono); }
.page-head .actions { display: flex; gap: 10px; flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 12px; font-weight: 500;
  padding: 8px 12px; border-radius: 2px; cursor: pointer;
  border: 1px solid var(--line-2); background: transparent; color: var(--ink);
  transition: all 0.12s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #00130a; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); color: #00130a; }
.btn.danger { color: var(--red); border-color: #3a1a1a; }
.btn.danger:hover { background: rgba(255,92,92,0.08); border-color: var(--red); color: var(--red); }
.btn.ghost { border-color: transparent; color: var(--mute); }
.btn.ghost:hover { color: var(--accent); border-color: var(--line-2); }
.btn.sm { padding: 4px 8px; font-size: 11px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px; color: var(--mute); letter-spacing: 0.06em;
}
.card-head b { color: var(--ink); font-weight: 500; }
.card-head .tag {
  margin-left: auto; padding: 2px 8px; border: 1px solid var(--line-2); border-radius: 2px;
  font-size: 10.5px; color: var(--accent);
}

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--d-gap);
  margin-bottom: var(--d-gap);
}
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  padding: var(--d-pad);
  position: relative; overflow: hidden;
}
.stat .lbl {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em;
  color: var(--mute); text-transform: uppercase;
}
.stat .val {
  font-family: var(--mono); font-weight: 400;
  font-size: 30px; margin-top: 8px; letter-spacing: -0.01em;
  color: var(--ink);
}
.stat .val .accent { color: var(--accent); }
.stat .val .unit { font-size: 14px; color: var(--mute); margin-left: 4px; }
.stat .delta { margin-top: 6px; font-family: var(--mono); font-size: 11px; color: var(--accent); }
.stat .delta.down { color: var(--red); }
.stat .spark { position: absolute; right: 10px; bottom: 10px; opacity: 0.7; }

.grid-2 { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: var(--d-gap); margin-bottom: var(--d-gap); }
.grid-2-wide { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--d-gap); margin-bottom: var(--d-gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--d-gap); margin-bottom: var(--d-gap); }

.table { width: 100%; }
.th, .tr {
  display: grid; align-items: center;
  padding: 10px 16px;
  font-family: var(--mono); font-size: 12px;
}
.th {
  color: var(--mute); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.tr { border-bottom: 1px solid var(--line); transition: background 0.1s; }
.tr:hover { background: rgba(0,255,156,0.025); }
.tr:last-child { border-bottom: 0; }

.nodecell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nodecell .ic {
  width: 26px; height: 26px; border: 1px solid var(--line-2); border-radius: 2px;
  display: flex; align-items: center; justify-content: center; color: var(--mute); flex: 0 0 26px;
  background: var(--bg-2);
}
.nodecell .info { display: flex; flex-direction: column; min-width: 0; }
.nodecell .info .name { color: var(--ink); font-weight: 500; }
.nodecell .info .sub { color: var(--mute); font-size: 10.5px; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 2px;
  border: 1px solid var(--line-2); font-size: 10.5px; color: var(--mute);
  font-family: var(--mono);
}
.pill.live  { color: var(--accent); border-color: var(--accent-dim); background: rgba(0,255,156,0.05); }
.pill.warn  { color: var(--warn); border-color: #5b3d10; background: rgba(255,184,77,0.05); }
.pill.red   { color: var(--red); border-color: #3a1a1a; background: rgba(255,92,92,0.05); }
.pill.tag   { color: var(--mute); }

.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width 0.3s ease; }
.bar > i.warn { background: var(--warn); }
.bar > i.off  { background: var(--dim); }

.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11.5px;
}
.input {
  flex: 1; min-width: 0;
  background: var(--bg); border: 1px solid var(--line-2); color: var(--ink);
  padding: 6px 10px; font-family: var(--mono); font-size: 12px; border-radius: 2px;
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: var(--dim); }
.filter {
  padding: 5px 10px; border: 1px solid var(--line-2); border-radius: 2px;
  color: var(--mute); cursor: pointer; font-size: 11px;
  font-family: var(--mono);
}
.filter:hover { color: var(--ink); }
.filter.active { color: var(--accent); border-color: var(--accent-dim); background: rgba(0,255,156,0.04); }

.chart-wrap {
  height: 240px; padding: 16px;
  position: relative;
}
.chart-grid {
  position: absolute; inset: 16px;
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 12.5% 25%;
}
.chart-svg { width: 100%; height: 100%; position: relative; z-index: 1; overflow: visible; }

.log {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.7;
  padding: 8px 0;
  height: 320px; overflow-y: auto;
}
.log-row {
  padding: 2px 16px;
  display: grid; grid-template-columns: 80px 60px 80px 1fr auto auto; gap: 10px;
  align-items: center;
  border-left: 2px solid transparent;
}
.log-row:hover { background: rgba(255,255,255,0.02); }
.log-row.ok { border-left-color: var(--accent); }
.log-row.warn { border-left-color: var(--warn); }
.log-row.red { border-left-color: var(--red); }
.log-row .t { color: var(--dim); }
.log-row .m { color: var(--accent); }
.log-row .m.warn { color: var(--warn); }
.log-row .m.red { color: var(--red); }
.log-row .node { color: var(--mute); }
.log-row .url { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-row .lat { color: var(--mute); }
.log-row .ag { color: var(--mute); }

.map-wrap { padding: 8px; height: 280px; position: relative; }
.map-svg { width: 100%; height: 100%; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal {
  width: 560px; max-width: 92vw; max-height: 86vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px;
}
.modal-head b { color: var(--ink); }
.modal-head .x { margin-left: auto; color: var(--mute); cursor: pointer; }
.modal-head .x:hover { color: var(--red); }
.modal-body { padding: 22px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-family: var(--mono); font-size: 11px; color: var(--mute); letter-spacing: 0.08em; text-transform: uppercase; }
.field input, .field select, .field textarea {
  background: var(--bg); border: 1px solid var(--line-2); color: var(--ink);
  padding: 9px 12px; font-family: var(--mono); font-size: 12.5px; border-radius: 2px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.tag-options { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-opt {
  padding: 5px 10px; border: 1px solid var(--line-2); border-radius: 2px;
  font-family: var(--mono); font-size: 11px; color: var(--mute); cursor: pointer;
}
.tag-opt:hover { color: var(--ink); }
.tag-opt.on { color: var(--accent); border-color: var(--accent-dim); background: rgba(0,255,156,0.05); }

.install-block {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 2px;
  padding: 14px 16px; font-family: var(--mono); font-size: 12px; color: var(--ink);
  line-height: 1.6;
  position: relative;
}
.install-block .copy { position: absolute; top: 8px; right: 10px; color: var(--mute); cursor: pointer; font-size: 11px; }
.install-block .copy:hover { color: var(--accent); }
.install-block .c { color: var(--mute); }
.install-block .a { color: var(--accent); }

.policy-card {
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--panel);
}
.policy-row {
  display: grid; grid-template-columns: 30px 1fr auto auto; gap: 14px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 12px;
}
.policy-row:last-child { border-bottom: none; }
.policy-row .order {
  width: 22px; height: 22px; border: 1px solid var(--line-2); border-radius: 2px;
  display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--mute);
}
.policy-row .pat { color: var(--accent); }
.policy-row .arrow { color: var(--mute); margin: 0 4px; }
.policy-row .target { color: var(--ink); }
.policy-row .strat { color: var(--mute); font-size: 10.5px; }
.switch {
  width: 32px; height: 18px; border-radius: 2px; background: var(--line); position: relative;
  cursor: pointer; transition: background 0.15s;
}
.switch.on { background: var(--accent); }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  background: var(--bg); transition: transform 0.15s; border-radius: 1px;
}
.switch.on::after { transform: translateX(14px); background: #00130a; }

.key-row .secret {
  color: var(--accent); background: var(--bg); padding: 4px 8px; border: 1px solid var(--line-2);
  border-radius: 2px; font-size: 11.5px;
  user-select: all;
}

.empty {
  padding: 40px 20px; text-align: center; color: var(--mute);
  font-family: var(--mono); font-size: 12px;
}
.empty b { color: var(--ink); }

.legend { display: flex; gap: 16px; font-family: var(--mono); font-size: 11px; color: var(--mute); }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 91;
  display: flex; flex-direction: column;
  box-shadow: -30px 0 60px rgba(0,0,0,0.5);
  animation: drawerIn 0.2s ease-out;
}
@keyframes drawerIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 18px 22px; border-bottom: 1px solid var(--line); }
.drawer-head .row { display: flex; align-items: center; gap: 14px; }
.drawer-head h3 { margin: 0; font-size: 20px; font-weight: 500; }
.drawer-head .x { margin-left: auto; color: var(--mute); cursor: pointer; }
.drawer-head .x:hover { color: var(--red); }
.drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; font-family: var(--mono); font-size: 12px; margin-bottom: 18px; }
.kv .k { color: var(--mute); }
.kv .v { color: var(--ink); }
.drawer-section-title { font-family: var(--mono); font-size: 10.5px; color: var(--mute); letter-spacing: 0.1em; text-transform: uppercase; margin: 24px 0 10px; }

.mini { height: 80px; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-2-wide { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 60px 1fr; }
  .sidebar .label, .sidebar .group, .sidebar .footer, .sidebar .brand .v, .sidebar .brand .name { display: none; }
}

.fade-in { animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
