:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #222632;
  --border: #2c3140;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --accent: #4f8cff;
  --on: #2ecc71;
  --off: #59607a;
  --warn: #f5a623;
  --danger: #ff5c5c;
  --radius: 14px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eceef3;
    --border: #d9dce5;
    --text: #151821;
    --muted: #616a80;
    --off: #a3a9b8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 0 calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 12px; }

.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--off); }
.conn.ok { background: var(--on); }
.conn.down { background: var(--danger); }

.banner {
  margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  font-size: 14px;
}

main { padding: 8px 16px; max-width: 720px; margin: 0 auto; }

/* ---- device grid */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.device {
  position: relative; width: 100%; min-height: 128px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between;
  padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: inherit; font: inherit; text-align: left;
  cursor: pointer; transition: transform .1s ease, border-color .2s;
}
.device:active { transform: scale(.97); }
.device .power {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px;
  background: var(--surface-2); color: var(--muted);
}
.device.online .power { background: color-mix(in srgb, var(--on) 22%, transparent); color: var(--on); }
.device.online { border-color: color-mix(in srgb, var(--on) 50%, var(--border)); }
.device.waking .power { color: var(--warn); animation: pulse 1s ease-in-out infinite; }
.device .name { font-weight: 600; margin-top: 12px; word-break: break-word; }
.device .meta { color: var(--muted); font-size: 12px; }
.device .tag {
  position: absolute; top: 12px; right: 12px; font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
}
@keyframes pulse { 50% { transform: scale(1.12); opacity: .6; } }

.empty { color: var(--muted); text-align: center; margin-top: 48px; }
.empty a { color: var(--accent); }

/* ---- forms & lists */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.form label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
.form label small { font-size: 12px; }
.form input:not([type=checkbox]) {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form .check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); }
.form .check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); }
details { margin-bottom: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: -4px 0 12px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.cmd { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 14px; color: var(--muted); }
pre {
  margin: 6px 0 0; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; white-space: pre-wrap; word-break: break-all; user-select: all;
}

.row { display: flex; gap: 8px; flex-wrap: wrap; }
button.primary, button.ghost, button.small {
  font: inherit; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
}
a.button { display: inline-block; text-decoration: none; }
a.button.ghost { color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 11px 18px; }
button.primary { background: var(--accent); color: #fff; padding: 11px 18px; font-weight: 600; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); padding: 11px 18px; }
button.small { background: var(--surface-2); color: var(--text); padding: 6px 10px; font-size: 14px; }
button.small.danger { color: var(--danger); }

.list { list-style: none; margin: 0 0 12px; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); margin-bottom: 8px;
}
.list li .info { flex: 1; min-width: 0; }
.list li .info div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .sub { color: var(--muted); font-size: 12px; }

/* ---- tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--border);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 20px; padding: 4px;
}
.tabs a span { font-size: 11px; }
.tabs a.active { color: var(--accent); }

/* ---- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
