* { box-sizing: border-box; }

:root {
  --bg: #0b0c0f;
  --bg-sidebar: #111217;
  --bg-panel: #16181d;
  --bg-hover: #1c1f26;
  --border: #262830;
  --text: #e6e7eb;
  --text-dim: #8b8f99;
  --accent: #4da3ff;
  --accent-dim: #2a3b55;
  --green: #3ecf8e;
  --red: #e5484d;
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ---------------------------------------------------------------- login */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}
.login-card h1 { margin: 0 0 0.5rem; font-size: 1.1rem; }
.login-card label { color: var(--text-dim); font-size: 0.85rem; }
#login input {
  padding: 0.5rem 0.6rem;
  font-size: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.form-error { color: var(--red); font-size: 0.85rem; margin: 0; }
#mfa-qr { width: 200px; height: 200px; align-self: center; background: #fff; border-radius: 6px; padding: 8px; }
.mfa-manual-key {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  word-break: break-all;
  margin: 0;
}
.logged-in-as {
  padding: 0 0.65rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  word-break: break-all;
}

/* ---------------------------------------------------------------- app shell */
#app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 1.25rem;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--accent);
  color: #06121f;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--text); }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 2rem;
  overflow-x: auto;
}

.view { max-width: 1200px; }

/* ---------------------------------------------------------------- page chrome */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.page-header h1 { margin: 0; font-size: 1.3rem; }

.breadcrumb {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-input {
  flex: 1;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.chip-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(77, 163, 255, 0.08);
}

/* -------------------------------------------------------------- dropdown */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.dropdown-actions {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.checklist li:hover { background: var(--bg-hover); }
.checklist input[type="checkbox"] { pointer-events: none; }

.inline-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.inline-form input {
  flex: 1;
  max-width: 320px;
  padding: 0.5rem 0.6rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

/* ---------------------------------------------------------------- buttons */
button { font-family: inherit; }
.btn {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #06121f;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: #6bb4ff; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(229, 72, 77, 0.12); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table .device-name { font-weight: 500; }
.data-table .audit-detail {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.75rem;
}
.badge.count { border-color: var(--accent); color: var(--accent); }
.badge-select {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  background: var(--text-dim);
}
.status-dot.active { background: var(--green); }
.status-dot.inactive { background: var(--red); }
.status-label { display: inline-flex; align-items: center; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.card h3 { margin: 0 0 0.75rem; font-size: 0.95rem; }
.card h4 { margin: 0 0 0.5rem; font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.03em; }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.summary-card { margin-bottom: 0; }
.summary-stats { display: flex; gap: 1.25rem; }
.summary-stat { display: flex; flex-direction: column; }
.summary-stat .num { font-size: 1.4rem; font-weight: 600; }
.summary-stat .label { font-size: 0.75rem; color: var(--text-dim); }
.summary-stat.warn .num { color: #e8b339; }
.summary-stat.ok .num { color: var(--green); }

.empty-state { padding: 2rem 0; text-align: center; color: var(--text-dim); }
.empty-state p { margin: 0 0 0.35rem; }
.empty-state .muted { font-size: 0.85rem; }

/* ---------------------------------------------------------------- tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0.5rem 0.9rem;
  border-radius: 4px 4px 0 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 0.85rem;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
}

/* ---------------------------------------------------------------- device detail */
.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.device-title { display: flex; align-items: center; gap: 0.5rem; }
.device-title h1 { margin: 0; font-size: 1.3rem; }
.device-actions { display: flex; gap: 0.5rem; }

.device-body {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.25rem;
  align-items: start;
}
.device-body-side .card { margin-bottom: 0; }

.activity-log {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 480px;
  overflow-y: auto;
}
.activity-log li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.activity-log li:last-child { border-bottom: none; }
.activity-log .event-time { color: var(--text-dim); font-size: 0.72rem; display: block; margin-top: 0.15rem; }
.activity-log .event-msg { color: var(--text); }

dl.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.4rem 0.75rem;
  margin: 0;
}
dl.kv dt { color: var(--text-dim); }
dl.kv dd { margin: 0; }

.disk-box {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.usage-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  margin-top: 0.5rem;
  overflow: hidden;
}
.usage-bar div { height: 100%; background: var(--accent); }

.reconcile-status { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.reconcile-status li { padding: 0.25rem 0; color: var(--text-dim); font-size: 0.85rem; }

/* ---------------------------------------------------------------- services / config */
.service-list { list-style: none; padding: 0; margin: 0; }
.service-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.service-list li:last-child { border-bottom: none; }

.config-block { margin-bottom: 0.75rem; }
.config-block:last-child { margin-bottom: 0; }
.config-block h4 { margin: 0 0 0.5rem; color: var(--text); text-transform: none; font-size: 0.85rem; font-weight: 600; }

.service-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.svc-secret-fields {
  margin: 0.6rem 0 0 1.6rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}
.config-field {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
}
.config-field span { min-width: 180px; color: var(--text-dim); font-size: 0.82rem; }
.config-field input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

#enrollment-panel code {
  display: block;
  background: var(--bg);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  overflow-x: auto;
  border: 1px solid var(--border);
}

/* ---------------------------------------------------------------- terminal */
.terminal-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.terminal-header span:first-child { font-weight: 600; }
#terminal {
  height: 420px;
  background: #000;
  padding: 0.25rem;
  border-radius: 6px;
}
