:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #1f2937;
  --card: #ffffff;
  --line: rgba(255,255,255,0.08);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.14);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.26);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, Arial, sans-serif; background: linear-gradient(180deg, #0b1120, #111827); color: var(--text); min-height: 100%; }
button, input, select { font: inherit; }
button { cursor: pointer; border: none; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; }

.sidebar {
  background: rgba(17, 24, 39, 0.92);
  border-right: 1px solid var(--line);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 1.2rem; margin: 0; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .92rem; }
.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
  box-shadow: var(--shadow);
}

.nav { display: flex; flex-direction: column; gap: 10px; }
.nav-item {
  text-align: left;
  background: transparent;
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  transition: .18s ease;
}
.nav-item:hover, .nav-item.active {
  background: var(--primary-soft);
  color: #dbeafe;
}

.sidebar-footer { margin-top: auto; }

.main { padding: 28px; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 22px;
}
.topbar h2 { margin: 0; font-size: 1.8rem; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.user-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.primary-btn, .secondary-btn, .ghost-btn {
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 600;
  transition: .2s ease;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 28px rgba(37,99,235,.25); }
.secondary-btn { background: rgba(255,255,255,.08); color: white; border: 1px solid var(--line); }
.ghost-btn { background: transparent; color: var(--text); border: 1px solid var(--line); width: 100%; }

.auth-layout { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.auth-card {
  width: min(560px, 100%);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.tabs { display: flex; gap: 8px; background: rgba(255,255,255,.03); padding: 8px; border-radius: 18px; margin-bottom: 20px; }
.tab-btn { flex: 1; background: transparent; color: var(--muted); padding: 12px 14px; border-radius: 14px; }
.tab-btn.active { background: white; color: #111827; font-weight: 700; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stack-form { display: grid; gap: 12px; }
.stack-form.compact { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.stack-form input, .stack-form select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: white;
  padding: 14px 16px;
  border-radius: 14px;
  outline: none;
}
.stack-form input::placeholder { color: #cbd5e1; }

.message {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  display: none;
}
.message.show { display: block; }
.message.success { background: rgba(16,185,129,.14); color: #d1fae5; border: 1px solid rgba(16,185,129,.2); }
.message.error { background: rgba(239,68,68,.14); color: #fee2e2; border: 1px solid rgba(239,68,68,.2); }
.message.info { background: rgba(37,99,235,.14); color: #dbeafe; border: 1px solid rgba(37,99,235,.2); }

.stats-grid, .cards-grid, .device-grid, .two-col-grid {
  display: grid;
  gap: 16px;
}
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.two-col-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card, .stat-card {
  background: rgba(255,255,255,.96);
  color: #111827;
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3, .stat-card h3 { margin: 0 0 8px; }
.card p, .stat-card p { margin: 4px 0; color: #475569; }

.stat-card .value {
  font-size: 2rem;
  font-weight: 800;
  color: #0f172a;
}
.stat-card .label {
  color: #64748b;
  font-size: .95rem;
}

.card-header, .row-between {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: .84rem;
  font-weight: 700;
}
.badge.online { background: rgba(16,185,129,.12); color: var(--success); }
.badge.offline { background: rgba(239,68,68,.12); color: var(--danger); }
.badge.pending { background: rgba(245,158,11,.12); color: var(--warning); }
.badge.active { background: rgba(37,99,235,.12); color: var(--primary); }

.inline-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 24px 0 14px;
}
.section-title h3 { margin: 0; font-size: 1.2rem; color: white; }
.section-title p { margin: 4px 0 0; color: var(--muted); }

.list-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255,255,255,.96);
  color: #111827;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.list-table th, .list-table td { padding: 14px 16px; text-align: left; border-bottom: 1px solid rgba(15,23,42,.08); }
.list-table th { color: #475569; font-size: .92rem; background: rgba(15,23,42,.03); }
.list-table tr:last-child td { border-bottom: none; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15,23,42,.04);
}
.toggle input { accent-color: var(--primary); }

.empty-state {
  padding: 28px;
  border-radius: 24px;
  border: 1px dashed var(--line);
  text-align: center;
  color: var(--muted);
}

.toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  gap: 12px;
  z-index: 9999;
}
.toast {
  min-width: 280px;
  max-width: 380px;
  background: #111827;
  color: white;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.toast strong { display: block; margin-bottom: 6px; }

@media (max-width: 1180px) {
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .cards-grid, .device-grid, .two-col-grid, .stats-grid { grid-template-columns: 1fr; }
  .main { padding: 18px; }
  .list-table { display: block; overflow-x: auto; }
}