:root {
  --bg: #f6f5f1; --panel: #ffffff; --panel-2: #f0eee8; --ink: #17161a; --muted: #6e6b73; --line: #e4e1da;
  --accent: #1f5f4a; --accent-ink: #ffffff; --accent-soft: #e2efe9; --warn: #a15c00; --warn-soft: #fbf0df;
  --bad: #a3271e; --bad-soft: #fbe6e3; --info: #2a4f8f; --info-soft: #e5ecf8;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,20,30,.05), 0 4px 16px rgba(20,20,30,.05);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113; --panel: #18181b; --panel-2: #202024; --ink: #ecebe8; --muted: #9b98a0; --line: #2b2a30;
    --accent: #5fbf9a; --accent-ink: #0c1512; --accent-soft: #1a2c25; --warn: #e3a64c; --warn-soft: #2d2415;
    --bad: #ef7d73; --bad-soft: #321b19; --info: #8db1ef; --info-soft: #1b2436; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.err { color: var(--bad); min-height: 1em; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; background: var(--panel); }
.brand { font-weight: 700; font-size: 15px; display: flex; gap: 8px; align-items: center; padding: 0 8px; }
.brand.big { font-size: 20px; padding: 0; }
.mark { color: var(--accent); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: var(--ink); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
nav a:hover { background: var(--panel-2); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; padding: 0 8px; }
.view { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stat .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* forms */
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; font-size: 13px; }
label.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: wait; }
.link { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font: inherit; }
.link:hover { color: var(--ink); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* pills */
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }

/* results */
.result { display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: none; }
.score { font-weight: 700; font-size: 18px; text-align: center; border-radius: 8px; background: var(--panel-2); padding: 6px 0; align-self: start; }
.score small { display: block; font-size: 10px; color: var(--muted); font-weight: 500; }
.via { font-size: 12px; color: var(--muted); }
.via b { color: var(--ink); font-weight: 600; }
.reason { font-size: 13px; margin-top: 4px; }

.facts { display: flex; flex-direction: column; gap: 14px; }
.fact { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.fact:last-child { border-bottom: none; }
.fact .lbl { font-weight: 600; min-width: 110px; }
.fact .x { margin-left: auto; opacity: .4; }
.fact:hover .x { opacity: 1; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--info-soft); color: var(--info); font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
pre.msg { white-space: pre-wrap; font: 13px/1.5 Inter, sans-serif; background: var(--panel-2); padding: 12px; border-radius: 8px; margin: 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }

/* toast + modal */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500; z-index: 50; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 22px; width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; border: 1px solid var(--line); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; }
  .view { padding: 20px 16px 48px; }
  .g2, .g3, .g4, .g-main, .form-grid { grid-template-columns: 1fr; }
  .result { grid-template-columns: 44px 1fr; }
  .result > :last-child { grid-column: 1 / -1; }
}
#c-list { max-height: 560px; overflow-y: auto; }

/* Connections.csv drop zone */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; background: var(--panel-2); cursor: pointer;
  color: var(--muted); font-size: 13px; transition: border-color .15s, background .15s; }
.drop b { color: var(--ink); font-size: 14px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop input { display: none; }
.template { white-space: pre-wrap; background: var(--panel-2); border-radius: 8px; padding: 12px; font-size: 13px; margin: 0 0 10px; }
