:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d212b;
  --border: #272c38;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --gray: #4b5263;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* keep display rules from defeating the hidden attribute */

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 13px; }
.logo { width: 44px; height: auto; display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4)); }
.brand-text { display: flex; flex-direction: column; gap: 1px; }
h1 { font-size: 20px; margin: 0; font-weight: 800; letter-spacing: -0.2px; }
.wm-my { color: #79c83f; }
.wm-pk { color: #4f9bff; }
.tagline { font-size: 11px; font-style: italic; color: var(--muted); letter-spacing: 0.3px; }
h2 { font-size: 14px; margin: 0; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 16px; }
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); }
.conn.ok .dot { background: var(--green); }
.conn.err .dot { background: var(--red); }

main { padding: 24px; display: flex; flex-direction: column; gap: 24px; max-width: 1200px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 18px; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
tbody tr { border-top: 1px solid var(--border); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }
tbody tr.selected { background: var(--panel-2); }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--gray); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(52,211,153,0.15); }
.status-dot.idle { background: var(--amber); }
.status-dot.offline { background: var(--gray); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  background: var(--panel-2);
  font-size: 12px;
  text-transform: capitalize;
}

.chev { color: var(--muted); }
/* Bulk-select checkbox column. .chk-admin only shows for admins (body.is-admin). */
.chk { width: 30px; text-align: center; }
.chk input { cursor: pointer; }
.chk-admin { display: none; }
.is-admin .chk-admin { display: table-cell; }
.row-end { white-space: nowrap; text-align: right; }
.row-end .chev { margin-left: 6px; }
/* Delete device: admin-only, revealed by body.is-admin (see loadMe). */
.dev-del { display: none; padding: 2px 8px; font-size: 13px; line-height: 1; }
.is-admin .dev-del { display: inline-flex; }
.dev-del:hover { color: #ff8a8a; border-color: #5a2f2f; }
.empty { padding: 24px 18px; color: var(--muted); margin: 0; }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }
/* Destructive actions (Delete selected, ✕): red, and fill red on hover — matches the portal. */
button.ghost.danger, .ghost.danger { color: #ff8a8a; border-color: #5a2f2f; }
button.ghost.danger:hover, .ghost.danger:hover { color: #fff; background: #7a2b2b; border-color: #7a2b2b; }

code.data {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  max-width: 360px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

/* --- Auth pages (login / signup) --- */
.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2230, var(--bg));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  margin: 24px;
  padding: 28px 28px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.auth-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 18px; }
.auth-brand .logo { filter: drop-shadow(0 3px 8px rgba(0,0,0,0.5)); margin-bottom: 6px; }
.auth-brand h1 { font-size: 22px; }
.auth-title { text-align: center; font-size: 15px; color: var(--muted); font-weight: 500; margin: 0 0 16px; }
.auth-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fca5a5;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin: 0 0 14px;
}
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card .hint { color: var(--gray); font-size: 11px; }
.auth-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
}
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18); }
.auth-card button {
  margin-top: 4px;
  padding: 12px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, #4f9bff, #2f7fd1);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.auth-card button:disabled { opacity: 0.6; cursor: default; }
.auth-alt { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0 0; }
.auth-alt a { color: var(--accent); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }

/* --- Device provisioning + blocking (node dashboard) --- */
.panel-actions { display: flex; align-items: center; gap: 14px; }
.small { font-size: 11px; }
.search {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 6px 11px; font-size: 12px; min-width: 190px;
}
.search:focus { outline: none; border-color: var(--accent); }
td .del { padding: 3px 10px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; }
.pager button:disabled { opacity: 0.4; cursor: default; }

/* Activity panel: stat tiles, 24h volume chart, breakdown bars */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; padding: 16px 18px; }
.tile { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.tile-n { font-size: 24px; font-weight: 800; }
.tile-l { color: var(--muted); font-size: 12px; margin-top: 3px; }
.tile.warn { border-color: #7a3b3b; }
.tile.warn .tile-n { color: #ff8a8a; }
/* A tile that opens a drill-down dialog. */
.tile-btn { text-align: left; cursor: pointer; font: inherit; color: var(--text); transition: border-color .12s ease, transform .12s ease; }
.tile-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.dialog-head h3 { margin: 0; }
.wide-dialog { max-width: 640px; width: 92vw; }
.ai-table-wrap { max-height: 60vh; overflow-y: auto; margin-top: 10px; }
.ai-table { width: 100%; border-collapse: collapse; }
.ai-table th { position: sticky; top: 0; background: var(--panel); }
.ai-table td { font-size: 12px; }
.chart-block { padding: 4px 18px 12px; }
.chart-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.legend { text-transform: none; letter-spacing: 0; font-size: 11px; display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.lg-q { background: var(--accent); }
.lg-b { background: #ff8a8a; }
.volume-chart { width: 100%; height: 150px; display: block; }
.area-q { fill: rgba(79, 140, 255, 0.20); stroke: none; }
.line-q { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.line-b { fill: none; stroke: #ff8a8a; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-x { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }
.breakdowns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 8px 18px 18px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 10px; font-size: 12px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.bar-track { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); }
.bar-val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 720px) { .breakdowns { grid-template-columns: 1fr; } }

button.primary {
  background: linear-gradient(135deg, #4f9bff, #2f7fd1);
  border: 0;
  color: #fff;
  border-radius: 7px;
  padding: 6px 13px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:hover { filter: brightness(1.07); }

/* Blocking toggle switch */
.switch { position: relative; display: inline-block; width: 38px; height: 21px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--gray); transition: background 0.15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 15px; width: 15px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform 0.15s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(17px); }
.block-cell { text-align: center; }
.org-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; max-width: 160px;
}
.org-select:focus { outline: none; border-color: var(--accent); }

/* Domain-activity pills */
.pill.cat { background: rgba(79,140,255,0.16); color: #9cc2ff; }
.pill.blocked { background: rgba(248,113,113,0.16); color: #fca5a5; }
.pill.allowed { background: rgba(52,211,153,0.14); color: #6ee7b7; }
.pill.alert { background: rgba(248,113,113,0.18); color: #fca5a5; font-weight: 600; }
.badge.alert { background: rgba(248,113,113,0.18); color: #fca5a5; margin-left: 6px; }

/* Provisioning panel */
.provision { display: flex; gap: 26px; padding: 18px; flex-wrap: wrap; }
.provision-qr { text-align: center; }
.provision-qr img { background: #fff; border-radius: 10px; padding: 8px; }
.provision-info { flex: 1; min-width: 280px; }
.provision-info label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 5px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px;
}
.steps { margin: 12px 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.steps strong { color: var(--text); }

/* Dialogs (add device, add domain, category rule, override) */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px; width: 340px;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog form h3 { margin: 0 0 14px; }
dialog form label { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 5px; }
dialog form input, dialog form select {
  width: 100%; box-sizing: border-box; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 14px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
