:root {
  --bg: #0b0e14;
  --bg2: #10141d;
  --panel: #141a26;
  --panel2: #1a2231;
  --border: #232d40;
  --text: #e6ecf5;
  --muted: #8b97ab;
  --accent: #22d3ee;
  --accent2: #0ea5e9;
  --green: #34d399;
  --red: #f87171;
  --orange: #fbbf24;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  padding: 20px 14px;
  gap: 8px;
}
.logo { display: flex; gap: 12px; align-items: center; padding: 6px 10px 18px; }
.logo-icon { font-size: 30px; }
.logo h1 { font-size: 20px; letter-spacing: .5px; }
.logo-sub { font-size: 11px; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; color: var(--muted);
  font-size: 14px; padding: 11px 12px; border-radius: 8px;
  cursor: pointer; text-align: left; transition: .15s;
}
.nav-btn:hover { background: var(--panel); color: var(--text); }
.nav-btn.active { background: linear-gradient(90deg, rgba(14,165,233,.18), rgba(34,211,238,.06)); color: var(--accent); border: 1px solid rgba(34,211,238,.3); }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; }
.pill {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; padding: 8px 10px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.pill.online .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.pill.online { color: var(--green); }

/* ---------- Content ---------- */
.content { margin-left: 240px; flex: 1; padding: 24px 32px; max-width: 1200px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.topbar h2 { font-size: 24px; }
.clock { color: var(--muted); font-size: 13px; }
.page { display: flex; flex-direction: column; gap: 18px; }
.hidden { display: none !important; }
.page-head p { color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 800px; }
.page-head { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card.full { width: 100%; }
.card-title { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.big-status { font-size: 26px; font-weight: 700; }
.big-status.on { color: var(--green); }
.big-status.off { color: var(--red); }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.device-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.device-holder { color: var(--muted); font-size: 13px; }
.device-item { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.device-item .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.device-item .v { font-size: 15px; font-weight: 600; margin-top: 4px; word-break: break-all; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); padding: 9px 16px;
  border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: .15s; display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: linear-gradient(90deg, var(--accent2), var(--accent)); color: #04121a; font-weight: 700; border: none; }
.btn.danger { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.4); color: var(--red); }
.btn.warn { background: rgba(251,191,36,.12); border-color: rgba(251,191,36,.4); color: var(--orange); }
.btn.ghost { background: none; border-color: var(--border); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Firmware / DB grid ---------- */
.fw-grid, .app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.fw-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 10px;
}
.fw-card .fw-head { display: flex; align-items: center; gap: 10px; }
.fw-card .fw-head .fw-icon { font-size: 28px; }
.fw-card h3 { font-size: 17px; }
.fw-ver { font-size: 12px; color: var(--accent); background: rgba(34,211,238,.1); border: 1px solid rgba(34,211,238,.3); padding: 2px 8px; border-radius: 20px; }
.fw-desc { font-size: 13px; color: var(--muted); line-height: 1.5; flex: 1; }
.fw-meta { font-size: 11px; color: var(--muted); }
.fw-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.fw-error { color: var(--red); font-size: 12px; }

/* ---------- Apps ---------- */
.search-box { display: flex; gap: 10px; }
.search-box input {
  flex: 1; background: var(--panel); border: 1px solid var(--border);
  color: var(--text); padding: 10px 14px; border-radius: 8px; font-size: 14px;
  max-width: 420px;
}
.app-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.app-card h4 { font-size: 15px; }
.app-card .app-meta { font-size: 12px; color: var(--muted); }
.app-card .app-desc { font-size: 12.5px; color: var(--muted); flex: 1; line-height: 1.5; }
.app-card .app-cat { font-size: 11px; color: var(--accent2); background: rgba(14,165,233,.1); padding: 2px 8px; border-radius: 20px; align-self: flex-start; }
.app-status { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; align-self: flex-start; margin-top: 2px; }
.app-status.uptodate { color: var(--green); background: rgba(52,211,153,.12); border: 1px solid rgba(52,211,153,.3); }
.app-status.update { color: var(--orange); background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.4); animation: pulse 1.6s ease-in-out infinite; }
.app-status.detected { color: var(--accent2); background: rgba(14,165,233,.1); border: 1px solid rgba(14,165,233,.3); }
.btn.update { background: linear-gradient(90deg, #f59e0b, var(--orange)); color: #1a1300; font-weight: 700; border: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .65; } }

/* ---------- Debug panel ---------- */
#dbg-panel {
  position: fixed; bottom: 0; right: 0; z-index: 80;
  width: 720px; max-width: 96vw; height: 340px;
  background: #0a0d13; border: 1px solid #22d3ee; border-radius: 10px 0 0 0;
  font-family: "Fira Code", "Cascadia Code", "Consolas", monospace;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
  display: none; flex-direction: column;
}
#dbg-panel.open { display: flex; }
#dbg-head { display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: #10141d; border-bottom: 1px solid var(--border); border-radius: 10px 0 0 0; }
#dbg-head b { color: var(--accent); font-size: 13px; }
#dbg-head span { display: flex; gap: 6px; }
#dbg-head .btn { padding: 4px 10px; font-size: 12px; }
#dbg-pre { margin: 0; flex: 1; overflow: auto; padding: 8px 12px;
  font-size: 11.5px; line-height: 1.5; color: #c8d3e6; white-space: pre-wrap; word-break: break-all; }
#dbg-toggle {
  position: fixed; bottom: 12px; right: 12px; z-index: 79;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--accent); cursor: pointer; font-size: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
#dbg-toggle:hover { border-color: var(--accent); }

/* ---------- Upload ---------- */
.upload-box { display: flex; align-items: center; gap: 14px; margin: 14px 0; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-width: 520px; }
.form-row label { font-size: 12.5px; color: var(--muted); }
.form-row input, .form-row select {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 8px; font-size: 14px;
}
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Settings ---------- */
.kv { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.kv-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 10px 14px; background: var(--panel2); border-radius: 8px; border: 1px solid var(--border); }
.kv-row span { color: var(--muted); font-size: 13px; }
.kv-row code { color: var(--accent); font-size: 13px; word-break: break-all; text-align: right; }
.code-block {
  background: #0a0d13; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; font-size: 13px; color: #a5f3fc; overflow-x: auto;
  line-height: 1.7; margin: 10px 0;
}
h3 { font-size: 15px; margin-top: 18px; }

/* ---------- Jobs ---------- */
.job-empty { color: var(--muted); font-size: 13px; }
.job-item { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel2); }
.job-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.job-label { font-weight: 600; font-size: 14px; }
.job-status { font-size: 11px; padding: 2px 10px; border-radius: 20px; }
.job-status.queued, .job-status.running { background: rgba(251,191,36,.12); color: var(--orange); }
.job-status.done { background: rgba(52,211,153,.12); color: var(--green); }
.job-status.error { background: rgba(248,113,113,.12); color: var(--red); }
.job-msg { font-size: 12.5px; color: var(--muted); margin-top: 6px; word-break: break-word; }
.job-bar { height: 5px; background: var(--border); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.job-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .4s; }

/* ---------- Modal / Toast ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 26px; max-width: 460px; width: 90%; }
.modal-box h3 { margin: 0 0 10px; }
.modal-box p { font-size: 14px; color: var(--text); line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 60;
  background: var(--panel2); border: 1px solid var(--accent2);
  color: var(--text); padding: 14px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 380px;
}
.toast.error { border-color: var(--red); }

/* ---------- Misc ---------- */
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.9s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .sidebar { position: static; width: 100%; }
  body { flex-direction: column; }
  .content { margin-left: 0; padding: 16px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; }
}
