/**
 * OrbPanel theme safety net — GitHub Primer–inspired product dark / soft light.
 * Research refs: GitHub dark canvas #0d1117, Linear/Vercel product neutrals,
 * Cloudflare dashboard grays. No neon purple “AI template” indigo.
 */

html { color-scheme: light dark; }
html, body, .fx-app, .fx-sidebar, .fx-main, .fx-content, .card, .modal-content,
.table, .form-control, .form-select, .btn, .badge, .alert {
  transition: background-color .2s ease, color .18s ease, border-color .18s ease, box-shadow .2s ease;
}

/* ═══════════════ LIGHT ═══════════════ */
[data-bs-theme="light"] {
  --bs-body-bg: #f6f8fa;
  --bs-body-color: #1f2328;
  --bs-secondary-color: #656d76;
  --bs-border-color: #d0d7de;
  --bs-primary: #0969da;
  --bs-primary-rgb: 9, 105, 218;
  --bs-success: #1a7f37;
  --bs-danger: #cf222e;
  --bs-warning: #9a6700;
  --bs-info: #0969da;
  color-scheme: light;
}
[data-bs-theme="light"] body { background: #f6f8fa !important; color: #1f2328 !important; }
[data-bs-theme="light"] .card,
[data-bs-theme="light"] .modal-content,
[data-bs-theme="light"] .list-group-item,
[data-bs-theme="light"] .dropdown-menu,
[data-bs-theme="light"] .offcanvas {
  background: #ffffff !important; color: #1f2328 !important; border-color: #d0d7de !important;
}
[data-bs-theme="light"] .card-header,
[data-bs-theme="light"] .modal-header { background: #f6f8fa !important; color: #1f2328 !important; border-color: #d0d7de !important; }
[data-bs-theme="light"] .table {
  --bs-table-bg: #fff; --bs-table-color: #1f2328; --bs-table-striped-bg: #f6f8fa;
  --bs-table-hover-bg: #ddf4ff; --bs-table-border-color: #d0d7de; color: #1f2328 !important;
}
[data-bs-theme="light"] .table > :not(caption) > * > * {
  background-color: var(--bs-table-bg) !important; color: #1f2328 !important; border-bottom-color: #d0d7de !important;
}
[data-bs-theme="light"] .table-light, [data-bs-theme="light"] thead.table-light, [data-bs-theme="light"] .table thead th {
  background: #f6f8fa !important; color: #424a53 !important;
}
[data-bs-theme="light"] .form-control, [data-bs-theme="light"] .form-select {
  background: #fff !important; color: #1f2328 !important; border-color: #d0d7de !important;
}
[data-bs-theme="light"] .form-control:focus, [data-bs-theme="light"] .form-select:focus {
  border-color: #0969da !important; box-shadow: 0 0 0 3px rgba(9,105,218,.18) !important;
}
[data-bs-theme="light"] .text-muted { color: #656d76 !important; }
[data-bs-theme="light"] .btn-primary {
  background: #0969da !important; border-color: #0969da !important; color: #fff !important;
  box-shadow: 0 1px 0 rgba(27,31,36,.04);
}
[data-bs-theme="light"] .btn-primary:hover { background: #0550ae !important; border-color: #0550ae !important; color: #fff !important; }
[data-bs-theme="light"] .btn-outline-secondary {
  color: #424a53 !important; border-color: #d0d7de !important; background: #fff !important;
}
[data-bs-theme="light"] .btn-outline-secondary:hover { background: #f6f8fa !important; color: #1f2328 !important; }
[data-bs-theme="light"] .btn-danger { background: #cf222e !important; border-color: #cf222e !important; color: #fff !important; }
[data-bs-theme="light"] .btn-success { background: #1a7f37 !important; border-color: #1a7f37 !important; color: #fff !important; }
[data-bs-theme="light"] .badge.bg-success, [data-bs-theme="light"] .badge.text-bg-success { background: #dafbe1 !important; color: #116329 !important; }
[data-bs-theme="light"] .badge.bg-secondary, [data-bs-theme="light"] .badge.text-bg-secondary { background: #eaeef2 !important; color: #424a53 !important; }
[data-bs-theme="light"] .badge.bg-primary, [data-bs-theme="light"] .badge.text-bg-primary { background: #ddf4ff !important; color: #0550ae !important; }
[data-bs-theme="light"] .badge.bg-danger, [data-bs-theme="light"] .badge.text-bg-danger { background: #ffebe9 !important; color: #a40e26 !important; }
[data-bs-theme="light"] .badge.bg-warning, [data-bs-theme="light"] .badge.text-bg-warning { background: #fff8c5 !important; color: #7d4e00 !important; }
[data-bs-theme="light"] a:not(.btn):not(.dropdown-item):not(.fx-sidebar-link) { color: #0969da; }
[data-bs-theme="light"] a:not(.btn):hover { color: #0550ae; }
[data-bs-theme="light"] code { color: #cf222e !important; background: #fff !important; border: 1px solid #d0d7de; border-radius: 4px; padding: .1em .35em; }
[data-bs-theme="light"] [data-theme-toggle] { background: #ddf4ff !important; color: #0550ae !important; border: 1px solid #b6e3ff !important; border-radius: 8px !important; }

/* ═══════════════ DARK (GitHub Primer canvas) ═══════════════ */
[data-bs-theme="dark"] {
  --bs-body-bg: #0d1117;
  --bs-body-color: #e6edf3;
  --bs-secondary-color: #8b949e;
  --bs-border-color: #30363d;
  --bs-primary: #58a6ff;
  --bs-primary-rgb: 88, 166, 255;
  --bs-success: #3fb950;
  --bs-danger: #f85149;
  --bs-warning: #d29922;
  --bs-info: #58a6ff;
  --bs-tertiary-bg: #21262d;
  color-scheme: dark;
}
[data-bs-theme="dark"] body { background: #0d1117 !important; color: #e6edf3 !important; }

[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .modal-overlay .modal-content,
[data-bs-theme="dark"] .list-group-item,
[data-bs-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .offcanvas,
[data-bs-theme="dark"] .popover,
[data-bs-theme="dark"] .toast,
[data-bs-theme="dark"] .accordion-item {
  background: #161b22 !important; color: #e6edf3 !important; border-color: #30363d !important;
}
[data-bs-theme="dark"] .card-header,
[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-footer,
[data-bs-theme="dark"] .accordion-button {
  background: #21262d !important; color: #e6edf3 !important; border-color: #30363d !important;
}
[data-bs-theme="dark"] .accordion-button:not(.collapsed) {
  background: rgba(56,139,253,.12) !important; color: #79c0ff !important; box-shadow: none !important;
}

/* Tables — never white in dark */
[data-bs-theme="dark"] .table {
  --bs-table-bg: #161b22;
  --bs-table-color: #e6edf3;
  --bs-table-striped-bg: #21262d;
  --bs-table-striped-color: #e6edf3;
  --bs-table-hover-bg: #30363d;
  --bs-table-hover-color: #f0f6fc;
  --bs-table-border-color: #30363d;
  color: #e6edf3 !important; border-color: #30363d !important;
}
[data-bs-theme="dark"] .table > :not(caption) > * > * {
  background-color: var(--bs-table-bg) !important; color: #e6edf3 !important;
  border-bottom-color: #30363d !important; box-shadow: none !important;
}
[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] thead.table-light,
[data-bs-theme="dark"] .table thead th,
[data-bs-theme="dark"] .table > thead {
  --bs-table-bg: #21262d !important;
  background: #21262d !important; color: #8b949e !important; border-color: #30363d !important;
}
[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
  background: #21262d !important; color: #e6edf3 !important;
}
[data-bs-theme="dark"] .bg-white,
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-body,
[data-bs-theme="dark"] .bg-body-tertiary,
[data-bs-theme="dark"] .bg-body-secondary {
  background: #21262d !important; color: #e6edf3 !important;
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .input-group-text {
  background: #0d1117 !important; color: #e6edf3 !important; border-color: #30363d !important;
}
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  background: #161b22 !important; border-color: #58a6ff !important; color: #f0f6fc !important;
  box-shadow: 0 0 0 3px rgba(56,139,253,.25) !important;
}
[data-bs-theme="dark"] .form-control::placeholder { color: #6e7681 !important; }
[data-bs-theme="dark"] .text-muted, [data-bs-theme="dark"] .form-text { color: #8b949e !important; }
[data-bs-theme="dark"] .text-dark, [data-bs-theme="dark"] .text-black { color: #e6edf3 !important; }
[data-bs-theme="dark"] .border, [data-bs-theme="dark"] .border-bottom, [data-bs-theme="dark"] .border-top { border-color: #30363d !important; }

[data-bs-theme="dark"] .btn-primary {
  background: #238636 !important; /* GitHub green primary CTA alternative: use blue */
  background: #1f6feb !important;
  border-color: #1f6feb !important; color: #ffffff !important;
}
[data-bs-theme="dark"] .btn-primary:hover { background: #388bfd !important; border-color: #388bfd !important; color: #fff !important; }
[data-bs-theme="dark"] .btn-outline-secondary,
[data-bs-theme="dark"] .btn-outline-primary,
[data-bs-theme="dark"] .btn-light {
  background: #21262d !important; border-color: #30363d !important; color: #e6edf3 !important;
}
[data-bs-theme="dark"] .btn-outline-secondary:hover,
[data-bs-theme="dark"] .btn-outline-primary:hover {
  background: #30363d !important; border-color: #8b949e !important; color: #f0f6fc !important;
}
[data-bs-theme="dark"] .btn-danger { background: #da3633 !important; border-color: #da3633 !important; color: #fff !important; }
[data-bs-theme="dark"] .btn-success { background: #238636 !important; border-color: #238636 !important; color: #fff !important; }

[data-bs-theme="dark"] .badge.bg-success, [data-bs-theme="dark"] .badge.text-bg-success {
  background: rgba(46,160,67,.2) !important; color: #3fb950 !important;
}
[data-bs-theme="dark"] .badge.bg-secondary, [data-bs-theme="dark"] .badge.text-bg-secondary {
  background: rgba(110,118,129,.25) !important; color: #c9d1d9 !important;
}
[data-bs-theme="dark"] .badge.bg-primary, [data-bs-theme="dark"] .badge.text-bg-primary {
  background: rgba(56,139,253,.2) !important; color: #79c0ff !important;
}
[data-bs-theme="dark"] .badge.bg-danger, [data-bs-theme="dark"] .badge.text-bg-danger {
  background: rgba(248,81,73,.2) !important; color: #ff7b72 !important;
}
[data-bs-theme="dark"] .badge.bg-warning, [data-bs-theme="dark"] .badge.text-bg-warning {
  background: rgba(187,128,9,.2) !important; color: #e3b341 !important;
}
[data-bs-theme="dark"] .badge.bg-info, [data-bs-theme="dark"] .badge.text-bg-info {
  background: rgba(56,139,253,.15) !important; color: #79c0ff !important;
}

[data-bs-theme="dark"] a:not(.btn):not(.dropdown-item):not(.fx-sidebar-link) { color: #58a6ff; }
[data-bs-theme="dark"] a:not(.btn):hover { color: #79c0ff; }
[data-bs-theme="dark"] .fx-sidebar-brand, [data-bs-theme="dark"] .navbar-brand { color: #f0f6fc !important; }

[data-bs-theme="dark"] code {
  color: #ff7b72 !important; background: rgba(110,118,129,.2) !important;
  border-radius: 4px; padding: .1em .35em;
}
[data-bs-theme="dark"] .alert-success { background: rgba(46,160,67,.15) !important; color: #3fb950 !important; border-color: rgba(46,160,67,.35) !important; }
[data-bs-theme="dark"] .alert-danger { background: rgba(248,81,73,.15) !important; color: #ff7b72 !important; border-color: rgba(248,81,73,.35) !important; }
[data-bs-theme="dark"] .alert-warning { background: rgba(187,128,9,.15) !important; color: #e3b341 !important; border-color: rgba(187,128,9,.35) !important; }
[data-bs-theme="dark"] .alert-info { background: rgba(56,139,253,.12) !important; color: #79c0ff !important; border-color: rgba(56,139,253,.3) !important; }

[data-bs-theme="dark"] .dropdown-item { color: #e6edf3 !important; }
[data-bs-theme="dark"] .dropdown-item:hover { background: #30363d !important; color: #f0f6fc !important; }
[data-bs-theme="dark"] .page-link { background: #161b22 !important; color: #58a6ff !important; border-color: #30363d !important; }
[data-bs-theme="dark"] .page-link:hover { background: #21262d !important; color: #79c0ff !important; }
[data-bs-theme="dark"] .progress { background: #21262d !important; }

[data-bs-theme="dark"] .fm-cpanel-toolbar,
[data-bs-theme="dark"] .fm-utilitybar,
[data-bs-theme="dark"] .fm-selectionbar,
[data-bs-theme="dark"] .fm-commandbar {
  background: #161b22 !important; border-color: #30363d !important; color: #e6edf3 !important;
}

[data-bs-theme="dark"] [data-theme-toggle] {
  background: #21262d !important; color: #e6edf3 !important; border: 1px solid #30363d !important; border-radius: 8px !important;
}
[data-bs-theme="dark"] [data-theme-toggle]:hover { background: #30363d !important; }

/* Live metric widgets */
.live-metric-card .live-value { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: -0.02em; }
.live-metric-card .live-bar {
  height: 6px; border-radius: 999px; background: var(--fx-surface-3, #30363d); overflow: hidden; margin-top: .5rem;
}
.live-metric-card .live-bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #238636, #3fb950);
  width: 0%; transition: width .6s ease;
}
.live-metric-card.warn .live-bar > i { background: linear-gradient(90deg, #9a6700, #d29922); }
.live-metric-card.crit .live-bar > i { background: linear-gradient(90deg, #cf222e, #f85149); }
.live-pulse {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; color: var(--fx-text-muted);
}
.live-pulse::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #3fb950;
  box-shadow: 0 0 0 0 rgba(63,185,80,.5); animation: livePulse 1.6s infinite;
}
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(63,185,80,.45); }
  70% { box-shadow: 0 0 0 8px rgba(63,185,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,185,80,0); }
}
