:root {
  --app-primary: #0b5394;
  --app-accent: #2e8bda;
  --app-bg: #f3f5f9;
  --app-sidebar-bg: #1b2433;
  --app-sidebar-fg: #c7d0dd;
  --app-sidebar-active: #2e8bda;
  --app-navbar-h: 56px;
  --app-sidebar-w: 256px;
  --app-border: #e4e8ef;
}

* { box-sizing: border-box; }

body {
  background-color: var(--app-bg);
  color: #1f2733;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  margin: 0;
}

/* ---------- Top navbar ---------- */
.app-navbar {
  height: var(--app-navbar-h);
  background: linear-gradient(90deg, var(--app-primary), var(--app-accent));
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1040;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-navbar .navbar-brand { color: #fff; font-weight: 600; font-size: 1.05rem; }
.brand-logo { height: 30px; width: auto; max-width: 160px; object-fit: contain; }
.sidebar-logo { max-height: 44px; max-width: 100%; object-fit: contain; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--app-accent);
  display: inline-block; box-shadow: 0 0 0 3px rgba(46,139,218,0.25);
}
@media (max-width: 575px) { .brand-text { display: none; } }

/* ---------- Shell + sidebar ---------- */
.app-shell { display: flex; padding-top: var(--app-navbar-h); }

.app-sidebar {
  position: fixed;
  top: var(--app-navbar-h);
  bottom: 0; left: 0;
  width: var(--app-sidebar-w);
  background: var(--app-sidebar-bg);
  color: var(--app-sidebar-fg);
  overflow-y: auto;
  z-index: 1035;
  transition: transform 0.2s ease;
}
.sidebar-header {
  padding: 12px 16px; border-bottom: 1px solid var(--app-border);
  background: #ffffff;  /* white so a dark/colored logo is clearly visible */
  display: flex; align-items: center; min-height: 64px;
}
.sidebar-logo-fallback { color: var(--app-primary); font-weight: 600; }
.sidebar-nav { padding: 8px 0; }
.nav-link-item {
  display: block; padding: 9px 18px; color: var(--app-sidebar-fg);
  text-decoration: none; font-size: 0.92rem; border-left: 3px solid transparent;
}
.nav-link-item.sub { padding-left: 38px; font-size: 0.88rem; }
.nav-link-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link-item.active {
  background: rgba(46,139,218,0.18); color: #fff;
  border-left-color: var(--app-sidebar-active); font-weight: 600;
}
.nav-link-item i { width: 18px; }
.nav-group-toggle {
  width: 100%; background: none; border: 0; color: var(--app-sidebar-fg);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; font-size: 0.92rem; cursor: pointer;
}
.nav-group-toggle:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-group-toggle i { width: 18px; }
/* Chevron points down when the group is open, right when collapsed. */
.nav-group-toggle .bi-chevron-down { transition: transform 0.15s ease; }
.nav-group-toggle[aria-expanded="false"] .bi-chevron-down { transform: rotate(-90deg); }

.sidebar-backdrop {
  display: none; position: fixed; inset: var(--app-navbar-h) 0 0 0;
  background: rgba(0,0,0,0.4); z-index: 1034;
}

/* ---------- Content ---------- */
.app-content {
  margin-left: var(--app-sidebar-w);
  padding: 20px 24px 48px;
  width: calc(100% - var(--app-sidebar-w));
  min-height: calc(100vh - var(--app-navbar-h));
}
/* ---------- Global context bar (Change 12) ---------- */
.context-bar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--app-border); border-radius: 10px;
  padding: 8px 14px; margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
.ctx-group { display: flex; flex-direction: column; line-height: 1.15; }
.ctx-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.04em; color: #8a93a2; }
.ctx-value { font-size: 0.85rem; font-weight: 600; max-width: 220px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.ctx-mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-weight: 500; }
.ctx-env { align-self: flex-start; }
.ctx-status { font-size: 0.8rem; color: #495057; display: inline-flex; align-items: center; gap: 6px; }
.ctx-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.ctx-dot.live { background: #198754; box-shadow: 0 0 0 3px rgba(25,135,84,0.18); }
.ctx-dot.cached { background: #fd7e14; box-shadow: 0 0 0 3px rgba(253,126,20,0.18); }
.ctx-spacer { flex: 1 1 auto; }
.ctx-user { display: flex; align-items: center; gap: 8px; }
.ctx-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--app-accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem;
}
.ctx-user-meta { display: flex; flex-direction: column; line-height: 1.1; }
.ctx-user-name { font-size: 0.82rem; font-weight: 600; }
.ctx-user-email { font-size: 0.72rem; color: #8a93a2; max-width: 200px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px; flex-wrap: wrap;
}
.page-title { font-size: 1.4rem; font-weight: 600; margin: 0; }
.section-subtitle { font-weight: 600; margin-bottom: 10px; }

.content-section { display: none; }
.content-section.section-active { display: block; animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Cards / KPIs ---------- */
.app-card { border: 1px solid var(--app-border); border-radius: 10px; box-shadow: 0 1px 2px rgba(16,24,40,0.04); }
.app-card-header {
  background: #fff; border-bottom: 1px solid var(--app-border);
  font-weight: 600; font-size: 0.9rem; border-radius: 10px 10px 0 0;
}
.kpi-card { border-left: 4px solid var(--app-accent); }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.kpi-card .kpi-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: #6c757d; }
.kpi-card.critical { border-left-color: #dc3545; }
.kpi-card.open { border-left-color: #fd7e14; }
.kpi-card.closed { border-left-color: #198754; }
.metric-value { font-size: 1.5rem; font-weight: 700; }
.metric-label { font-size: 0.72rem; text-transform: uppercase; color: #6c757d; }

/* ---------- Filters / status ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start;
  background: #fff; border: 1px solid var(--app-border); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px;
}
.filter-bar .form-select, .filter-bar .form-control { min-width: 150px; }
.status-line { font-size: 0.85rem; color: #6c757d; display: inline-block; margin-bottom: 8px; }
.status-line.error { color: #dc3545; }

/* ---------- Tables ---------- */
.table thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; color: #6c757d; }
.la-results-table thead th { cursor: pointer; user-select: none; white-space: nowrap; }
.la-results-table thead th .sort-ind { opacity: 0.5; font-size: 0.7rem; }

/* ---------- Severity badges ---------- */
.severity-badge { font-weight: 600; }
.sev-Sev0, .sev-Sev1 { background-color: #dc3545 !important; color: #fff !important; }
.sev-Sev2 { background-color: #fd7e14 !important; color: #fff !important; }
.sev-Sev3 { background-color: #ffc107 !important; color: #212529 !important; }
.sev-Sev4 { background-color: #6c757d !important; color: #fff !important; }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; height: 200px; }

/* ---------- Activity list + timeline ---------- */
.activity-list { max-height: 230px; overflow-y: auto; }
.activity-item { padding: 6px 8px; border-bottom: 1px solid #f0f2f5; font-size: 0.84rem; }
.activity-item:last-child { border-bottom: 0; }
.activity-item .meta { color: #8a93a2; font-size: 0.75rem; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--app-border); }
.timeline-item { position: relative; padding: 4px 0 14px 16px; }
.timeline-item::before {
  content: ""; position: absolute; left: -25px; top: 6px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--app-accent);
  box-shadow: 0 0 0 3px #fff;
}
.timeline-item.t-alert::before { background: #dc3545; }
.timeline-item.t-failure::before { background: #fd7e14; }
.timeline-item.t-performance::before { background: #6f42c1; }
.timeline-item.t-query::before { background: #198754; }
.timeline-item .t-time { font-size: 0.75rem; color: #8a93a2; }

/* ---------- Empty / loading ---------- */
.empty-state { color: #8a93a2; font-style: italic; padding: 14px 6px; text-align: center; }

/* Skeleton loading cards (Phase 11) */
.skeleton-card {
  height: 120px; border: 1px solid var(--app-border);
  background: linear-gradient(90deg, #eef1f5 25%, #f7f9fc 37%, #eef1f5 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.loading-spinner {
  display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite;
  vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

textarea.font-monospace { font-size: 0.85rem; }

/* ---------- AI Copilot chat ---------- */
.cop-chat-log { max-height: 420px; overflow-y: auto; padding: 4px; }
.cop-chat-msg { margin-bottom: 8px; display: flex; }
.cop-chat-msg > div {
  padding: 8px 12px; border-radius: 12px; max-width: 80%; font-size: 0.9rem; white-space: pre-wrap;
}
.cop-chat-user { justify-content: flex-end; }
.cop-chat-user > div { background: var(--app-accent); color: #fff; border-bottom-right-radius: 2px; }
.cop-chat-assistant > div { background: #eef1f5; color: #1f2733; border-bottom-left-radius: 2px; }

/* ---------- Auth pages (no sidebar) ---------- */
.auth-page .app-content { margin-left: 0; width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); }
  .app-sidebar.open { transform: translateX(0); }
  .app-content { margin-left: 0; width: 100%; padding: 16px; }
  .sidebar-backdrop.show { display: block; }
}
/* Context bar collapses intelligently as width shrinks */
@media (max-width: 991.98px) { .context-bar .ctx-hide-md { display: none; } }
@media (max-width: 575.98px) {
  .context-bar { gap: 10px 14px; }
  .context-bar .ctx-hide-sm { display: none; }
  .ctx-value { max-width: 150px; }
}

/* ---------- Global resource search (Enhancement 5) ---------- */
.global-search {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
  margin: 0 16px;
  display: flex;
  align-items: center;
}
.global-search-icon {
  position: absolute; left: 10px; color: #6b7686; font-size: 0.9rem; pointer-events: none;
}
.global-search input {
  padding-left: 30px; padding-right: 26px;
  border: none; border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
}
.global-search input:focus { background: #fff; box-shadow: 0 0 0 2px rgba(46, 139, 218, 0.5); }
.global-search-kbd {
  position: absolute; right: 8px; font-size: 0.7rem; color: #6b7686;
  background: #eef1f6; border-radius: 4px; padding: 0 5px;
}
.global-search-panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--app-border); border-radius: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
  max-height: 70vh; overflow-y: auto; z-index: 1100; padding: 4px;
}
.gs-heading { font-size: 0.7rem; text-transform: uppercase; color: #8a94a6; padding: 6px 10px 2px; }
.gs-empty { padding: 12px; color: #6b7686; font-size: 0.875rem; }
.gs-item { padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.gs-item:hover, .gs-item.active { background: #eef4fb; }
.gs-main { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.gs-name { font-weight: 600; color: #1f2733; }
.gs-type { font-size: 0.72rem; color: #2e8bda; white-space: nowrap; }
.gs-sub { display: flex; justify-content: space-between; align-items: center;
  font-size: 0.78rem; color: #6b7686; margin-top: 2px; }
.gs-recent { color: #455065; }
@media (max-width: 767px) { .global-search { max-width: none; margin: 0 8px; } }

/* ---------- Subscription selector (Enhancement 3) ---------- */
.ctx-sub-btn {
  background: #fff; border: 1px solid var(--app-border);
  font-weight: 600; font-size: 0.82rem; padding: 2px 10px; color: #1f2733;
}
.ctx-sub-btn:hover { background: #f1f4f9; }
.ctx-sub-menu {
  min-width: 300px; max-width: 380px;
  z-index: 1090;                 /* above the sticky context bar (1020) */
  max-height: 60vh; overflow-y: auto;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
}
.ctx-sub-item { white-space: normal; padding: 8px 14px; line-height: 1.3; }
.ctx-sub-item.active { background: #eef4fb; font-weight: 600; }
.ctx-sub-name { display: block; font-weight: 600; }
.ctx-sub-id { display: block; font-size: 0.72rem; color: #8a93a2; word-break: break-all; }
/* The sticky context bar must not clip the open subscription menu. */
.context-bar { overflow: visible; }

/* ---------- VM inventory per-column filter row ---------- */
.vm-filter-row th { padding-top: 4px; padding-bottom: 6px; background: #fafbfd; }
.vm-filter-row .vm-col-filter { min-width: 90px; font-size: 0.78rem; }
.vm-power-btn { min-width: 60px; }

/* ---------- Clickable KPI cards (interactive overview) ---------- */
.kpi-clickable { cursor: pointer; transition: transform .08s ease, box-shadow .12s ease; }
.kpi-clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12); }
.kpi-clickable:focus-visible { outline: 2px solid var(--app-accent); outline-offset: 2px; }
.kpi-clickable::after {
  content: "\F138";  /* bi-chevron-right */
  font-family: "bootstrap-icons"; font-size: 0.7rem; color: #b8c0cc;
  position: absolute; top: 8px; right: 10px;
}
.kpi-clickable { position: relative; }

/* ---------- Alert History per-column filter row ---------- */
.hist-filter-row th { padding-top: 4px; padding-bottom: 6px; background: #fafbfd; }
.hist-filter-row .hist-col-filter { min-width: 90px; font-size: 0.78rem; }

/* ---------- Admin navigation ---------- */
.sidebar-admin-label {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #6b7686; padding: 14px 18px 4px; border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 8px;
}

/* ===================== Enterprise AI Query Studio ===================== */
.qs-layout { display: flex; gap: 12px; align-items: flex-start; }
.qs-explorer {
  flex: 0 0 270px; max-width: 270px; align-self: stretch;
  border: 1px solid var(--border-color, #dee2e6); border-radius: 8px;
  background: var(--card-bg, #fff); max-height: 78vh; display: flex; flex-direction: column;
}
.qs-explorer-head {
  padding: 8px 10px; border-bottom: 1px solid var(--border-color, #dee2e6);
  font-size: .82rem; font-weight: 600;
}
.qs-tree { overflow: auto; padding: 4px 2px 8px; font-size: .82rem; flex: 1 1 auto; }
.qs-main { flex: 1 1 auto; min-width: 0; }
.qs-node-row {
  display: flex; align-items: center; gap: 2px; padding: 2px 6px; border-radius: 4px;
  cursor: pointer; white-space: nowrap; user-select: none;
}
.qs-node-row:hover { background: rgba(13,110,253,0.08); }
.qs-caret { width: 12px; display: inline-block; color: #888; font-size: .7rem; }
.qs-node-body { padding-left: 14px; }
.qs-node-label { overflow: hidden; text-overflow: ellipsis; }
.qs-node-meta { color: #8a93a2; font-size: .72rem; margin-left: 4px; }
.qs-pin { margin-left: auto; color: #c9ad3a; opacity: .35; font-size: .72rem; }
.qs-pin.pinned { opacity: 1; }
.qs-pin:hover { opacity: .9; }
.qs-node-row[draggable="true"]:active { opacity: .6; }
@media (max-width: 991px) { .qs-layout { flex-direction: column; } .qs-explorer { max-width: 100%; flex-basis: auto; } }

/* Query Studio — AI Copilot conversation */
.qs-cop-transcript { max-height: 240px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.qs-cop-msg { padding: 6px 10px; border-radius: 10px; font-size: .85rem; max-width: 92%; }
.qs-cop-msg.user { align-self: flex-end; background: rgba(13,110,253,0.12); }
.qs-cop-msg.assistant { align-self: flex-start; background: var(--surface-2, #f1f3f5); }
.qs-cop-msg .qs-cop-role { font-size: .68rem; text-transform: uppercase; color: #8a93a2; letter-spacing: .03em; }
.qs-cop-kql { font-family: var(--bs-font-monospace, monospace); font-size: .78rem;
  background: rgba(0,0,0,0.04); border-radius: 6px; padding: 4px 6px; margin-top: 4px; white-space: pre-wrap; }
.qs-insight-h { font-weight: 600; font-size: .8rem; margin-top: 6px; }
