:root {
  color-scheme: dark;
  --bg: #0b0d14;
  --bg-2: #11141d;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef0f6;
  --muted: #9aa1b5;
  --accent: #7c8cff;
  --accent-2: #4fd1ff;
  --up: #22c55e;
  --down: #ef4444;
  --unknown: #6b7280;
  --test: #f59e0b;
  --danger: #f87171;
  --radius: 18px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f6fb;
    --bg-2: #ffffff;
    --surface: rgba(255, 255, 255, 0.75);
    --surface-2: rgba(15, 23, 42, 0.05);
    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.16);
    --text: #0f172a;
    --muted: #5b6478;
    --accent: #4f5bd5;
    --accent-2: #0ea5e9;
    --test: #d97706;
    --danger: #dc2626;
    --shadow: 0 10px 30px -14px rgba(15, 23, 42, 0.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.block { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- background ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-orbs span { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.35; }
.bg-orbs span:nth-child(1) { width: 520px; height: 520px; background: var(--accent); top: -180px; left: -140px; }
.bg-orbs span:nth-child(2) { width: 460px; height: 460px; background: var(--accent-2); bottom: -200px; right: -120px; opacity: 0.25; }
.bg-orbs span:nth-child(3) { width: 300px; height: 300px; background: #c084fc; top: 40%; left: 55%; opacity: 0.15; }
@media (prefers-color-scheme: light) { .bg-orbs span { opacity: 0.18; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px; padding: 10px 16px;
  font-weight: 600; font-size: 0.95rem; cursor: pointer; text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-lg { width: 100%; padding: 14px 18px; font-size: 1rem; border-radius: 14px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 8px 24px -10px var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: transparent; border: 1px solid var(--border); cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 0.85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- inputs ---------- */
input[type=text], input[type=password], input[type=url], input:not([type]), select {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
input[type=color] { width: 100%; height: 46px; padding: 4px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.field > span { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.field-sm { flex: 0 0 84px; }
.field-row { display: flex; gap: 12px; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 999px; background: var(--border-strong); position: relative; cursor: pointer; transition: background 0.2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch:checked { background: var(--up); }
.switch:checked::after { transform: translateX(18px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; padding: 36px 28px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); box-shadow: var(--shadow);
}
.login-logo { border-radius: 16px; box-shadow: 0 10px 30px -10px var(--accent); }
.login-card h1 { margin: 16px 0 4px; font-size: 1.8rem; letter-spacing: -0.02em; }
.login-card > p.muted { margin: 0 0 28px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; max-width: 1180px; margin: 0 auto;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; letter-spacing: -0.01em; }
.brand img { border-radius: 9px; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- dashboard ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 8px 16px 48px; }
.hero { margin: 16px 0 28px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); letter-spacing: -0.03em; margin: 0; }
.hero p { margin: 4px 0 0; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 0.82rem; }

.group { margin-bottom: 32px; }
.group-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; font-size: 0.95rem; font-weight: 600; color: var(--muted); margin: 0 0 14px; }
.pill { font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; }
.pill-live { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.pill-test { background: color-mix(in srgb, var(--test) 20%, transparent); color: var(--test); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }

.tile {
  --c: var(--accent);
  position: relative; display: flex; flex-direction: column; gap: 14px; padding: 18px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  color: inherit; text-decoration: none; overflow: hidden; min-height: 132px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.tile::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.0; transition: opacity 0.2s;
  background: radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--c) 22%, transparent), transparent 60%);
}
.tile:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--c) 50%, transparent); box-shadow: 0 16px 36px -18px var(--c); }
.tile:hover::before { opacity: 1; }
.tile-icon {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.55rem; font-weight: 700;
  background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); color: var(--c);
}
.tile-name { font-weight: 650; font-size: 1.02rem; letter-spacing: -0.01em; }
.tile-host { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { margin-top: auto; }
.tile-status { position: absolute; top: 16px; right: 16px; display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); flex: none; }
.dot.up { background: var(--up); box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 60%, transparent); animation: pulse 2.4s infinite; }
.dot.down { background: var(--down); box-shadow: 0 0 10px var(--down); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.up { animation: none; } .tile, .tile:hover { transform: none; } }

.tile.is-test .tile-meta { padding-right: 40px; }
.tile.is-test { border-style: dashed; border-color: color-mix(in srgb, var(--test) 55%, transparent); }
.tile.is-test::after {
  content: "TEST"; position: absolute; bottom: 14px; right: -30px; transform: rotate(-35deg);
  background: repeating-linear-gradient(45deg, var(--test) 0 8px, color-mix(in srgb, var(--test) 75%, #000) 8px 16px);
  color: #111; font-size: 0.65rem; font-weight: 900; letter-spacing: 0.15em; padding: 3px 34px;
}
@media (max-width: 520px) {
  .tile { padding: 14px; min-height: 120px; }
  .tile-icon { width: 42px; height: 42px; font-size: 1.35rem; }
  .tile-status .label { display: none; }
}
.empty { text-align: center; padding: 48px 0; }

/* ---------- dialogs ---------- */
dialog { color: var(--text); background: var(--bg-2); border: 1px solid var(--border); padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 7, 12, 0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet {
  margin: 0 0 0 auto; height: 100vh; height: 100dvh; max-height: none; width: min(460px, 100vw); max-width: 100vw;
  border-radius: 22px 0 0 22px; border-right: 0; overflow-y: auto; padding: 0 20px 32px;
}
.sheet[open] { animation: slide-in 0.22s ease-out; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
@media (max-width: 520px) { .sheet { border-radius: 0; } }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 18px 0 12px; background: var(--bg-2); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 1.3rem; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 16px; }
.tab { flex: 1; padding: 8px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.card { padding: 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: 1rem; }
.card p { margin: 0; }

.app-list, .passkey-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.app-row {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
}
.app-row.dragging { opacity: 0.4; }
.app-row.drop-target { border-color: var(--accent); }
.app-row .handle { cursor: grab; color: var(--muted); padding: 0 2px; user-select: none; touch-action: none; }
.app-row .tile-icon { width: 36px; height: 36px; font-size: 1.1rem; border-radius: 10px; }
.app-row .info { flex: 1; min-width: 0; }
.app-row .info .name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.app-row .info .host { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-row.is-hidden .tile-icon, .app-row.is-hidden .info { opacity: 0.45; }
.app-row .moves { display: flex; flex-direction: column; gap: 2px; }
.app-row .moves .icon-btn { width: 26px; height: 20px; border-radius: 6px; font-size: 0.65rem; }
.passkey-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.passkey-list .muted { font-size: 0.75rem; }

.modal { width: min(460px, calc(100vw - 32px)); border-radius: 20px; }
.modal[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } }
.modal form { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.modal h2 { margin: 0 0 4px; font-size: 1.2rem; }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
@media (max-width: 420px) { .field-row { flex-wrap: wrap; } .field-row .field:first-child { flex-basis: 100%; } .field-sm { flex: 1; } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
