/**
 * CPNBuilder dashboard — original blue shell (layout from trading-style mobile pass).
 */

html.cpn-dashboard-root {
  --dash-bg-deep: #0b1120;
  --dash-bg-mid: #0f172a;
  --dash-bg-top: #172554;
  --dash-header: #111827;
  --dash-sidebar: #1e3a8a;
  --dash-sidebar-hover: #1e40af;
  --dash-nav-btn: #2563eb;
  --dash-panel-top: #1e293b;
  --dash-panel-bottom: #111827;
  --dash-border: rgba(148, 163, 184, 0.18);
  --dash-text: #e5e7eb;
  --dash-text-muted: #64748b;
  --dash-text-dim: #cbd5e1;
  --dash-accent: #2563eb;
  --dash-accent-strong: #1d4ed8;
  --dash-accent-soft: rgba(37, 99, 235, 0.15);
  --dash-sidebar-w: 196px;
  --dash-bottom-nav-h: 56px;
  --dash-font: Inter, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
}

html.cpn-dashboard-root,
html.cpn-dashboard-root body {
  margin: 0;
  padding: 0;
  font-family: var(--dash-font);
  background: radial-gradient(circle at top, var(--dash-bg-top) 0%, var(--dash-bg-mid) 48%, var(--dash-bg-deep) 100%);
  color: var(--dash-text);
  overflow-x: clip;
  overflow-y: auto;
  scroll-behavior: smooth;
}

html.cpn-dashboard-root {
  overflow-anchor: none;
}

/* ── Shell ───────────────────────────────────────────────────────── */
html.cpn-dashboard-root .dashboard-wrapper {
  display: flex;
  min-height: 100vh;
  height: auto;
  align-items: flex-start;
  overflow: visible;
  background: transparent;
}

html.cpn-dashboard-root .main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: auto;
  height: auto;
  overflow: visible;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.94) 0%, rgba(11, 17, 32, 0.98) 100%);
}

html.cpn-dashboard-root .header-bar,
html.cpn-dashboard-root .cpn-dash-header {
  height: auto;
  min-height: 60px;
  background: var(--dash-header);
  border-bottom: 1px solid var(--dash-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  color: var(--dash-text);
}

html.cpn-dashboard-root .breadcrumb {
  font-size: 0.9rem;
  color: var(--dash-text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

html.cpn-dashboard-root .breadcrumb span + span::before {
  content: "/";
  margin: 0 6px;
  color: var(--dash-text-muted);
}

/* Document scroll only — never trap scroll inside #output (causes white cutoff in tools) */
html.cpn-dashboard-root #output {
  flex: none;
  flex-grow: 0;
  flex-shrink: 0;
  margin: 24px;
  height: auto;
  min-height: 0;
  max-height: none;
  background: linear-gradient(180deg, var(--dash-panel-top) 0%, var(--dash-panel-bottom) 100%);
  border: 1px solid var(--dash-border);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  overflow: visible;
  overflow-y: visible;
  padding: 24px;
  color: var(--dash-text);
}

html.cpn-dashboard-root .footer {
  height: auto;
  min-height: 40px;
  background: transparent;
  text-align: center;
  font-size: 0.75rem;
  color: var(--dash-text-muted);
  border-top: 1px solid var(--dash-border);
  line-height: 1.4;
  padding: 10px 16px;
}

html.cpn-dashboard-root .cpn-dash-compliance {
  background: var(--dash-bg-deep) !important;
  color: var(--dash-text) !important;
  border-bottom: 1px solid var(--dash-border);
}

html.cpn-dashboard-root .status-slot {
  margin-left: 0;
}

/* ── Sidebar (desktop + drawer) ──────────────────────────────────── */
html.cpn-dashboard-root .sidebar,
html.cpn-dashboard-root #navigation_bar.sidebar {
  width: var(--dash-sidebar-w);
  background: var(--dash-sidebar) !important;
  color: #fff;
  padding: 20px 12px;
  flex-shrink: 0;
  box-sizing: border-box;
  border-right: none;
}

html.cpn-dashboard-root .sidebar h2,
html.cpn-dashboard-root .cpn-sidebar-brand {
  margin: 0 0 1rem;
  padding: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
  border-bottom: none;
  line-height: 1.3;
}

html.cpn-dashboard-root .cpn-sidebar-brand span {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.65);
  margin-top: 4px;
}

html.cpn-dashboard-root .nav-btn {
  display: block;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  text-align: left;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 1rem;
  color: #fff;
  background: var(--dash-nav-btn);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
  text-decoration: none;
}

html.cpn-dashboard-root .nav-btn:hover {
  background: var(--dash-sidebar-hover);
  color: #fff;
}

html.cpn-dashboard-root .nav-btn.is-active,
html.cpn-dashboard-root .nav-btn[aria-current="page"] {
  background: var(--dash-sidebar-hover);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

html.cpn-dashboard-root .nav-btn-ecosystem {
  background: #065f46;
  border: 1px solid #6ee7b7;
  color: #fff;
  font-weight: 700;
}

html.cpn-dashboard-root .nav-btn-ecosystem:hover {
  background: #047857;
  color: #fff;
}

html.cpn-dashboard-root .nav-btn-help {
  background: #7c3aed;
  border: 1px solid #c4b5fd;
  color: #fff;
  font-weight: 600;
}

html.cpn-dashboard-root .nav-btn-help:hover {
  background: #6d28d9;
  color: #fff;
}

html.cpn-dashboard-root .logout-btn {
  margin-top: 20px;
  background: #ef4444 !important;
  border: none;
  color: #fff !important;
}

html.cpn-dashboard-root .logout-btn:hover {
  background: #dc2626 !important;
  color: #fff !important;
}

html.cpn-dashboard-root .admin-nav-btn {
  margin-top: 12px;
  background: #ef4444;
  border: 1px solid #fecaca;
  color: #fff;
  font-weight: 600;
}

html.cpn-dashboard-root .admin-nav-btn:hover {
  background: #b91c1c;
  color: #fff;
}

html.cpn-dashboard-root .sidebar hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 12px 0;
}

html.cpn-dashboard-root .cp-sidebar-toggle,
html.cpn-dashboard-root .mobile-menu-trigger {
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: var(--dash-sidebar);
  color: #fff;
}

/* ── Mobile bottom nav (Trading-style) ───────────────────────────── */
.cpn-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  /* Primary nav is bottom bar (Trading pattern); drawer opened via More */
  html.cpn-dashboard-root .cpn-dash-header-zone__menu-row,
  html.cpn-dashboard-root .cpn-dash-header-zone__menu-row.cp-mobile-menu-row--active {
    display: none !important;
  }

  .cpn-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    align-items: stretch;
    justify-content: space-around;
    min-height: var(--dash-bottom-nav-h);
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: var(--dash-sidebar);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  html.cpn-dashboard-root .main {
    padding-bottom: calc(var(--dash-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  }

  html.cpn-dashboard-root body.cpn-in-tool-view .main,
  html.cpn-dashboard-root body[data-current-tool]:not([data-current-tool=""]) .main {
    padding-bottom: calc(var(--dash-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  html.cpn-dashboard-root #output {
    margin: 0 !important;
    padding: 12px !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .cpn-bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--dash-bottom-nav-h);
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--dash-text-muted);
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
  }

  .cpn-bottom-nav__item.is-active {
    color: var(--dash-accent);
  }

  .cpn-bottom-nav__icon {
    font-size: 1.15rem;
    line-height: 1;
  }

  .cpn-bottom-nav__label {
    font-size: 9px;
    line-height: 1.1;
    letter-spacing: 0.02em;
  }

  /* Hide duplicate fixed dock when bottom nav handles primary nav */
  html.cpn-dashboard-root .cpn-mobile-sticky.cpn-mobile-dock--fixed {
    bottom: calc(var(--dash-bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  }
}

@media (min-width: 769px) {
  /* Document scroll on every section (Tools hub footer grid was clipped without this) */
  html.cpn-dashboard-root,
  html.cpn-dashboard-root body {
    height: auto !important;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto !important;
  }

  /* Block layout + left gutter — sidebar is viewport-fixed, not a flex sibling */
  html.cpn-dashboard-root .dashboard-wrapper {
    display: block !important;
    height: auto !important;
    min-height: 100vh;
    padding-left: var(--dash-sidebar-w) !important;
    box-sizing: border-box !important;
    overflow: visible !important;
  }

  html.cpn-dashboard-root .sidebar,
  html.cpn-dashboard-root #navigation_bar.sidebar,
  html.cpn-dashboard-root #navigation_bar.cpn-sidebar--desktop-pinned {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: var(--dash-sidebar-w) !important;
    max-width: var(--dash-sidebar-w) !important;
    height: 100vh !important;
    max-height: 100vh !important;
    z-index: 300 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    transform: none !important;
    flex: none !important;
  }

  html.cpn-dashboard-root .main {
    display: flex;
    flex-direction: column;
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    height: auto !important;
    overflow: visible !important;
    margin-left: 0 !important;
  }

  html.cpn-dashboard-root #output {
    flex: none !important;
    flex-grow: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 16px 24px 24px;
    overflow: visible !important;
    overflow-y: visible !important;
  }
}

@media (max-width: 768px) {
  html.cpn-dashboard-root,
  html.cpn-dashboard-root body {
    height: auto !important;
    min-height: 100%;
  }

  html.cpn-dashboard-root .dashboard-wrapper {
    height: auto !important;
    min-height: 0 !important;
  }

  html.cpn-dashboard-root .main {
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
  }

  html.cpn-dashboard-root #output {
    display: block !important;
    flex: none !important;
    flex-grow: 0 !important;
    overflow: visible !important;
    overflow-y: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  html.cpn-dashboard-root .main {
    display: block !important;
  }
}
