:root {
  --bg: #0f172a;
  --surface: #111827;
  --panel: #1f2937;
  --border: #273549;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #60a5fa;
  --primary-dark: #2563eb;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at 20% 20%, rgba(96, 165, 250, 0.07), transparent 40%),
    radial-gradient(circle at 80% 10%, rgba(16, 185, 129, 0.07), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(120deg, rgba(37, 99, 235, 0.08), rgba(15, 23, 42, 0.95));
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, #2563eb, #60a5fa);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #0b1221;
  box-shadow: var(--shadow);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-weight: 700;
  letter-spacing: 0.4px;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-icon {
  width: 22px;
  height: 22px;
  vertical-align: -4px;
  margin-right: 4px;
  opacity: 0.7;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav a:hover {
  background: rgba(96, 165, 250, 0.1);
  color: var(--primary);
}

.nav a:hover .nav-icon {
  opacity: 1;
}

.logout-form button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.logout-form button:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.08);
}

.user-pill {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(96, 165, 250, 0.12);
}

.user-name {
  font-weight: 600;
}

.user-id {
  color: var(--muted);
  font-size: 12px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 6px 0;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 8px 0;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.card {
  background: linear-gradient(145deg, rgba(31, 41, 55, 0.9), rgba(15, 23, 42, 0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
}

.device-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.meta dt {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta dd {
  margin: 0;
  font-weight: 600;
}

.status-badge {
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.5px;
  border: 1px solid var(--border);
}

.status-badge.online {
  background: rgba(74, 222, 128, 0.15);
  color: #bbf7d0;
  border-color: rgba(74, 222, 128, 0.4);
}

.status-badge.offline {
  background: rgba(248, 113, 113, 0.15);
  color: #fecdd3;
  border-color: rgba(248, 113, 113, 0.4);
}

.status-badge.degraded {
  background: rgba(251, 191, 36, 0.15);
  color: #fef3c7;
  border-color: rgba(251, 191, 36, 0.4);
}

.actions {
  margin-top: auto;
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.primary-btn {
  background: linear-gradient(120deg, var(--primary-dark), var(--primary));
  color: #0b1221;
  border: none;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.primary-btn:hover,
.secondary-btn:hover,
.logout-form button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

input,
textarea {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 15px;
}

.auth-card {
  max-width: 460px;
  margin: 60px auto;
  padding: 28px;
  background: linear-gradient(160deg, rgba(31, 41, 55, 0.9), rgba(37, 99, 235, 0.08));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-weight: 600;
}

.alert-error {
  background: rgba(248, 113, 113, 0.18);
  color: #fecdd3;
  border-color: rgba(248, 113, 113, 0.4);
}

.alert-success {
  background: rgba(74, 222, 128, 0.18);
  color: #bbf7d0;
  border-color: rgba(74, 222, 128, 0.4);
}

.table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: rgba(255, 255, 255, 0.03);
}

th,
td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form input {
  width: 100%;
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--border);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.value {
  font-weight: 700;
  font-size: 16px;
}

.pill-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.table-wrapper input,
.inline-form input,
.form input {
  background: rgba(255, 255, 255, 0.02);
}

.code-block {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
    monospace;
  font-size: 13px;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.control-btn {
  border: 1px solid var(--border);
  background: rgba(96, 165, 250, 0.08);
  color: var(--text);
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  cursor: default;
}

.control-label {
  display: block;
  font-weight: 700;
}

.control-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.indicators {
  margin-top: 16px;
}

.indicator-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.indicator-title {
  font-weight: 600;
}

.log-list {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  max-height: 260px;
  overflow-y: auto;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
}

.log-item {
  padding: 4px 0;
  border-bottom: 1px solid rgba(226, 232, 240, 0.08);
  word-break: break-all;
}

.log-item:last-child {
  border-bottom: none;
}

.log-item.error {
  color: #fca5a5;
}

.code-chip {
  display: inline-block;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 12px;
  margin-top: 6px;
}

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}

.toggle-btn {
  background: transparent;
  border: none;
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.toggle-btn.active {
  background: rgba(96, 165, 250, 0.15);
  color: var(--text);
}

.view-panel {
  margin-top: 10px;
}

.gatt-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.gatt-column h3 {
  margin: 0 0 4px 0;
}

.gatt-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.inline-form select {
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.pagination {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.gatt-scroll {
  max-height: 220px;
  overflow: auto;
}

.layout-select {
  min-width: 260px;
  padding: 12px 14px;
  font-size: 15px;
  min-height: 44px;
  line-height: 1.4;
}

.layout-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
@media (max-width: 720px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .nav {
    gap: 10px;
  }

  .nav a,
  .logout-form button {
    padding: 8px 10px;
  }
}
