:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1b2333;
  --muted: #667085;
  --line: #e4e7ef;
  --primary: #3156d3;
  --primary-ink: #ffffff;
  --ok: #12805c;
  --warn: #b25e09;
  --warn-bg: #fff4e5;
  --danger: #c0352b;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d;
    --card: #1a202b;
    --text: #e6e9f0;
    --muted: #98a2b3;
    --line: #2a3242;
    --primary: #6d8cff;
    --primary-ink: #0d1220;
    --ok: #3ccf91;
    --warn: #f0a24b;
    --warn-bg: #2d2416;
    --danger: #ff6b5f;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: 1rem; margin: 0 0 12px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); margin: 0; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.wrap { flex-wrap: wrap; }
.gap { gap: 10px; }
.grow { flex: 1; }

label { display: block; font-size: 0.9rem; margin: 8px 0; }
input[type=email], input[type=password], input[type=number], input[type=time], input[type=search], input:not([type]) {
  display: block; width: 100%; margin-top: 4px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 9px 14px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 600; }
button.ghost { background: transparent; }
button.danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small-btn { padding: 5px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.brand { font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { margin: 18px 0 8px; }
.auth-card button.primary { width: 100%; margin-top: 10px; }

/* layout */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--line); padding: 16px; background: var(--card); }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.device-list { list-style: none; padding: 0; margin: 0; }
.device-list li { padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 4px; }
.device-list li:hover { background: var(--bg); }
.device-list li.active { background: var(--bg); outline: 1px solid var(--line); }
.device-list .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: var(--ok); }
.dot.warn { background: var(--warn); }

.detail { padding: 20px; max-width: 1150px; padding-bottom: 90px; }
.empty { color: var(--muted); padding: 60px 0; text-align: center; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid .card { margin-bottom: 0; }
.grid + .card { margin-top: 16px; }
.map { height: 330px; border-radius: 8px; border: 1px solid var(--line); }

.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 0; cursor: pointer; }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(18px); }

.paircode { text-align: center; }
.paircode .code { font-size: 2.4rem; letter-spacing: 0.3em; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0; }
.warnings .warn-item { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 0.9rem; }

.search { max-width: 240px; margin: 0 0 12px; }
table.apps { width: 100%; border-collapse: collapse; }
table.apps th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
table.apps td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.apps .num { text-align: right; }
table.apps .center { text-align: center; }
table.apps input[type=number] { width: 90px; display: inline-block; margin: 0; padding: 6px 8px; text-align: right; }
table.apps .pkg { color: var(--muted); font-size: 0.78rem; word-break: break-all; }
table.apps input[type=checkbox] { width: 18px; height: 18px; }

.savebar { position: fixed; bottom: 0; left: 260px; right: 0; display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 12px 20px; background: var(--card); border-top: 1px solid var(--line); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 0; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-body { padding: 20px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .grid { grid-template-columns: 1fr; }
  .savebar { left: 0; }
  .detail { padding: 16px; padding-bottom: 90px; }
  table.apps th:nth-child(5), table.apps td:nth-child(5) { display: none; }
}
