/* Dark Winbox-inspired palette — mirrors the Android app's colors.xml */
:root {
  --bg-primary: #0D1117;
  --bg-surface: #161B27;
  --bg-tile: #1C2333;
  --bg-tile-pressed: #243049;
  --accent: #00BFFF;
  --accent-dim: #1A4A66;
  --online: #00E676;
  --offline: #FF3D3D;
  --unknown: #607D8B;
  --text: #E8EDF5;
  --text-2: #8A9BB5;
  --hint: #4A5568;
  --divider: #1E2D42;
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg-primary);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--text-2); }
button { font: inherit; color: inherit; cursor: pointer; }
input {
  font: inherit; color: var(--text);
  background: var(--bg-primary);
  border: 1px solid var(--divider);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  margin-top: 4px;
}
input:focus { outline: none; border-color: var(--accent); }
label { display: block; color: var(--text-2); font-size: 12px; margin-bottom: 12px; }

.btn {
  background: var(--bg-tile); border: 1px solid var(--divider);
  border-radius: 8px; padding: 10px 16px; font-weight: 600;
}
.btn:hover { background: var(--bg-tile-pressed); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #001018; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--offline); border-color: #5a1f25; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); padding: 4px 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg-tile); border: 1px solid var(--divider);
  font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: var(--bg-tile-pressed); }
.form-error { color: var(--offline); min-height: 1em; margin: 4px 0 10px; font-size: 13px; }
.form-ok { color: var(--online); margin: 0 0 10px; font-size: 13px; }
.form-ok:empty, .form-error:empty { display: none; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; margin: 0; }
.brand.small { font-weight: 700; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); box-shadow: 0 0 10px var(--online);
}

/* ---------- Auth ---------- */
.auth {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #13233a 0%, var(--bg-primary) 60%);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-surface); border: 1px solid var(--divider);
  border-radius: 14px; padding: 28px 24px;
}
.auth-card .muted { margin: 6px 0 20px; }
.auth-card .btn { width: 100%; }
.auth-links { display: flex; justify-content: space-between; margin-top: 14px; }

/* ---------- App shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--bg-surface);
  border-bottom: 1px solid var(--divider); z-index: 5;
}
.counts { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.pill {
  border-radius: 999px; padding: 3px 10px; font-size: 12px;
  border: 1px solid var(--divider); color: var(--text-2);
}
.pill b { font-family: var(--mono); }
.pill.online b { color: var(--online); }
.pill.offline b { color: var(--offline); }
.pill.stale b { color: var(--unknown); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-email { font-size: 12px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner {
  background: #3a2a08; color: #ffcf66; border-bottom: 1px solid #5c440f;
  padding: 8px 16px; font-size: 13px; text-align: center; z-index: 4;
}

/* ---------- Canvas (Dude-style) ---------- */
.canvas {
  position: relative; flex: 1; overflow: hidden;
  touch-action: none; cursor: grab;
  background-color: var(--bg-primary);
  background-image: radial-gradient(circle, rgba(0,191,255,.18) 1px, transparent 1.5px);
}
.canvas.panning { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

.empty {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; gap: 12px; color: var(--text-2);
}

/* Device tile. Laid out in CSS px, then scaled by --d so one tile covers the
   same number of world units as on the phone (world units = phone pixels). */
.tile {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  min-width: 150px;
  background: var(--bg-tile);
  border: 2px solid var(--unknown);
  border-radius: 10px;
  padding: 6px 10px 8px;
  user-select: none; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  transition: box-shadow .2s, background .2s;
}
.tile:hover { background: var(--bg-tile-pressed); }
.tile.dragging { cursor: grabbing; box-shadow: 0 10px 30px rgba(0,0,0,.6); z-index: 10; }
.tile .strip {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .06em;
  padding-bottom: 5px; border-bottom: 1px solid var(--unknown);
}
.tile .strip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--unknown); }
.tile .strip .dur { margin-left: auto; font-family: var(--mono); font-weight: 500; color: var(--text-2); }
.tile .name { font-size: 16px; font-weight: 800; margin-top: 6px; white-space: nowrap; }
.tile .addr {
  font-family: var(--mono); font-weight: 700; font-size: 12px;
  color: var(--online); text-shadow: 0 0 6px rgba(0,230,118,.55);
  white-space: nowrap;
}
.tile .ms { text-align: right; font-family: var(--mono); font-size: 11px; color: var(--accent); min-height: 1em; }

.tile.online { border-color: var(--online); }
.tile.online .strip { color: var(--online); border-color: var(--online); }
.tile.online .strip .dot { background: var(--online); box-shadow: 0 0 6px var(--online); }
.tile.offline { border-color: var(--offline); }
.tile.offline .strip { color: var(--offline); border-color: var(--offline); }
.tile.offline .strip .dot { background: var(--offline); box-shadow: 0 0 6px var(--offline); }
.tile.offline .addr { color: var(--offline); text-shadow: 0 0 6px rgba(255,61,61,.5); }
.tile.stale { border-color: var(--unknown); opacity: .75; }
.tile.stale .strip { color: var(--unknown); border-color: var(--unknown); }
.tile.stale .strip .dot { background: var(--unknown); box-shadow: none; }
.tile.stale .addr { color: var(--text-2); text-shadow: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(0,230,118,.8); }
  100% { box-shadow: 0 0 0 18px rgba(0,230,118,0); }
}
.tile.pulse { animation: pulse 1s ease-out 2; }

.canvas-tools {
  position: fixed; left: 16px; bottom: 16px;
  display: flex; gap: 6px; z-index: 5;
}
.fab-row {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; align-items: center; gap: 12px; z-index: 5;
}
.version { font-family: var(--mono); font-size: 11px; color: var(--hint); }
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--accent); color: #001018; font-size: 28px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,191,255,.35);
}
.fab:hover { filter: brightness(1.1); }

/* ---------- Detail slide-over ---------- */
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%);
  background: var(--bg-surface); border-left: 1px solid var(--divider);
  z-index: 20; overflow-y: auto; padding: 16px 18px 24px;
  box-shadow: -10px 0 40px rgba(0,0,0,.5);
  animation: slideIn .18s ease-out;
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-head h2 { margin: 0; font-size: 20px; }
.detail .ip { margin: 2px 0 0; font-family: var(--mono); color: var(--online); }
.detail h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 20px 0 8px; }

.status-strip {
  display: flex; align-items: center; gap: 8px; margin: 14px 0;
  padding: 10px 12px; border-radius: 8px; background: var(--bg-tile);
  border: 1px solid var(--unknown); font-weight: 700;
}
.status-strip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--unknown); }
.status-strip .since { margin-left: auto; font-family: var(--mono); font-weight: 500; color: var(--text-2); }
.status-strip.online { border-color: var(--online); color: var(--online); }
.status-strip.online .dot { background: var(--online); }
.status-strip.offline { border-color: var(--offline); color: var(--offline); }
.status-strip.offline .dot { background: var(--offline); }
.status-strip.stale { color: var(--unknown); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--bg-tile); border-radius: 8px; padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat span { font-size: 11px; color: var(--text-2); }
.stat b { font-family: var(--mono); font-size: 15px; }

.chart-head { display: flex; justify-content: space-between; align-items: center; }
.chart-wrap { position: relative; }
#chart {
  width: 100%; height: 200px; display: block;
  background: var(--bg-primary); border-radius: 8px; cursor: grab; touch-action: pan-y;
}
.chart-hint { font-size: 11px; margin: 4px 0 0; text-align: right; }

.events { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.events li {
  display: flex; gap: 10px; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--divider); font-size: 13px;
}
.events li .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.events li .t { margin-left: auto; font-family: var(--mono); color: var(--text-2); font-size: 12px; }
.events .none { color: var(--text-2); }

.detail-actions { display: flex; gap: 10px; margin-top: 20px; }
.detail-actions .btn { flex: 1; }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; background: var(--bg-primary); border: 1px solid var(--divider); border-radius: 8px; padding: 2px; }
.seg button {
  border: 0; background: none; padding: 5px 12px; border-radius: 6px;
  color: var(--text-2); font-size: 13px;
}
.seg button.on { background: var(--accent-dim); color: var(--text); }

/* ---------- Dialog ---------- */
dialog {
  width: min(420px, calc(100% - 32px));
  background: var(--bg-surface); color: var(--text);
  border: 1px solid var(--divider); border-radius: 14px; padding: 22px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog .row { display: flex; gap: 10px; }
dialog .grow { flex: 1; }
dialog .port { width: 96px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { color: var(--text-2); font-size: 12px; margin-bottom: 6px; padding: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Menu + toast ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 140px;
  background: var(--bg-surface); border: 1px solid var(--divider);
  border-radius: 8px; padding: 4px; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 12px; border-radius: 6px; }
.menu button:hover { background: var(--bg-tile-pressed); }
.menu .danger { color: var(--offline); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--bg-tile); border: 1px solid var(--divider);
  padding: 10px 16px; border-radius: 8px; z-index: 40; max-width: calc(100% - 32px);
}
.toast.error { border-color: var(--offline); color: var(--offline); }

@media (max-width: 640px) {
  .user-email, .version { display: none; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .brand.small span:last-child { display: none; }
}

/* ============================================================ BILLING / TEAMS */
.small { font-size: 12px; }
.center { text-align: center; }
.trial-note { margin: 16px 0 0; }
.legal-links { margin-top: 0; font-size: 12px; color: var(--text-2); text-align: center; }
.legal-links a { color: var(--text-2); }

.loading { height: 100%; display: grid; place-content: center; justify-items: center; gap: 12px; }
.loading .brand-dot { animation: pulse 1.2s ease-out infinite; }

.ctx-select {
  background: var(--bg-tile); color: var(--text); border: 1px solid var(--divider);
  border-radius: 8px; padding: 7px 8px; font: inherit; font-size: 13px; max-width: 220px;
}
.role-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent); border: 1px solid var(--accent-dim); border-radius: 6px; padding: 3px 7px;
}
.plan-badge {
  background: var(--bg-tile); border: 1px solid var(--divider); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; color: var(--text-2);
}
.plan-badge:hover { border-color: var(--accent); color: var(--text); }
.plan-badge.warn { color: #ffcf66; border-color: #5c440f; }

.menu-wrap { position: relative; }
.account-menu { position: absolute; right: 0; top: 44px; min-width: 200px; }
.menu-email { padding: 8px 12px 10px; font-size: 12px; color: var(--text-2); border-bottom: 1px solid var(--divider); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; }
.banner a, .banner button.link { color: inherit; text-decoration: underline; font-weight: 700; }
.banner.info { background: #0f2a3d; color: #9fdcff; border-color: var(--accent-dim); }

.paywall { flex: 1; overflow-y: auto; padding: 32px 16px; }
.paywall-box { max-width: 900px; margin: 0 auto; text-align: center; }
.paywall-box h2 { margin: 0 0 8px; font-size: 24px; }
.paywall-box > .muted { margin: 0 0 24px; }

/* Sheet (billing / team / admin) */
.sheet {
  position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.6);
  display: grid; place-items: start center; overflow-y: auto; padding: 40px 16px;
}
.sheet-card {
  width: min(920px, 100%); background: var(--bg-surface); border: 1px solid var(--divider);
  border-radius: 14px; padding: 20px 22px 26px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 24px 0 10px; }
.note { background: var(--bg-tile); border-radius: 8px; padding: 12px 14px; }
.note.warn { color: #ffcf66; border: 1px solid #5c440f; background: #2a2008; }

.billing-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cycle-toggle { justify-content: center; margin-bottom: 14px; }
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.plan {
  position: relative; background: var(--bg-tile); border: 1px solid var(--divider);
  border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 4px;
}
.plan.popular { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.plan .tag {
  position: absolute; top: -10px; right: 14px; background: var(--accent); color: #001018;
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 10px;
}
.plan h3 { margin: 0; font-size: 16px; color: var(--text); text-transform: none; letter-spacing: 0; }
.plan .price { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }
.plan .price span { font-size: 14px; font-weight: 500; color: var(--text-2); }
.plan p { margin: 0; }
.plan .btn { margin-top: 14px; }
.seat-box { margin-top: 8px; }
.seat-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seat-row b { font-family: var(--mono); font-size: 18px; min-width: 24px; text-align: center; }
.portal-row { margin-top: 24px; }

.seats-used { color: var(--text-2); }
.invite-row { display: flex; gap: 8px; margin: 12px 0 16px; flex-wrap: wrap; }
.invite-row input { flex: 1; min-width: 200px; margin: 0; }
.invite-row select, .people select {
  background: var(--bg-primary); color: var(--text); border: 1px solid var(--divider);
  border-radius: 8px; padding: 8px; font: inherit;
}
.people { list-style: none; padding: 0; margin: 0; }
.people li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--divider); }
.people .who { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.link.danger { color: var(--offline); }

.admin-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.admin-tools input { margin: 0; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; color: var(--text-2); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--divider); white-space: nowrap; }
.admin-table td { padding: 8px; border-bottom: 1px solid var(--divider); white-space: nowrap; }
.badge { border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.badge.ok { color: var(--online); background: rgba(0,230,118,.1); }
.badge.bad { color: var(--offline); background: rgba(255,61,61,.1); }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--hint); border-radius: 999px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--online); }
.switch input:checked + span::before { transform: translateX(16px); }

.read-only .fab, .read-only #emptyAddBtn { display: none; }

@media (max-width: 760px) {
  .plans, .billing-summary { grid-template-columns: 1fr 1fr; }
  .plans { grid-template-columns: 1fr; }
  .ctx-select { max-width: 130px; }
  .plan-badge { display: none; }
}
