:root {
  --bg: #10141a;
  --bg-raised: #171d26;
  --bg-inset: #0c1015;
  --border: #26303d;
  --text: #e6edf3;
  --muted: #8b97a6;
  --accent: #3ea86a;
  --accent-hover: #4bc07d;
  --danger: #d9534f;
  --warn: #d9a441;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

/*
 * Make the `hidden` attribute actually win.
 *
 * The browser's own rule for [hidden] lives in the UA stylesheet, and ANY
 * author rule that sets `display` beats it — so `.drawer { display: flex }`
 * silently overrode `element.hidden = true` and the drawer could never be
 * closed. Elements toggled by `.hidden` in app.js must keep working no matter
 * what display value a component rule sets, so this guard is global.
 *
 * `!important` is required, not decoration: `[hidden]` and `.drawer` both have
 * specificity (0,1,0), so without it plain source order would decide the
 * winner, and .drawer is declared further down this file.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); }
.error {
  color: var(--danger);
  background: rgba(217, 83, 79, 0.1);
  border: 1px solid rgba(217, 83, 79, 0.35);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 12px;
  font-size: 14px;
}

/* ------------------------------------------------------------------ layout */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar__brand { font-weight: 650; letter-spacing: 0.01em; }
.topbar__right { display: flex; align-items: center; gap: 12px; }

.brand { font-size: 22px; margin: 0 0 6px; }
.brand__mark {
  display: inline-block;
  background: var(--accent);
  color: #08120c;
  font-family: var(--mono);
  font-weight: 700;
  border-radius: 6px;
  padding: 1px 7px;
  margin-right: 4px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1.2fr);
  gap: 18px;
  padding: 22px;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card--narrow { width: min(420px, 100%); }
.card h2 { margin: 0 0 8px; font-size: 17px; }

/* ------------------------------------------------------------------ forms */

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 14px 0 6px;
}
input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
input.mono { font-family: var(--mono); letter-spacing: 0.04em; }
input:focus, button:focus-visible, .agent:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: #3a4757; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08120c;
  font-weight: 600;
}
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn--ghost { background: transparent; }
.btn--small { padding: 6px 12px; font-size: 13px; }
.btn--block { width: 100%; margin-top: 18px; }

/* ------------------------------------------------------------------- code */

.code-display {
  margin-top: 16px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--mono);
  font-size: clamp(20px, 4.4vw, 30px);
  letter-spacing: 0.1em;
  text-align: center;
  user-select: all;
  word-break: break-all;
}
.code-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; }

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
}
.pill--live { color: var(--accent); border-color: rgba(62, 168, 106, 0.5); background: rgba(62, 168, 106, 0.1); }
.pill--dead { color: var(--danger); border-color: rgba(217, 83, 79, 0.5); background: rgba(217, 83, 79, 0.1); }
.pill--idle { color: var(--muted); }

/* ----------------------------------------------------------------- agents */

.agents { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.agent {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "dot name" "dot meta";
  gap: 2px 10px;
  align-items: center;
  text-align: left;
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}
.agent:hover { border-color: #3a4757; }
.agent--revoked { opacity: 0.55; }
.agent__name { grid-area: name; font-weight: 600; }
.agent__meta { grid-area: meta; }

.dot {
  grid-area: dot;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.dot--online { background: var(--accent); box-shadow: 0 0 0 3px rgba(62, 168, 106, 0.18); }
.dot--offline { background: #4a5666; }

/* ----------------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 13, 0.62);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}
.drawer__panel {
  width: min(560px, 100%);
  height: 100%;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 12px;
}
.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.drawer__actions { display: flex; gap: 8px; }
.command-form { display: flex; gap: 8px; }
.command-form input { flex: 1; }

.events {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
}
.event { border-left: 3px solid var(--border); padding-left: 10px; }
.event--in { border-left-color: var(--accent); }
.event--out { border-left-color: #4a7fd9; }
.event__head { display: flex; gap: 10px; align-items: baseline; }
.event__kind { font-family: var(--mono); }
.event__body { word-break: break-word; white-space: pre-wrap; margin-top: 2px; }
