@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500&display=swap');

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --bg-0: #05080f;
  --bg-1: #0a1018;
  --bg-2: #111a24;
  --bg-3: #182230;
  --bg-glass: rgba(17, 26, 36, 0.85);
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #10b981;
  --accent-2: #06b6d4;
  --accent-hover: #34d399;
  --accent-glow: rgba(16, 185, 129, 0.25);
  --gradient-brand: linear-gradient(135deg, #10b981, #06b6d4);
  --danger: #f87171;
  --warning: #fbbf24;
  --sidebar-w: 300px;
  --topbar-h: 60px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(6, 182, 212, 0.08), transparent),
    radial-gradient(ellipse 50% 40% at 0% 100%, rgba(16, 185, 129, 0.06), transparent),
    var(--bg-0);
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  border: 2px solid var(--border-strong);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.brand h1 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand p {
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 2px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-bottom: 14px;
  transition: color var(--transition);
}

.home-link:hover { color: var(--accent); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--gradient-brand);
  color: #fff;
  width: 100%;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.08);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.1);
}

.btn-sm { padding: 6px 10px; font-size: 0.8rem; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.session-list::-webkit-scrollbar { width: 6px; }
.session-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}

.session-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 6px;
  transition: var(--transition);
  font-family: inherit;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.session-item.active {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.35);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}

.status-dot.connected { background: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.status-dot.connecting,
.status-dot.pairing,
.status-dot.reconnecting { background: var(--warning); animation: pulse 1.5s infinite; }
.status-dot.disconnected,
.status-dot.logged_out { background: var(--text-dim); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.session-meta strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.session-meta span {
  color: var(--text-dim);
  font-size: 0.76rem;
  line-height: 1.3;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.5;
}

/* Main area */
.main-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
}

.topbar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.topbar-title span { color: var(--text); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
}

.health-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

.main {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  text-align: center;
  gap: 16px;
}

.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.2);
  display: grid;
  place-items: center;
  font-size: 2rem;
}

.empty-state h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.panel-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.panel-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg-2);
  text-transform: capitalize;
}

.badge.connected { color: var(--accent); border-color: rgba(16, 185, 129, 0.35); background: rgba(16, 185, 129, 0.08); }
.badge.pairing,
.badge.connecting,
.badge.reconnecting { color: var(--warning); border-color: rgba(251, 191, 36, 0.35); }
.badge.disconnected,
.badge.logged_out { color: var(--text-dim); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.stat-card label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.stat-card strong {
  font-size: 0.95rem;
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.card {
  background: linear-gradient(180deg, rgba(24, 34, 48, 0.6), rgba(17, 26, 36, 0.8));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}

.card h3 {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card h3::before {
  content: '';
  width: 4px;
  height: 14px;
  border-radius: 2px;
  background: var(--gradient-brand);
}

.field { margin-bottom: 14px; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="url"],
input[type="tel"],
input[type="password"],
textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; padding-bottom: 0; }

.toggle-info strong {
  display: block;
  margin-bottom: 3px;
  font-size: 0.9rem;
}

.toggle-info span {
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.4;
}

.switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition);
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: var(--transition);
}

.switch input:checked + .slider {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(22px);
  background: var(--accent);
}

.pairing-box {
  background: rgba(16, 185, 129, 0.06);
  border: 1px dashed rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-top: 14px;
}

.pairing-code {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--accent);
  margin: 12px 0;
  font-family: var(--font-mono);
}

.status-message {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
  margin-top: 8px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.whitelist-input {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.whitelist-input input { flex: 1; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 8px 5px 12px;
  font-size: 0.82rem;
}

.hint {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-top: 5px;
  line-height: 1.45;
}

.session-id {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  word-break: break-all;
  margin-top: 4px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--bg-2);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(12px);
  transition: var(--transition);
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  font-weight: 500;
  font-size: 0.9rem;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Auth modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 300;
  padding: 24px;
}

.modal-overlay[hidden] { display: none; }

.modal {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.modal h2 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.modal p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal .btn-primary { margin-top: 12px; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 150;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.4);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-toggle { display: grid; place-items: center; }

  .grid, .stats-row { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .main { padding: 16px; }
  .topbar { padding: 0 16px; }
}
