:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --editor-bg: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --green: #16a34a;
  --green-dot: #22c55e;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-dot: #ef4444;
  --red-bg: #fee2e2;
  --amber: #d97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
}

.booting #token-view, .booting #app-view { display: none; }
body.auth #token-view { display: none; }
body.auth #app-view { display: flex; }
body:not(.auth) #token-view { display: flex; }
body:not(.auth) #app-view { display: none; }

/* ---- token view ---- */
#token-view { height: 100vh; align-items: center; justify-content: center; }
#token-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#token-form h1 { font-size: 20px; }
#token-form p { color: var(--muted); font-size: 13px; }

/* ---- app shell ---- */
#app-view { flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { font-weight: 600; font-size: 15px; }
.body { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---- left pane ---- */
.left {
  width: 300px;
  flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.left-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--faint);
}
#route-list { list-style: none; flex: 1 1 auto; overflow-y: auto; padding: 6px; }
.route-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.route-row:hover { background: var(--bg); }
.route-row.selected { background: var(--accent-bg); }
.route-row.selected .row-name { color: var(--accent); }
.route-row.selected .row-host { color: #60a5fa; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--faint); }
.dot.up { background: var(--green-dot); }
.dot.down { background: var(--red-dot); }
.dot.off { background: var(--faint); }
.row-text { min-width: 0; }
.row-name { font-weight: 600; font-size: 13px; }
.row-host { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.left-foot {
  padding: 13px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* ---- right pane ---- */
.right { flex: 1 1 auto; background: var(--editor-bg); overflow-y: auto; min-width: 0; }
.empty { padding: 60px; color: var(--faint); text-align: center; }
.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.editor-head h2 { font-size: 20px; }
.subtle { font-size: 12px; color: var(--faint); margin-top: 3px; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.live { background: var(--green-bg); color: var(--green); }
.pill.down { background: var(--red-bg); color: var(--red); }
.pill.disabled { background: var(--bg); color: var(--muted); }

#route-form { padding: 28px; display: flex; flex-direction: column; gap: 20px; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
input, select {
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.upstream { display: flex; align-items: center; gap: 9px; }
.upstream input[name="upstream_port"] { width: 100px; flex: 0 0 auto; }
.colon { color: var(--faint); font-weight: 600; }

.hint { font-size: 12px; margin-top: 4px; }
.hint.ok { color: var(--green); }
.hint.warn { color: var(--amber); }

.tls-status { font-size: 12px; margin-top: -8px; }
.tls-status.valid { color: var(--green); }
.tls-status.expiring { color: var(--amber); }
.tls-status.invalid { color: var(--red); }
.tls-status.off { color: var(--muted); }

.options {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.options legend {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--faint);
  padding: 0 4px;
}
.check { display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; }
.check input { width: auto; }
.subform { display: flex; gap: 12px; padding-left: 28px; }
.subform .field { flex: 1; }
.field.sm > span { font-size: 11px; color: var(--muted); }
.field.sm input { padding: 9px 11px; background: var(--editor-bg); }

.actions { display: flex; justify-content: space-between; align-items: center; }

button { font: inherit; cursor: pointer; border: none; border-radius: 7px; }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; padding: 11px 18px; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-danger {
  background: var(--panel);
  color: var(--red);
  font-weight: 600;
  padding: 11px 16px;
  border: 1px solid #fecaca;
}
.link { background: none; color: var(--muted); font-size: 13px; padding: 0; }
.link:hover { color: var(--accent); }

.banner {
  margin: 0 28px;
  margin-top: 20px;
  padding: 12px 14px;
  border-radius: 7px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
}
.error { color: var(--red); font-size: 13px; }
