:root {
  --bg: #f4f7fa; --surface: #ffffff; --surface-2: #eef2f6; --border: #e1e7ee;
  --text: #0f1b2a; --muted: #5d6b7c;
  --primary: #0b4f8a; --primary-600: #093f6f; --accent: #0fa3a3;
  --ok: #12a05c; --ok-bg: #e3f6ec; --bad: #d63a3a; --bad-bg: #fdeaea; --warn: #b7791f; --warn-bg: #fdf3e0;
  --shadow: 0 1px 2px rgba(15,27,42,.05), 0 8px 24px rgba(15,27,42,.06);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b121b; --surface: #121c29; --surface-2: #192536; --border: #223247;
    --text: #e8eef5; --muted: #8fa1b5;
    --primary: #3b8fe0; --primary-600: #5aa3ec; --accent: #2cc5c5;
    --ok: #3cc785; --ok-bg: #11301f; --bad: #f06a6a; --bad-bg: #3a1717; --warn: #e6b04f; --warn-bg: #3a2d12;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; min-height: 100vh; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { width: 30px; height: 30px; border-radius: 9px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav button { background: none; border: 0; padding: 8px 14px; border-radius: 10px; color: var(--muted); cursor: pointer; font-weight: 550; transition: .15s; }
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--surface-2); color: var(--primary); }
.spacer { flex: 1; }
.user { color: var(--muted); font-size: 14px; }
main { max-width: 1120px; margin: 0 auto; padding: 28px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- buttons / inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; transition: transform .1s, background .15s, box-shadow .15s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=password] { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
input.code { text-align: center; font-size: 28px; letter-spacing: .4em; padding-left: calc(14px + .4em); font-variant-numeric: tabular-nums; font-weight: 600; }
.error { color: var(--bad); background: var(--bad-bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 16px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent),
              radial-gradient(900px 500px at 100% 110%, color-mix(in srgb, var(--primary) 22%, transparent), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px;
  padding: 32px; box-shadow: var(--shadow); animation: rise .35s ease both; }
.auth-card .logo { width: 52px; height: 52px; border-radius: 15px; display: block; margin-bottom: 18px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 14px; border: 1px solid var(--border); margin: 0 auto 14px; width: fit-content; }
.qr svg, .qr img { display: block; width: 200px; height: 200px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--surface-2); padding: 10px 12px;
  border-radius: 10px; word-break: break-all; text-align: center; margin-bottom: 18px; user-select: all; }

/* ---------- site cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  transition: transform .18s, box-shadow .18s; animation: rise .3s ease both; }
.card:hover { transform: translateY(-2px); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card h3 { font-size: 17px; word-break: break-word; }
.host { color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.idle { color: var(--muted); background: var(--surface-2); }
.rows { margin: 16px 0; display: grid; gap: 8px; }
.row { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.row b { color: var(--text); font-weight: 600; }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; border-top: 1px solid var(--border); }
.toggle-label { font-weight: 600; font-size: 14px; }
.toggle-label small { display: block; color: var(--muted); font-weight: 450; font-size: 12px; }
.switch { position: relative; width: 52px; height: 30px; border-radius: 999px; border: 0; background: var(--bad); cursor: pointer; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s cubic-bezier(.3,.7,.4,1.3); }
.switch[aria-checked=true] { background: var(--ok); }
.switch[aria-checked=true]::after { transform: translateX(22px); }
.switch:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 2px; }
.switch:disabled { opacity: .5; cursor: progress; }
.ctl { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); color: var(--bad); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8,15,24,.55); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 20; animation: fade .15s ease both; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border-radius: 20px; padding: 26px; border: 1px solid var(--border); box-shadow: 0 24px 60px rgba(0,0,0,.35); animation: rise .2s ease both; max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 640px; }
.modal h2 { font-size: 19px; margin-bottom: 6px; }
.modal .sub { color: var(--muted); margin: 0 0 20px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
pre.snippet { background: #0b1520; color: #d6e6f5; padding: 14px; border-radius: 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-all; margin: 8px 0 14px; }
.warnbox { background: var(--warn-bg); color: var(--warn); padding: 10px 14px; border-radius: 12px; font-size: 13.5px; margin-bottom: 14px; font-weight: 550; }
ol.steps { padding-left: 20px; color: var(--muted); margin: 0 0 14px; }
ol.steps li { margin-bottom: 4px; }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 40; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: rise .2s ease both; font-weight: 550; }
.toast.err { background: var(--bad); color: #fff; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; }
  .nav { order: 3; width: 100%; margin-left: 0; }
  .nav button { flex: 1; }
  .user { display: none; }
  .grid { grid-template-columns: 1fr; }
  .page-head .btn { width: 100%; }
}
