/* =========================================================
   Browser Monitor — responsive control center
   ========================================================= */

:root {
  --bg: #0a0e1a;
  --bg-elev: #0f1424;
  --surface: #141a2e;
  --surface-2: #1b2238;
  --surface-3: #232c47;
  --border: #232b45;
  --border-2: #2e3759;
  --text: #eaeefb;
  --text-dim: #9aa6c7;
  --text-mute: #6b76a0;
  --accent: #6c8cff;
  --accent-2: #a56bff;
  --accent-grad: linear-gradient(135deg, #6c8cff, #a56bff);
  --green: #3ddc85;
  --amber: #ffbb4d;
  --red: #ff6b7d;
  --r: 14px;
  --r-sm: 10px;
  --r-xs: 8px;
  --sidebar-w: 236px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  overflow-x: hidden; /* safety net against any stray horizontal overflow */
}
img,
svg,
pre,
textarea,
input,
select {
  max-width: 100%;
}
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14.5px;
  line-height: 1.45;
}
h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}
p {
  margin: 0;
}
button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}
code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
.hint {
  color: var(--text-mute);
}
.sm {
  font-size: 12.5px;
}
.hidden {
  display: none !important;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- sidebar (desktop) ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 16px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  font-size: 19px;
  box-shadow: 0 5px 16px rgba(108, 140, 255, 0.4);
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-text strong {
  font-size: 14.5px;
}
.brand-text span {
  font-size: 11.5px;
  color: var(--text-mute);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 550;
  transition: background 0.14s, color 0.14s;
  text-align: left;
}
.nav-item:hover {
  background: var(--surface);
  color: var(--text);
}
.nav-item.active {
  background: var(--surface-2);
  color: var(--text);
}
.nav-item.active .ic {
  color: var(--accent);
}
.nav-item .ic {
  width: 19px;
  height: 19px;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
}
.server-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.server-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
}
.server-pill.online .dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

/* ---------- main ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: rgba(10, 14, 26, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.device-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.device-switch select {
  min-width: 180px;
  max-width: 320px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 650;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-mute);
  white-space: nowrap;
}
.chip.on {
  color: var(--green);
  border-color: rgba(61, 220, 133, 0.3);
}
.chip.off {
  color: var(--red);
}

.content {
  padding: 24px;
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  row-gap: 8px;
}
.card-head h3 {
  font-size: 14.5px;
}
.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}
/* let grid/flex children shrink below their content width (prevents overflow) */
.grid-2 > *,
.stack > * {
  min-width: 0;
}
.card,
.card-head > h3 {
  min-width: 0;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ---------- stats ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.stat span {
  font-size: 11.5px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat strong {
  font-size: 22px;
  font-weight: 650;
}

/* ---------- buttons ---------- */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--r-sm);
  font-weight: 600;
  transition: transform 0.08s, filter 0.14s, background 0.14s;
}
button:active {
  transform: scale(0.97);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* icons */
.ic {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.primary-btn,
.ghost-btn,
.danger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
}
.icon-btn:hover {
  background: var(--surface-3);
}

/* clear keyboard focus (accessibility) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus:not(:focus-visible) {
  outline: none;
}
.primary-btn {
  background: var(--accent-grad);
  color: #fff;
  padding: 10px 16px;
}
.primary-btn:hover {
  filter: brightness(1.07);
}
.primary-btn.sm,
.ghost-btn.sm,
.danger-btn.sm {
  padding: 7px 12px;
  font-size: 12.5px;
}
.ghost-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  padding: 9px 14px;
}
.ghost-btn:hover {
  background: var(--surface-3);
}
.danger-btn {
  background: rgba(255, 107, 125, 0.14);
  color: var(--red);
  border: 1px solid rgba(255, 107, 125, 0.32);
  padding: 10px 16px;
}
.danger-btn:hover {
  background: rgba(255, 107, 125, 0.22);
}
.btn-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

/* ---------- inputs ---------- */
input,
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  outline: none;
  transition: border 0.14s;
  width: 100%;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-mute);
}
textarea {
  resize: vertical;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}
.full-input {
  width: 100%;
}
.field-row {
  display: flex;
  gap: 8px;
}
.field-row.wrap {
  flex-wrap: wrap;
}
.field-row.end {
  justify-content: flex-end;
}
.field-row input,
.field-row select {
  flex: 1;
  min-width: 120px;
}
.field-row button {
  flex-shrink: 0;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
.switch-sm {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
}
.switch-sm input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- monitor ---------- */
.monitor-stage {
  position: relative;
  background: #05070f;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  min-height: 200px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.monitor-stage img {
  width: 100%;
  display: block;
}
.monitor-stage img:not([src]),
.monitor-stage img[src=""] {
  display: none;
}
.monitor-stage .hint {
  padding: 28px 18px;
  text-align: center;
}

/* ---------- lists ---------- */
.list {
  display: flex;
  flex-direction: column;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
}
.row:first-child {
  border-top: none;
}
.row .favicon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--surface-2);
  flex-shrink: 0;
  object-fit: contain;
}
.row-main {
  flex: 1;
  min-width: 0;
}
.row-title {
  font-size: 14px;
  font-weight: 550;
}
.row-sub {
  font-size: 12px;
  color: var(--text-mute);
}
.row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.mini {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
}
.mini.danger {
  color: var(--red);
  border-color: rgba(255, 107, 125, 0.3);
}
.badge {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-mute);
}
.badge.live {
  background: rgba(61, 220, 133, 0.16);
  color: var(--green);
}

/* ---------- subnav ---------- */
.subnav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.sub-btn {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 15px;
  font-size: 13px;
  border-radius: var(--r-sm);
}
.sub-btn.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
}

/* ---------- output ---------- */
.output {
  margin: 0;
  background: #05070f;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 13px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: #c5cef0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow: auto;
}

/* ---------- capability tag + list ---------- */
.cap-tag {
  font-size: 10.5px;
  font-weight: 650;
  padding: 2px 8px;
  border-radius: 999px;
}
.cap-tag.on {
  background: rgba(61, 220, 133, 0.16);
  color: var(--green);
}
.cap-tag.off {
  background: rgba(255, 187, 77, 0.16);
  color: var(--amber);
}
.cap-list {
  display: flex;
  flex-direction: column;
}
.cap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.cap-row:first-child {
  border-top: none;
}
.cap-row .cap-name {
  font-size: 13.5px;
  font-weight: 550;
}
.cap-row .cap-desc {
  font-size: 12px;
  color: var(--text-mute);
}
.cap-row.risk .cap-name::after {
  content: "sensitive";
  margin-left: 8px;
  font-size: 9.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 187, 77, 0.16);
  color: var(--amber);
  vertical-align: middle;
  font-weight: 700;
}
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 999px;
  transition: 0.18s;
}
.slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.18s;
}
.switch input:checked + .slider {
  background: var(--accent-grad);
  border-color: transparent;
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
}

/* ---------- checkboxes ---------- */
.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

/* ---------- devices ---------- */
.device-card {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.device-card + .device-card {
  margin-top: 10px;
}
.device-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.state {
  font-size: 11px;
  font-weight: 650;
  padding: 4px 10px;
  border-radius: 999px;
}
.state.online {
  background: rgba(61, 220, 133, 0.16);
  color: var(--green);
}
.state.offline {
  background: rgba(255, 107, 125, 0.14);
  color: var(--red);
}
.state.revoked {
  background: var(--surface-3);
  color: var(--text-mute);
}
.device-meta {
  font-size: 12.5px;
  color: var(--text-mute);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.device-actions {
  display: flex;
  gap: 8px;
}

/* ---------- empty ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 30px;
  color: var(--accent);
}

/* ---------- bottom nav (mobile) ---------- */
.bottomnav {
  display: none;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 15, 0.72);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 430px;
  background: var(--bg-elev);
  border: 1px solid var(--border-2);
  border-radius: var(--r);
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  box-shadow: var(--shadow);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  background: none;
  color: var(--text-mute);
  font-size: 22px;
}
.eyebrow {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}
.pair-code {
  font-size: 36px;
  letter-spacing: 7px;
  font-weight: 700;
  text-align: center;
  padding: 16px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px dashed var(--border-2);
}
.steps {
  margin: 4px 0 0;
  padding-left: 20px;
  color: var(--text-mute);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  z-index: 80;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.error {
  border-color: var(--red);
  color: #ffd7dd;
}

/* =========================================================
   Responsive — phone / tablet
   ========================================================= */
@media (max-width: 899px) {
  .sidebar {
    display: none;
  }
  .topbar {
    padding: calc(12px + var(--safe-t)) 16px 12px;
  }
  .content {
    padding: 16px;
    padding-bottom: calc(84px + var(--safe-b));
    gap: 14px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .stat-row {
    grid-template-columns: 1fr 1fr;
  }
  .check-grid {
    grid-template-columns: 1fr 1fr;
  }
  .device-switch select {
    min-width: 0;
    flex: 1;
  }
  .topbar {
    gap: 8px;
  }

  .bottomnav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 7px 4px calc(7px + var(--safe-b));
    background: rgba(9, 12, 24, 0.92);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
  }
  .bn-item {
    background: none;
    border: none;
    color: var(--text-mute);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 0;
    font-size: 10.5px;
    font-weight: 600;
    border-radius: 10px;
  }
  .bn-item .ic {
    width: 20px;
    height: 20px;
  }
  .bn-item.active {
    color: var(--text);
    background: var(--surface);
  }
  .bn-item.active .ic {
    color: var(--accent);
  }
  .bn-item:active {
    transform: none;
  }
}

/* big screens: let grid breathe a touch more */
@media (min-width: 1280px) {
  .content {
    max-width: 1240px;
  }
}

/* =========================================================
   Login page
   ========================================================= */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, #1b2350 0%, transparent 55%),
    var(--bg);
}
.login-container {
  width: 100%;
  max-width: 400px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.login-brand h1 {
  font-size: 22px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-brand p {
  color: var(--text-mute);
  font-size: 13.5px;
  margin-top: 6px;
}
#loginForm {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#loginForm label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
  font-weight: 550;
}
.login-button {
  margin-top: 20px;
  padding: 12px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 15px;
}
.login-error {
  margin-top: 14px;
  padding: 10px 13px;
  border-radius: var(--r-sm);
  background: rgba(255, 107, 125, 0.12);
  border: 1px solid rgba(255, 107, 125, 0.3);
  color: #ffd7dd;
  font-size: 13px;
  text-align: center;
}

/* =========================================================
   Polish — skeletons, motion, affordances
   ========================================================= */

/* loading skeleton rows */
.skeleton {
  display: flex;
  flex-direction: column;
}
.sk-row {
  height: 44px;
  border-top: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.sk-row:first-child {
  border-top: none;
}
.sk-row::after {
  content: "";
  position: absolute;
  inset: 11px 0;
  border-radius: 7px;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  width: 70%;
}
.sk-row:nth-child(2n)::after {
  width: 85%;
}
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* capability tag doubles as a quick enable toggle when off */
.cap-tag[data-cap] {
  cursor: pointer;
  user-select: none;
}
.cap-tag.off::after {
  content: " · enable";
  opacity: 0.8;
}

/* gentle view transition */
.view:not(.hidden) {
  animation: fade-in 0.18s ease;
}
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* toast neutral (loading) variant */
.toast.info {
  border-color: var(--border-2);
}

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