/* ═══════════════════════════════════════════
   SwitchAR — Dark network aesthetic
   Palette: #0a0f1e (bg) | #0ff (cyan) | #0af (blue-cyan) | #f5a623 (warning) | #e74c3c (danger)
═══════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0f1e;
  --bg2: #0d1428;
  --bg3: #111b35;
  --surface: #162040;
  --surface2: #1e2d55;
  --border: rgba(0,255,255,0.15);
  --cyan: #0ff;
  --cyan-dim: rgba(0,255,255,0.6);
  --blue: #0af;
  --green: #00e676;
  --orange: #f5a623;
  --red: #e74c3c;
  --text: #d0e8ff;
  --text-dim: rgba(208,232,255,0.5);
  --radius: 10px;
  --nav-h: 64px;
  --header-h: 56px;
  font-size: 15px;
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── SPLASH ─────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.splash-inner { text-align: center; }
.splash-logo {
  margin: 0 auto 20px;
  animation: pulse-glow 2s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,100% { filter: drop-shadow(0 0 8px var(--cyan)); }
  50% { filter: drop-shadow(0 0 20px var(--cyan)); }
}
#splash h1 {
  font-size: 2.4rem; font-weight: 700; letter-spacing: .12em;
  color: var(--cyan); text-shadow: 0 0 20px var(--cyan);
}
#splash p { color: var(--text-dim); margin-top: 6px; letter-spacing: .05em; }
.splash-loader {
  margin: 28px auto 0;
  width: 180px; height: 2px;
  background: var(--surface);
  border-radius: 2px; overflow: hidden;
}
.splash-loader div {
  height: 100%; background: linear-gradient(90deg, transparent, var(--cyan));
  animation: loading 1.6s ease-in-out forwards;
}
@keyframes loading { from { width: 0; } to { width: 100%; } }

/* ── APP SHELL ───────────────────────────── */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ── NAVBAR ──────────────────────────────── */
#navbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; z-index: 100;
  backdrop-filter: blur(12px);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: .68rem;
  letter-spacing: .04em; text-transform: uppercase;
  transition: color .2s;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn svg { transition: filter .2s; }
.nav-btn.active { color: var(--cyan); }
.nav-btn.active svg { filter: drop-shadow(0 0 6px var(--cyan)); }

/* ── VIEWS ───────────────────────────────── */
.view {
  position: absolute; inset: 0; bottom: var(--nav-h);
  overflow-y: auto; overflow-x: hidden;
  display: none; flex-direction: column;
}
.view.active { display: flex; }

.view-header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.view-header h2 {
  font-size: 1rem; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text);
}

/* ── BUTTONS ─────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, #0066cc, #0099ff);
  color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: .82rem; font-weight: 600;
  cursor: pointer; letter-spacing: .04em;
  transition: opacity .2s, transform .1s;
  box-shadow: 0 2px 12px rgba(0,153,255,.35);
}
.btn-primary:active { transform: scale(.96); }
.btn-secondary {
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; font-size: .82rem; cursor: pointer;
  transition: background .2s;
}
.btn-secondary:active { background: var(--surface2); }
.btn-sm {
  padding: 6px 14px; font-size: .78rem; border-radius: 6px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  transition: background .2s;
}
.btn-sm:active { background: var(--cyan); color: var(--bg); }
.btn-danger { background: rgba(231,76,60,.15) !important; border-color: rgba(231,76,60,.4) !important; color: var(--red) !important; }

/* ── TREE VIEW ───────────────────────────── */
#tree-canvas-wrap {
  flex: 1; position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(0,100,200,.08) 0%, transparent 60%),
    var(--bg);
}
#tree-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#tree-nodes { position: absolute; inset: 0; pointer-events: none; }

.tree-node {
  position: absolute; pointer-events: all;
  display: flex; flex-direction: column; align-items: center;
  cursor: grab; transform: translate(-50%, -50%);
  -webkit-tap-highlight-color: transparent;
}
.tree-node:active { cursor: grabbing; }
.node-body {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 110px;
  display: flex; flex-direction: column; gap: 3px;
  box-shadow: 0 2px 20px rgba(0,0,0,.5);
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.node-body::before {
  content: '';
  position: absolute; top: 0; left: 50%;
  transform: translateX(-50%);
  width: 60%; height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  opacity: 0; transition: opacity .2s;
}
.tree-node:hover .node-body { border-color: var(--cyan-dim); box-shadow: 0 0 20px rgba(0,255,255,.12); }
.tree-node:hover .node-body::before { opacity: 1; }
.tree-node.selected .node-body { border-color: var(--cyan); box-shadow: 0 0 24px rgba(0,255,255,.2); }

.node-icon { font-size: 1.1rem; text-align: center; }
.node-name { font-size: .75rem; font-weight: 600; color: var(--text); text-align: center; }
.node-ip { font-size: .65rem; color: var(--cyan-dim); text-align: center; font-family: monospace; }
.node-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  margin: 2px auto 0;
}
.dot-online { background: var(--green); box-shadow: 0 0 6px var(--green); animation: blink 2s infinite; }
.dot-offline { background: var(--red); }
.dot-warning { background: var(--orange); box-shadow: 0 0 6px var(--orange); animation: blink 1s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.hint-bar {
  height: 28px; display: flex; align-items: center; justify-content: center;
  font-size: .65rem; color: var(--text-dim); letter-spacing: .04em;
  background: var(--bg2); border-top: 1px solid var(--border); flex-shrink: 0;
}

/* ── AR VIEW ─────────────────────────────── */
#view-ar { overflow: hidden; background: #000; }
.ar-overlay { position: relative; width: 100%; height: 100%; flex: 1; }
#ar-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: 1;
}
#ar-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 2;
}
#ar-hud { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 20px; }
.hud-top {
  align-self: stretch;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(10,15,30,.7); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px;
  backdrop-filter: blur(8px);
}
.hud-label { font-size: .65rem; font-weight: 700; letter-spacing: .15em; color: var(--cyan); }
#ar-status { font-size: .72rem; color: var(--text-dim); }

.scan-reticle {
  width: 220px; height: 220px;
  position: relative; flex-shrink: 0;
}
.corner {
  position: absolute; width: 24px; height: 24px;
  border-color: var(--cyan); border-style: solid;
  border-width: 0;
}
.corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 4px; }
.corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 4px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 4px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 4px; }
.scan-line {
  position: absolute; left: 8px; right: 8px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: scan 2s ease-in-out infinite;
  box-shadow: 0 0 8px var(--cyan);
}
@keyframes scan { 0% { top: 8px; } 50% { top: calc(100% - 10px); } 100% { top: 8px; } }

.hud-bottom { align-self: stretch; display: flex; justify-content: center; }
.btn-ar {
  background: rgba(0,255,255,.1);
  border: 1.5px solid var(--cyan);
  color: var(--cyan); border-radius: 40px;
  padding: 12px 28px; font-size: .85rem; font-weight: 600;
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  letter-spacing: .05em;
  box-shadow: 0 0 20px rgba(0,255,255,.2);
  transition: background .2s, box-shadow .2s;
}
.btn-ar:active { background: rgba(0,255,255,.25); }

#ar-info-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(10,15,30,.95);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 16px; backdrop-filter: blur(12px);
  animation: slide-up .3s ease;
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.ar-panel-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
#ar-device-name { font-size: 1.1rem; font-weight: 700; color: var(--cyan); flex: 1; }
.status-badge {
  font-size: .65rem; font-weight: 700; letter-spacing: .08em;
  padding: 3px 9px; border-radius: 20px; text-transform: uppercase;
}
.status-badge.online { background: rgba(0,230,118,.15); color: var(--green); border: 1px solid rgba(0,230,118,.3); }
.status-badge.offline { background: rgba(231,76,60,.15); color: var(--red); border: 1px solid rgba(231,76,60,.3); }
.status-badge.warning { background: rgba(245,166,35,.15); color: var(--orange); border: 1px solid rgba(245,166,35,.3); }
#ar-panel-close { background: none; border: none; color: var(--text-dim); font-size: 1.1rem; cursor: pointer; }

.ar-panel-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.ar-info-item { background: var(--surface); border-radius: 8px; padding: 10px; }
.ar-info-label { font-size: .62rem; color: var(--text-dim); letter-spacing: .05em; text-transform: uppercase; margin-bottom: 4px; }
.ar-info-value { font-size: .82rem; font-family: monospace; color: var(--text); }
.ar-panel-actions { display: flex; gap: 10px; }
.ar-panel-actions .btn-sm { flex: 1; text-align: center; }

/* ── DEVICES LIST ─────────────────────────── */
#device-search-wrap { padding: 12px 16px; flex-shrink: 0; }
#device-search {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 14px; color: var(--text); font-size: .85rem;
  outline: none; transition: border-color .2s;
}
#device-search:focus { border-color: var(--cyan); }

#devices-list { flex: 1; overflow-y: auto; padding: 0 16px 16px; display: flex; flex-direction: column; gap: 10px; }

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; align-items: flex-start; gap: 12px;
  cursor: pointer; transition: border-color .2s, transform .15s;
  position: relative; overflow: hidden;
}
.device-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--green);
  transition: background .3s;
}
.device-card.offline::before { background: var(--red); }
.device-card.warning::before { background: var(--orange); }
.device-card:active { transform: scale(.98); }
.device-card-icon {
  width: 38px; height: 38px; border-radius: 8px;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.device-card-body { flex: 1; min-width: 0; }
.device-card-name { font-size: .88rem; font-weight: 600; color: var(--text); }
.device-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.dc-tag {
  font-size: .65rem; font-family: monospace;
  padding: 2px 8px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--cyan-dim);
}
.device-card-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* ── QR VIEW ─────────────────────────────── */
#qr-list { flex: 1; overflow-y: auto; padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.qr-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: pointer; transition: border-color .2s;
}
.qr-card:active { border-color: var(--cyan); }
.qr-card canvas, .qr-card img { border-radius: 6px; display: block; }
.qr-thumb-wrap { line-height: 0; }
.qr-card-name { font-size: .72rem; font-weight: 600; color: var(--text); text-align: center; }
.qr-card-ip { font-size: .65rem; font-family: monospace; color: var(--cyan-dim); }

/* ── MODAL ───────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.75);
  display: flex; align-items: flex-end;
  backdrop-filter: blur(4px);
  animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-height: 90vh;
  background: var(--bg2);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slide-up .3s ease;
  overflow: hidden;
}
.modal-qr-view { max-height: 70vh; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; color: var(--text); }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 1.1rem; cursor: pointer; }
.modal-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-body.center { align-items: center; }
.modal-footer {
  display: flex; gap: 10px; padding: 14px 18px;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.modal-footer .btn-secondary, .modal-footer .btn-primary { flex: 1; text-align: center; }

/* ── FORM ────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group label { font-size: .72rem; color: var(--text-dim); letter-spacing: .05em; text-transform: uppercase; }
.form-group input, .form-group select, .form-group textarea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; color: var(--text); font-size: .85rem;
  outline: none; transition: border-color .2s; width: 100%;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--cyan); }
.form-group select { appearance: none; }
.form-group textarea { resize: none; font-family: inherit; }
.radio-group { display: flex; gap: 14px; }
.radio-opt { display: flex; align-items: center; gap: 6px; font-size: .82rem; cursor: pointer; color: var(--text); }
.radio-opt input { accent-color: var(--cyan); }

/* ── QR MODAL ────────────────────────────── */
.qr-subtitle { font-size: .75rem; color: var(--text-dim); text-align: center; }
.mt { margin-top: 8px; }
#qr-modal-canvas-wrap canvas { border-radius: 10px; padding: 10px; background: #fff; }

/* ── TOAST ───────────────────────────────── */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%;
  transform: translateX(-50%);
  background: var(--surface2); color: var(--text);
  padding: 10px 20px; border-radius: 24px; font-size: .82rem;
  border: 1px solid var(--border);
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
  z-index: 500; white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; }

/* ── AR MESH OVERLAY ─────────────────────── */
.ar-mesh-label {
  position: absolute;
  background: rgba(0,255,255,.12);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-size: .65rem; font-family: monospace;
  padding: 3px 7px; border-radius: 4px;
  pointer-events: none;
  animation: mesh-appear .3s ease;
  white-space: nowrap;
}
@keyframes mesh-appear { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: scale(1); } }

/* ── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── EMPTY STATE ─────────────────────────── */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  padding: 40px; text-align: center;
}
.empty-state svg { opacity: .3; }
.empty-state p { color: var(--text-dim); font-size: .85rem; line-height: 1.5; }

@media (min-width: 600px) {
  .modal { max-width: 520px; margin: 0 auto; border-radius: 16px; border: 1px solid var(--border); }
  .modal-backdrop { align-items: center; }
  #qr-list { grid-template-columns: repeat(3, 1fr); }
}
