/* ═══════════════════════════════════════════════════════════════
   CPI AR Dashboard — Design System v2
   Font: Inter (loaded in base.html)
   ═══════════════════════════════════════════════════════════════ */

/* ── Global loading overlay ───────────────────────────────────── */
#cpiLoadingOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,23,42,.28);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
#cpiLoadingOverlay.cpi-loading {
  opacity: 1;
  pointer-events: auto;
}
.cpi-spinner-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cpi-spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: #60a5fa;
  animation: cpi-spin .75s linear infinite;
}
.cpi-spinner-ico {
  font-size: 1.5rem;
  color: #fff;
  animation: cpi-pulse 1.2s ease-in-out infinite;
}
@keyframes cpi-spin  { to { transform: rotate(360deg); } }
@keyframes cpi-pulse { 0%,100% { opacity:.6; } 50% { opacity:1; } }

/* ── CSS Variables ──────────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:           #f0f4f8;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #f1f5f9;

  /* Borders */
  --border:       #e2e8f0;
  --border-light: #f1f5f9;

  /* Text */
  --text:         #0f172a;
  --text-2:       #475569;
  --text-3:       #94a3b8;
  --text-4:       #cbd5e1;

  /* Accent */
  --accent:       #2563eb;
  --accent-lt:    #eff6ff;
  --accent-mid:   #3b82f6;
  --accent-dark:  #1d4ed8;

  /* Brand navy */
  --navy:         #0d1b2e;
  --navy-2:       #122336;
  --navy-3:       #1a2f47;
  --navy-4:       #223859;

  /* Semantics */
  --success:      #059669;
  --success-lt:   #ecfdf5;
  --warning:      #d97706;
  --warning-lt:   #fffbeb;
  --danger:       #dc2626;
  --danger-lt:    #fff1f2;
  --info:         #0891b2;
  --info-lt:      #f0f9ff;

  /* Shape */
  --radius:       12px;
  --radius-lg:    16px;
  --radius-md:    10px;
  --radius-sm:    8px;
  --radius-xs:    6px;

  /* Shadows */
  --shadow-xs:    0 1px 2px rgba(15,23,42,.05);
  --shadow-sm:    0 1px 4px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md:    0 4px 16px rgba(15,23,42,.09), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg:    0 12px 40px rgba(15,23,42,.12), 0 4px 10px rgba(15,23,42,.05);
  --shadow-xl:    0 20px 60px rgba(15,23,42,.16), 0 8px 16px rgba(15,23,42,.06);

  /* Layout */
  --topbar-h:     56px;
  --sidebar-w:    236px;
  --sidebar-col:  60px;

  /* Motion */
  --ease:         0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce:  0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Base Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: .875rem;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

/* ══════════════════════════════════════════════════════════════════
   TOP NAVBAR
══════════════════════════════════════════════════════════════════ */
.cpi-navbar {
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.05);
  box-shadow: 0 1px 0 rgba(0,0,0,.25), 0 4px 16px rgba(0,0,0,.15);
  height: var(--topbar-h);
  padding: 0 1.1rem;
  flex-wrap: nowrap !important; /* Prevent Bootstrap navbar from wrapping to 2nd row */
  overflow: visible;            /* Keep dropdowns visible below navbar */
}

.cpi-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1030;
  overflow: visible; /* Allow dropdowns to extend below the fixed bar */
}

/* Brand */
.cpi-navbar .navbar-brand {
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: #fff !important;
  text-decoration: none !important;
  transition: opacity var(--ease);
}
.cpi-navbar .navbar-brand:hover { opacity: .85; }

/* Brand icon pill */
.nav-brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(59,130,246,.3) 0%, rgba(37,99,235,.15) 100%);
  border: 1px solid rgba(96,165,250,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Navbar utility buttons */
.nav-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .65rem;
  border-radius: var(--radius-sm);
  font-size: .73rem;
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--ease);
  text-decoration: none !important;
  outline: none;
}

.nav-pill-fav {
  background: rgba(245,158,11,.1);
  border-color: rgba(245,158,11,.2);
  color: rgba(252,211,77,.6);
}
.nav-pill-fav:hover,
.nav-pill-fav.active {
  background: rgba(245,158,11,.22);
  border-color: rgba(245,158,11,.4);
  color: #fcd34d;
}

.nav-pill-manual {
  background: rgba(99,102,241,.12);
  border-color: rgba(99,102,241,.25);
  color: #c7d2fe;
}
.nav-pill-manual:hover {
  background: rgba(99,102,241,.24);
  border-color: rgba(99,102,241,.4);
  color: #e0e7ff;
}

/* Data freshness badge */
.nav-freshness {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .28rem .65rem;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  font-size: .7rem;
}

/* Sidebar toggle */
.sidebar-toggle {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: 1px solid transparent !important;
  color: rgba(255,255,255,.65) !important;
  transition: all var(--ease) !important;
  flex-shrink: 0;
  padding: 0 !important;
}
.sidebar-toggle:hover {
  background: rgba(255,255,255,.09) !important;
  border-color: rgba(255,255,255,.12) !important;
  color: #fff !important;
}

/* ══ TOP RIBBON NAVIGATION ══════════════════════════════════════════ */
#topRibbon {
  flex-shrink: 1;    /* Allow ribbon to shrink on narrow viewports */
  min-width: 0;      /* Let flexbox compress below natural size */
  overflow: visible; /* Must be visible so dropdown menus aren't clipped */
}

.ribbon-group { position: relative; }

.ribbon-btn {
  display: inline-flex;
  align-items: center;
  gap: .32rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: rgba(255,255,255,.72);
  font-size: .74rem;
  font-weight: 600;
  padding: .3rem .7rem;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
  letter-spacing: .01em;
  text-decoration: none;
  border-radius: 0;
  line-height: var(--topbar-h);
  height: var(--topbar-h);
}
.ribbon-btn:hover,
.ribbon-btn.show {
  color: #fff;
  background: rgba(255,255,255,.07);
}
.ribbon-btn.ribbon-active {
  color: #fff;
  border-bottom-color: #60a5fa;
}
.ribbon-caret {
  font-size: .55rem;
  opacity: .6;
  transition: transform .2s;
}
.ribbon-btn.show .ribbon-caret { transform: rotate(180deg); }

/* Coming-soon badge in ribbon */
.ribbon-soon {
  font-size: .44rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  background: linear-gradient(135deg,#f59e0b,#ef4444);
  color: #fff;
  border-radius: 3px;
  padding: 1px 4px;
  vertical-align: middle;
  margin-left: 2px;
  flex-shrink: 0;
}
/* dim the link when coming-soon */
.ribbon-drop-item.soon-item {
  opacity: .72;
  pointer-events: none; /* prevent click */
  cursor: default;
}
/* direct ribbon button coming soon */
.ribbon-btn.ribbon-coming-soon {
  opacity: .72;
  cursor: default;
  pointer-events: none;
}

/* Mega-drop panel */
.ribbon-drop {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.13);
  margin-top: 0 !important;
}
.ribbon-drop-hdr {
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #94a3b8;
  padding: .25rem .5rem .15rem;
  margin-top: .1rem;
}
.ribbon-drop-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .28rem .5rem;
  border-radius: 7px;
  color: #334155;
  font-size: .77rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s, color .12s;
  cursor: pointer;
}
.ribbon-drop-item:hover,
.ribbon-drop-item.active {
  background: #f1f5f9;
  color: #0d1b2e;
}
.ribbon-drop-item.active { font-weight: 600; }
.ribbon-drop-item i { font-size: .82rem; flex-shrink: 0; width: 16px; text-align: center; }

/* User menu button */
.nav-user-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .28rem .65rem .28rem .3rem;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.9);
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ease);
}
.nav-user-btn:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.2);
  color: #fff;
}

.nav-user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(96,165,250,.2);
  border: 1px solid rgba(96,165,250,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Admin users link */
.cpi-navbar .btn-outline-light {
  font-size: .73rem;
  font-weight: 500;
  padding: .28rem .65rem;
  border-color: rgba(255,255,255,.18);
  color: rgba(255,255,255,.8);
  border-radius: var(--radius-sm);
  transition: all var(--ease);
}
.cpi-navbar .btn-outline-light:hover {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.35);
  color: #fff;
}

/* Dropdown */
.cpi-navbar .dropdown-menu {
  font-size: .83rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .4rem;
  margin-top: 8px;
  animation: dropIn .15s ease;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cpi-navbar .dropdown-item {
  border-radius: var(--radius-xs);
  padding: .45rem .8rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  transition: background var(--ease);
}
.cpi-navbar .dropdown-item:hover { background: var(--surface-2); }
.cpi-navbar .dropdown-item.text-danger { color: var(--danger) !important; }
.cpi-navbar .dropdown-item.text-danger:hover { background: #fff5f5; }
.cpi-navbar .dropdown-divider { margin: .35rem 0; border-color: var(--border); }

/* ══════════════════════════════════════════════════════════════════
   SHELL LAYOUT
══════════════════════════════════════════════════════════════════ */
.cpi-shell {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

.cpi-main {
  margin-left: 0;
  flex: 1;
  min-width: 0;
  padding: 0;
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════════════════ */
.cpi-sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--ease);
  z-index: 1020;
  display: flex;
  flex-direction: column;
  padding: .6rem 0 .75rem;
  border-right: 1px solid rgba(255,255,255,.04);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.08) transparent;
}
.cpi-sidebar::-webkit-scrollbar { width: 3px; }
.cpi-sidebar::-webkit-scrollbar-track { background: transparent; }
.cpi-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }


/* Section labels */
.sidebar-section-label {
  font-size: .58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .13em;
  color: rgba(255,255,255,.22);
  padding: .65rem .85rem .2rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .35rem;
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.05);
  margin: .35rem .75rem;
}

/* Links */
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .9rem .4rem .75rem;
  color: rgba(255,255,255,.58);
  text-decoration: none;
  font-size: .795rem;
  font-weight: 450;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 1px .45rem 1px 0;
  position: relative;
}
.sidebar-link:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.88);
  border-left-color: rgba(255,255,255,.18);
}
.sidebar-link.active {
  background: linear-gradient(90deg, rgba(37,99,235,.22) 0%, rgba(37,99,235,.08) 100%);
  color: #93c5fd;
  border-left-color: #3b82f6;
  font-weight: 550;
}
.sidebar-link i {
  font-size: .9rem;
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
  transition: color var(--ease);
}

/* Sidebar star buttons */
.sb-star-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.18);
  font-size: .68rem;
  padding: 3px 4px;
  opacity: 0;
  transition: opacity var(--ease), color var(--ease);
  z-index: 5;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
}
.sidebar-link:hover .sb-star-btn { opacity: 1; }
.sb-star-btn.sb-starred { opacity: 1 !important; color: #f59e0b; }
.sb-star-btn:hover { color: #fbbf24 !important; opacity: 1; }

/* Ribbon dropdown star buttons */
.rb-star-btn {
  margin-left: auto;
  flex-shrink: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #cbd5e1;
  font-size: .68rem;
  padding: 2px 5px 2px 8px;
  opacity: 0;
  transition: opacity .12s, color .12s, transform .15s;
  border-radius: 4px;
  line-height: 1;
}
.ribbon-drop-item:hover .rb-star-btn { opacity: 1; }
.rb-star-btn.rb-starred { opacity: 1 !important; color: #f59e0b; }
.rb-star-btn:hover { color: #fbbf24 !important; opacity: 1; }

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding: .75rem .85rem .5rem;
  border-top: 1px solid rgba(255,255,255,.05);
}

/* ══════════════════════════════════════════════════════════════════
   PAGE CONTENT
══════════════════════════════════════════════════════════════════ */
.cpi-main .container-fluid,
.cpi-main .container {
  padding-top: 1.35rem;
  padding-bottom: 2rem;
}

/* Flash alerts */
.cpi-main .alert {
  border-radius: var(--radius);
  border: none;
  font-size: .84rem;
  font-weight: 500;
  margin: .75rem 1rem 0;
}
.alert-success { background: #f0fdf4; color: #14532d; box-shadow: 0 0 0 1px #bbf7d0 inset; }
.alert-danger  { background: #fff7ed; color: #7c2d12; box-shadow: 0 0 0 1px #fed7aa inset; }
.alert-warning { background: #fffbeb; color: #78350f; box-shadow: 0 0 0 1px #fde68a inset; }
.alert-info    { background: #f0f9ff; color: #0c4a6e; box-shadow: 0 0 0 1px #bae6fd inset; }

/* ══════════════════════════════════════════════════════════════════
   SECTION HEADERS (home + report pages)
══════════════════════════════════════════════════════════════════ */
.sec-hdr {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-2);
  padding: .3rem 0 .65rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  margin-top: 24px;
}
.sec-hdr:first-child { margin-top: 0; }
.sec-hdr i { font-size: .85rem; opacity: .9; }

/* Inline section divider used in some reports */
.sh {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  margin: 20px 0 12px;
}

/* ══════════════════════════════════════════════════════════════════
   CARDS (global)
══════════════════════════════════════════════════════════════════ */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}

.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .7rem 1rem;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .01em;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}

.card-body { padding: 1rem; }

/* Dark card header (for report section headers) */
.cpi-card-header {
  background: linear-gradient(90deg, var(--navy-2), var(--navy-3));
  color: rgba(255,255,255,.92);
  font-size: .77rem;
  font-weight: 600;
  padding: .55rem .9rem;
  letter-spacing: .03em;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── KPI Cards (report pages) ────────────────────────────────────── */
.kpi-card {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: transform var(--ease), box-shadow var(--ease);
  background: var(--surface) !important;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md) !important;
}

.kpi-label {
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-2);
  line-height: 1.2;
}
.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.025em;
  color: var(--text);
}

/* ── Dashboard Nav Cards (Home page) ─────────────────────────────── */
.dashboard-nav-card {
  cursor: pointer;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  transition: border-color var(--ease), transform var(--ease), box-shadow var(--ease);
  background: var(--surface) !important;
  text-decoration: none;
}
.dashboard-nav-card:hover {
  border-color: rgba(37,99,235,.3) !important;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md) !important;
}
.dashboard-nav-card .card-body {
  padding: .85rem 1rem;
}

/* Icon box inside nav cards */
.dash-icon {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.dash-card-name {
  font-size: .86rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}
.dash-card-desc {
  font-size: .75rem;
  color: var(--text-3);
  line-height: 1.45;
  margin-top: 2px;
}

/* ── Home KPI Banner ─────────────────────────────────────────────── */
.home-kstat {
  border-radius: var(--radius);
  padding: 18px 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: none;
}
.home-kstat .kv {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.025em;
}
.home-kstat .kl {
  font-size: .63rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .75;
  margin-top: 4px;
  font-weight: 600;
}
.home-kstat .ki {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.6rem;
  opacity: .12;
}

/* ── KPI Stat (legacy kstat alias) ──────────────────────────────── */
.kstat {
  border-radius: var(--radius);
  padding: 18px 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.kstat .kv {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.025em;
}
.kstat .kl {
  font-size: .63rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .75;
  margin-top: 4px;
  font-weight: 600;
}
.kstat .ki {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.6rem;
  opacity: .12;
}

/* ── KPI stat (new analytics, .kc) ──────────────────────────────── */
.kc {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  height: 100%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--ease), box-shadow var(--ease);
}
.kc:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kc .kv {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.025em;
}
.kc .kl {
  font-size: .63rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  opacity: .7;
  margin-top: 2px;
  font-weight: 600;
}
.kc .ks { font-size: .75rem; margin-top: 5px; opacity: .82; }
.kc .ki {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 2.4rem;
  opacity: .12;
}

/* ══════════════════════════════════════════════════════════════════
   FILTER BAR
══════════════════════════════════════════════════════════════════ */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-xs) !important;
}
.filter-bar .card-body { padding: .6rem .9rem; }
.filter-bar .form-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  margin-bottom: .25rem;
}
.filter-bar .form-control,
.filter-bar .form-select {
  font-size: .82rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.filter-bar .form-control:focus,
.filter-bar .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
  background: var(--surface);
}

/* ══════════════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════════ */
.btn {
  font-size: .8rem;
  font-weight: 550;
  letter-spacing: .01em;
  border-radius: var(--radius-sm);
  transition: all var(--ease);
}
.btn-sm {
  font-size: .775rem;
  padding: .3rem .7rem;
}
.btn-xs {
  padding: .15rem .4rem;
  font-size: .7rem;
  border-radius: var(--radius-xs);
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  box-shadow: 0 3px 10px rgba(37,99,235,.3);
}

/* ══════════════════════════════════════════════════════════════════
   TABLES
══════════════════════════════════════════════════════════════════ */
.table {
  --bs-table-bg: transparent;
  font-size: .82rem;
  color: var(--text);
  margin-bottom: 0;
}
.table thead th {
  font-size: .71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  padding: .55rem .75rem;
}
.table td {
  font-size: .82rem;
  vertical-align: middle;
  color: var(--text);
  padding: .5rem .75rem;
  border-color: var(--border-light);
}
.table tbody tr:hover td { background: #f8fbff; }
.table-bordered { border: 1px solid var(--border); }
.table-bordered th, .table-bordered td { border-color: var(--border); }

/* Scrollable table */
.tbl-scroll {
  overflow-x: auto;
  max-height: 440px;
  overflow-y: auto;
  border-radius: 0 0 var(--radius-xs) var(--radius-xs);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tbl-scroll::-webkit-scrollbar { width: 5px; height: 5px; }
.tbl-scroll::-webkit-scrollbar-track { background: transparent; }
.tbl-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tbl-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--navy-2);
  color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.08);
  font-size: .7rem;
}

/* ══════════════════════════════════════════════════════════════════
   NAV TABS
══════════════════════════════════════════════════════════════════ */
.nav-tabs {
  border-bottom: 1px solid var(--border);
  gap: .15rem;
}
.nav-tabs .nav-link {
  font-size: .8rem;
  font-weight: 550;
  color: var(--text-2);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  padding: .55rem .9rem;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
  margin-bottom: -1px;
}
.nav-tabs .nav-link:hover { color: var(--accent); background: var(--accent-lt); border-bottom-color: #bfdbfe; }
.nav-tabs .nav-link.active {
  color: var(--accent);
  background: var(--surface);
  border-bottom-color: var(--accent);
  font-weight: 650;
}
.tab-content.border {
  border: 1px solid var(--border) !important;
  border-top: none !important;
  border-radius: 0 0 var(--radius) var(--radius) !important;
  background: var(--surface);
}

/* ══════════════════════════════════════════════════════════════════
   INSIGHT CARDS
══════════════════════════════════════════════════════════════════ */
#insightsPanel .card { animation: fadeInUp .22s ease both; }
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ins-card {
  border-left: 3px solid;
  border-radius: var(--radius-xs);
  padding: 9px 13px;
  font-size: .82rem;
  margin-bottom: 7px;
  transition: box-shadow var(--ease);
}
.ins-card:hover { box-shadow: var(--shadow-sm); }
.ins-good  { border-color: #059669; background: #f0fdf4; }
.ins-bad   { border-color: #ea580c; background: #fff7ed; }
.ins-warn  { border-color: #d97706; background: #fffbeb; }
.ins-info  { border-color: #0891b2; background: #f0f9ff; }

.ins-expand { font-size: .77rem; color: #475569; border-top: 1px solid rgba(0,0,0,.07); margin-top: 10px; padding-top: 8px; }
.ins-expand-label { font-size: .67rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
.ins-why-label { color: #7c3aed; }
.ins-fix-label { color: #059669; }

/* ══════════════════════════════════════════════════════════════════
   PROGRESS / METERS
══════════════════════════════════════════════════════════════════ */
.meter-wrap {
  background: var(--border);
  border-radius: 6px;
  height: 7px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  border-radius: 6px;
  transition: width .7s cubic-bezier(.4,0,.2,1);
}

/* ══════════════════════════════════════════════════════════════════
   PRACTICE / FILTER TOGGLE PILLS
══════════════════════════════════════════════════════════════════ */
.prac-btn, .practice-btn {
  border-radius: 20px;
  font-size: .73rem;
  padding: 3px 12px;
  margin: 2px;
  font-weight: 500;
  transition: all var(--ease);
}

/* ══════════════════════════════════════════════════════════════════
   BADGES
══════════════════════════════════════════════════════════════════ */
.badge {
  font-weight: 600;
  letter-spacing: .02em;
}

/* ══════════════════════════════════════════════════════════════════
   ADR BADGES
══════════════════════════════════════════════════════════════════ */
.badge-open    { background: #dc2626; }
.badge-pending { background: #d97706; }
.badge-closed  { background: #059669; }

/* ══════════════════════════════════════════════════════════════════
   FORM CONTROLS (global)
══════════════════════════════════════════════════════════════════ */
.form-control, .form-select {
  border-color: var(--border);
  border-radius: var(--radius-xs);
  font-size: .84rem;
  color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-label { font-size: .8rem; font-weight: 550; color: var(--text-2); }

/* ══════════════════════════════════════════════════════════════════
   MODALS
══════════════════════════════════════════════════════════════════ */
.modal-content {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
}
.modal-header { border-bottom: 1px solid var(--border); padding: .9rem 1.1rem; }
.modal-title  { font-size: .95rem; font-weight: 650; }
.modal-body   { padding: 1.1rem; }
.modal-footer { border-top: 1px solid var(--border); padding: .75rem 1.1rem; }

/* ══════════════════════════════════════════════════════════════════
   DATATABLES
══════════════════════════════════════════════════════════════════ */
div.dataTables_wrapper div.dataTables_filter input,
div.dataTables_wrapper div.dataTables_length select {
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: .28rem .5rem;
  font-size: .8rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  box-shadow: none;
}
div.dataTables_wrapper div.dataTables_filter input:focus,
div.dataTables_wrapper div.dataTables_length select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
div.dataTables_wrapper div.dataTables_info,
div.dataTables_wrapper div.dataTables_paginate {
  font-size: .77rem;
  color: var(--text-2);
  padding-top: .75rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button { border-radius: var(--radius-xs) !important; font-size: .77rem; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

/* ══════════════════════════════════════════════════════════════════
   DROPDOWN MENUS (general)
══════════════════════════════════════════════════════════════════ */
.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .83rem;
  padding: .4rem;
}
.dropdown-item {
  border-radius: var(--radius-xs);
  padding: .42rem .8rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text);
  transition: background var(--ease);
}
.dropdown-item:hover { background: var(--surface-2); color: var(--text); }
.dropdown-divider { border-color: var(--border); margin: .35rem 0; }

/* ══════════════════════════════════════════════════════════════════
   LOGIN
══════════════════════════════════════════════════════════════════ */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-3) 55%, #1a3a6e 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 400px;
  border: 1px solid rgba(255,255,255,.08) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 24px 60px rgba(0,0,0,.4) !important;
  background: rgba(255,255,255,.97) !important;
}

/* ══════════════════════════════════════════════════════════════════
   CHART
══════════════════════════════════════════════════════════════════ */
.chart-wrap {
  position: relative;
  min-height: 190px;
}

/* ══════════════════════════════════════════════════════════════════
   DANGER THEME OVERRIDE (orange → red)
══════════════════════════════════════════════════════════════════ */
.btn-danger, .btn-danger:focus, .btn-danger:active {
  background-color: var(--danger) !important;
  border-color: var(--danger) !important;
  color: #fff !important;
}
.btn-danger:hover { background-color: #b91c1c !important; border-color: #b91c1c !important; }
.btn-outline-danger { color: var(--danger) !important; border-color: var(--danger) !important; }
.btn-outline-danger:hover { background-color: var(--danger) !important; color: #fff !important; }
.text-danger  { color: var(--danger) !important; }
.bg-danger    { background-color: var(--danger) !important; }
.border-danger{ border-color: var(--danger) !important; }
.badge.bg-danger { background-color: var(--danger) !important; }

/* ══════════════════════════════════════════════════════════════════
   SCROLLBAR (page)
══════════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
  .cpi-sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
  }
  .cpi-sidebar.mobile-open { transform: translateX(0); }
  .cpi-main { margin-left: 0 !important; }
}

/* ══════════════════════════════════════════════════════════════════
   OVERLAP / OVERFLOW FIXES — all zoom levels & screen sizes
══════════════════════════════════════════════════════════════════ */

/* 1. Top ribbon: allow horizontal scroll when compressed (high zoom / narrow
      screens) so buttons never overlap each other or right-side nav items.
      scrollbar hidden — users drag or it stays off-screen gracefully. */
#topRibbon {
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#topRibbon::-webkit-scrollbar { display: none; }

/* 2. Tab bars across all dashboards: never wrap to a second row.
      Horizontal scroll instead — tabs stay on one clean line. */
.nav-tabs {
  flex-wrap: nowrap !important;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 1px; /* prevent bottom-border clipping on scroll */
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs .nav-link { white-space: nowrap; flex-shrink: 0; }

/* 3. Filter bar: wrap filter items at narrow / high-zoom viewports
      so they stack cleanly instead of spilling outside the card. */
.filter-bar .row { flex-wrap: wrap !important; }
.filter-bar .col-auto { flex-shrink: 0; }

/* 4. Facility select: don't force min-width beyond what fits */
.filter-bar #fAccount,
.filter-bar select[id="fAccount"] { min-width: 160px !important; max-width: 240px; }

/* 5. Bootstrap column children: min-width 0 prevents flex children
      from overflowing their column at any grid breakpoint. */
.row > [class*="col"] { min-width: 0; }

/* 6. Cards: prevent content from breaking out of column boundaries. */
.card { min-width: 0; }

/* 7. KPI values: truncate with ellipsis instead of overflowing the card. */
.kpi-value,
.kc .kv,
.kstat .kv,
.home-kstat .kv {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 8. Chart canvases: always respect their container width. */
canvas { max-width: 100% !important; }

/* 9. Prevent any table-scroll overflow from leaking out of cards. */
.tbl-scroll { max-width: 100%; }

/* 10. Dropdown menus that appear inside .card: need visible overflow on
       the card so the dropdown isn't clipped. Applied per-element to avoid
       breaking tbl-scroll. */
.filter-bar { overflow: visible !important; }
.card.overflow-visible { overflow: visible !important; }

/* 11. Insights panel: prevent internal content from overflowing. */
.ip-body { overflow-x: hidden; }

/* 12. At very narrow effective widths (high zoom on laptops): ensure
       the main shell itself doesn't cause a horizontal scrollbar. */
body { overflow-x: hidden; }
.cpi-shell { overflow-x: hidden; }

/* ══════════════════════════════════════════════════════════════════
   UTILITY
══════════════════════════════════════════════════════════════════ */
.text-muted  { color: var(--text-3) !important; }
.fw-semibold { font-weight: 550; }
h4 { font-weight: 650; letter-spacing: -.01em; }
h5 { font-weight: 650; }

/* ══════════════════════════════════════════════════════════════════
   INSIGHTS RIGHT PANEL — shared across all dashboards
══════════════════════════════════════════════════════════════════ */
.ip-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.ip-hdr {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  color: #fff;
  padding: .6rem 1rem;
  font-size: .67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.ip-hdr .ip-badge {
  margin-left: auto;
  font-size: .6rem;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  font-weight: 600;
}
.ip-body {
  padding: .65rem;
  overflow-y: auto;
  max-height: 600px;
}
/* Force single-column inside narrow right panel */
.ip-body .row > [class*="col-md-6"],
.ip-body .row > [class*="col-xl-4"] {
  flex: 0 0 100%;
  max-width: 100%;
  width: 100%;
}
/* Tighten insight card fonts inside panel */
.ip-body [style*="border-left:4px"] {
  font-size: .8rem !important;
}
@media (min-width: 992px) {
  .ip-sticky { position: sticky; top: 1rem; }
}

/* ══════════════════════════════════════════════════════════════════
   PRINT
══════════════════════════════════════════════════════════════════ */
@media print {
  .cpi-navbar, .cpi-sidebar, #cpi-export-btns,
  .filter-bar, .wkly-tab-bar, .ccm-tab-bar, .ps-tabs, .ps-topbar,
  .nav-tabs, .sidebar-toggle, .alert { display: none !important; }
  .cpi-shell { display: block !important; }
  .cpi-main  { margin-left: 0 !important; width: 100% !important; padding: .5rem !important; }
  .tab-pane  { display: block !important; opacity: 1 !important; height: auto !important; }
  .wkly-pane, .ccm-pane, .ps-pane { display: block !important; }
  table { page-break-inside: avoid; font-size: 10pt; }
  .card { page-break-inside: avoid; border: 1px solid #ddd !important; box-shadow: none !important; }
  @page { margin: 1cm; size: A4 landscape; }
}
