:root {
  --bg: #0f172a; --panel: #1e293b; --panel2: #273449; --line: #334155;
  --text: #e2e8f0; --muted: #94a3b8; --accent: #38bdf8; --accent2: #0ea5e9;
  --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); padding: 6px 12px;
  border-radius: 8px; transition: background .15s;
}
button:hover { background: #334155; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #04263a; font-weight: 600; }
button.primary:hover { background: var(--accent); }
button.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
input, select {
  font: inherit; background: #0b1222; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
a { color: var(--accent); }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; background: var(--panel); border-bottom: 1px solid var(--line);
}
header h1 { font-size: 17px; margin: 0; letter-spacing: .3px; }
header .sub { color: var(--muted); font-size: 12px; margin-left: 10px; }

nav { display: flex; gap: 4px; padding: 10px 18px 0; background: var(--panel); }
nav button { border: none; background: transparent; color: var(--muted); border-radius: 8px 8px 0 0; padding: 9px 16px; }
nav button.active { background: var(--bg); color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:last-child td { border-bottom: none; }
td .row-actions { display: flex; gap: 6px; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.on { background: rgba(34,197,94,.15); color: var(--ok); }
.pill.off { background: rgba(148,163,184,.15); color: var(--muted); }
.pill.open { background: rgba(56,189,248,.15); color: var(--accent); }
.pill.close { background: rgba(245,158,11,.15); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label.field { display: block; margin-bottom: 10px; }
label.field span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(2,6,23,.7); display: none; align-items: center; justify-content: center; z-index: 50; }
.overlay.show { display: flex; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: 420px; max-width: 92vw; }
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* login */
#login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; }
#login .box { width: 320px; }
#login h2 { text-align: center; margin: 0 0 18px; }

.empty { color: var(--muted); text-align: center; padding: 40px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--bad); }
.keybox { background: #0b1222; border: 1px dashed var(--accent); border-radius: 8px; padding: 10px; margin-top: 8px; word-break: break-all; }
.hidden { display: none !important; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } main { padding: 12px; } }
