:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2f4058;
  --text: #e8eef7;
  --muted: #8b9cb3;
  --accent: #5b9fd4;
  --accent-2: #7bc96f;
  --warn: #e8b84a;
  --danger: #e06c75;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  display: block;
  height: 48px;
  width: auto;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.brand-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  line-height: 1.1;
}

.brand .subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.health-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.health-pill.ok {
  color: var(--accent-2);
  border-color: #3d6b38;
}

.health-pill.warn {
  color: var(--warn);
  border-color: #7a6020;
}

.health-pill.bad {
  color: var(--danger);
  border-color: #7a3038;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1.5rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.6rem 1rem;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-color: var(--bg);
  margin-bottom: -1px;
}

main {
  padding: 1.25rem 1.5rem 2rem;
  max-width: 1280px;
  margin: 0 auto;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.grid {
  display: grid;
  gap: 1rem;
}

.two-col {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-top: 1rem;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.card h2 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.hint {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}

.stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.25rem;
}

.progress-wrap {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}

.metric-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.chart-box {
  position: relative;
  height: 220px;
}

.placeholder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}

.placeholder {
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
}

.funnel {
  list-style: none;
  padding: 0;
  margin: 0;
}

.funnel li {
  display: flex;
  justify-content: space-between;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.75rem;
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.toolbar select,
.toolbar button {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.toolbar button {
  cursor: pointer;
}

.toolbar button:hover {
  border-color: var(--accent);
}

.identity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
}

.identity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.identity-card:hover {
  border-color: var(--accent);
}

.identity-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.identity-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.niche {
  color: var(--accent);
  border-color: #2f5570;
}

.badge.status-approved,
.badge.status-active {
  color: var(--accent-2);
}

.badge.warn {
  color: var(--warn);
  border-color: #7a6020;
}

.btn-primary,
.btn-secondary {
  font: inherit;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #3d7aa8);
  border-color: #3d7aa8;
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.35rem;
}

.detail-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.detail-toolbar h2 {
  margin: 0;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.65rem;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-grid label,
.identity-edit-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.identity-edit-form input,
.identity-edit-form select,
.identity-edit-form textarea,
.inline-form input,
.inline-form select {
  font: inherit;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.identity-edit-form textarea,
.form-grid textarea {
  resize: vertical;
  min-height: 2.5rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: 640px;
  width: calc(100% - 2rem);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal form {
  padding: 1rem 1.1rem 1.1rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.platform-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem 0.75rem;
}

.platform-fieldset legend {
  padding: 0 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.platform-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.platform-skip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.platform-skip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.upload-image-form input[type="file"] {
  max-width: 16rem;
}

.enrichment-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.enrichment-item {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}

.enrichment-item input[type="checkbox"] {
  margin-top: 0.35rem;
}

.enrichment-item textarea {
  width: 100%;
  margin-top: 0.35rem;
  font: inherit;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

.enrichment-item strong {
  font-size: 0.82rem;
  color: var(--accent);
}

.identity-card p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.85rem;
}

.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.image-card .img-placeholder {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.75rem;
  background: var(--surface-2);
  padding: 0.5rem;
  text-align: center;
}

.image-card .caption {
  padding: 0.55rem 0.65rem;
  font-size: 0.78rem;
}

.image-card .caption strong {
  display: block;
  font-size: 0.82rem;
}

.detail-card {
  position: relative;
  margin-top: 1rem;
}

.detail-card.hidden {
  display: none;
}

.close-detail {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.detail-section {
  margin-bottom: 1rem;
}

.detail-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  font-size: 0.85rem;
}

.code-block {
  margin: 0;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.45;
  max-height: 70vh;
}

.empty-state {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  grid-column: 1 / -1;
}

/* Stealth panel */
.stealth-dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
  font-size: 0.85rem;
}
.stealth-dl dt {
  color: var(--muted);
  padding: 0.35rem 0;
}
.stealth-dl dd {
  margin: 0;
  padding: 0.35rem 0;
  font-weight: 600;
  text-align: right;
}
.stealth-dl dd .on  { color: var(--accent-2); }
.stealth-dl dd .off { color: var(--muted); }
.stealth-dl dd .warn { color: var(--warn); }

.stealth-coverage-table {
  width: 100%;
  font-size: 0.85rem;
}
.stealth-coverage-table td:last-child,
.stealth-coverage-table th:last-child {
  text-align: right;
}

.stat-card .value {
  font-size: 1.35rem;
  font-weight: 700;
}

.stat-card.health-ok .value {
  color: var(--accent-2);
}

.stat-card.health-warn .value {
  color: var(--warn);
}

.stat-card.health-down .value {
  color: var(--danger);
}

.stat-card .health-detail {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.stealth-vnc-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.stealth-vnc-toolbar label {
  flex: 1;
  min-width: 200px;
}
.stealth-vnc-toolbar input {
  width: 100%;
}

.stealth-vnc-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  min-height: 200px;
}
.stealth-vnc-wrap iframe {
  display: block;
  width: 100%;
  height: 600px;
  border: none;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.login-card {
  width: min(420px, calc(100vw - 2rem));
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 1rem;
}

.login-card h1 {
  margin: 0;
  font-size: 1.35rem;
}

.login-error {
  color: var(--danger, #c0392b);
  margin: 0;
}

.hidden {
  display: none !important;
}

.edit-account-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 520px;
  width: calc(100vw - 2rem);
}

.edit-account-dialog form {
  display: grid;
  gap: 0.75rem;
  padding: 1.25rem;
}

.edit-account-dialog label {
  display: grid;
  gap: 0.35rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.account-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
