/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f1117;
  --surface:    #1a1d2e;
  --surface2:   #222640;
  --border:     #2e3255;
  --primary:    #4f8ef7;
  --primary-dk: #3a72d8;
  --danger:     #e25c6a;
  --danger-dk:  #c0404e;
  --success:    #3ecf8e;
  --warning:    #f5a623;
  --text:       #e6e8f0;
  --text-muted: #8488a8;
  --radius:     10px;
  --sidebar-w:  220px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 10;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 1.25rem 1.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.logo-icon { font-size: 1.2rem; }

.nav-links { list-style: none; }

.nav-item {
  padding: .65rem 1.25rem;
  cursor: pointer;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-right: .75rem;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }

/* ── Main ─────────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { font-size: 1.1rem; font-weight: 600; }

.topbar-actions { display: flex; gap: .75rem; }

/* ── Views ────────────────────────────────────────────────── */
.view { display: none; padding: 2rem; }
.view.active { display: block; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* ── Device Grid ──────────────────────────────────────────── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color .2s;
}

.device-card:hover { border-color: var(--primary); }

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}

.device-name { font-weight: 600; font-size: 1rem; }

.device-meta {
  display: grid;
  row-gap: .35rem;
  margin-bottom: 1rem;
  font-size: .8rem;
}

.device-meta div { display: flex; gap: .5rem; }
.device-meta label {
  color: var(--text-muted);
  min-width: 80px;
  flex-shrink: 0;
}

.device-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .2rem .55rem;
  border-radius: 999px;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.badge-green  { background: rgba(62,207,142,.15); color: var(--success); border: 1px solid rgba(62,207,142,.3); }
.badge-yellow { background: rgba(245,166,35,.15);  color: var(--warning); border: 1px solid rgba(245,166,35,.3); }
.badge-red    { background: rgba(226,92,106,.15);  color: var(--danger);  border: 1px solid rgba(226,92,106,.3); }
.badge-grey   { background: rgba(132,136,168,.15); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  padding: .5rem 1rem;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dk); }

.btn-secondary { background: var(--surface2);  color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-danger    { background: var(--danger);    color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dk); }

.btn-small { padding: .35rem .7rem; font-size: .78rem; }
.btn-wide  { width: 100%; padding: .7rem; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  margin-bottom: .35rem;
  color: var(--text-muted);
  font-size: .82rem;
}

.input-full {
  width: 100%;
  padding: .55rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .85rem;
}

.input-small {
  width: 80px;
  padding: .45rem .6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: .85rem;
}

.input-full:focus, .input-small:focus {
  outline: none;
  border-color: var(--primary);
}

hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Result box ───────────────────────────────────────────── */
.result-box {
  margin-top: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 1rem;
  font-size: .78rem;
  color: var(--success);
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 400px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-small { width: 380px; text-align: center; }
.modal-small p { margin: .75rem 0 1.5rem; color: var(--text-muted); }

.modal-close {
  position: absolute;
  top: .75rem; right: .75rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-actions { display: flex; gap: .75rem; justify-content: center; }

.modal-content h2 { margin-bottom: 1.25rem; font-size: 1.1rem; }

/* ── QR Code ──────────────────────────────────────────────── */
.qr-container { text-align: center; margin-top: 1.5rem; }
.qr-container img {
  max-width: 280px;
  border-radius: 8px;
  border: 3px solid var(--border);
  background: white;
  padding: 8px;
  margin: .75rem auto;
  display: block;
}

.qr-info {
  font-size: .8rem;
  color: var(--text-muted);
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .75rem;
  margin: .75rem 0;
}

.qr-info p { margin: .3rem 0; }

.hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: .75rem;
  line-height: 1.5;
}

/* ── Misc ─────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.loading { color: var(--text-muted); padding: 2rem; text-align: center; }
.error   { color: var(--danger);   padding: 2rem; text-align: center; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state p  { margin-bottom: 1rem; font-size: 1rem; }

.mono {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: .8rem;
}

.truncate {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}

/* ── Toast notifications ──────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 200;
  animation: slideUp .25s ease;
  max-width: 340px;
}

.toast-success { background: var(--success);  color: #0a2e1f; }
.toast-error   { background: var(--danger);   color: #fff; }
.toast-info    { background: var(--primary);  color: #fff; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
}
