:root {
  --bg: #0b1020;
  --bg-elevated: #121a2f;
  --bg-card: #151e36;
  --bg-card-hover: #1a2542;
  --border: rgba(148, 163, 184, 0.14);
  --text: #e8eefc;
  --muted: #93a0bd;
  --accent: #5b8cff;
  --accent-2: #35d0ba;
  --online: #22c55e;
  --offline: #f43f5e;
  --warn: #f59e0b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(91, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(53, 208, 186, 0.12), transparent 55%),
    var(--bg);
  min-height: 100%;
}

.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent), var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}
.brand.compact { margin-bottom: 0; }
.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.35rem;
  color: white;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(91, 140, 255, 0.35);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}
.field.row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.field input[type="password"],
.field input[type="text"],
.toolbar input,
.toolbar select {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  outline: none;
}
.field input:focus,
.toolbar input:focus,
.toolbar select:focus {
  border-color: rgba(91, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.15);
}

.btn {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn.primary {
  width: 100%;
  border: none;
  background: linear-gradient(135deg, var(--accent), #4f74ff);
  color: white;
  padding: 12px 16px;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 10px; font-size: 0.85rem; border-radius: 10px; }
.btn.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  font-size: 1.25rem;
  line-height: 1;
}

.error { color: #fda4af; min-height: 1.2em; font-size: 0.9rem; }

.dash-view { min-height: 100vh; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 32, 0.72);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}
.pill strong { color: var(--text); font-weight: 600; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.online { background: var(--online); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15); }
.dot.offline { background: var(--offline); }

main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr 180px auto;
  gap: 12px;
  margin-bottom: 18px;
  align-items: center;
}
@media (max-width: 800px) {
  .toolbar { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; }
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

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

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), transparent 40%), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  transition: 0.15s ease;
}
.card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(91, 140, 255, 0.28);
  transform: translateY(-1px);
}

.preview {
  position: relative;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(135deg, rgba(91,140,255,0.08), rgba(53,208,186,0.05)),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 8px, transparent 8px 16px);
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: zoom-in;
}
.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.preview .placeholder {
  text-align: center;
  color: var(--muted);
  padding: 16px;
  font-size: 0.9rem;
}
.preview .placeholder code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: #c7d2fe;
}
.badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  backdrop-filter: blur(8px);
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.08);
}
.badge.online { color: #bbf7d0; }
.badge.offline { color: #fecdd3; }

.model-chip {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #e0e7ff;
  background: rgba(79, 70, 229, 0.55);
  border: 1px solid rgba(165, 180, 252, 0.35);
  backdrop-filter: blur(8px);
  z-index: 2;
}
.model-line {
  color: #a5b4fc !important;
  font-family: var(--sans) !important;
  font-size: 0.82rem !important;
  margin-top: 2px !important;
}

.card-body { padding: 14px 16px 16px; }
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}
.card-head h3 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.card-head .meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 12px 0 14px;
}
.metric {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}
.metric .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 4px;
}
.metric .value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.metric .bar {
  margin-top: 8px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.metric .bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}
.metric.warn .bar > span { background: linear-gradient(90deg, var(--warn), #ef4444); }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty h2 { color: var(--text); margin-bottom: 8px; }

dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: calc(100vw - 32px);
}
dialog::backdrop {
  background: rgba(3, 6, 16, 0.72);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(520px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-card.wide { width: min(960px, 100%); }
.modal-card header,
.modal-card footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-card footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; }
.modal-card h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 16px; }
.modal-body pre {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.modal-body p { color: var(--muted); margin: 0 0 12px; font-size: 0.92rem; }
.preview-frame {
  background: #000;
  min-height: 240px;
  display: grid;
  place-items: center;
}
.preview-frame img {
  max-width: 100%;
  max-height: min(70vh, 720px);
  display: block;
}

.copy-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.copy-row input {
  flex: 1;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 0.82rem;
}
