:root {
  --bg: #071018;
  --bg-2: #0c1824;
  --panel: #102132;
  --panel-2: #153047;
  --line: #23415c;
  --text: #d7e6f2;
  --muted: #7fa0b8;
  --cyan: #3ee0c9;
  --ok: #3ddc97;
  --down: #ff6b6b;
  --warn: #f5c15c;
  --unk: #7fa0b8;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; min-height: 100dvh; }
html { overflow-x: hidden; }
#app { min-height: 100%; min-height: 100dvh; }
body {
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #12324a 0%, transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, #050b11 100%);
  color: var(--text);
  overflow-x: hidden;
}
body.nav-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100dvh; }
.nav-backdrop { display: none; }
.mobile-bar { display: none; }
.sidebar {
  background: rgba(8, 18, 28, 0.92);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), #2a8cff);
  display: grid; place-items: center; font-weight: 700; color: #042018;
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.04em; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { padding: 10px 12px; border-radius: 10px; color: var(--muted); }
.nav a.active, .nav a:hover { background: var(--panel); color: var(--text); }
.nav .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); margin-right: 8px; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: 12px; }
.sidebar-foot button {
  margin-top: 10px; width: 100%; background: transparent; border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; cursor: pointer;
}
.main { padding: 24px 28px 40px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 26px; overflow-wrap: anywhere; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn { background: var(--cyan); color: #042018; border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; touch-action: manipulation; }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--down); color: #2a0000; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.card {
  background: linear-gradient(180deg, var(--panel), #0d1c2a);
  border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 32px; font-weight: 700; margin-top: 6px; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.table-wrap { overflow: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.mono { font-family: "IBM Plex Mono", monospace; }
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.up { color: var(--ok); background: rgba(61, 220, 151, 0.12); }
.down { color: var(--down); background: rgba(255, 107, 107, 0.12); }
.degraded, .warn { color: var(--warn); background: rgba(245, 193, 92, 0.12); }
.unknown, .available, .reserved { color: var(--unk); background: rgba(127, 160, 184, 0.12); }
.in_use { color: var(--cyan); background: rgba(62, 224, 201, 0.12); }
.modal-bg { position: fixed; inset: 0; background: rgba(3, 8, 14, 0.7); display: grid; place-items: center; padding: 24px; z-index: 50; }
.modal {
  width: min(860px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 32px 36px;
  max-height: min(92vh, 920px);
  overflow: auto;
  box-sizing: border-box;
}
.modal h2 { margin: 0 0 20px; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid #loc-hint { margin: 4px 0 0; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea { background: #0a1722; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.row-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; padding-bottom: 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.node-grid { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.node-card { cursor: pointer; }
.node-card h3 { margin: 0 0 6px; }
.meta { color: var(--muted); font-size: 13px; }
.rack-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
.rack-vis { background: #08141e; border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-height: 70vh; overflow: auto; }
.u-row { display: grid; grid-template-columns: 36px 1fr; gap: 8px; min-height: 18px; font-size: 11px; color: var(--muted); }
.u-slot { border: 1px solid #1b3348; border-radius: 4px; min-height: 16px; }
.u-slot.filled { background: linear-gradient(90deg, #1c5f58, #164e78); color: white; padding: 2px 6px; }
.login-page { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-box { width: min(420px, 100%); }
.flash { color: var(--down); font-size: 14px; }
.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.metric { background: #0a1824; border-radius: 12px; padding: 12px; border: 1px solid var(--line); }
.metric b { display: block; margin-top: 6px; }
.check-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.check-list label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check-list input { width: auto; }
.check-inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); white-space: nowrap; }
.check-inline input { width: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters input, .filters select { min-width: 150px; }
.filter-count { color: var(--muted); font-size: 13px; }
.seg-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.seg { background: #0a1824; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg:hover, .seg.active { border-color: var(--cyan); color: var(--cyan); }
.menu-toggle {
  width: 42px; height: 42px; flex: 0 0 auto;
  display: grid; place-content: center; gap: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; padding: 0;
}
.menu-toggle span { display: block; width: 16px; height: 2px; background: var(--text); border-radius: 2px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(3, 8, 14, 0.55);
    z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .app.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(280px, 86vw); z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    padding-top: max(22px, env(safe-area-inset-top));
    padding-bottom: max(22px, env(safe-area-inset-bottom));
    overflow: auto;
    box-shadow: none;
  }
  .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
  .mobile-bar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 15;
    margin: -24px -16px 16px;
    padding: max(10px, env(safe-area-inset-top)) 16px 12px;
    background: rgba(7, 16, 24, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  .brand.compact h1 { font-size: 16px; }
  .main {
    padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
  }
  .split, .rack-layout, .metrics { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; }
  .nav a { min-height: 44px; display: flex; align-items: center; }
  .sidebar-foot button { min-height: 44px; }
}

@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .value { font-size: 24px; }
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .topbar h2 { font-size: 22px; }
  .topbar .actions { width: 100%; justify-content: stretch; }
  .topbar .actions .btn { flex: 1 1 calc(50% - 8px); text-align: center; }
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select, .filters .btn, .filters button {
    width: 100%; min-width: 0 !important; max-width: 100%;
  }
  .check-inline { white-space: normal; }
  .modal-bg { padding: 0; align-items: end; place-items: end center; }
  .modal {
    width: 100%;
    max-height: min(92dvh, 920px);
    border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .modal h2 { font-size: 18px; margin-bottom: 14px; }
  .row-actions { flex-direction: column-reverse; gap: 8px; margin-top: 16px; }
  .row-actions .btn { width: 100%; min-height: 44px; }
  .btn { min-height: 42px; }
  .login-page { padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  input, select, textarea { font-size: 16px; }
  .seg { min-height: 40px; }
}
