:root {
  --rail: #0f1b2d;
  --rail-2: #162640;
  --ink: #152033;
  --muted: #667789;
  --line: #d9e2ec;
  --canvas: #eef2f6;
  --panel: #ffffff;
  --accent: #1f6feb;
  --accent-2: #0d9488;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --chip: #e8eef6;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--canvas);
}

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.rail {
  background: linear-gradient(180deg, var(--rail) 0%, #0b1524 100%);
  color: #dbe7f5;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0a1320;
}
.rail-brand {
  display: flex; gap: 0.75rem; align-items: center;
  padding: 1.1rem 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.rail-brand .mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #1f6feb, #0d9488);
  font-weight: 700;
}
.rail-brand strong { display: block; font-size: 0.95rem; letter-spacing: 0.04em; }
.rail-brand small { color: #8aa0b8; font-size: 0.7rem; }
.rail-nav { padding: 0.75rem 0.55rem; display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.rail-nav button {
  appearance: none; border: 0; background: transparent; color: inherit;
  text-align: left; padding: 0.62rem 0.75rem; border-radius: 8px;
  cursor: pointer; font: inherit; font-size: 0.92rem;
}
.rail-nav button:hover, .rail-nav button.active { background: rgba(255,255,255,0.08); }
.rail-nav .section {
  margin: 0.75rem 0.75rem 0.35rem;
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: #7f93a9;
}
.rail-foot { padding: 0.75rem; border-top: 1px solid rgba(255,255,255,0.06); }
.org-picker { position: relative; margin-bottom: 0.45rem; }
.org-chip {
  appearance: none; border: 1px solid transparent; width: 100%;
  background: var(--rail-2); border-radius: 8px; padding: 0.55rem 0.7rem;
  font: inherit; font-size: 0.8rem; color: #b6c7da;
  cursor: pointer; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 0.4rem;
}
.org-chip::after {
  content: "▾"; font-size: 0.65rem; opacity: 0.55; flex-shrink: 0;
}
.org-chip:hover, .org-chip[aria-expanded="true"] {
  border-color: rgba(255,255,255,0.12);
  color: #dbe7f5;
}
.org-menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px);
  background: #132338; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; max-height: 260px; overflow: auto; z-index: 30;
  box-shadow: 0 -10px 28px rgba(0,0,0,0.4);
}
.org-menu button {
  appearance: none; border: 0; background: transparent; width: 100%;
  color: #dbe7f5; text-align: left; padding: 0.55rem 0.75rem;
  font: inherit; font-size: 0.8rem; cursor: pointer;
}
.org-menu button:hover, .org-menu button.active { background: rgba(255,255,255,0.08); }
.org-menu .org-menu-all {
  color: #8aa0b8;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.org-menu .org-menu-meta {
  display: block; font-size: 0.68rem; color: #7f93a9; margin-top: 0.1rem;
}

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 1.25rem; background: rgba(255,255,255,0.86);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.crumbs { font-weight: 600; font-size: 0.98rem; }
.top-actions { display: flex; gap: 0.5rem; align-items: center; }
.search {
  width: min(360px, 42vw); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.45rem 0.7rem; font: inherit; background: #fff;
}
.icon-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer; font-size: 1rem;
}
.content { padding: 1rem 1.25rem 2rem; }

.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.65rem; margin-bottom: 1rem;
}
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 0.9rem 1rem;
  box-shadow: 0 1px 0 rgba(15,27,45,0.03);
}
.stat .label { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em; }
.stat .value { font-size: 1.55rem; font-weight: 700; margin-top: 0.2rem; }
.stat .hint { color: var(--muted); font-size: 0.75rem; margin-top: 0.15rem; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  margin-bottom: 1rem; overflow: hidden;
}
.panel-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem; border-bottom: 1px solid var(--line); background: #f8fafc;
}
.panel-h h2 { margin: 0; font-size: 0.92rem; font-weight: 650; }
.panel-b { padding: 0.75rem 1rem; }

.toolbar { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.75rem; }
.btn, select, input[type="text"], textarea {
  font: inherit; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.42rem 0.7rem; background: #fff;
}
.btn {
  background: var(--accent); color: #fff; border-color: var(--accent); cursor: pointer;
  font-weight: 600; font-size: 0.86rem;
}
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
th { color: var(--muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; background: #f8fafc; }
.table-sort {
  appearance: none; border: 0; padding: 0; background: transparent; color: inherit;
  cursor: pointer; font: inherit; font-weight: inherit; letter-spacing: inherit; text-transform: inherit;
}
.table-sort:hover { color: var(--accent); }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f3f7fb; }
tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.12rem 0.5rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.online { background: #dcfce7; color: var(--ok); }
.badge.offline { background: #fee2e2; color: var(--danger); }
.badge.unknown { background: #e5e7eb; color: var(--muted); }
.badge.open, .badge.pending, .badge.in_progress { background: #ffedd5; color: var(--warn); }
.badge.acked, .badge.resolved, .badge.installed, .badge.approved, .badge.closed { background: #dcfce7; color: var(--ok); }
.badge.installing { background: #e0f2fe; color: #0369a1; }
.badge.unchecked { background: #e5e7eb; color: var(--muted); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warning { background: #ffedd5; color: var(--warn); }
.badge.critical, .badge.rejected, .badge.failed { background: #fee2e2; color: var(--danger); }
.badge.succeeded { background: #dcfce7; color: var(--ok); }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); padding: 0 0.5rem; background: #f8fafc; overflow-x: auto; }
.tabs button {
  appearance: none; border: 0; background: transparent; padding: 0.75rem 0.85rem;
  cursor: pointer; font: inherit; font-size: 0.86rem; color: var(--muted); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }

.device-head {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1rem; border-bottom: 1px solid var(--line);
}
.device-head h1 { margin: 0; font-size: 1.25rem; }
.meta { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.action-bar { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0.75rem; }
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
}

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 0.35rem 0.75rem; font-size: 0.88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

pre.out {
  background: #0b1524; color: #d7e6f5; padding: 0.85rem; border-radius: 8px;
  overflow: auto; font-family: var(--mono); font-size: 0.78rem; min-height: 120px;
}
.muted { color: var(--muted); }
.err { color: var(--danger); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

.stub-banner {
  background: linear-gradient(90deg, #eff6ff, #f0fdfa);
  border: 1px solid #bfdbfe; border-radius: 10px; padding: 0.85rem 1rem;
  margin-bottom: 0.85rem; font-size: 0.88rem;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(31, 111, 235, 0.18), transparent 60%),
    radial-gradient(700px 360px at 90% 0%, rgba(13, 148, 136, 0.14), transparent 55%),
    linear-gradient(180deg, #e8eef6 0%, #f5f7fa 100%);
}
.auth-gate[hidden],
.shell[hidden] {
  display: none !important;
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.35rem 1.35rem 1.5rem;
  box-shadow: 0 18px 40px rgba(15, 27, 45, 0.08);
}
.auth-brand {
  display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1.1rem;
}
.auth-brand .mark {
  width: 36px; height: 36px; border-radius: 9px;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, #1f6feb, #0d9488);
}
.auth-brand strong { display: block; }
.auth-brand small { color: var(--muted); font-size: 0.75rem; }
.auth-card h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.auth-form { display: grid; gap: 0.75rem; margin-top: 1rem; }
.auth-form label { display: grid; gap: 0.35rem; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.auth-form input {
  font: inherit; font-weight: 500; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.7rem;
}
.auth-error { margin-top: 0.75rem; font-size: 0.88rem; }
.mfa-qr {
  display: block; width: 200px; height: 200px; margin: 0.75rem auto;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.mono-secret { text-align: center; font-size: 0.82rem; }
.mono-secret code, .backup-codes code {
  font-family: var(--mono); font-size: 0.85rem;
}
.backup-codes {
  list-style: none; padding: 0; margin: 0.75rem 0 1rem;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem;
}
.backup-codes li {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.45rem 0.55rem; text-align: center;
}
.user-chip {
  margin-top: 0.45rem; font-size: 0.75rem; color: #9bb0c7;
}
.btn.ghost.logout-btn {
  margin-top: 0.55rem; width: 100%;
  background: transparent;
  color: #e8f0fa;
  border-color: rgba(255, 255, 255, 0.28);
}
.btn.ghost.logout-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.4);
}

a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; color: #fff;
}
a.btn.secondary { color: var(--ink); }

.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0;
}
@media (max-width: 980px) {
  .metrics-row { grid-template-columns: 1fr; }
}
.metric-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem 0.55rem;
}
.metric-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 0.35rem; font-size: 0.82rem; color: var(--muted); font-weight: 600;
}
.metric-head strong { font-size: 1.25rem; color: var(--ink); font-weight: 700; }
.metric-card canvas {
  width: 100%; height: 140px; display: block; border-radius: 8px;
}
.metric-sub { margin-top: 0.25rem; font-size: 0.75rem; }

.asset-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.85rem 1rem 0;
}
@media (max-width: 1100px) {
  .asset-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .asset-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.asset-cell {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  min-width: 0;
}
.asset-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.asset-cell strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-title {
  font-size: 0.9rem;
  margin: 0 0 0.65rem;
}
.table-scroll {
  overflow: auto;
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.svc-table { font-size: 0.8rem; }
.svc-table th { white-space: nowrap; position: sticky; top: 0; background: #f8fafc; z-index: 1; }
.svc-desc, .svc-path { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-actions { white-space: nowrap; }
.btn-xs { padding: 0.2rem 0.45rem; font-size: 0.72rem; }
.shell-input {
  width: 100%;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  resize: vertical;
  box-sizing: border-box;
}
.toggle { display: inline-flex; align-items: center; }

.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-top: 0.85rem;
}
.download-card {
  display: flex; flex-direction: column; justify-content: space-between; gap: 0.85rem;
  border: 1px solid var(--line); border-radius: 12px; padding: 1rem;
  background: #f8fafc;
}
.download-card h3 { margin: 0.15rem 0 0.35rem; font-size: 1rem; }
.download-platform {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--accent);
}
.download-card .btn { align-self: flex-start; }

.xfer-lead { margin: 0 0 0.85rem; }
.xfer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.xfer-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 0.95rem 1rem;
  background: #f8fafc;
  min-width: 0;
}
.xfer-heading {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}
.xfer-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.xfer-steps > li {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.xfer-step-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}
.xfer-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  align-self: flex-start;
}
.xfer-toggle-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
}
.xfer-toggle-btn + .xfer-toggle-btn {
  border-left: 1px solid var(--line);
}
.xfer-toggle-btn.active {
  background: var(--chip);
  color: var(--ink);
  font-weight: 600;
}
.xfer-pick {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-start;
}
.xfer-files {
  font-size: 0.82rem;
  word-break: break-word;
  max-width: 100%;
}
.xfer-panel input[type="text"] {
  width: 100%;
  max-width: 100%;
}
.xfer-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
}
.xfer-progress {
  margin-top: 0.85rem;
}
.xfer-progress-track {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.xfer-progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}
.xfer-status {
  margin: 0;
  min-height: 2.5rem;
}
@media (max-width: 900px) {
  .xfer-grid { grid-template-columns: 1fr; }
}
