:root {
  --bg: #0b0d12;
  --panel: #151922;
  --card: #1b2030;
  --line: #262d40;
  --text: #e7ecf5;
  --muted: #97a1b8;
  --accent: #0a84ff;
  --accent2: #5e5ce6;
  --warn: #ff9f0a;
  --danger: #ff453a;
  --ok: #30d158;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 800px at 70% -10%, #1a2030 0%, var(--bg) 55%);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.7); backdrop-filter: blur(8px);
}
.brand { font-weight: 600; letter-spacing: 0.2px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; color: var(--muted); background: var(--card);
  border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px;
}
.pill.ok { color: var(--ok); border-color: #1f4d33; }
.pill.bad { color: var(--danger); border-color: #5a2230; }

.stage {
  flex: 1; display: flex; gap: 26px; padding: 26px; overflow: auto;
  align-items: flex-start; justify-content: center;
}

/* ---------- Device ---------- */
.device-wrap { display: flex; justify-content: center; }
.device { position: relative; padding: 0; }
.bezel {
  position: relative;
  background: linear-gradient(#0a0a0c, #16181d);
  border: 2px solid #2a2d36;
  border-radius: 54px;
  padding: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 0 2px #000, 0 0 0 6px #07080b;
}
.screen {
  position: relative;
  width: min(46vh, 420px);
  aspect-ratio: 393 / 852;
  background: #000;
  border-radius: 42px;
  overflow: hidden;
  outline: none;
  cursor: crosshair;
  touch-action: none;
}
.screen canvas, .screen video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: fill; display: block; background: #000;
}
#video { display: none; }
.island {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  width: 34%; height: 26px; background: #000; border-radius: 16px; z-index: 5;
  pointer-events: none;
}
.home-indicator {
  position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%);
  width: 34%; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.5); z-index: 6;
  pointer-events: none;
}
.overlay {
  position: absolute; inset: 0; z-index: 7; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(0,0,0,0.72); color: var(--muted); font-size: 13px; text-align: center; padding: 20px;
}
.overlay.show { display: flex; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* side buttons */
.side {
  position: absolute; border: none; padding: 0; cursor: pointer;
  background: #23262e; border-radius: 3px; z-index: 2;
}
.side:active { background: var(--accent); }
.btn-power { right: -4px; top: 190px; width: 4px; height: 86px; }
.btn-volup { left: -4px; top: 150px; width: 4px; height: 54px; }
.btn-voldn { left: -4px; top: 214px; width: 4px; height: 54px; }

/* ---------- Panel ---------- */
.panel { width: 340px; min-width: 300px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.row { display: flex; gap: 8px; margin-bottom: 10px; }
.row input { flex: 1; }
input[type=text] {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 9px 11px; font-size: 13px; outline: none;
}
input[type=text]:focus { border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

button {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 10px; font-size: 13px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
button:hover { border-color: #3a425a; background: #20263a; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.warn { color: var(--warn); border-color: #5a4420; }
button.danger { color: var(--danger); border-color: #5a2230; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.status { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.status dt { color: var(--muted); }
.status dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.notes { margin-top: 10px; font-size: 12px; color: var(--muted); }
.notes summary { cursor: pointer; }
.notes ul { margin: 8px 0 0; padding-left: 16px; }
.notes li { margin-bottom: 4px; }

.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.hint b { color: var(--text); }

.log {
  font-size: 12px; color: var(--muted); min-height: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Auth header (sign-out) ---------- */
.auth-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 12px;
}
.auth-user {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.auth-role {
  font-size: 11px;
  color: var(--accent);
  background: rgba(10,132,255,0.12);
  border-radius: 6px;
  padding: 1px 6px;
}
.auth-signout {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
}

@media (max-width: 820px) {
  .stage { flex-direction: column; align-items: center; }
  .panel { width: min(420px, 92vw); }
}

/* ---------- Account card ---------- */
.account-identity {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}
.account-identity strong {
  color: var(--text);
}
.account-section {
  margin-bottom: 14px;
}
.account-section-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 8px;
}
.account-section-header--admin {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.account-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  align-self: center;
}
.account-select {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
.account-select:focus { border-color: var(--accent); }
.account-refresh-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 0 4px;
  cursor: pointer;
  line-height: 1;
}
.account-refresh-btn:hover { color: var(--text); }

/* Invite result */
.invite-result {
  margin-top: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.invite-code {
  font-size: 22px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--ok);
  text-align: center;
}
.invite-expiry {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.invite-link-row {
  display: flex;
  gap: 6px;
}
.invite-link-input {
  flex: 1;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 7px;
  color: var(--muted);
  cursor: text;
  user-select: all;
}

/* Users table */
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.users-table th {
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  padding: 4px 6px 6px;
  border-bottom: 1px solid var(--line);
}
.users-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.users-table tr:last-child td { border-bottom: none; }
.users-table .user-actions { display: flex; gap: 4px; justify-content: flex-end; }
.users-table .user-actions button {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
}
.role-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.role-badge--admin {
  color: var(--accent);
  background: rgba(10,132,255,0.12);
}
.role-badge--user {
  color: var(--muted);
  background: rgba(150,160,180,0.1);
}
#users-table-wrap {
  overflow-x: auto;
}

/* ---------- Push Capture card ---------- */
#push-capture-results { display: flex; flex-direction: column; gap: 6px; }
.pc-entry {
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font-size: 12px;
}
.pc-entry--click { border-color: #2a3a50; }
.pc-entry-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.pc-ts { color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.pc-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--ok); background: rgba(48,209,88,0.1); border-radius: 5px; padding: 1px 5px; flex-shrink: 0;
}
.pc-label--click { color: var(--accent); background: rgba(10,132,255,0.1); }
.pc-title { color: var(--text); font-weight: 500; }
.pc-body { color: var(--muted); }
.pc-shows { margin-top: 4px; color: var(--muted); font-size: 11px; }
.pc-action { color: var(--accent2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

/* ---------- Mobile (phones) ---------- */
@media (max-width: 680px) {
  /* Let the whole page scroll naturally instead of an inner scroll area,
     and size the device by WIDTH so it doesn't swallow the viewport. */
  .app { height: auto; min-height: 100dvh; }
  .topbar { padding: 10px 12px; flex-wrap: wrap; row-gap: 8px; }
  .brand { white-space: nowrap; font-size: 15px; }
  .pills { width: 100%; justify-content: flex-start; gap: 6px; }
  .pill { font-size: 11px; padding: 3px 8px; }
  .stage { overflow: visible; padding: 12px 10px 28px; gap: 16px; }
  .bezel {
    padding: 9px; border-radius: 38px;
    box-shadow: 0 14px 40px rgba(0,0,0,0.5), inset 0 0 2px #000, 0 0 0 4px #07080b;
  }
  .screen { width: min(74vw, 300px); border-radius: 28px; }
  .island { top: 15px; height: 17px; }
  .home-indicator { bottom: 7px; }
  .panel { width: 100%; max-width: 480px; min-width: 0; }
  .auth-header { margin-left: 0; }
  /* roomier tap targets */
  button { padding: 11px 12px; }
  .users-table .user-actions button { padding: 6px 10px; }
}
