/* ==========================================================
   OBZERV — Dark SaaS Theme
   Bootstrap 5.3 · Dark default · Light mode via data-bs-theme
   ========================================================== */

/* ── Palette variables ─────────────────────────────────── */
:root {
  --obzerv-bg:           #0d1117;
  --obzerv-surface:      #161b22;
  --obzerv-surface-2:    #1c2128;
  --obzerv-border:       #30363d;
  --obzerv-accent:       #2563eb;
  --obzerv-accent-hover: #1d4ed8;
  --obzerv-text:         #e6edf3;
  --obzerv-text-muted:   #8b949e;
  --obzerv-danger:       #f85149;
  --obzerv-success:      #3fb950;
  --obzerv-warning:      #d29922;
  --obzerv-navbar-h:     56px;
}

/* ── Bootstrap 5.3 dark-mode overrides ─────────────────── */
[data-bs-theme="dark"] {
  --bs-body-bg:              var(--obzerv-bg);
  --bs-body-color:           var(--obzerv-text);
  --bs-secondary-color:      var(--obzerv-text-muted);
  --bs-border-color:         var(--obzerv-border);
  --bs-card-bg:              var(--obzerv-surface);
  --bs-card-border-color:    var(--obzerv-border);
  --bs-table-bg:             transparent;
  --bs-table-striped-bg:     rgba(255,255,255,0.03);
  --bs-table-hover-bg:       rgba(37,99,235,0.12);
  --bs-table-border-color:   var(--obzerv-border);
  --bs-input-bg:             var(--obzerv-surface-2);
  --bs-input-border-color:   var(--obzerv-border);
  --bs-input-color:          var(--obzerv-text);
  --bs-link-color:           #58a6ff;
  --bs-link-hover-color:     #79b8ff;
  color-scheme: dark;
}

[data-bs-theme="light"] {
  --obzerv-bg:        #f6f8fa;
  --obzerv-surface:   #ffffff;
  --obzerv-surface-2: #f0f2f5;
  --obzerv-border:    #d0d7de;
  --obzerv-text:      #1f2328;
  --obzerv-text-muted:#656d76;
  color-scheme: light;
}

/* ── Base ───────────────────────────────────────────────── */
html, body {
  min-height: 100%;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background-color: var(--obzerv-bg);
  color: var(--obzerv-text);
}

/* space for fixed navbar */
body { padding-top: var(--obzerv-navbar-h); }

a { color: var(--bs-link-color, #58a6ff); }
a:hover { color: var(--bs-link-hover-color, #79b8ff); }

/* ── Navbar ─────────────────────────────────────────────── */
.obzerv-navbar {
  height: var(--obzerv-navbar-h);
  background: rgba(13,17,23,0.97) !important;
  border-bottom: 1px solid var(--obzerv-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1040;
}

[data-bs-theme="light"] .obzerv-navbar {
  background: rgba(255,255,255,0.97) !important;
  border-bottom: 1px solid var(--obzerv-border);
}

.obzerv-navbar .navbar-brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  color: var(--obzerv-text) !important;
  gap: 8px;
}

.obzerv-navbar .navbar-brand img { border-radius: 6px; }

.obzerv-navbar .nav-link {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--obzerv-text-muted) !important;
  padding: 6px 10px !important;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}

.obzerv-navbar .nav-link:hover,
.obzerv-navbar .nav-link.active {
  color: var(--obzerv-text) !important;
  background: rgba(255,255,255,0.06);
}

[data-bs-theme="light"] .obzerv-navbar .nav-link:hover,
[data-bs-theme="light"] .obzerv-navbar .nav-link.active {
  background: rgba(0,0,0,0.06);
}

.obzerv-navbar .nav-link .bi {
  font-size: 0.95rem;
  vertical-align: -0.1em;
  margin-right: 4px;
}

/* icon-only nav buttons (bell, theme toggle) */
.obzerv-navbar .nav-link.nav-icon-btn {
  padding: 6px 8px !important;
  font-size: 1rem;
}
.obzerv-navbar .nav-link.nav-icon-btn .bi { margin-right: 0; }

/* Dropdown menus */
.obzerv-navbar .dropdown-menu {
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  padding: 4px;
  min-width: 210px;
  margin-top: 4px !important;
  font-size: 0.82rem;
}

[data-bs-theme="light"] .obzerv-navbar .dropdown-menu {
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.obzerv-navbar .dropdown-item {
  color: var(--obzerv-text-muted);
  border-radius: 5px;
  padding: 6px 12px;
  transition: background 0.12s, color 0.12s;
}

.obzerv-navbar .dropdown-item:hover,
.obzerv-navbar .dropdown-item:focus {
  background: rgba(37,99,235,0.15);
  color: var(--obzerv-text);
}

.obzerv-navbar .dropdown-divider {
  border-color: var(--obzerv-border);
  margin: 4px 8px;
}

.obzerv-navbar .dropdown-header {
  color: var(--obzerv-text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 12px 4px;
  font-weight: 600;
}

/* ── Multi-level (submenu) dropdowns ────────────────────── */
.dropdown-submenu { position: relative; }

.dropdown-submenu > .dropdown-menu {
  top: 0;
  left: 100%;
  margin-top: -4px !important;
  margin-left: 2px;
  display: none;
  max-height: var(--submenu-max-h, 80vh);
  overflow-y: auto;
  overflow-x: hidden;
  /* scrollbar always visible so layout is stable */
  scrollbar-width: thin;
  scrollbar-color: var(--obzerv-border) transparent;
}

.dropdown-submenu > .dropdown-item::after {
  content: "\F285"; /* bi-chevron-right */
  font-family: "bootstrap-icons";
  float: right;
  margin-top: 1px;
  font-size: 0.75rem;
}

.dropdown-submenu:hover > .dropdown-menu,
.dropdown-submenu:focus-within > .dropdown-menu {
  display: block;
}

/* Active-case badge in navbar */
.obzerv-case-badge {
  font-size: 0.75rem;
  background: rgba(37,99,235,0.18);
  color: #58a6ff;
  border: 1px solid rgba(37,99,235,0.35);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.obzerv-case-badge.shared { color: var(--obzerv-warning); border-color: rgba(210,153,34,0.35); background: rgba(210,153,34,0.1); }

/* ── Page content wrapper ───────────────────────────────── */
.obzerv-content {
  padding: 24px 20px;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 10px;
}

.card-header {
  background: var(--obzerv-surface-2);
  border-bottom: 1px solid var(--obzerv-border);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 12px 16px;
}

/* ── Tables ─────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-bottom: 16px;
  background: transparent;
}

th, td {
  padding: 7px 10px !important;
  border: 1px solid var(--obzerv-border);
  vertical-align: middle;
}

th {
  background: var(--obzerv-surface-2);
  color: var(--obzerv-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

tbody tr:hover { background: rgba(37,99,235,0.07); }
tbody tr:nth-child(even) { background: rgba(255,255,255,0.02); }

[data-bs-theme="light"] th { background: #f6f8fa; }
[data-bs-theme="light"] tbody tr:nth-child(even) { background: rgba(0,0,0,0.02); }

/* ── Forms ──────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="search"],
select,
textarea {
  background: var(--obzerv-surface-2) !important;
  color: var(--obzerv-text) !important;
  border: 1px solid var(--obzerv-border) !important;
  border-radius: 6px !important;
  padding: 7px 10px !important;
  font-size: 0.85rem !important;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
select:focus,
textarea:focus {
  border-color: var(--obzerv-accent) !important;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.2) !important;
  outline: none !important;
}

input[disabled], select[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

[data-bs-theme="light"] input[type="text"],
[data-bs-theme="light"] input[type="password"],
[data-bs-theme="light"] input[type="email"],
[data-bs-theme="light"] input[type="number"],
[data-bs-theme="light"] input[type="date"],
[data-bs-theme="light"] input[type="time"],
[data-bs-theme="light"] select,
[data-bs-theme="light"] textarea {
  background: #ffffff !important;
  color: #1f2328 !important;
  border-color: #d0d7de !important;
}

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--obzerv-text-muted);
  margin-bottom: 4px;
  display: block;
}

/* ── Buttons ─────────────────────────────────────────────── */
button,
input[type="submit"] {
  background: var(--obzerv-accent) !important;
  color: #fff !important;
  border: none !important;
  padding: 7px 16px !important;
  margin: 4px 4px 4px 0 !important;
  font-size: 0.82rem !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  border-radius: 6px !important;
  transition: background 0.15s !important;
  font-family: inherit !important;
  line-height: 1.4 !important;
}

button:hover,
input[type="submit"]:hover {
  background: var(--obzerv-accent-hover) !important;
}

button:disabled,
input[type="submit"]:disabled {
  background: var(--obzerv-surface-2) !important;
  color: var(--obzerv-text-muted) !important;
  cursor: not-allowed !important;
  opacity: 0.6 !important;
}

/* ── Headings ────────────────────────────────────────────── */
h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 16px; color: var(--obzerv-text); }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; color: var(--obzerv-text); }
h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 10px; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  border-radius: 8px;
  font-size: 0.85rem;
  border: 1px solid;
  padding: 10px 14px;
}

/* ── Select (multiple) ───────────────────────────────────── */
select[multiple] {
  min-height: 140px;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--obzerv-bg); }
::-webkit-scrollbar-thumb { background: var(--obzerv-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--obzerv-text-muted); }

/* ── Chart.js dark defaults ──────────────────────────────── */
canvas { max-width: 100%; }

/* ── Geo map fix ─────────────────────────────────────────── */
#map { height: 600px; width: 100%; border-radius: 10px; border: 1px solid var(--obzerv-border); }

/* ── Login page ──────────────────────────────────────────── */
.obzerv-login-wrap {
  min-height: calc(100vh - var(--obzerv-navbar-h));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.obzerv-login-card {
  width: 100%;
  max-width: 400px;
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 12px;
  padding: 36px 32px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.obzerv-login-card h2 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.3rem;
}

/* ── Filter bar ──────────────────────────────────────────── */
.obzerv-filter-bar {
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}

.obzerv-filter-bar label {
  min-width: 160px;
}

/* ── Action link buttons in tables ───────────────────────── */
a.btn-action {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(37,99,235,0.15);
  color: #58a6ff;
  text-decoration: none;
  border: 1px solid rgba(37,99,235,0.3);
  display: inline-block;
  margin: 1px;
  transition: background 0.12s;
}

a.btn-action:hover { background: rgba(37,99,235,0.3); color: #fff; }
a.btn-action.danger { background: rgba(248,81,73,0.1); color: var(--obzerv-danger); border-color: rgba(248,81,73,0.3); }
a.btn-action.danger:hover { background: rgba(248,81,73,0.25); color: #fff; }

/* ── HR ──────────────────────────────────────────────────── */
hr { border-color: var(--obzerv-border); opacity: 1; }

/* ── Notification bell badge ─────────────────────────────── */
.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: var(--obzerv-danger);
  border-radius: 50%;
  border: 2px solid var(--obzerv-bg);
}

/* ── Case chart row ──────────────────────────────────────── */
.obzerv-chart-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.obzerv-chart-box {
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 10px;
  padding: 12px;
  height: 220px;
  position: relative;
}

.obzerv-chart-box canvas {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 1200px) { .obzerv-chart-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px)  { .obzerv-chart-grid { grid-template-columns: 1fr; } }

/* ── Docs sidebar ────────────────────────────────────────── */
.obzerv-docs-sidebar {
  background: var(--obzerv-surface);
  border: 1px solid var(--obzerv-border);
  border-radius: 10px;
  padding: 16px;
  position: sticky;
  top: calc(var(--obzerv-navbar-h) + 16px);
}

.obzerv-docs-sidebar a {
  display: block;
  padding: 5px 8px;
  border-radius: 5px;
  color: var(--obzerv-text-muted);
  font-size: 0.82rem;
  text-decoration: none;
}

.obzerv-docs-sidebar a:hover { background: rgba(255,255,255,0.05); color: var(--obzerv-text); }

/* ── Mobile nav ──────────────────────────────────────────── */
/* Flip submenu to the left when it would overflow the right edge */
.dropdown-submenu.flip-left > .dropdown-menu {
  left: auto;
  right: 100%;
  margin-left: 0;
  margin-right: 2px;
}

@media (max-width: 1199px) {
  /* Let navbar grow vertically when collapsed menu is open */
  .obzerv-navbar { height: auto !important; }

  /* Collapsed panel: full-width opaque panel below the brand row */
  .obzerv-navbar .navbar-collapse {
    background: rgba(13,17,23,0.98);
    border-top: 1px solid var(--obzerv-border);
    padding: 8px 0 12px;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  [data-bs-theme="light"] .obzerv-navbar .navbar-collapse {
    background: rgba(255,255,255,0.98);
  }

  /* Dropdowns inside the collapsed panel: flat, no floating */
  .obzerv-navbar .dropdown-menu {
    position: static;
    box-shadow: none;
    margin: 0;
    border: none;
    border-radius: 0;
    background: rgba(255,255,255,0.05);
    min-width: 0;
  }
  [data-bs-theme="light"] .obzerv-navbar .dropdown-menu {
    background: rgba(0,0,0,0.04);
  }

  .dropdown-submenu > .dropdown-menu { left: 0; top: auto; margin-left: 16px !important; max-height: none; }
  .dropdown-submenu > .dropdown-item::after { display: none; }
}

/* ── Subscription tier gating ──────────────────────────── */
.obzerv-locked {
  position: relative;
  cursor: not-allowed !important;
}
/* Dim locked items with a muted colour instead of element opacity, so the
   dropdown's solid background stays opaque (no page content bleeding through). */
.obzerv-locked > a,
.obzerv-locked * {
  pointer-events: none;
  cursor: not-allowed !important;
  color: var(--obzerv-text-muted, #8b949e) !important;
}
/* Re-enable click so our JS capture-phase listener fires */
.obzerv-locked { pointer-events: auto !important; }

.obzerv-lock-badge {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  padding-left: 0.5rem;
  color: var(--obzerv-text-muted, #8b949e);
  font-size: 0.7rem;
}

/* Subscription / ProAI badge colours */
.bg-purple { background: linear-gradient(135deg, #7c3aed, #2563eb) !important; }

/* D3 call-graph tooltip */
.tooltipd3 {
  display: none;
  position: absolute;
  padding: 6px 10px;
  background: var(--obzerv-surface, #161b22);
  color: var(--obzerv-text, #e6edf3);
  border: 1px solid var(--obzerv-border, #30363d);
  border-radius: 6px;
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* Row colorizer — tables with class "colorable" */
table.colorable tbody tr { cursor: default; }
table.colorable tbody tr.row-highlighted {
  background-color: rgba(255, 193, 7, 0.30) !important;
  outline: 1px solid rgba(255, 193, 7, 0.55);
  outline-offset: -1px;
}
