:root {
  --bg: #0e1117;
  --bg-elev: #161b24;
  --bg-elev-2: #1c2330;
  --border: #262d3a;
  --border-soft: #1f2632;
  --text: #e6e9ef;
  --text-dim: #9aa4b2;
  --text-faint: #6b7585;
  --accent: #6366f1;
  --accent-soft: #6366f133;
  --accent-2: #22d3ee;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

.layout { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand-mark {
  font-size: 22px; width: 40px; height: 40px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 11px;
}
.brand-title { font-weight: 700; letter-spacing: .2px; }
.brand-sub { color: var(--text-faint); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: transparent; color: var(--text-dim);
  border: none; border-radius: var(--radius-sm);
  padding: 10px 12px; cursor: pointer; text-align: left; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item span { width: 18px; text-align: center; opacity: .85; }
.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #fff; }
.nav-item.active span { opacity: 1; }

.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 9px; padding: 10px 8px 2px; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); box-shadow: 0 0 0 0 transparent; }
.conn-dot.ok { background: var(--green); box-shadow: 0 0 0 4px #34d39922; }
.conn-dot.err { background: var(--red); box-shadow: 0 0 0 4px #f8717122; }
.conn-text { color: var(--text-faint); font-size: 12px; }

/* Main */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--border); gap: 16px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 650; }
.keybar { display: flex; gap: 8px; align-items: center; }
.keybar input {
  width: 240px; background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 9px 12px; font-family: var(--mono);
}
.keybar input:focus { outline: none; border-color: var(--accent); }

.content { overflow-y: auto; padding: 26px; }
.view { max-width: 1180px; margin: 0 auto; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text);
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 550;
  transition: filter .15s, background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #f8717155; }
.btn.danger:hover { background: #f8717118; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

/* Cards & grid */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.card .label { color: var(--text-dim); font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; }
.card .value { font-size: 30px; font-weight: 700; margin-top: 8px; }
.card .value.accent { color: var(--accent-2); }
.card .sub { color: var(--text-faint); font-size: 12.5px; margin-top: 4px; }

.panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 22px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--border-soft);
}
.panel-head h2 { font-size: 15px; margin: 0; font-weight: 620; }
.panel-head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-body { padding: 4px 4px; }
.panel-body.pad { padding: 18px 20px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tbody tr:hover { background: #ffffff06; }
tbody tr:last-child td { border-bottom: none; }
td.mono, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-faint); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.on { background: #34d39920; color: var(--green); }
.badge.off { background: #f8717120; color: var(--red); }
.badge.warn { background: #fbbf2420; color: var(--amber); }
.badge.neutral { background: #ffffff10; color: var(--text-dim); }
.chip { display: inline-block; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; font-size: 12px; margin: 2px 3px 2px 0; font-family: var(--mono); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { color: var(--text-dim); font-size: 12.5px; font-weight: 550; }
.field .hint { color: var(--text-faint); font-size: 11.5px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  background: var(--bg-elev-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }

/* States */
.empty, .loading { padding: 40px 20px; text-align: center; color: var(--text-faint); }
.spinner {
  width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gate { max-width: 460px; margin: 60px auto; text-align: center; }
.gate .lock { font-size: 44px; margin-bottom: 12px; }
.gate h2 { margin: 0 0 8px; }
.gate p { color: var(--text-dim); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: #00000088; backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; box-shadow: var(--shadow); animation: pop .15s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 10px; }
.modal .x { background: none; border: none; color: var(--text-dim); font-size: 20px; cursor: pointer; line-height: 1; }

.codebox {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; word-break: break-all;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.json {
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 8px 10px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  max-width: 360px; max-height: 140px; overflow: auto; color: var(--text-dim);
}

/* Toasts */
.toast-root { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast {
  background: var(--bg-elev-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; min-width: 240px; max-width: 360px;
  box-shadow: var(--shadow); animation: slidein .2s ease;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast .t-title { font-weight: 650; margin-bottom: 2px; }
.toast .t-msg { color: var(--text-dim); font-size: 13px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

.row-actions { display: flex; gap: 7px; justify-content: flex-end; }
.section-note { color: var(--text-faint); font-size: 12.5px; margin: -8px 0 16px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; }
.tenant-detail > td { background: var(--bg-elev-2); padding: 0 0 6px 24px; }
