:root {
  --bg: #0f141b;
  --bg-2: #151c25;
  --panel: #18212c;
  --panel-2: #1d2835;
  --line: #2a3746;
  --text: #e8eef5;
  --muted: #94a3b4;
  --accent: #4c9aff;
  --accent-2: #2d7ae6;
  --ok: #38c172;
  --warn: #f0a73a;
  --bad: #ed5b5b;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(76, 154, 255, .14), transparent 60%),
    radial-gradient(900px 500px at 95% 0%, rgba(56, 193, 114, .08), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

h1, h2 { margin: 0; font-weight: 650; letter-spacing: .2px; }
h1 { font-size: 20px; }
h1 span { color: var(--muted); font-weight: 500; }
h2 { font-size: 17px; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .05s;
}
button:hover { border-color: #3d5064; background: #22303f; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: var(--accent); border-color: var(--accent); }
button.ghost { background: transparent; }
button.danger { color: #ffb4b4; border-color: #503035; }
button.danger:hover { background: #3a2126; border-color: #7b3c44; }
button.icon { padding: 5px 8px; line-height: 1; }
button:disabled { opacity: .5; cursor: default; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #1d5fbd);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  box-shadow: 0 6px 20px rgba(76, 154, 255, .3);
}
.brand.small .brand-mark { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }

/* ---------- login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 26px; }
.login-card p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.login-card label { display: block; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 14px 16px;
  font-size: 26px;
  letter-spacing: .42em;
  text-align: center;
  color: var(--text);
  background: #0d1219;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(76, 154, 255, .18); }
.login-card button { width: 100%; margin-top: 14px; padding: 12px; font-size: 16px; }
.hint { margin-top: 16px !important; font-size: 12px !important; text-align: center; }

/* ---------- app ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 27, .75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-actions { display: flex; align-items: center; gap: 10px; }
#refresh-note { font-size: 12px; }

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 44px) 40px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--bad); }

.panel {
  background: rgba(24, 33, 44, .72);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}
.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.panel-head p { margin: 0; font-size: 12px; }

.devices { display: grid; gap: 12px; }

.device {
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), #18222d);
  padding: 14px 16px;
  display: grid;
  gap: 12px;
}
.device.online { border-left-color: var(--ok); }
.device.revoked { opacity: .62; border-left-color: #6b3b42; }

.dev-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dev-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); flex: 0 0 auto; box-shadow: 0 0 0 4px rgba(237, 91, 91, .12); }
.device.online .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(56, 193, 114, .12); }
.device.revoked .dot { background: #7b3c44; box-shadow: none; }
.dev-title { min-width: 0; }
.dev-name { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dev-name .edit { font-size: 12px; padding: 2px 7px; opacity: .65; }
.dev-host { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #121a23;
}
.badge.ok { color: var(--ok); border-color: rgba(56, 193, 114, .35); background: rgba(56, 193, 114, .08); }
.badge.bad { color: var(--bad); border-color: rgba(237, 91, 91, .35); background: rgba(237, 91, 91, .08); }
.badge.warn { color: var(--warn); border-color: rgba(240, 167, 58, .35); background: rgba(240, 167, 58, .08); }
.badge.blue { color: #8ec2ff; border-color: rgba(76, 154, 255, .35); background: rgba(76, 154, 255, .08); }

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px 14px;
}
.fact label { display: block; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 2px; }
.fact span { font-size: 13.5px; }
.fact .mono { font-variant-numeric: tabular-nums; }

.dev-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.rename { display: flex; gap: 6px; flex-wrap: wrap; }
.rename input {
  font: inherit;
  color: var(--text);
  background: #0d1219;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 5px 9px;
  min-width: 190px;
}

.empty { text-align: center; padding: 40px 10px; }

.foot {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 44px) 26px;
  font-size: 12px;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, .7);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}
.modal-card {
  width: min(760px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { overflow: auto; padding: 8px 18px 18px; }
.log-row { display: grid; grid-template-columns: 132px 62px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid #222e3b; font-size: 13px; }
.log-row:last-child { border-bottom: 0; }
.log-row time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.log-row .lvl { font-weight: 650; font-size: 11px; text-transform: uppercase; }
.log-row .lvl.info { color: var(--accent); }
.log-row .lvl.warn { color: var(--warn); }
.log-row .lvl.error { color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #22303f;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  font-size: 13px;
}

@media (max-width: 620px) {
  .top { padding: 12px 16px; }
  .top-actions #refresh-note { display: none; }
  .device { padding: 13px; }
  .dev-head { flex-direction: column; }
  .dev-actions { justify-content: flex-start; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .log-row { grid-template-columns: 1fr; gap: 2px; }
  .log-row time { font-size: 11px; }
}
