:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --panel-2: #222c38;
  --text: #e8eef4;
  --muted: #8b9aab;
  --line: #2c3846;
  --accent: #3d9cf0;
  --accent-2: #1f6fb8;
  --ok: #3ecf8e;
  --bad: #f07178;
  --warn: #e6c07b;
  --radius: 10px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --nav-w: 220px;
  --topbar-h: 56px;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Desktop: fixed sidebar + fluid content */
.shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}
.nav {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: rgba(14, 20, 27, 0.96);
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar { display: none; }
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 1rem;
  font-size: 1.05rem;
}
.nav-link {
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  min-height: 42px;
  display: flex;
  align-items: center;
}
.nav-link:hover { background: var(--panel-2); text-decoration: none; }
.nav-link.active { background: rgba(61, 156, 240, 0.16); color: #9cc9f5; }
.nav-foot { margin-top: auto; padding-top: 1.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; }

.main { padding: 1.5rem 1.75rem 3rem; width: 100%; }
.page-head { margin-bottom: 1rem; }
.page-head h1 { margin: 0; font-size: 1.55rem; font-weight: 650; }
.section-title { margin: 0 0 0.75rem; font-size: 1.1rem; font-weight: 650; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}
.card {
  background: linear-gradient(180deg, var(--panel) 0%, #161d26 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  min-width: 0;
}
.card .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.card .value { font-size: 1.8rem; font-weight: 700; margin-top: 0.25rem; word-break: break-word; }

.panel {
  background: rgba(26, 34, 44, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.toolbar-panel { padding-bottom: 0.85rem; }

.filter-chips {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #11171e;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  font-size: 0.9rem;
  min-height: 36px;
}
.chip:hover { border-color: var(--accent-2); text-decoration: none; }
.chip.active {
  background: rgba(61, 156, 240, 0.18);
  border-color: var(--accent);
  color: #cfe6fb;
}

.location-group { padding-top: 1rem; }
.location-head { margin-bottom: 0.85rem; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 0.7rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.95rem;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.badge-online { background: rgba(62, 207, 142, 0.15); color: var(--ok); }
.badge-offline { background: rgba(240, 113, 120, 0.15); color: var(--bad); }
.badge-unknown { background: rgba(230, 192, 123, 0.15); color: var(--warn); }

.btn, button, input[type=submit] {
  appearance: none;
  border: 1px solid var(--accent-2);
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font: inherit;
  min-height: 40px;
}
.btn-secondary {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}
.btn-danger {
  background: linear-gradient(180deg, #d45a62 0%, #a33b42 100%);
  border-color: #8d3036;
}
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

label { display: block; margin: 0.75rem 0 0.3rem; color: var(--muted); font-size: 0.85rem; }
input[type=text], input[type=password], input[type=number], input[type=email], textarea, select {
  width: 100%;
  max-width: 520px;
  background: #11171e;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  min-height: 42px;
}
textarea { min-height: 90px; max-width: 720px; }
.form-grid { display: grid; gap: 0.25rem; max-width: 720px; }
.form-grid input, .form-grid textarea, .form-grid select { max-width: none; }
.checkbox { display: flex; gap: 0.5rem; align-items: center; margin: 0.6rem 0; color: var(--text); }
.checkbox input { width: auto; min-height: auto; }

.flash {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--line);
}
.flash-ok { background: rgba(62, 207, 142, 0.12); color: var(--ok); }
.flash-error { background: rgba(240, 113, 120, 0.12); color: var(--bad); }
.flash-info { background: rgba(61, 156, 240, 0.12); color: #9cc9f5; }

.script-box {
  width: 100%;
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: #0b1015;
  border: 1px solid var(--line);
  color: #d7e2ec;
  border-radius: 8px;
  padding: 0.85rem;
  white-space: pre;
  overflow-x: auto;
}

.device-list { display: grid; gap: 0.75rem; }
.device-card {
  display: grid;
  gap: 0.55rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #141b24;
}
.device-card.link-card { color: inherit; text-decoration: none; }
.device-card.link-card:hover { border-color: var(--accent-2); text-decoration: none; }
.device-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
}
.device-card-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  font-size: 0.9rem;
}
.meta-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.15rem;
}
.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Desktop: tables on, mobile cards off */
.mobile-cards { display: none; }
.desktop-table { display: block; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(26, 34, 44, 0.95);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.help { color: var(--muted); font-size: 0.9rem; margin: 0.35rem 0 1rem; }

.nav-toggle {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-weight: 600;
  min-height: 40px;
}

/* Mobile / narrow screens only */
@media (max-width: 960px) {
  .shell { flex-direction: column; }
  .nav {
    display: none;
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.75rem;
  }
  body.nav-open .nav { display: flex; }
  .topbar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    align-items: center;
    gap: 0.75rem;
    padding: 0 0.85rem;
    background: rgba(14, 20, 27, 0.96);
    border-bottom: 1px solid var(--line);
  }
  .topbar .brand { margin: 0; font-size: 1rem; }
  .nav-foot { margin-top: 0.5rem; }
  .main { padding: 1rem; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card .value { font-size: 1.35rem; }
  .page-head h1 { font-size: 1.3rem; }
  .desktop-table { display: none; }
  .mobile-cards { display: grid; }
  .filter-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.15rem;
  }
}

@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 0.65rem; }
  .card { padding: 0.8rem; }
  .device-card-meta { grid-template-columns: 1fr; }
  .toolbar .btn-row { width: 100%; }
  .toolbar .btn-row .btn { flex: 1 1 auto; text-align: center; }
  .script-box { min-height: 180px; font-size: 0.75rem; }
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
}
