:root {
  --bg: #f4f5f2; --surface: #ffffff; --surface-2: #eceee8; --text: #1b1f1a; --muted: #5f675c;
  --border: #d6dad1; --accent: #2f6d3a; --accent-text: #ffffff; --danger: #b3261e; --ok: #2e8540; --off: #9aa197;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512; --surface: #1b1f1b; --surface-2: #232823; --text: #e6e9e3; --muted: #9ba396;
    --border: #2f352e; --accent: #5fb36d; --accent-text: #0d140e; --danger: #f2817a; --ok: #6cc77b; --off: #5b6258;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

.btn { display: inline-flex; align-items: center; gap: .4em; border: 1px solid var(--border); background: var(--surface);
  padding: .5em .9em; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
input[type=text], input[type=password], input[type=search] {
  width: 100%; padding: .6em .75em; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
input:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- logowanie ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.login { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 1.35rem; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
.login .btn { width: 100%; justify-content: center; margin-top: 20px; padding: .7em; }
.error { color: var(--danger); font-size: .9rem; margin-top: 12px; min-height: 1.2em; }

/* ---------- panel ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; letter-spacing: .01em; }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: .9rem; }
main.panel { max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 340px; }
.counts { color: var(--muted); font-size: .9rem; }
.devices { display: grid; gap: 10px; }
.device { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.device .name { font-weight: 600; }
.device .meta { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.device .meta code { font-size: .85em; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- podglad ---------- */
body.viewer { display: flex; flex-direction: column; overflow: hidden; background: #0b0d0b; }
.vbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.vbar .title { font-weight: 600; margin-right: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.status { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
#screen { flex: 1; min-height: 0; position: relative; }
#screen > div:not(.overlay) { background: #0b0d0b !important; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 5; background: rgba(8,10,8,.72); }
.overlay .card { padding: 24px; max-width: 380px; width: 100%; text-align: center; }
.overlay .card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.overlay .card p { margin: 0 0 16px; color: var(--muted); }
.overlay .card input { margin-bottom: 12px; }
.overlay .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.badge-view { font-size: .8rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }

@media (max-width: 560px) {
  .device { grid-template-columns: auto 1fr; }
  .device .btn { grid-column: 1 / -1; justify-content: center; }
  .vbar .title { max-width: 100%; flex-basis: 100%; }
}
