html,
body {
  margin: 0;
  padding: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

body.is-sidebar-locked {
  overflow: hidden;
}

body.is-ai-agent-open {
  overflow: hidden;
}

canvas {
  width: 100% !important;
  height: 100% !important;
}

.ai-agent-backdrop {
  position: fixed;
  top: var(--cw-app-header-height, 0px);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 45;
  background: rgba(15, 23, 42, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.ai-agent-backdrop.is-active {
  opacity: 1;
  pointer-events: auto;
}

.ai-agent-drawer {
  position: fixed;
  top: var(--cw-app-header-height, 0px);
  right: 0;
  z-index: 50;
  width: min(100vw, 28rem);
  height: calc(100vh - var(--cw-app-header-height, 0px));
  transform: translateX(100%);
  border-left: 1px solid rgb(226, 232, 240);
  box-shadow: -18px 0 45px rgba(15, 23, 42, 0.18);
  transition: transform 0.24s ease;
}

.ai-agent-drawer.is-open {
  transform: translateX(0);
}

.ai-agent-example {
  display: block;
  width: 100%;
  border: 1px solid rgb(226, 232, 240);
  border-radius: 0.75rem;
  background: white;
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-size: 0.8125rem;
  line-height: 1.25rem;
  color: rgb(51, 65, 85);
}

.ai-agent-example:hover {
  background: rgb(248, 250, 252);
  color: rgb(15, 23, 42);
}

/* "Thinking" loading bubble — three dots that pulse. */
.cw-ai-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 1px;
  border-radius: 9999px;
  background: rgb(148, 163, 184);
  animation: cw-ai-bounce 1.2s infinite ease-in-out both;
}
.cw-ai-dot:nth-child(2) { animation-delay: 0.15s; }
.cw-ai-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes cw-ai-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Markdown rendered into assistant bubbles. Tailwind's typography plugin
   isn't loaded here, so spell out the spacing/lists/tables ourselves. */
.cw-ai-md p { margin: 0.25rem 0; }
.cw-ai-md p:first-child { margin-top: 0; }
.cw-ai-md p:last-child  { margin-bottom: 0; }
.cw-ai-md ul, .cw-ai-md ol { margin: 0.4rem 0 0.4rem 1rem; }
.cw-ai-md li { margin: 0.15rem 0; }
.cw-ai-md ul { list-style: disc; }
.cw-ai-md ol { list-style: decimal; }
.cw-ai-md code {
  background: rgb(241, 245, 249);
  padding: 0 4px;
  border-radius: 4px;
  font-size: 0.85em;
}
.cw-ai-md pre {
  background: rgb(241, 245, 249);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.78rem;
  margin: 0.4rem 0;
}
.cw-ai-md pre code { background: none; padding: 0; }
.cw-ai-md table {
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.8125rem;
  border-collapse: collapse;
}
.cw-ai-md th, .cw-ai-md td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid rgb(226, 232, 240);
  text-align: left;
}
.cw-ai-md th { font-weight: 600; color: rgb(15, 23, 42); }
.cw-ai-md a { color: rgb(37, 99, 235); text-decoration: underline; }
.cw-ai-md blockquote {
  border-left: 3px solid rgb(203, 213, 225);
  padding-left: 0.6rem;
  color: rgb(71, 85, 105);
  margin: 0.4rem 0;
}

/* Sidebar: expanded (default) */
.sidebar {
  width: 18rem;
  padding: 1.5rem;
  transition: width 0.2s ease, padding 0.2s ease;
}

/* Mobile drawer: below lg (1024px) the sidebar slides in over the page */
@media (max-width: 1023.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 10px 30px rgba(2, 6, 23, 0.4);
  }

  .sidebar.is-mobile-open {
    transform: translateX(0);
  }

  /* The desktop collapse toggle is meaningless inside a mobile drawer. */
  #sidebarToggleBtn {
    display: none;
  }
}

.sidebar-mobile-toggle {
  display: inline-flex;
}

@media (min-width: 1024px) {
  .sidebar-mobile-toggle {
    display: none;
  }
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.is-active {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 1024px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* Desktop collapse rules (lg+ only): below lg the drawer always shows the
   expanded layout regardless of the saved preference. */
@media (min-width: 1024px) {
  .sidebar.is-collapsed {
    width: 4.25rem;
    padding: 0.75rem 0.5rem;
  }

  .sidebar.is-collapsed .sidebar-top {
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }

  .sidebar.is-collapsed .sidebar-brand {
    display: none;
  }

  .sidebar.is-collapsed .sidebar-expanded-only {
    display: none;
  }

  .sidebar.is-collapsed .sidebar-nav {
    margin-top: 0.5rem;
  }

  .sidebar.is-collapsed .nav-item {
    justify-content: center;
    gap: 0;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    position: relative;
  }

  .sidebar.is-collapsed .nav-item-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .sidebar.is-collapsed #sidebarToggleIcon {
    transform: rotate(180deg);
  }
}

/* Performance KPI cards: responsive label + trend pill without overflow */
.kpi-card {
  container-type: inline-size;
  container-name: kpi;
}

.kpi-label-short {
  display: none;
}

/* Trend pill: show delta whenever it fits; arrow-only when .trend-pill--compact (set by layout script) */
.trend-pill {
  flex-shrink: 0;
  min-width: 0;
  white-space: nowrap;
}

.trend-pill-delta {
  white-space: nowrap;
}

.trend-pill--compact .trend-pill-delta {
  display: none;
}

.trend-pill--compact {
  padding-left: 0.35rem;
  padding-right: 0.35rem;
  min-width: 1.75rem;
  justify-content: center;
}

/* Narrow card: abbreviated KPI title only */
@container kpi (max-width: 360px) {
  .kpi-label-long {
    display: none;
  }

  .kpi-label-short {
    display: block;
  }
}

/* Hover-only popover tooltips should not latch on touch (mobile/tablets). */
@media (hover: none) {
  [role="tooltip"].tooltip {
    display: none !important;
  }
}
