:root {
  --bg: #0f1419;
  --bg-elev: #171d25;
  --bg-soft: #1e2630;
  --line: #2a3441;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --accent: #3d9cf0;
  --accent-2: #1f6fb2;
  --ok: #3ecf8e;
  --warn: #e6b35a;
  --danger: #e25d6a;
  --radius: 12px;
  --font: "Segoe UI", "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1a3a5c 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #163528 0%, transparent 45%),
    var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; }

/* Auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-shell { width: min(920px, 100%); display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; align-items: stretch; }
@media (max-width: 800px) { .auth-shell { grid-template-columns: 1fr; } }
.auth-brand {
  padding: 36px 28px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: linear-gradient(160deg, rgba(61,156,240,.12), transparent 50%), var(--bg-elev);
  display: flex; flex-direction: column; justify-content: end; gap: 8px;
}
.auth-brand h1 { margin: 0; font-size: 2.4rem; letter-spacing: -0.03em; }
.auth-brand p { margin: 0; color: var(--muted); max-width: 28ch; }
.brand-mark {
  width: 56px; height: 56px; border-radius: 14px;
  display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: white; margin-bottom: 18px;
}
.brand-mark.sm { width: 40px; height: 40px; border-radius: 10px; margin: 0; font-size: .9rem; }
.auth-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card h2 { margin: 0; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.auth-card input, .content input, .content select, .content textarea, .tenant-switch select {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}
.auth-card button, .btn {
  border: 0; border-radius: 8px; padding: 11px 14px; font: inherit; font-weight: 600;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: white; cursor: pointer;
}
.btn.secondary { background: var(--bg-soft); border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: linear-gradient(180deg, #e25d6a, #b43b48); }
.btn:disabled { opacity: .6; cursor: wait; }
.footer-note { margin: 8px 0 0; color: var(--muted); font-size: .8rem; }

/* App shell */
#app, .app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.brand-row { display: flex; gap: 12px; align-items: center; padding: 4px 8px 12px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-body label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .85rem; }
.modal-body input, .modal-body select, .modal-body textarea {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font: inherit;
}
.content label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .85rem; }
.content select, .content input { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 10px 12px; font: inherit; }
.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(15,20,25,.85);
  backdrop-filter: blur(8px);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 18px;
}
.sidebar-brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 12px; }
.sidebar-brand strong { display: block; }
.sidebar-brand .muted { font-size: .8rem; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#nav a {
  color: var(--muted); padding: 10px 12px; border-radius: 8px; text-decoration: none;
}
#nav a:hover, #nav a.active { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.sidebar-foot { display: flex; flex-direction: column; gap: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.tenant-switch { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; color: var(--muted); }
.user-chip { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; align-items: center; }
main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 28px 8px; gap: 12px;
}
.topbar h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
#top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { padding: 12px 28px 36px; }

.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.card .value { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.03em; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  background: var(--bg-soft); color: var(--muted); text-transform: uppercase;
}
.badge.on { color: var(--ok); background: rgba(62,207,142,.12); }
.badge.off { color: var(--danger); background: rgba(226,93,106,.12); }
.badge.unknown { color: var(--warn); background: rgba(230,179,90,.12); }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .85rem; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  padding: 20px;
}
.modal h2 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 900px) {
  #app, .app { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 10; }
  .form-grid { grid-template-columns: 1fr; }
}
