:root {
  --bg: #0f141a;
  --panel: #171e26;
  --panel2: #1d2630;
  --border: #2a3542;
  --text: #dce5ee;
  --muted: #8fa1b3;
  --accent: #4da3ff;
  --accent2: #2f7fd4;
  --error: #ff6b6b;
  --ok: #51cf80;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 13px; cursor: pointer; font: inherit;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent2); border-color: var(--accent2); font-weight: 600; }
button.primary:hover { background: var(--accent); }
input[type=text], input[type=password], input[type=search] {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font: inherit; width: 100%;
}
input:focus { outline: none; border-color: var(--accent); }
.hidden { display: none !important; }
.spacer { flex: 1; }
.error { color: var(--error); margin-top: 12px; white-space: pre-wrap; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---- connect / loading ---- */
.screen { height: 100%; }
#connect-screen, #domain-screen, #loading-screen {
  display: flex; align-items: center; justify-content: center;
  position: fixed; inset: 0; overflow: auto;
}
.connect-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 30px 34px; width: 430px; max-width: 94vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.connect-card h1 { margin: 0 0 6px; font-size: 22px; }
.connect-card .sub { color: var(--muted); margin: 0 0 20px; }
.connect-card label { display: block; margin: 12px 0 0; font-weight: 600; font-size: 13px; }
.connect-card label input { margin-top: 5px; font-weight: 400; }
.connect-card label.check { font-weight: 400; color: var(--muted); }
.connect-card label.check input { width: auto; margin-right: 6px; }
.connect-card .row { display: flex; gap: 10px; margin-top: 20px; }
.fineprint { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.pick-list { max-height: 50vh; overflow: auto; margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; }
.pick-list button {
  display: block; width: 100%; text-align: left; border: none;
  border-bottom: 1px solid var(--border); border-radius: 0; background: none;
}
.pick-list button:hover { background: var(--panel2); }
.progress-outer { height: 8px; background: var(--bg); border-radius: 4px; margin: 16px 0 10px; overflow: hidden; }
.progress-inner { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.load-log { color: var(--muted); font-size: 12px; max-height: 40vh; overflow: auto; white-space: pre-wrap; margin: 0; }

/* ---- main layout ---- */
#main-screen { display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 8px 14px; flex: none;
}
.brand { font-weight: 700; white-space: nowrap; }
.hdr-domain { color: var(--accent); font-weight: 600; }
.hdr-stats { color: var(--muted); font-size: 12px; }
#search { width: 300px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  min-width: 280px; padding: 6px; box-shadow: 0 8px 26px rgba(0,0,0,.5);
}
.menu button { display: block; width: 100%; text-align: left; border: none; background: none; }
.menu button:hover { background: var(--panel); }
.menu hr { border: none; border-top: 1px solid var(--border); margin: 5px 0; }

#workspace { flex: 1; display: flex; min-height: 0; }

/* ---- sidebar ---- */
#sidebar {
  width: 320px; flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
}
#side-tabs { display: flex; flex: none; }
#side-tabs button {
  flex: 1; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  background: none; color: var(--muted); padding: 9px 0; font-size: 13px;
}
#side-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
#side-list { flex: 1; overflow: auto; padding: 4px 0; }
.group-head {
  padding: 7px 14px 3px; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; position: sticky; top: 0;
  background: var(--panel); cursor: pointer; user-select: none;
}
.side-item {
  padding: 6px 14px; cursor: pointer; display: flex; gap: 8px; align-items: baseline;
  border-left: 3px solid transparent;
}
.side-item:hover { background: var(--panel2); }
.side-item.selected { background: var(--panel2); border-left-color: var(--accent); }
.side-item .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.side-item .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .badge {
  margin-left: auto; font-size: 10px; padding: 1px 7px; border-radius: 9px;
  border: 1px solid var(--border); color: var(--muted); flex: none;
}
.side-empty { color: var(--muted); padding: 18px 14px; }

/* ---- canvas ---- */
#canvas-wrap { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
#canvas-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px;
  border-bottom: 1px solid var(--border); background: var(--panel); flex: none;
}
#canvas-toolbar button { padding: 4px 10px; }
#view-title { font-weight: 600; }
#canvas { flex: 1; overflow: hidden; cursor: grab; }
#canvas:active { cursor: grabbing; }
#canvas svg { display: block; width: 100%; height: 100%; }
#legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend-chip { width: 12px; height: 12px; border-radius: 3px; }
#empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-align: center; pointer-events: none; font-size: 15px;
}

/* ---- detail panel ---- */
#detail {
  width: 360px; flex: none; background: var(--panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
#detail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 700;
}
#detail-head button { border: none; background: none; padding: 2px 6px; }
#detail-body { overflow: auto; padding: 12px 14px; flex: 1; }
#detail-body h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
#detail-body table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#detail-body td { padding: 3px 6px 3px 0; vertical-align: top; }
#detail-body td:first-child { color: var(--muted); white-space: nowrap; }
#detail-body pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; font-size: 11px; overflow: auto; max-height: 300px;
}
.detail-link { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 18px; z-index: 100; box-shadow: 0 8px 26px rgba(0,0,0,.5);
}
