:root {
  /* KM Technolabs company palette */
  --brand-blue: #0675ac;
  --brand-blue-dark: #055a86;
  --brand-blue-soft: rgba(6, 117, 172, 0.1);
  --brand-green: #54af4b;
  --brand-green-dark: #50a947;
  --brand-green-soft: rgba(84, 175, 75, 0.12);
  --brand-green-light: #59ae52;
  --surface-mint: #dbe4da;

  --bg: #eaeaea;
  --bg-elevated: #ffffff;
  --bg-soft: #dbe4da;
  --border: #d0d5d0;
  --border-strong: #b8c0b8;
  --text: #1a1a1a;
  --text-muted: #5a6560;
  --accent: var(--brand-blue);
  --danger: #c62828;
  --warning: #c47a00;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(26, 26, 26, 0.05);
  --sidebar-width: 260px;
  --font-sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --bg-elevated: #161b22;
  --bg-soft: #1a2a22;
  --border: #2d3748;
  --border-strong: #3d4a5c;
  --text: #eaeaea;
  --text-muted: #9aaba0;
  --brand-blue-soft: rgba(6, 117, 172, 0.2);
  --brand-green-soft: rgba(84, 175, 75, 0.18);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-blue); text-decoration: none; }
a:hover { color: var(--brand-blue-dark); text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.brand-link {
  display: block;
  text-decoration: none !important;
  color: inherit;
  padding: 0 1.1rem 1rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 168px;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 0 0.65rem;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
}
.brand-logo-for-dark { display: none; }
[data-theme="dark"] .brand-logo-for-light { display: none; }
[data-theme="dark"] .brand-logo-for-dark { display: block; }
.brand-text {
  padding-left: 0.1rem;
}
.brand-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.brand-sub {
  color: var(--text-muted);
  font-size: 0.6875rem;
  margin-top: 0.1rem;
  font-weight: 500;
}

.nav-section { margin-top: 0.35rem; }
.nav-label {
  color: var(--text-muted);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.55rem 1.1rem 0.25rem;
}
.nav-link {
  display: block;
  color: var(--text-muted);
  padding: 0.38rem 1.1rem;
  font-size: 0.8125rem;
  text-decoration: none !important;
  border-left: 3px solid transparent;
}
.nav-link:hover {
  color: var(--text);
  background: var(--bg-soft);
}
.nav-link.active {
  color: var(--brand-blue);
  background: var(--brand-blue-soft);
  border-left-color: var(--brand-blue);
  font-weight: 500;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.sidebar-footer-label { font-weight: 600; color: var(--text); }

/* Main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}
.topbar-meta {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 0.1rem;
}

.content { padding: 1.5rem; max-width: 1400px; }

.page-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem;
  color: var(--text);
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0;
}

.page-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .stat-grid { grid-template-columns: 1fr; }
}

.stat-card, .panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-card {
  padding: 1rem 1.125rem;
}
.stat-label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 0.35rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-unit {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
}
.stat-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.panel { padding: 1.25rem; margin-bottom: 1rem; }
.panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Health & lists */
.health-list { display: flex; flex-direction: column; gap: 0; }
.health-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.health-row:last-child { border-bottom: 0; }
.health-name { flex: 1; color: var(--text); }
.health-status {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.rank-list li:last-child { border-bottom: 0; }
.rank-name { color: var(--text); }
.rank-value {
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.rank-empty { color: var(--text-muted); font-size: 0.875rem; padding: 0.25rem 0; }

/* Tables */
.table { color: var(--text); font-size: 0.875rem; }
.table > :not(caption) > * > * {
  background: transparent;
  color: var(--text);
  border-bottom-color: var(--border);
  padding: 0.625rem 0.75rem;
  vertical-align: middle;
}
.table thead th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg-soft);
}
.data-table tbody tr:hover td { background: var(--bg-soft); }
.req-id {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Badges */
.badge-soft {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-muted);
}
.badge-success {
  color: #2f7a2c;
  border-color: #b5d9b0;
  background: var(--surface-mint);
}
[data-theme="dark"] .badge-success {
  color: var(--brand-green-light);
  border-color: rgba(84, 175, 75, 0.35);
  background: var(--brand-green-soft);
}
.badge-danger {
  color: #991b1b;
  border-color: #fecaca;
  background: #fef2f2;
}
[data-theme="dark"] .badge-danger {
  color: #fca5a5;
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.1);
}

/* Buttons */
.btn {
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius);
}
.btn-primary {
  --bs-btn-bg: var(--brand-blue);
  --bs-btn-border-color: var(--brand-blue);
  --bs-btn-hover-bg: var(--brand-blue-dark);
  --bs-btn-hover-border-color: var(--brand-blue-dark);
}
.btn-outline-secondary {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--bg-elevated);
}
.btn-outline-secondary:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Forms */
.form-control, .form-select {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text);
  font-size: 0.875rem;
  border-radius: var(--radius);
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px var(--brand-blue-soft);
}
.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.text-muted, .form-text, .small.text-muted {
  color: var(--text-muted) !important;
}

/* Auth */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-logo-wrap { text-align: center; margin-bottom: 1.25rem; }
.auth-logo {
  width: 180px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
}
.auth-brand {
  font-size: 1.125rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 0.25rem;
}
.auth-sub {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

/* Health dots */
.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.health-ok { background: var(--brand-green); }
.health-down { background: var(--danger); }
.health-unknown { background: var(--warning); }

/* Code blocks */
.code-block {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}
.code-block pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  padding-right: 4rem;
}
.copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; }

/* Docs */
.docs-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}
.docs-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.docs-brand-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none !important;
  color: inherit;
}
.docs-logo {
  width: 148px;
  height: auto;
  object-fit: contain;
}
.docs-topbar-muted { font-size: 0.8125rem; color: var(--text-muted); }
.docs-lead { color: var(--text-muted); font-size: 0.9375rem; margin-bottom: 1.5rem; }
.docs-body { color: var(--text); font-size: 0.875rem; margin-bottom: 0.5rem; }
.docs-section-title { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }
.docs-h3 { font-size: 0.875rem; font-weight: 600; margin: 1rem 0 0.5rem; }
.docs-mini {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
}
.docs-mini-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.docs-card-link { text-decoration: none !important; color: inherit; display: block; }
.docs-card:hover { border-color: var(--border-strong); }
.docs-card-title { font-size: 1rem; font-weight: 600; margin: 0 0 0.25rem; color: var(--text); }
.docs-card-meta { font-size: 0.8125rem; color: var(--text-muted); }
.docs-card-desc { font-size: 0.875rem; color: var(--text-muted); margin: 0.75rem 0; line-height: 1.5; }
.docs-card-cta { font-size: 0.8125rem; font-weight: 500; color: var(--brand-blue); }
.docs-endpoint-url { font-size: 0.8125rem; font-family: var(--font-mono); word-break: break-all; }
.badge-method {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
}
.docs-table th { font-size: 0.6875rem; }
.docs-lang-tabs .nav-link {
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 0.35rem 0.75rem;
}
.docs-lang-tabs .nav-link.active {
  background: var(--brand-blue-soft);
  color: var(--brand-blue);
}

/* KM brand loader — dual swoosh arcs (logo motif) */
.km-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}
.km-loader.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}
.km-loader-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  width: 32%;
  border-radius: 0 2px 2px 0;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-green));
  box-shadow: 0 0 8px rgba(6, 117, 172, 0.35);
  animation: km-bar-run 1.05s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
.km-loader-veil {
  position: absolute;
  inset: 0;
  background: rgba(234, 234, 234, 0.55);
  backdrop-filter: blur(1px);
}
[data-theme="dark"] .km-loader-veil {
  background: rgba(15, 20, 25, 0.55);
}
.km-loader-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
}
.km-loader-mark::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.km-arc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid transparent;
}
.km-arc-blue {
  border-top-color: var(--brand-blue);
  border-right-color: var(--brand-blue);
  animation: km-spin 0.85s linear infinite;
}
.km-arc-green {
  inset: 5px;
  border-bottom-color: var(--brand-green);
  border-left-color: var(--brand-green);
  animation: km-spin-rev 1.15s linear infinite;
}
.km-loader-core {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-green), var(--brand-blue));
  animation: km-pulse 1s ease-in-out infinite;
}
.km-loader.is-slim .km-loader-veil,
.km-loader.is-slim .km-loader-mark {
  display: none;
}
@keyframes km-spin {
  to { transform: rotate(360deg); }
}
@keyframes km-spin-rev {
  to { transform: rotate(-360deg); }
}
@keyframes km-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.72); opacity: 0.65; }
}
@keyframes km-bar-run {
  0% { left: -32%; width: 28%; }
  50% { width: 42%; }
  100% { left: 100%; width: 28%; }
}
@media (prefers-reduced-motion: reduce) {
  .km-arc-blue,
  .km-arc-green,
  .km-loader-core,
  .km-loader-bar {
    animation: none;
  }
  .km-loader-bar {
    left: 0;
    width: 100%;
    opacity: 0.85;
  }
}
