:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-soft: #0d121d;
  --card: rgba(255, 255, 255, 0.045);
  --card-strong: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef2ff;
  --muted: #95a0b8;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #fb7185;
  --radius: 18px;
  --tap: 48px;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(34, 211, 238, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.55rem; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; letter-spacing: -0.02em; }
h3 { font-size: 1.02rem; letter-spacing: -0.01em; }
a { color: var(--accent-2); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 6px;
  border-radius: 6px;
}

.shell { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(150px + env(safe-area-inset-bottom)); }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  margin: -4px -4px 8px;
  background: rgba(8, 11, 18, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; flex: none;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.35);
}
.brand-mark::after {
  content: "";
  width: 0; height: 0;
  border-left: 11px solid #080b12;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  margin-left: 3px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 0.98rem; letter-spacing: -0.01em; }
.brand-text span { font-size: 0.74rem; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; font-weight: 600;
  padding: 7px 11px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-muted { color: var(--muted); }
.pill-ok { color: var(--ok); }
.pill-warn { color: var(--warn); }
.pill-bad { color: var(--bad); }

.content { display: block; }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h3 { margin-top: 2px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.68rem; font-weight: 700; color: var(--accent-2); margin-bottom: 7px; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; line-height: 1.45; }
.error { color: var(--bad); font-size: 0.9rem; margin-top: 10px; }

.hero { display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
.hero h2 { margin-bottom: 6px; }
.hero .muted { max-width: 56ch; }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; gap: 3px; margin: 0; padding: 15px; }
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.stat strong { font-size: 1.12rem; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; }

.primary-btn, .secondary-btn, .ghost-btn {
  font: inherit; cursor: pointer; border-radius: 13px;
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 18px; font-weight: 700;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}
.primary-btn {
  color: #fff;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #0891b2);
  box-shadow: 0 10px 30px rgba(124, 58, 237, 0.30);
}
.secondary-btn {
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--card-strong);
}
.ghost-btn {
  color: var(--muted);
  border: 1px solid var(--border);
  background: transparent;
  min-height: 38px; padding: 0 12px; border-radius: 10px; font-size: 0.82rem;
}
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover { filter: brightness(1.1); }
.primary-btn:active, .secondary-btn:active, .ghost-btn:active { transform: scale(0.985); }
.primary-btn:disabled, .secondary-btn:disabled, .ghost-btn:disabled { opacity: 0.55; cursor: progress; }
.ghost-btn.danger { color: var(--bad); border-color: rgba(251, 113, 133, 0.3); }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 3px; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 0.86rem; }
.field > span { color: var(--muted); font-weight: 600; }
.field em { font-style: normal; color: #6f7a92; font-weight: 500; }
.field input {
  width: 100%; min-height: var(--tap);
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 0 14px;
  font: inherit;
  font-size: 1rem;
}
.field input:focus { border-color: rgba(34, 211, 238, 0.55); outline: none; box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12); }
.inline-fields { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 14px; }

.steps { margin: 14px 0 0; padding-left: 20px; color: var(--muted); line-height: 1.65; font-size: 0.92rem; }
.steps strong { color: var(--text); }

.device-list { display: flex; flex-direction: column; gap: 10px; }
.device {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 14px; border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}
.device-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; min-width: 0; }
.device-main strong { font-size: 0.95rem; }
.device-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.76rem; color: var(--muted); }
.device-actions { display: flex; gap: 6px; flex: none; }
.badge { font-size: 0.68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); }
.badge-warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }

.category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 12px; }
.category {
  display: flex; align-items: center; gap: 10px;
  min-height: 46px; padding: 0 12px;
  border-radius: 12px; border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.16);
  cursor: pointer; font-size: 0.88rem; font-weight: 600;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.category input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.category:has(input:checked) {
  border-color: rgba(139, 92, 246, 0.55);
  background: rgba(139, 92, 246, 0.12);
}

.toggle-list { display: flex; flex-direction: column; margin-top: 8px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 13px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row > span { display: flex; flex-direction: column; gap: 2px; font-size: 0.92rem; }
.toggle-row em { font-style: normal; color: var(--muted); font-size: 0.79rem; }
.toggle-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  width: 50px; height: 30px; flex: none; border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  position: relative; transition: background 0.16s ease;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; transition: transform 0.16s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.toggle-row input:checked + .switch { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }
.toggle-row input:focus-visible + .switch { outline: 2px solid var(--accent-2); outline-offset: 3px; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.savebar {
  position: sticky;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 8;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 12px 11px 16px;
  margin-top: 4px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(13, 18, 29, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.savebar .primary-btn { min-height: 44px; padding: 0 18px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(8, 11, 18, 0.86);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.tab-btn {
  flex: 1 1 0; max-width: 180px; min-height: 52px;
  border: none; border-radius: 13px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 700; font-size: 0.82rem;
  cursor: pointer; transition: color 0.12s ease, background 0.12s ease;
}
.tab-btn.is-active { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.tab-btn.is-active::before {
  content: ""; display: block; width: 18px; height: 3px; border-radius: 999px;
  margin: 0 auto 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  max-width: min(92vw, 520px);
  padding: 12px 16px; border-radius: 13px;
  background: rgba(20, 26, 40, 0.96);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-ok { border-color: rgba(52, 211, 153, 0.45); }
.toast.is-warn { border-color: rgba(251, 191, 36, 0.45); }
.toast.is-bad { border-color: rgba(251, 113, 133, 0.5); }

.banner {
  display: flex; flex-direction: column; gap: 3px;
  padding: 13px 15px; margin-bottom: 14px;
  border-radius: 14px; border: 1px solid rgba(52, 211, 153, 0.32);
  background: rgba(52, 211, 153, 0.07);
  font-size: 0.86rem;
}
.banner span { color: var(--muted); }
.banner-warn { border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.07); }
.banner-warn strong { color: var(--warn); }
.banner-warn span { color: var(--warn); }

.logs {
  margin: 0; padding: 14px;
  max-height: 62vh; overflow: auto;
  border-radius: 13px; border: 1px solid var(--border);
  background: #05070c;
  color: #b9c6e0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.76rem; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(420px, 100%); margin: 0; padding: 26px; }
.login-card .brand { margin-bottom: 22px; }
.login-card h1 { margin-bottom: 6px; }
.login-card .muted { margin-bottom: 4px; }
.login-card .small { margin-top: 16px; }

@media (min-width: 640px) {
  .hero { flex-direction: row; align-items: center; justify-content: space-between; }
  .inline-fields { grid-template-columns: 1fr 1fr; }
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .shell { padding-left: 24px; padding-right: 24px; }
  .card { padding: 22px; }
}

@media (min-width: 900px) {
  .category-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .tabbar { background: transparent; border-top: none; backdrop-filter: none; -webkit-backdrop-filter: none; padding-bottom: 18px; }
  .tabbar .tab-btn { background: rgba(13, 18, 29, 0.72); backdrop-filter: blur(14px); }
  .tabbar .tab-btn.is-active { background: rgba(255, 255, 255, 0.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
