/* ============================================================
   Carebridge Portal — application chrome
   Built strictly on Carebridge design tokens (var(--*)).
   Tweak hooks: [data-density], [data-side], [data-accent] on .cb-app
   ============================================================ */

.cb-app {
  --side-w: 264px;
  --accent: var(--teal-500);
  --accent-600: var(--teal-600);
  --accent-soft: var(--teal-50);
  --accent-soft-2: var(--teal-100);
  --pad-card: var(--space-6);
  --pad-page: clamp(20px, 3vw, 40px);
  --gap-grid: var(--space-6);
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-page);
  color: var(--text-body);
  font-family: var(--font-body);
}
.cb-app[data-accent="navy"] {
  --accent: var(--navy-600);
  --accent-600: var(--navy-700);
  --accent-soft: var(--navy-50);
  --accent-soft-2: var(--navy-100);
}
.cb-app[data-density="compact"] {
  --pad-card: var(--space-5);
  --pad-page: clamp(16px, 2.2vw, 28px);
  --gap-grid: var(--space-5);
}

/* ---------- Sidebar ---------- */
.cb-side {
  background: var(--navy-700);
  color: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  border-right: 1px solid rgba(255,255,255,0.06);
}
.cb-side::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 30% 12%, rgba(28,168,156,0.18), transparent 42%),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 64px);
  pointer-events: none;
}
.cb-app[data-side="light"] .cb-side {
  background: var(--paper);
  color: var(--text-strong);
  border-right: 1px solid var(--border-subtle);
}
.cb-app[data-side="light"] .cb-side::before { opacity: 0; }

.cb-side__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px var(--space-6);
  position: relative; z-index: 1;
  min-height: var(--nav-h);
}
.cb-brandmark {
  width: 40px; height: 40px; flex: none;
  border-radius: 11px;
  background: var(--grad-bridge);
  display: grid; place-items: center;
  box-shadow: 0 6px 16px -6px rgba(28,168,156,0.6);
}
.cb-brandmark svg { width: 23px; height: 23px; color: #fff; }
.cb-brand__name { font-family: var(--font-display); font-weight: 800; font-size: 17px; letter-spacing: -0.01em; line-height: 1.05; color: inherit; }
.cb-brand__sub { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.6; font-weight: 600; }
.cb-app[data-side="light"] .cb-brand__sub { color: var(--text-muted); opacity: 1; }

.cb-nav { flex: 1; overflow-y: auto; padding: var(--space-4) var(--space-4) var(--space-6); position: relative; z-index: 1; }
.cb-nav::-webkit-scrollbar { width: 6px; }
.cb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 6px; }
.cb-nav__label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.14em;
  font-weight: 700; opacity: 0.5; padding: 16px 12px 8px;
}
.cb-app[data-side="light"] .cb-nav__label { color: var(--text-faint); opacity: 1; }
.cb-nav__item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-md);
  color: rgba(255,255,255,0.78); font-size: 14.5px; font-weight: 500;
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  font-family: var(--font-body);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  position: relative;
}
.cb-app[data-side="light"] .cb-nav__item { color: var(--text-body); }
.cb-nav__item svg { width: 19px; height: 19px; flex: none; opacity: 0.92; }
.cb-nav__item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.cb-app[data-side="light"] .cb-nav__item:hover { background: var(--navy-50); color: var(--navy-700); }
.cb-nav__item.is-active { background: rgba(28,168,156,0.16); color: #fff; font-weight: 600; }
.cb-app[data-side="light"] .cb-nav__item.is-active { background: var(--accent-soft); color: var(--accent-600); }
.cb-nav__item.is-active::before {
  content: ""; position: absolute; left: -4px; top: 9px; bottom: 9px; width: 3px;
  border-radius: 3px; background: var(--accent);
}
.cb-nav__item .cb-nav__count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,0.16); color: #fff; padding: 2px 8px; border-radius: 999px;
}
.cb-app[data-side="light"] .cb-nav__item .cb-nav__count { background: var(--navy-100); color: var(--navy-600); }

.cb-side__foot { padding: var(--space-4); position: relative; z-index: 1; border-top: 1px solid rgba(255,255,255,0.08); }
.cb-app[data-side="light"] .cb-side__foot { border-top: 1px solid var(--border-subtle); }
.cb-side__user { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: var(--radius-md); cursor: pointer; }
.cb-side__user:hover { background: rgba(255,255,255,0.07); }
.cb-app[data-side="light"] .cb-side__user:hover { background: var(--navy-50); }
.cb-side__uname { font-size: 13.5px; font-weight: 600; color: inherit; line-height: 1.2; }
.cb-side__urole { font-size: 11.5px; opacity: 0.62; }
.cb-app[data-side="light"] .cb-side__urole { color: var(--text-muted); opacity: 1; }
.cb-signout {
  width: 34px; height: 34px; border-radius: var(--radius-sm); flex: none;
  display: grid; place-items: center; color: rgba(255,255,255,0.62);
  text-decoration: none; transition: background var(--dur-fast), color var(--dur-fast);
}
.cb-signout:hover { background: rgba(255,255,255,0.1); color: #fff; }
.cb-app[data-side="light"] .cb-signout { color: var(--text-faint); }
.cb-app[data-side="light"] .cb-signout:hover { background: var(--navy-50); color: var(--navy-700); }

/* ---------- Main ---------- */
.cb-main { min-width: 0; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; }
.cb-main::-webkit-scrollbar { width: 10px; }
.cb-main::-webkit-scrollbar-thumb { background: var(--sky-300); border-radius: 8px; }

.cb-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--space-5);
  padding: 14px var(--pad-page);
  background: rgba(247,245,240,0.82);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  min-height: var(--nav-h);
}
.cb-top__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cb-top__title h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.cb-top__title .cb-crumb { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.cb-top__spacer { flex: 1; }
.cb-search {
  display: flex; align-items: center; gap: 9px;
  background: #fff; border: 1px solid var(--border-subtle); border-radius: var(--radius-pill);
  padding: 9px 16px; min-width: 240px; color: var(--text-muted);
  box-shadow: var(--shadow-xs);
}
.cb-search svg { width: 17px; height: 17px; color: var(--text-faint); }
.cb-search input { border: none; outline: none; background: none; font-family: var(--font-body); font-size: 14px; color: var(--text-body); width: 100%; }
.cb-top__actions { display: flex; align-items: center; gap: 10px; }
.cb-icon-pill {
  position: relative; width: 42px; height: 42px; border-radius: var(--radius-md);
  display: grid; place-items: center; background: #fff; border: 1px solid var(--border-subtle);
  color: var(--navy-600); cursor: pointer; box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.cb-icon-pill:hover { border-color: var(--navy-300); background: var(--sky-100); }
.cb-icon-pill svg { width: 19px; height: 19px; }
.cb-icon-pill .cb-dot {
  position: absolute; top: 8px; right: 9px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal-500); border: 2px solid var(--bg-page);
}

.cb-page { padding: var(--pad-page); flex: 1; }
.cb-page__intro { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-5); flex-wrap: wrap; margin-bottom: var(--space-6); }
.cb-page__intro p { color: var(--text-muted); font-size: 15px; max-width: 60ch; margin-top: 4px; }

/* ---------- Cards ---------- */
.cb-card {
  background: var(--surface-card); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--pad-card);
}
.cb-card--pad0 { padding: 0; overflow: hidden; }
.cb-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-5); }
.cb-card__head h3 { font-size: 17px; font-weight: 700; }
.cb-card__head .cb-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.cb-link { color: var(--teal-600); font-weight: 600; font-size: 13.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; background: none; border: none; font-family: var(--font-body); }
.cb-link svg { width: 15px; height: 15px; }
.cb-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.cb-grid { display: grid; gap: var(--gap-grid); }

/* ---------- Stat card ---------- */
.cb-stat { display: flex; flex-direction: column; gap: 14px; }
.cb-stat__top { display: flex; align-items: center; justify-content: space-between; }
.cb-chip {
  width: 44px; height: 44px; border-radius: var(--radius-md); display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-600); flex: none;
}
.cb-chip svg { width: 22px; height: 22px; }
.cb-chip--navy { background: var(--navy-50); color: var(--navy-600); }
.cb-chip--sky { background: var(--sky-100); color: var(--sky-700); }
.cb-chip--warm { background: var(--warning-soft); color: #8a5b1c; }
.cb-stat__val { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--text-strong); letter-spacing: -0.02em; line-height: 1; }
.cb-stat__label { font-size: 13.5px; color: var(--text-muted); font-weight: 600; margin-top: 6px; }
.cb-delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.cb-delta svg { width: 13px; height: 13px; }
.cb-delta--up { background: var(--teal-50); color: var(--teal-700); }
.cb-delta--down { background: var(--danger-soft); color: var(--danger); }
.cb-delta--flat { background: var(--sky-100); color: var(--sky-700); }

/* ---------- Avatar ---------- */
.cb-av { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; font-family: var(--font-display); flex: none; }
.cb-av--sm { width: 30px; height: 30px; font-size: 11px; }
.cb-av--lg { width: 56px; height: 56px; font-size: 19px; }

/* ---------- Table ---------- */
.cb-table { width: 100%; border-collapse: collapse; }
.cb-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-faint); font-weight: 700; padding: 12px var(--space-5); border-bottom: 1px solid var(--border-subtle);
  background: var(--sky-100);
}
.cb-table td { padding: 14px var(--space-5); border-bottom: 1px solid var(--border-subtle); font-size: 14px; vertical-align: middle; }
.cb-table tbody tr { transition: background var(--dur-fast); cursor: pointer; }
.cb-table tbody tr:hover { background: var(--sky-100); }
.cb-table tbody tr:last-child td { border-bottom: none; }
.cb-cellname { display: flex; align-items: center; gap: 11px; }
.cb-cellname b { font-weight: 600; color: var(--text-strong); font-size: 14px; display: block; }
.cb-cellname small { color: var(--text-muted); font-size: 12px; }

/* ---------- Pills / tags ---------- */
.cb-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px; white-space: nowrap; }
.cb-pill svg { width: 13px; height: 13px; }
.cb-pill--teal { background: var(--teal-50); color: var(--teal-700); }
.cb-pill--navy { background: var(--navy-50); color: var(--navy-600); }
.cb-pill--sky { background: var(--sky-100); color: var(--sky-700); }
.cb-pill--warn { background: var(--warning-soft); color: #8a5b1c; }
.cb-pill--danger { background: var(--danger-soft); color: var(--danger); }
.cb-pill--muted { background: var(--sky-100); color: var(--text-muted); }
.cb-pill--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Progress ---------- */
.cb-prog { height: 7px; border-radius: 999px; background: var(--sky-200); overflow: hidden; width: 100%; }
.cb-prog__fill { height: 100%; border-radius: 999px; background: var(--grad-heartbeat); }
.cb-prog--navy .cb-prog__fill { background: var(--navy-500); }

/* ---------- Stage track ---------- */
.cb-stages { display: flex; align-items: center; gap: 0; width: 100%; }
.cb-stage { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.cb-stage__dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--sky-200); color: var(--text-faint); z-index: 1; border: 2px solid var(--bg-page); }
.cb-stage__dot svg { width: 15px; height: 15px; }
.cb-stage.is-done .cb-stage__dot { background: var(--teal-500); color: #fff; }
.cb-stage.is-current .cb-stage__dot { background: var(--navy-600); color: #fff; box-shadow: 0 0 0 4px var(--navy-100); }
.cb-stage__line { position: absolute; top: 15px; left: 50%; width: 100%; height: 2px; background: var(--sky-200); z-index: 0; }
.cb-stage.is-done .cb-stage__line { background: var(--teal-400); }
.cb-stage:last-child .cb-stage__line { display: none; }
.cb-stage__name { font-size: 12px; font-weight: 600; color: var(--text-muted); text-align: center; }
.cb-stage.is-current .cb-stage__name { color: var(--navy-700); }
.cb-stage.is-done .cb-stage__name { color: var(--teal-700); }

/* ---------- Bars chart ---------- */
.cb-bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 10px; }
.cb-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.cb-bar__stack { width: 100%; max-width: 30px; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; height: 100%; }
.cb-bar__seg { width: 100%; border-radius: 5px 5px 3px 3px; background: var(--navy-500); transition: height var(--dur-slow) var(--ease-out); }
.cb-bar__seg--accent { background: var(--teal-500); }
.cb-bar__lbl { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }

/* ---------- Donut legend ---------- */
.cb-donut-wrap { display: flex; align-items: center; gap: var(--space-6); flex-wrap: wrap; }
.cb-legend { display: flex; flex-direction: column; gap: 11px; flex: 1; min-width: 160px; }
.cb-legend__row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.cb-legend__sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.cb-legend__row b { margin-left: auto; color: var(--text-strong); font-weight: 700; font-family: var(--font-display); }

/* ---------- Misc ---------- */
.cb-divider { height: 1px; background: var(--border-subtle); margin: var(--space-5) 0; }
.cb-row { display: flex; align-items: center; gap: var(--space-4); }
.cb-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.cb-muted { color: var(--text-muted); }
.cb-soft-panel { background: var(--sky-100); border-radius: var(--radius-md); padding: var(--space-5); }
.cb-seg {
  display: inline-flex; background: var(--sky-100); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill); padding: 3px;
}
.cb-seg button {
  border: none; background: none; font-family: var(--font-body); font-size: 13px; font-weight: 600;
  color: var(--text-muted); padding: 7px 15px; border-radius: 999px; cursor: pointer;
}
.cb-seg button.is-active { background: #fff; color: var(--navy-700); box-shadow: var(--shadow-xs); }

.cb-tag-list { display: flex; flex-wrap: wrap; gap: 7px; }
.cb-spec { font-size: 12px; font-weight: 600; color: var(--navy-600); background: var(--navy-50); padding: 4px 10px; border-radius: 999px; }

.cb-empty { text-align: center; padding: var(--space-12) var(--space-6); color: var(--text-muted); }

/* ============================================================
   RESPONSIVE
   >1080px      full sidebar (264px)
   761–1080px   icon rail (76px)
   ≤760px       off-canvas drawer + single-column, scrollable tables
   ============================================================ */

.cb-burger { display: none; }
.cb-scrim {
  position: fixed; inset: 0; background: rgba(21,42,71,0.5);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  z-index: 55; opacity: 0; pointer-events: none; transition: opacity var(--dur-base) var(--ease-out);
}

/* ---- Tablet: icon rail ---- */
@media (max-width: 1080px) and (min-width: 761px) {
  .cb-app { grid-template-columns: 76px 1fr; }
  .cb-side__brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .cb-side__brand .cb-brand__text,
  .cb-nav__label,
  .cb-nav__item span,
  .cb-nav__item .cb-nav__count,
  .cb-side__user .cb-side__utext,
  .cb-side__user .cb-signout { display: none; }
  .cb-nav__item { justify-content: center; }
  .cb-side__user { justify-content: center; }
  .cb-search { min-width: 0; width: 44px; padding: 9px; }
  .cb-search input { display: none; }
}

/* ---- Tablet/desktop: collapse wide content grids ---- */
@media (max-width: 1080px) {
  .cb-app [style*="repeat(4"] { grid-template-columns: repeat(2, 1fr) !important; }
  .cb-app [style*="340px 1fr"],
  .cb-app [style*="320px 1fr"] { grid-template-columns: 1fr !important; }
}
@media (max-width: 900px) {
  .cb-app [style*="fr 1fr"],
  .cb-app [style*="1fr 1.4fr"],
  .cb-app [style*="repeat(2,"],
  .cb-app [style*="repeat(2 ,"],
  .cb-app [style*="repeat(3"] { grid-template-columns: 1fr !important; }
  /* treatment-journey kanban scrolls horizontally instead of crushing */
  .cb-app [style*="repeat(5, 1fr)"]:not(.cb-grid) {
    grid-template-columns: repeat(5, minmax(220px, 1fr)) !important;
    overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px;
  }
}

/* ---- Mobile: off-canvas drawer ---- */
@media (max-width: 760px) {
  .cb-app { grid-template-columns: 1fr; }

  .cb-side {
    position: fixed; top: 0; bottom: 0; left: 0; width: 282px; max-width: 84vw;
    z-index: 60; transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease-out);
    box-shadow: var(--shadow-xl);
  }
  .cb-app.nav-open .cb-side { transform: translateX(0); }
  .cb-app.nav-open .cb-scrim { opacity: 1; pointer-events: auto; }

  /* labels always visible inside the drawer */
  .cb-side__brand .cb-brand__text,
  .cb-nav__label,
  .cb-nav__item span,
  .cb-nav__item .cb-nav__count,
  .cb-side__user .cb-side__utext,
  .cb-side__user .cb-signout { display: revert; }
  .cb-nav__item { justify-content: flex-start; }
  .cb-side__user { justify-content: flex-start; }

  .cb-burger {
    display: grid; place-items: center; width: 42px; height: 42px; flex: none;
    border-radius: var(--radius-md); background: #fff; border: 1px solid var(--border-subtle);
    color: var(--navy-700); cursor: pointer; box-shadow: var(--shadow-xs);
  }
  .cb-burger svg { width: 20px; height: 20px; }

  .cb-top { gap: 12px; padding: 12px var(--pad-page); }
  .cb-top__title h1 { font-size: 18px; }
  .cb-top__title .cb-crumb { display: none; }
  .cb-search { display: none; }
  .cb-top__actions .cb-help-hide { display: none; }

  /* everything stacks */
  .cb-app [style*="repeat("],
  .cb-app [style*="fr 1fr"],
  .cb-app [style*="1fr 1.4fr"] { grid-template-columns: 1fr !important; }
  .cb-app [style*="repeat(5, 1fr)"]:not(.cb-grid) { grid-template-columns: 1fr !important; overflow-x: visible; }

  /* tables scroll horizontally inside their cards */
  .cb-card--pad0 { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cb-table { min-width: 600px; }

  .cb-page__intro { flex-direction: column; align-items: flex-start; }
  .cb-seg { flex-wrap: wrap; }
}

@media (max-width: 460px) {
  .cb-stat__val { font-size: 26px; }
  .cb-card { padding: var(--space-5); }
}
