:root {
  --bg:#0f1115; --panel:#171a21; --panel2:#1e222b; --line:#272c37; --text:#e6e8ee; --muted:#8b93a3;
  --accent:#efbe49; --accent-text:#1a1400; --ok:#3ddc84; --bad:#ff5d5d; --warn:#ffb547;
  --radius:12px; --sidebar:224px;
}
* { box-sizing:border-box; }
html { color-scheme:dark; }
body { margin:0; background:var(--bg); color:var(--text); font:15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing:antialiased; }
a { color:inherit; text-decoration:none; }
h1 { font-size:24px; font-weight:700; margin:0; letter-spacing:-0.01em; }
h2 { font-size:13px; font-weight:600; text-transform:uppercase; letter-spacing:0.08em; color:var(--muted); margin:0 0 14px; }
p { margin:0 0 8px; }
.muted { color:var(--muted); }
.error { color:var(--bad); }

/* shell */
.shell { display:grid; grid-template-columns:var(--sidebar) 1fr; min-height:100vh; }
.sidebar { position:sticky; top:0; height:100vh; padding:20px 14px; background:var(--panel); border-right:1px solid var(--line); display:flex; flex-direction:column; gap:6px; }
.sidebar .logo { display:block; padding:6px 10px 22px; }
.sidebar .logo img { width:150px; display:block; }
.sidebar nav a, .sidebar .logout button { display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px; color:var(--muted); font-weight:500; width:100%; background:none; border:0; font:inherit; cursor:pointer; text-align:left; }
.sidebar nav a:hover, .sidebar .logout button:hover { background:var(--panel2); color:var(--text); }
.sidebar nav a.active { background:var(--panel2); color:var(--accent); }
.sidebar svg { width:18px; height:18px; flex:none; }
.sidebar .spacer { flex:1; }
.sidebar .who { padding:8px 12px; font-size:13px; color:var(--muted); }
.sidebar .who b { display:block; color:var(--text); font-size:14px; }
.topbar, .tabbar { display:none; }
.main { padding:28px 32px 40px; max-width:1200px; width:100%; min-width:0; overflow-x:hidden; }
.page-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:20px; flex-wrap:wrap; }
.page-head .sub { color:var(--muted); font-size:14px; margin-top:4px; }
.back { color:var(--muted); font-size:14px; display:inline-flex; align-items:center; gap:6px; margin-bottom:10px; }
.back:hover { color:var(--text); }

/* cards */
.card { min-width:0; overflow-wrap:anywhere; background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:18px; margin-bottom:16px; }
.card.danger { border-color:rgba(255,93,93,.35); }
.card.danger h2 { color:var(--bad); }
.grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.grid > * { min-width:0; }
.stats { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; margin-bottom:20px; }
.stat { background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:16px 18px; }
.stat .label { font-size:12px; text-transform:uppercase; letter-spacing:.08em; color:var(--muted); }
.stat .num { font-size:32px; font-weight:700; line-height:1.2; margin-top:4px; }
.stat.ok .num { color:var(--ok); }
.stat.bad .num { color:var(--bad); }

/* device tiles */
.tiles { display:grid; grid-template-columns:repeat(auto-fill, minmax(260px, 1fr)); gap:12px; }
.tile { display:block; background:var(--panel); border:1px solid var(--line); border-radius:var(--radius); padding:16px; transition:border-color .15s, transform .15s; }
.tile:hover { border-color:var(--accent); transform:translateY(-1px); }
.tile .name { display:flex; align-items:center; gap:10px; font-weight:600; font-size:16px; }
.tile .addr { color:var(--muted); margin-top:4px; min-height:1.4em; }
.tile .meta { display:flex; gap:12px; flex-wrap:wrap; margin-top:12px; font-size:13px; color:var(--muted); }
.tile .meta span { display:inline-flex; align-items:center; gap:5px; }
.tile.off { opacity:.75; }
.dot { width:10px; height:10px; border-radius:50%; background:var(--bad); flex:none; box-shadow:0 0 0 3px rgba(255,93,93,.15); }
.dot.on { background:var(--ok); box-shadow:0 0 0 3px rgba(61,220,132,.18); }
.badge { display:inline-flex; align-items:center; gap:6px; padding:3px 10px; border-radius:999px; font-size:12px; font-weight:600; background:rgba(255,93,93,.15); color:var(--bad); vertical-align:middle; }
.badge.on { background:rgba(61,220,132,.15); color:var(--ok); }
.badge .dot { width:7px; height:7px; box-shadow:none; }
.empty { color:var(--muted); padding:30px; text-align:center; }

/* levels */
.level { display:grid; grid-template-columns:110px 1fr 44px; align-items:center; gap:10px; margin:9px 0; }
.level .bar { height:10px; background:var(--panel2); border-radius:6px; overflow:hidden; }
.level .bar span { display:block; height:100%; border-radius:6px; background:var(--ok); transition:width .3s; }
.level .bar span.warn { background:var(--warn); }
.level .bar span.low { background:var(--bad); min-width:4px; }
.level .val { text-align:right; font-variant-numeric:tabular-nums; font-weight:600; }
.kv { display:flex; justify-content:space-between; gap:12px; padding:8px 0; border-bottom:1px solid var(--line); }
.kv:last-of-type { border-bottom:0; }
.kv .k { color:var(--muted); flex:none; }
.kv .v { text-align:right; min-width:0; }

/* forms */
label { display:block; margin-bottom:12px; font-size:13px; color:var(--muted); }
label input, label select { margin-top:5px; }
input[type=text], input[type=search], input[type=password], input[type=number], select {
  width:100%; padding:10px 12px; background:var(--panel2); border:1px solid var(--line); border-radius:9px;
  color:var(--text); font:inherit; min-height:42px; outline:none;
}
input:focus, select:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(239,190,73,.18); }
input::placeholder { color:#5c6474; }
.row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.row input[type=number] { width:100px; }
.row input[type=text], .row input[type=password], .row select { width:auto; flex:1; min-width:120px; }
.row .lbl { width:110px; flex:none; }
form.inline { display:inline; }
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px; min-height:42px; padding:9px 16px;
  background:var(--accent); color:var(--accent-text); border:1px solid transparent; border-radius:9px;
  font:inherit; font-weight:600; cursor:pointer; white-space:nowrap; transition:filter .15s, background .15s;
}
.btn:hover { filter:brightness(1.08); }
.btn-secondary { background:var(--panel2); color:var(--text); border-color:var(--line); }
.btn-secondary:hover { border-color:var(--muted); }
.btn-danger { background:transparent; color:var(--bad); border-color:rgba(255,93,93,.5); }
.btn-danger:hover { background:rgba(255,93,93,.12); }
.btn-warn { background:transparent; color:var(--warn); border-color:rgba(255,181,71,.5); }
.btn-warn:hover { background:rgba(255,181,71,.12); }
.btn-block { width:100%; }
.actions-row { display:flex; flex-wrap:wrap; gap:8px; }
.flash { background:rgba(239,190,73,.12); border:1px solid rgba(239,190,73,.35); color:var(--accent); border-radius:10px; padding:10px 14px; margin-bottom:16px; }
.flash p { margin:0; }

/* tables */
.table-wrap { overflow-x:auto; }
table { width:100%; border-collapse:collapse; font-size:14px; }
th, td { text-align:left; padding:10px 12px; border-bottom:1px solid var(--line); vertical-align:middle; white-space:nowrap; }
th { color:var(--muted); font-weight:600; font-size:12px; text-transform:uppercase; letter-spacing:.06em; }
tr:last-child td { border-bottom:0; }
td.wrap { white-space:normal; }
.pill { display:inline-block; padding:2px 8px; border-radius:6px; background:var(--panel2); font-size:12px; color:var(--muted); }

/* login */
.login-wrap { min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px; }
.login-card { width:100%; max-width:380px; background:var(--panel); border:1px solid var(--line); border-radius:16px; padding:32px 28px; }
.login-card img { width:170px; display:block; margin:0 auto 26px; }
.login-card .btn { width:100%; margin-top:6px; }

/* mobile */
@media (max-width: 860px) {
  .shell { grid-template-columns:1fr; }
  .sidebar { display:none; }
  .topbar { display:flex; align-items:center; justify-content:space-between; padding:12px 16px; background:var(--panel); border-bottom:1px solid var(--line); position:sticky; top:0; z-index:5; }
  .topbar img { width:120px; display:block; }
  .topbar .who { font-size:13px; color:var(--muted); }
  .main { padding:16px 14px 90px; }
  .tabbar { display:flex; position:fixed; left:0; right:0; bottom:0; z-index:5; background:var(--panel); border-top:1px solid var(--line); padding:6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { flex:1; display:flex; flex-direction:column; align-items:center; gap:3px; padding:6px 2px; color:var(--muted); font:inherit; font-size:11px; background:none; border:0; cursor:pointer; border-radius:8px; }
  .tabbar a.active { color:var(--accent); }
  .tabbar svg { width:22px; height:22px; }
  .tabbar form { flex:1; display:flex; }
  .grid { grid-template-columns:1fr; }
  .stats { grid-template-columns:repeat(3, 1fr); gap:8px; }
  .stat { padding:12px; }
  .stat .num { font-size:24px; }
  .tiles { grid-template-columns:1fr; }
  .level { grid-template-columns:90px 1fr 40px; }
  .row .lbl { width:90px; }
  h1 { font-size:20px; }
  .btn { min-height:44px; }
  .actions-row .btn { flex:1 1 45%; }
}

/* filters */
.filters { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:18px; }
.filters input[type=search] { width:auto; flex:1; min-width:160px; -webkit-appearance:none; }
.filters select { width:auto; }
.chips { display:flex; gap:6px; background:var(--panel); border:1px solid var(--line); border-radius:10px; padding:4px; }
.chip { display:inline-flex; align-items:center; gap:6px; padding:7px 12px; border-radius:7px; color:var(--muted); font-weight:500; font-size:14px; }
.chip span { font-size:12px; padding:1px 7px; border-radius:999px; background:var(--panel2); color:var(--muted); }
.chip.active { background:var(--panel2); color:var(--text); }
.chip.active.online { color:var(--ok); }
.chip.active.offline { color:var(--bad); }
.chip.active span { background:var(--bg); color:inherit; }
@media (max-width: 860px) {
  .filters { gap:8px; }
  .chips { width:100%; justify-content:space-between; }
  .chip { flex:1; justify-content:center; padding:8px 6px; }
  .filters input[type=search] { min-width:0; width:100%; flex:1 1 100%; }
  .filters select { flex:1; }
}

/* last sale */
.sale { background:var(--panel2); border-radius:10px; padding:10px 12px; margin-top:10px; }
.sale-head { display:flex; justify-content:space-between; gap:10px; font-size:13px; }
.sale-head b { color:var(--accent); font-size:15px; }
.sale-body { margin-top:4px; font-weight:500; }
.sale-body .muted { font-weight:400; font-size:13px; }

/* mqtt */
.mqtt { font-size:11px; font-weight:600; padding:1px 6px; border-radius:6px; background:var(--panel2); letter-spacing:.04em; vertical-align:middle; }
.mqtt-on { color:var(--ok); }
.mqtt-off { color:var(--muted); }

/* service + sensors */
.svc-group { display:flex; gap:10px; align-items:flex-start; margin-bottom:10px; }
.svc-group .lbl { width:110px; flex:none; color:var(--muted); font-size:13px; padding-top:10px; }
.sensor-ok { color:var(--ok); font-weight:600; }
.sensor-bad { color:var(--bad); font-weight:600; }
.sensor-warn { color:var(--warn); font-weight:600; }
.sensor-muted { color:var(--muted); }
@media (max-width: 860px) { .svc-group { flex-direction:column; gap:4px; } .svc-group .lbl { padding-top:0; } }
