:root {
  --bg: #f7f6fb;
  --surface: #ffffff;
  --surface-2: #f2f0f8;
  --border: #e4e1ee;
  --text: #1c1830;
  --muted: #6b6683;
  --accent: #6d4aff;
  --accent-strong: #5732f0;
  --accent-soft: #ece7ff;
  --on-accent: #ffffff;
  --ok: #138a52;
  --warn: #b26b00;
  --bad: #c62f3d;
  --idle: #9a96ad;
  --term-bg: #1d1733;
  --term-text: #ece9f7;
  --term-muted: #9d95c2;
  --shadow: 0 1px 2px rgba(28, 24, 48, .05), 0 8px 24px rgba(28, 24, 48, .06);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #110f1a; --surface: #1a1726; --surface-2: #221e31; --border: #302b43;
    --text: #ece9f7; --muted: #a29cbb; --accent: #8f74ff; --accent-strong: #a48fff;
    --accent-soft: #2b2348; --ok: #3ccf8e; --warn: #f0a840; --bad: #ff6b78; --idle: #6f6a86;
    --term-bg: #0c0a14; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #110f1a; --surface: #1a1726; --surface-2: #221e31; --border: #302b43;
  --text: #ece9f7; --muted: #a29cbb; --accent: #8f74ff; --accent-strong: #a48fff;
  --accent-soft: #2b2348; --ok: #3ccf8e; --warn: #f0a840; --bad: #ff6b78; --idle: #6f6a86;
  --term-bg: #0c0a14; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }
.boot { padding: 48px; color: var(--muted); }
.mt { margin-top: 10px; }
.mt-lg { margin-top: 20px; }
.left { text-align: left; }
.pre { white-space: pre-wrap; }
.offscreen { position: fixed; opacity: 0; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Layout */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.sidebar {
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 20px 16px; display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; padding: 0 8px; }
.brand img { width: 26px; height: 26px; }
.section-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 8px 6px; }
.team-switch { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .me { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 8px 0; font-size: 13px; }
.me .email { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 32px clamp(16px, 4vw, 48px); max-width: 1200px; width: 100%; }
.mobile-bar { display: none; }

/* Panels */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 640px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel { margin-top: 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-body { padding: 20px; }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 20px; }
.banner .grow { flex: 1; min-width: 200px; }
.banner.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 550; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .icon-btn:focus-visible, .pill:focus-visible, input:focus-visible, select:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }
.icon-btn svg { width: 18px; height: 18px; }

/* Filters */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.pill { border: 1px solid var(--border); background: var(--surface); padding: 4px 12px; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.pill[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }
.search { margin-left: auto; position: relative; }
.search input { padding: 7px 34px 7px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface-2); width: 240px; max-width: 100%; }
.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 12px var(--mono); color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
.sub { color: var(--muted); font-size: 13px; }
.name-cell { display: flex; align-items: center; gap: 10px; font-weight: 550; }
.token-id { color: var(--accent); font-family: var(--mono); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 16px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--muted); }
.badge.owner { color: var(--accent-strong); border-color: var(--accent); background: var(--accent-soft); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 13px; }
.field input, .field select, .inline-form input, .inline-form select {
  padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface);
}
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1; min-width: 200px; }
.error-text { color: var(--bad); font-size: 14px; }

/* Modal */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(20, 16, 36, .45); backdrop-filter: blur(4px); }
.modal { padding: 28px clamp(20px, 4vw, 40px) 32px; position: relative; }
.modal h2 { margin: 0 0 6px; font-size: 20px; }
.modal > p { margin: 0 0 20px; color: var(--muted); }
.modal .close { position: absolute; top: 16px; right: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* Terminal */
.term { background: var(--term-bg); color: var(--term-text); border-radius: 12px; overflow: hidden; font-family: var(--mono); font-size: 14px; }
.term-head { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.term-head .lights { display: flex; gap: 6px; margin-right: auto; }
.term-head .lights i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .22); }
.term-tab { background: transparent; border: 1px solid transparent; color: var(--term-muted); border-radius: 999px; padding: 2px 10px; font: 12px var(--mono); letter-spacing: .06em; cursor: pointer; }
.term-tab[aria-selected="true"] { border-color: #3ccf8e; color: #3ccf8e; background: rgba(60, 207, 142, .1); }
.term-body { padding: 8px 14px 14px; }
.term-step { padding-top: 12px; }
.term-step .c { color: var(--term-muted); }
.term-line { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.term-line .prompt { color: #3ccf8e; }
.term-line code { flex: 1; white-space: pre-wrap; word-break: break-all; font-size: 14px; }
.term .icon-btn { color: var(--term-muted); }
.term .icon-btn:hover { background: rgba(255, 255, 255, .08); color: var(--term-text); }
.term-note { color: var(--term-muted); padding: 12px 0 2px; font-size: 13px; }
.agent { margin-top: 22px; }
.agent h3 { margin: 0; font-size: 15px; }
.agent p { margin: 2px 0 12px; color: var(--muted); font-size: 14px; }
.secret { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); word-break: break-all; }
.secret code { flex: 1; }

/* Sign-in */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 36px 32px; text-align: center; }
.auth-card .brand { justify-content: center; font-size: 22px; margin-bottom: 8px; }
.auth-card p { color: var(--muted); margin: 0 0 24px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px 14px; margin-top: 10px; }
.code-big { font: 600 28px var(--mono); letter-spacing: .12em; margin: 8px 0 20px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 10; }

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); gap: 12px; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .me { margin-top: 0; }
  .search { margin-left: 0; width: 100%; }
  .search input { width: 100%; }
  th, td { padding: 12px 14px; }
  .hide-sm { display: none; }
}
