:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --border: #e6e5e1;
  --border-strong: #d4d3ce;
  --text: #1a1a18;
  --text-2: #5e5d58;
  --text-3: #8f8e88;
  --accent: #1f8a4c;
  --accent-soft: #e5f4ea;
  --accent-text: #13693a;
  --danger: #c2372f;
  --danger-soft: #fbeceb;
  --warn: #a86a00;
  --warn-soft: #fbf1dd;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 4px 16px rgba(20, 20, 15, 0.04);
  --shadow-lg: 0 12px 48px rgba(20, 20, 15, 0.16);
  --radius: 14px;
  --mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0e;
    --surface: #171716;
    --surface-2: #1f1f1d;
    --border: #2a2a27;
    --border-strong: #3a3a36;
    --text: #f1f0ec;
    --text-2: #a9a8a2;
    --text-3: #75746e;
    --accent: #3fbf74;
    --accent-soft: #15301f;
    --accent-text: #6fd99a;
    --danger: #ef6a61;
    --danger-soft: #3a1a18;
    --warn: #e0a83a;
    --warn-soft: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
a { color: var(--accent-text); }

/* ── nav ── */
.nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 14px max(16px, calc((100vw - 1120px) / 2));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; font-size: 16px; }
.brand svg { width: 26px; height: 26px; }
.nav .spacer { flex: 1; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-2);
}

/* ── layout ── */
main { max-width: 1120px; margin: 0 auto; padding: 36px 16px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
h1 { font-size: 28px; letter-spacing: -0.025em; margin: 0 0 4px; font-weight: 680; }
h2 { font-size: 17px; letter-spacing: -0.01em; margin: 0; font-weight: 620; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
.sub { color: var(--text-2); margin: 0; }
.muted { color: var(--text-3); }
.section { margin-top: 40px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* ── buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-weight: 550; font-size: 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: 0.88; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.icon-btn { padding: 6px; border-radius: 8px; }

/* ── stats ── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--text-2); }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 15px; color: var(--text-3); font-weight: 500; }

/* ── cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.servers { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.server { padding: 18px; display: flex; flex-direction: column; gap: 14px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.server:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.server-top { display: flex; gap: 12px; align-items: center; }
.server-icon {
  width: 44px; height: 44px; border-radius: 10px; flex: none;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; overflow: hidden; image-rendering: pixelated;
}
.server-icon img { width: 100%; height: 100%; }
.server-icon svg { width: 24px; height: 24px; }
.server-title { min-width: 0; flex: 1; }
.server-title h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-title .motd { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.meta span { display: inline-flex; align-items: center; gap: 6px; }
.meta svg { width: 14px; height: 14px; color: var(--text-3); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--text-2);
}
.badge.online { background: var(--accent-soft); color: var(--accent-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.online .dot { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 0%, transparent); } }

.address {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 6px 6px 12px; font-family: var(--mono); font-size: 13px;
}
.address .text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.address .tag { font-family: inherit; font-size: 11px; color: var(--text-3); }

/* ── onboarding ── */
.onboard { padding: 28px; }
.onboard-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; }
.onboard-grid > * { min-width: 0; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 18px; }
.steps li { display: flex; gap: 14px; }
.step-n {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 650;
  background: var(--surface-2); border: 1px solid var(--border);
}
.steps li.done .step-n { background: var(--accent); border-color: var(--accent); color: #fff; }
.steps li.active .step-n { background: var(--text); color: var(--bg); border-color: var(--text); }
.steps p { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }

.tabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); margin-bottom: 10px; }
.tabs button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 550; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.code {
  position: relative; background: #141413; color: #e9e8e3;
  border-radius: 12px; padding: 16px 52px 16px 16px;
  font-family: var(--mono); font-size: 13px; line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.code .c { color: #8a8983; }
.code .copy { position: absolute; top: 8px; right: 8px; color: #e9e8e3; background: #2a2a28; border-color: #3a3a37; }
.code .copy:hover { background: #3a3a37; }
.waiting { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 14px; color: var(--text-2); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--text); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── agents list ── */
.list { overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 560; }
.row .desc { font-size: 13px; color: var(--text-3); }
.empty { padding: 28px; text-align: center; color: var(--text-3); font-size: 14px; }

/* ── drawer ── */
.scrim { position: fixed; inset: 0; background: rgba(10, 10, 8, 0.35); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 50;
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.drawer-body { padding: 24px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 28px; }
.drawer .block h3 { margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.input-row { display: flex; gap: 8px; }
.input {
  flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); outline: none;
}
.input:focus { border-color: var(--text-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 10%, transparent); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 6px; min-height: 1em; }

.domain { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.domain-head { display: flex; align-items: center; gap: 8px; }
.domain-head .name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
table.dns { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dns th { text-align: left; font-weight: 550; color: var(--text-3); padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.dns td { padding: 8px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; vertical-align: top; }
table.dns tr:last-child td { border-bottom: 0; }
.check { font-size: 13px; border-radius: 10px; padding: 10px 12px; }
.check.ok { background: var(--accent-soft); color: var(--accent-text); }
.check.bad { background: var(--warn-soft); color: var(--warn); }
.check ul { margin: 4px 0 0; padding-left: 18px; }
.hint { font-size: 13px; color: var(--text-2); margin: 0; }
.danger-zone { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* ── modal ── */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 10, 8, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal .card { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 24px; box-shadow: var(--shadow-lg); }

/* ── toast ── */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; transition: all 0.2s;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; font-weight: 550;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

[hidden] { display: none !important; }

/* ── nav tabs ── */
.nav-tabs { display: flex; gap: 2px; margin-left: 12px; }
.nav-tabs button {
  border: 0; background: none; cursor: pointer; padding: 6px 12px; border-radius: 8px;
  font-size: 14px; font-weight: 550; color: var(--text-2);
}
.nav-tabs button:hover { background: var(--surface-2); color: var(--text); }
.nav-tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

/* ── status ── */
.pc { padding: 20px; margin-bottom: 14px; }
.pc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.pc-head .grow { flex: 1; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; }
.tile .big { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.tile .big small { font-size: 14px; color: var(--text-3); font-weight: 500; }
.tile .foot { font-size: 12px; color: var(--text-3); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .kvs { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin-top: 4px; }
.tile .kvs dt { color: var(--text-3); }
.tile .kvs dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.4s; }
.meter.high > span { background: var(--warn); }
.high-label { color: var(--warn); font-weight: 600; font-size: 12px; }
.spark { position: relative; margin-top: 10px; height: 48px; cursor: crosshair; }
.spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark .area { fill: var(--accent); opacity: 0.12; }
.spark .cursor { stroke: var(--text-3); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .tip {
  position: absolute; top: -30px; transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  background: var(--text); color: var(--bg); font-size: 12px; font-weight: 550; padding: 3px 8px; border-radius: 6px;
}
.spark .empty { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--text-3); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.btn.block { width: 100%; padding: 10px 14px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ── auth ── */
.auth {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px; gap: 20px;
  background:
    radial-gradient(600px 300px at 50% -60px, color-mix(in srgb, var(--accent) 14%, transparent), transparent),
    var(--bg);
}
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); padding: 32px;
}
.auth-brand { margin-bottom: 28px; }
.auth h1 { font-size: 24px; }
.auth .sub { margin-bottom: 24px; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 550; }
.field .input { font-weight: 400; font-size: 15px; padding: 10px 12px; }
.field small { font-weight: 400; }
.auth .error-text { margin: -4px 0 0; }
.auth-switch { margin: 20px 0 0; text-align: center; font-size: 14px; color: var(--text-2); }
.link { background: none; border: 0; padding: 0; color: var(--accent-text); font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }
.auth-foot { font-size: 13px; margin: 0; }
.brand [data-brand] { display: contents; }

/* ── account menu ── */
.menu-wrap { position: relative; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--accent-soft); color: var(--accent-text); font-weight: 650; font-size: 14px; cursor: pointer;
}
.avatar:hover { border-color: var(--text-3); }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  padding: 6px; display: flex; flex-direction: column;
}
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-name { font-weight: 600; }
.menu-email { font-size: 13px; color: var(--text-3); overflow-wrap: anywhere; }
.menu button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.menu button:hover { background: var(--surface-2); }
.modal .card.narrow { width: min(480px, 100%); }
a.btn { text-decoration: none; }
.more { margin-top: 14px; font-size: 13px; color: var(--text-2); }
.more summary { cursor: pointer; font-weight: 550; }
.more[open] summary { margin-bottom: 4px; }

@media (max-width: 760px) {
  .hide-sm { display: none; }
  .nav { gap: 8px; }
  .nav .brand { font-size: 0; gap: 0; }
  .nav-tabs { margin-left: 0; }
  .tiles { grid-template-columns: 1fr; }
  .auth-card { padding: 24px; }
  .stats { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 20px; }
  .onboard { padding: 18px; }
  .onboard-grid { grid-template-columns: 1fr; gap: 20px; }
  .servers { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
  .nav .pill { display: none; }
  .drawer-body, .drawer-head { padding-left: 16px; padding-right: 16px; }
}
