:root {
  --bg-body: #f5f6fa;
  --bg-sidebar: #020617;
  --bg-sidebar-accent: #0f172a;
  --bg-card: #ffffff;
  --bg-card-elevated: #ffffff;
  --text-main: #0f172a;
  --text-muted: #6b7280;
  --border-subtle: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc3545;
  --success: #198754;
  --warning: #f59e0b;
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.08);
}

/* Dark theme overrides */
body.theme-dark {
  --bg-body: #020617;
  --bg-sidebar: #020617;
  --bg-sidebar-accent: #0b1120;
  --bg-card: #0f172a;
  --bg-card-elevated: #020617;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --border-subtle: #1f2937;
  --accent: #3b82f6;
  --accent-soft: rgba(59,130,246,0.15);
  --shadow-soft: 0 10px 30px rgba(15, 23, 42, 0.65);
}

/* Base layout */

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#wrapper {
  min-height: 100vh;
}

/* Sidebar */

#sidebar {
  width: 240px;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #1e293b 0, var(--bg-sidebar) 40%, #020617 100%);
  color: #e5e7eb;
}

#sidebar .sidebar-inner {
  padding: 1rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#sidebar .navbar-brand {
  padding: 0.5rem 0.75rem 0.25rem;
}

#sidebar .navbar-brand span {
  letter-spacing: 0.04em;
}

#sidebar .nav-link {
  border-radius: 0.75rem;
  margin-bottom: 0.25rem;
  padding-inline: 0.75rem;
  padding-block: 0.4rem;
  font-size: 0.92rem;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#sidebar .nav-link i {
  width: 1.25rem;
  text-align: center;
  opacity: 0.9;
}

#sidebar .nav-link:hover {
  color: #f9fafb;
  background-color: rgba(148, 163, 184, 0.18);
  text-decoration: none;
}

#sidebar .nav-link.active {
  color: #f9fafb;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.5);
}

#sidebar .nav-link.active i {
  opacity: 1;
}

#sidebar .nav-link.text-white-50 {
  color: rgba(148, 163, 184, 0.9) !important;
}

#sidebar .nav-link.text-white-50 i {
  opacity: 0.7;
}

#sidebar .px-3.pb-3.mt-auto {
  border-top: 1px solid rgba(148,163,184,0.35);
  padding-top: 0.75rem !important;
}

/* Header / navbar */

.navbar-pure-white {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
}

body.theme-dark .navbar-pure-white {
  background-color: var(--bg-sidebar-accent);
  border-bottom-color: #111827;
}

.navbar-pure-white .navbar-brand {
  font-size: 1rem;
  color: var(--text-main);
}

body.theme-dark .navbar-pure-white .navbar-brand {
  color: #e5e7eb;
}

/* Top search bar */

.navbar-pure-white .form-control {
  border-radius: 999px;
  font-size: 0.9rem;
}

/* Theme toggle button */

.theme-toggle-btn {
  border-radius: 999px;
  padding-inline: 0.75rem;
}

/* Footer */

footer {
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
}

body.theme-dark footer {
  background-color: var(--bg-sidebar-accent);
  border-top-color: #111827;
}

/* Main layout content */

#content {
  background-color: var(--bg-body);
}

.card {
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-soft);
}

.card.border-0 {
  border-color: transparent;
}

.card.kpi-card {
  border-left: 4px solid transparent;
}

.kpi-card.kpi-primary {
  border-left-color: var(--accent);
}

.kpi-card.kpi-danger {
  border-left-color: var(--danger);
}

.kpi-card.kpi-success {
  border-left-color: var(--success);
}

.kpi-card.kpi-warning {
  border-left-color: var(--warning);
}

.kpi-card.kpi-secondary {
  border-left-color: var(--border-subtle);
}

/* Tables */

.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom-color: var(--border-subtle);
}

.table tbody td {
  font-size: 0.86rem;
  vertical-align: middle;
}

.table-hover tbody tr:hover {
  background-color: rgba(148, 163, 184, 0.12);
}

/* Forms */

.form-control,
.form-select {
  border-radius: 0.7rem;
  border-color: var(--border-subtle);
  font-size: 0.9rem;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.15rem rgba(37, 99, 235, 0.25);
}

/* Badges / status pills */

.badge-status {
  font-weight: 500;
  font-size: 0.72rem;
  border-radius: 999px;
  padding-inline: 0.6rem;
  padding-block: 0.22rem;
}

.badge-status-open {
  background-color: rgba(248, 250, 252, 0.95);
  color: #b45309;
  border: 1px solid rgba(234, 179, 8, 0.7);
}

body.theme-dark .badge-status-open {
  background-color: rgba(30, 64, 175, 0.2);
  color: #fde68a;
  border-color: rgba(234, 179, 8, 0.8);
}

.badge-status-closed {
  background-color: rgba(240, 253, 250, 0.95);
  color: #047857;
  border: 1px solid rgba(16, 185, 129, 0.6);
}

body.theme-dark .badge-status-closed {
  background-color: rgba(22, 163, 74, 0.15);
  color: #bbf7d0;
  border-color: rgba(34, 197, 94, 0.8);
}

.badge-status-other {
  background-color: rgba(239, 246, 255, 0.95);
  color: #1d4ed8;
  border: 1px solid rgba(59, 130, 246, 0.6);
}

body.theme-dark .badge-status-other {
  background-color: rgba(37, 99, 235, 0.18);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.8);
}

/* Incidents table specific */

.incident-ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.82rem;
}

/* Charts container */

.chart-container {
  position: relative;
  height: 260px;
}

/* SQL explorer */

.sql-editor {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  border-radius: 0.75rem;
}

/* Media preview */

.incident-media-preview img {
  border-radius: 0.75rem;
  box-shadow: var(--shadow-soft);
}

.incident-media-preview .placeholder {
  border-radius: 0.75rem;
  border: 1px dashed var(--border-subtle);
  padding: 1rem;
  color: var(--text-muted);
  text-align: center;
}

/* Utility */

.badge-soft {
  background-color: var(--accent-soft);
  color: var(--accent);
}

/* Ensure legacy bg-white and related classes respect dark mode */
body.theme-dark .bg-white {
  background-color: var(--bg-card) !important;
}


body.theme-dark .table {
  background-color: transparent;
}


/* SQL explorer tables */
.sql-table-wrapper {
  width: 100%;
  overflow-x: auto;
}


/* Avatar + logo in header/sidebar */
.logo-circle {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background-color: #e5e7eb;
  color: #111827;
  font-size: 0.75rem;
}

body.theme-dark .avatar-circle {
  background-color: #1f2937;
  color: #e5e7eb;
}

/* Bot select in top bar */
.bot-select {
  max-width: 220px;
}

/* Small form labels for filters */
.form-label-sm {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* Top bar spacing */
.navbar-pure-white {
  min-height: 56px;
}

/* KPI variations */
.kpi-primary {
  border-left-color: var(--accent);
}
.kpi-success {
  border-left-color: var(--success);
}
.kpi-warning {
  border-left-color: var(--warning);
}
.kpi-info {
  border-left-color: #0dcaf0;
}

/* Theme button tweaks */
.theme-toggle-btn {
  border-radius: 999px;
  padding-inline: 0.6rem;
  padding-block: 0.25rem;
  font-size: 0.75rem;
}




/* === Dark mode refinements & global polish ================================ */

/* Make content area honour theme */
#content {
  background-color: var(--bg-body);
}

/* Cards & surfaces in dark mode */
body.theme-dark .card {
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
}

/* Tables: make headers & rows  dark-aware */
.table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom-color: var(--border-subtle);
}

.table > :not(caption) > * > * {
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
}

body.theme-dark .table > :not(caption) > * > * {
  background-color: #020617;
  border-color: #1f2937;
}

body.theme-dark .table thead th {
  background-color: #020617;
  color: var(--text-muted);
}

.table-hover tbody tr:hover {
  background-color: rgba(148, 163, 184, 0.12);
}

body.theme-dark .table-hover tbody tr:hover {
  background-color: #0b1120;
}

/* Forms: tie backgrounds & text to theme vars */
.form-control,
.form-select,
.input-group-text {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

body.theme-dark .form-control,
body.theme-dark .form-select,
body.theme-dark .input-group-text {
  background-color: #020617;
  color: #e5e7eb;
  border-color: #1f2937;
}


body.theme-dark .alert {
  background-color: #020617;
  color: var(--text-main);
  border-color: #1f2937;
}


body.theme-dark .badge.bg-light,
body.theme-dark .badge.bg-white {
  background-color: #111827 !important;
  color: #e5e7eb !important;
}

/* Links & subtle text in dark mode */
a.link-secondary {
  color: #4b5563;
  text-decoration: none;
}

a.link-secondary:hover {
  color: var(--accent);
  text-decoration: underline;
}

body.theme-dark a,
body.theme-dark .nav-link,
body.theme-dark .page-link {
  color: var(--text-main);
}

body.theme-dark a:hover,
body.theme-dark .nav-link:hover,
body.theme-dark .page-link:hover {
  color: var(--accent);
}

body.theme-dark a.link-secondary {
  color: #e5e7eb;
}

body.theme-dark a.link-secondary:hover {
  color: var(--accent);
}

/* Headings & labels in dark mode */
body.theme-dark .card-title,
body.theme-dark .card-header,
body.theme-dark .modal-title {
  color: var(--text-main);
}

body.theme-dark .card-subtitle,
body.theme-dark .card-header small,
body.theme-dark .card-header .text-muted {
  color: var(--text-muted);
}

body.theme-dark .form-label,
body.theme-dark label {
  color: var(--text-main);
}

body.theme-dark .form-control::placeholder,
body.theme-dark .form-select::placeholder {
  color: var(--text-muted);
}

/* Tables & nav components */
body.theme-dark .table thead th {
  color: var(--text-main);
  border-bottom-color: #1f2937;
}

body.theme-dark .table tbody td {
  border-color: #1f2937;
}

body.theme-dark .nav-tabs .nav-link {
  color: var(--text-muted);
}

body.theme-dark .nav-tabs .nav-link.active {
  color: var(--text-main);
  background-color: #020617;
  border-color: #1f2937 #1f2937 transparent;
}

body.theme-dark .breadcrumb-item + .breadcrumb-item::before {
  color: var(--text-muted);
}

body.theme-dark .badge.bg-secondary,
body.theme-dark .badge.bg-info {
  color: #e5e7eb;
}


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





body.theme-dark .form-text {
  color: var(--text-muted);
}

/* List groups in dark mode */
body.theme-dark .list-group-item {
  background-color: #020617;
  color: var(--text-main);
  border-color: #1f2937;
}

body.theme-dark .list-group-item-action:hover {
  background-color: #0b1120;
  color: var(--text-main);
}

body.theme-dark .list-group-item.active {
  background-color: #1d4ed8;
  border-color: #1d4ed8;
  color: #f9fafb;
}

/* Form check labels (radio / checkbox) */
body.theme-dark .form-check-label {
  color: var(--text-main);
}

/* Breadcrumb text */
body.theme-dark .breadcrumb-item,
body.theme-dark .breadcrumb-item a {
  color: var(--text-muted);
}

body.theme-dark .breadcrumb-item.active {
  color: var(--text-main);
}

/* Outline secondary buttons on dark surfaces */
body.theme-dark .btn-outline-secondary {
  color: var(--text-main);
  border-color: #4b5563;
}

body.theme-dark .btn-outline-secondary:hover,
body.theme-dark .btn-outline-secondary:focus {
  background-color: #111827;
  color: var(--text-main);
  border-color: #9ca3af;
}

/* Subtle info badge used for media indicator in incident table */
body.theme-dark .badge.bg-info-subtle.text-info {
  background-color: rgba(37, 99, 235, 0.25);
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.7);
}


body.theme-dark .text-muted {
  color: var(--text-muted) !important;
}




/* KPI cards – make labels & values pop more in dark mode */
body.theme-dark .kpi-card .text-muted.small.text-uppercase {
  color: var(--text-main);
  letter-spacing: 0.08em;
}

body.theme-dark .kpi-card h3 {
  color: #f9fafb;
  font-weight: 700;
}

/* General card 'small' text – keep body text readable but leave labels muted */
body.theme-dark .card .small {
  color: var(--text-main);
}

/* Tables – ensure body cells are fully readable in dark mode */
body.theme-dark .table tbody td,
body.theme-dark .table tbody th {
  color: var(--text-main);
  border-color: #1f2937;
}


body.theme-dark code {
  background-color: rgba(15, 23, 42, 0.9);
  color: var(--accent);
}

/* Map legend / other small lists inside cards */
body.theme-dark .card .list-unstyled.small li {
  color: var(--text-main);
}

/* Bot analytics – text colors for details lists */
body.theme-dark .card .list-unstyled.small span {
  color: var(--text-main);
}

/* Status highlight utilities in dark mode */
body.theme-dark .text-success {
  color: #22c55e;
}

body.theme-dark .text-danger {
  color: #ef4444;
}

/* Sidebar vs content separation in dark mode */
body.theme-dark #sidebar {
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.9);
  border-right: 1px solid #111827;
}

body.theme-dark main.container-fluid {
  background-color: #020617;
}
