/* ====== Tokens ====== */
.page-insights {
  --primary:#2563eb;
  --text:#1f2937;
  --muted:#6b7280;
  --primary-mute: #272727;
  --line:#e9edf3;
  --bg:#f7f9fc;
  --surface:#ffffff;
  --radius:12px;
  --shadow:0 6px 16px rgba(0,0,0,.06);
}

/* ====== Banner ====== */
.insights-banner{
  background: linear-gradient(90deg,#0b50d4 0%, #093cac 40%, #091F48 100%);
  padding: 18px 0;
  color:#fff;
  margin: 0 0 16px 0;
}
.banner-inner{ width:100%; max-width:1200px; margin:0 auto; padding:0 12px; }
.banner-inner .title{ margin:6px 0 0 0; }
.crumbs{ display:flex; gap:6px; font-size:12px; opacity:.95; }
.crumbs a{ color:#fff; text-decoration:none; }

/* ====== Layout ====== */
.insights-body{ display:grid; grid-template-columns: 280px 1fr; gap: 20px; }
.section-head{ margin-bottom: 8px; }
.section-title{ margin:0; font-size:xx-large; color:var(--text); }
.section-sub{ margin:4px 0 0; margin-top: 5px; color:var(--muted); }
.section-sub-p{ margin:4px 0 0; font-size: large; color:var(--muted); }

/* ====== Sidebar ====== */
.sidebar{
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:var(--surface);
  box-shadow:var(--shadow);
  padding:12px;
}
.sidebar-search input{
  width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:10px;
}
.sidebar-section h3{
  margin:12px 0 8px; font-size:12px; text-transform:uppercase; letter-spacing:.05em; color:#3b4556;
}
.tree{ list-style:none; margin:0; padding:0; }
.tree > li{ margin:6px 0 10px; }
.tree-toggle{
  width:100%; background:transparent; border:none; text-align:left; padding:8px 6px; border-radius:8px; cursor:pointer; font-weight:600;
}
.tree-children{ list-style:none; margin:6px 0 0 8px; padding:0; }
.tree-children a{ display:block; padding:6px 8px; border-radius:8px; text-decoration:none; color:#222; }
.tree-children a.active, .tree-children a:hover{ background:#f4f6f9; }

/* ====== Tabs ====== */
.tabs{ display:flex; gap:18px; border-bottom:1px solid var(--line); margin:12px 0 14px; }
.tab{ background:transparent; border:none; padding:12px 0; cursor:pointer; color:#64748b; position:relative; font-weight:600; }
.tab.active{ color:#111827; }
.tab.active::after{ content:""; position:absolute; left:0; right:0; bottom:-1px; height:3px; background:var(--primary); border-radius:3px 3px 0 0; }

/* ====== Cards ====== */
.card{ border:1px solid var(--line); border-radius:var(--radius); background:var(--surface); box-shadow:var(--shadow); margin-bottom:16px; }
.card-header{ padding:12px 14px; border-bottom:1px solid var(--line); }
.card-header.row-between{ display:flex; align-items:center; justify-content:space-between; }
.card-body{ padding:14px; }
.badge{ padding:12px 8px; border-radius:10px; font-size:12px; font-weight:600; }
.badge.access{ background:#97add8; color:#0e4dc9; }

/* tokens */
.page-insights{
  --content-max: 1500px;   /* try 1120 / 1100 / 1000 if you want it tighter */
  --content-pad: 12px;
}



/* container */
.insights-body{
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;

  /* ↓ new */
  max-width: var(--content-max);
  margin: 0 auto;                 /* center the grid */
  padding: 0 var(--content-pad);  /* small side padding */
}


/* ====== Alerts ====== */
.alert.login-required{
  display:flex; gap:12px; align-items:center;
  padding:14px; border:1px solid #0a358b; background:#ebeeff; border-radius:10px; color:#041a47; margin-bottom:12px;
}

/* ====== Filters ====== */
.filters-card{ display:block !important; }
.header-actions{ display:flex; gap:8px; }
.filters-grid{ display:grid; grid-template-columns: repeat(4, minmax(200px,1fr)); gap: 14px; }
.filter label{ display:block; font-size:12px; color:#475569; margin-bottom:6px; }
.filter select, .filter input{
  width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:10px; background:#f3f6fb;
}
.filter.action-col{ display:flex; align-items:end; }

/* Header layout */
#filters-card .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;               /* gives space from the edges */
}
#filters-card .header-actions { display: flex; gap: 8px; }

/* Kill any old absolute positioning from legacy styles */
#btn-reset-filters { position: static !important; }

/* Namespaced button styles (avoid Bootstrap clashes) */
.i-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #111827;
  line-height: 1;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}
.i-btn:hover{ background:#f1f5f9; }
.i-btn:focus{ outline: none; }
.i-btn:focus-visible{ outline:2px solid var(--primary); outline-offset:2px; }

/* Variant */
.i-btn-soft{ background:#f8fafc; }

/* If you kept the old 'btn' class, make sure it still looks like a button here */
#filters-card .card-header .btn{
  display:inline-flex; align-items:center; justify-content:center;
  height:36px; padding:6px 12px; border-radius:10px; white-space:nowrap;
}

.i-btn-primary{ background:var(--primary); color:#fff; border-color:var(--primary); }
.i-btn-primary:hover{ filter:brightness(.95); }

/* kill the square blue border on tabs */
.tabs .tab:focus,
.tabs .tab:focus-visible {
  outline: none !important;
  box-shadow: none !important; /* in case Bootstrap adds one */
}


/* no box on mouse click */
.tabs .tab:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

/* optional: subtler keyboard focus (underline only, no square) */
.tabs .tab:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Plot container for actual charts (not the placeholder) */
.viz-plot {
  min-height: 420px;
  border: 1px dashed #cfd8e3;
  border-radius: 12px;
  display: block;          /* IMPORTANT: no flex/grid centering */
  padding: 4px;
  position: relative;
  overflow: visible;       /* let Plotly tooltips show */
}

/* Loading state */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  color: var(--muted);
}

.loading-spinner::after {
  content: "";
  width: 24px;
  height: 24px;
  margin-left: 10px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Error state */
.viz-error {
  padding: 12px;
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 8px;
  margin: 10px 0;
}

/* Warning state */
.viz-warning {
  padding: 12px;
  background: #fff7ed;
  color: #c2410c;
  border-radius: 8px;
  margin: 10px 0;
}


/* Make sure plots fill the container */
.js-plotly-plot {
  width: 100% !important;
}

/* Ensure responsive behavior */
@media (max-width: 768px) {
  .viz-plot {
    min-height: 350px;
  }
}

/* Keep the Plotly modebar visible */
.js-plotly-plot .plotly .modebar {
  z-index: 10;
}



/* (Optional) keep placeholder for other spots */
.viz-placeholder { 
  height: 200px;
  border: 1px dashed #cfd8e3;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* Load data button */
.btn-load {
  background-color: #0e4dc9;
  color: white;
  border-color: #0e4dc9;
}

/* Make sure the actions area has proper spacing */
.viz-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* Ensure plotly modebar appears above other elements */
.js-plotly-plot .plotly .modebar {
  z-index: 10;
}

/* Ensure the visualizations resize properly */
@media (max-width: 768px) {
  .viz-plot {
    min-height: 350px;
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

/* ====== Buttons ====== */
.btn{ display:inline-flex; align-items:center; gap:6px; padding:9px 12px; border-radius:10px; border:1px solid var(--line); background:#f8fafc; cursor:pointer; text-decoration:none; color:#111827; }
.btn:hover{ background:#f1f5f9; }
.btn-soft{ background:#f8fafc; }
.btn-primary{ background:var(--primary); color:#fff; border-color:var(--primary); }
.btn-primary:hover{ filter:brightness(0.95); }

/* ====== Viz grid ====== */
.grid{ display:grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
/* .viz-card{ grid-column: span 6; border:1px solid var(--line); border-radius:var(--radius); background:var(--surface); box-shadow:var(--shadow); overflow:hidden; } */
.viz-card .viz-header{ padding:12px 14px; border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between; }
.viz-card .viz-header h4{ margin:0; font-size:16px; color:var(--text); }
.viz-card .viz-body{ padding:14px; min-height:240px; background:#fafcff; }
.viz-placeholder{ height:200px; border:1px dashed #cfd8e3; border-radius:12px; display:grid; place-items:center; color:var(--muted); }
.viz-actions{ margin-top:10px; display:flex; gap:8px; justify-content:flex-end; }
.viz-card-head .viz-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.viz-card-head .viz-type {
  font-size: 12px;
  background: #eef2ff;
  color: #0e4dc9;
  padding: 3px 8px;
  border-radius: 999px;
}

.viz-plot {
  min-height: 420px; /* critical so Plotly has space */
  position: relative;
}

.viz-skeleton {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px;
}
.viz-skeleton .bar { background: linear-gradient(90deg,#f3f4f6,#e5e7eb,#f3f4f6);
  animation: shimmer 1.6s infinite; border-radius: 6px; }
@keyframes shimmer { 0%{background-position:-200% 0} 100%{background-position:200% 0} }

.viz-error, .viz-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center; color: #6b7280; font-size: 14px;
}

/* Force 2-up layout; collapse to 1 on small screens */
#viz-grid.grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(560px, 1fr));
  gap: 18px;
}

@media (max-width: 1200px){
  #viz-grid.grid{ grid-template-columns: 1fr; }
}


/* ====== Dataset & Reports ====== */
.dataset-list{ list-style:none; margin:0; padding:0; }
.dataset-item{ display:flex; justify-content:space-between; align-items:center; padding:12px; border-bottom:1px solid var(--line); }
.dataset-title{ font-weight:700; text-decoration:none; color:var(--text); }
.dataset-sub{ color:var(--muted); font-size:12px; margin-top:4px; }
.dataset-actions{ display:flex; gap:8px; }

.report-cards{ display:grid; grid-template-columns: repeat(12, 1fr); gap:16px; }
.report-card{ grid-column: span 4; display:flex; gap:14px; align-items:flex-start; padding:14px; border:1px solid var(--line); border-radius:var(--radius); background:var(--surface); box-shadow:var(--shadow); }
.report-icon{ font-size:22px; }
.report-title{ font-weight:700; text-decoration:none; color:var(--text); }
.report-sub{ color:var(--muted); font-size:12px; margin-top:4px; }
.report-actions{ margin-left:auto; display:flex; gap:8px; }


/* ===== Cards grid (responsive, no overflow) ===== */
.cards-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap:16px;
}

/* ===== Dataset cards ===== */
.dataset-card{
  display:flex; flex-direction:column; min-width:0;  /* prevent overflow */
  border:1px solid var(--line); border-radius:var(--radius);
  background:var(--surface); box-shadow:var(--shadow);
  padding:14px;
}
.dc-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; }
.dc-publisher{ font-size:12px; color:var(--muted); }
.pill{ padding:3px 8px; border-radius:999px; font-size:11px; font-weight:700; white-space:nowrap; }
.pill-indicator{ background:#e6efff; color:#0e4dc9; }
.dc-title{
  display:block; margin:2px 0 4px; font-weight:800; text-decoration:none; color:var(--text);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.dc-sub{ color:var(--muted); font-size:12px; margin-bottom:10px; }
.dc-actions{ margin-top:auto; display:flex; gap:8px; flex-wrap:wrap; }

/* ===== Report cards ===== */
/* ===== Reports: stack cards, don't stretch ===== */
.reports-grid{
  display:flex;               /* override .cards-grid's grid */
  flex-direction:column;
  gap:16px;
  align-items:flex-start;     /* so cards hug the left and keep their width */
}
.report-card{
  width: min(560px, 100%);    /* <- key line: content-relative width */
  border:1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding:16px;
  display:grid;
  grid-template-columns: 36px 1fr auto;
  grid-template-rows: auto auto auto;
  column-gap: 12px;
  row-gap: 6px;
}


/* Icon block */
.report-card .rc-icon{
  grid-column: 1;
  grid-row: 1 / span 2;
  width:36px; height:36px;
  display:grid; place-items:center;
  border-radius:8px; background:#eef2ff; color:#0e4dc9;
  font-size:18px;
}

/* Title on top row, full width to the right of the icon */
.report-card .rc-title{
  grid-column: 2 / 4;
  grid-row: 1;
  font-size:large;
  font-weight:700; text-decoration:none; color:var(--text);
}

/* “Published” line (separate from summary) */
.report-card .rc-meta{
  grid-column: 2 / 4;
  grid-row: 2;
  color:var(--muted); font-size:12px;
}

/* Summary paragraph */
.report-card .rc-summary{
  grid-column: 2 / 4;
  grid-row: 3;
  color: var(--text);
  opacity: .9;
  font-size: medium;
  margin-top: 6px;
}

/* Actions row */
.report-card .rc-actions{
  grid-column: 2 / 4;
  display:flex; gap:8px; margin-top: 8px;
}

.rc-head{ display:flex; align-items:center; gap:10px; }
.rc-icon{
  width:28px; height:28px; display:grid; place-items:center;
  border-radius:8px; background:#eef2ff; color:#0e4dc9; flex:0 0 28px;
}
.rc-title{
  font-weight:800; text-decoration:none; color:var(--text);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.rc-sub{ color:var(--muted); font-size:12px; margin:8px 0 10px; }
.rc-actions{ margin-top:auto; display:flex; gap:8px; flex-wrap:wrap; }

/* Make sure the grids don't bleed out of the card body */
.card-body > .cards-grid { margin: 0; }

/* Tighten large screens: 3-up reports, 3-up datasets if room */
@media (min-width: 1280px){
  .cards-grid{ grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
}

/* Small screens: comfortable single column */
@media (max-width: 680px){
  .cards-grid{ grid-template-columns: 1fr; }
}




/* ====== Panels ====== */
.panel{ display:block; }
.panel[hidden]{ display:none; }

/* ====== Responsive ====== */
@media (max-width: 1200px){
  .insights-body{ grid-template-columns:1fr; }
  .filters-grid{ grid-template-columns: repeat(2, minmax(200px,1fr)); }
  .viz-card{ grid-column: span 12; }
  .report-card{ grid-column: span 12; }
}
@media (max-width: 640px){
  .filters-grid{ grid-template-columns: 1fr; }
}

  /* Sidebar styling */
  #insights-sidebar .sidebar-section {
    margin-bottom: 1.5rem;
  }
  
  #insights-sidebar h5 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #333;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.5rem;
  }
  
  #insights-sidebar h6 {
    font-size: 0.95rem;
    font-weight: 500;
    margin: 1rem 0 0.5rem;
    color: #555;
  }
  
  #insights-sidebar .indicator-list {
    list-style: none;
    padding-left: 1rem;
    margin: 0.5rem 0;
  }
  
  #insights-sidebar .indicator-list li {
    margin-bottom: 0.5rem;
  }
  
  #insights-sidebar .indicator-list a {
    color: #0e4dc9;
    text-decoration: none;
    font-size: 0.9rem;
    display: inline-block;
    padding: 0.25rem 0;
  }
  
  #insights-sidebar .indicator-list a:hover {
    color: #0e4dc9;
    text-decoration: underline;
  }
  
  /* Loading state */
  .sidebar-loading {
    padding: 2rem 1rem;
    text-align: center;
    color: #666;
  }
  
  .loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0e4dc9;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }



  /* Sidebar styling enhancements */
.sidebar {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.sidebar-search {
  margin-bottom: 16px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
}

.sidebar-section h3 {
  margin: 12px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #3b4556;
}

/* Tree structure */
.tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree > li {
  margin: 6px 0 10px;
}

.tree-toggle {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
}

.tree-toggle::before {
  content: "▾";
  margin-right: 6px;
  font-size: 10px;
  color: #6b7280;
  transition: transform 0.2s;
}

.tree-toggle[aria-expanded="false"]::before {
  transform: rotate(-90deg);
}

.tree-toggle:hover {
  background: #f1f5f9;
}

.tree-children {
  list-style: none;
  margin: 6px 0 0 12px;
  padding: 0;
  transition: max-height 0.3s ease-out;
}

.tree-children[hidden] {
  display: none;
}

/* Package links */
.tree-children a {
  display: block;
  padding: 6px 8px;
  border-radius: 8px;
  text-decoration: none;
  color: #4b5563;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}

.tree-children a:hover {
  background: #f3f4f6;
  color: #111827;
}

.tree-children a.active {
  background: #eef2ff;
  color: #0e4dc9;
  font-weight: 500;
}

/* Loading state */
.sidebar-loading {
  padding: 2rem 1rem;
  text-align: center;
  color: #6b7280;
}

/* Loading animation */
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.sidebar li em {
  color: #6b7280;
  font-style: italic;
  animation: pulse 1.5s infinite;
  display: block;
  padding: 8px 0;
}

/* Empty states */
.empty-message {
  padding: 24px;
  text-align: center;
  color: #6b7280;
  background: #f9fafb;
  border-radius: 8px;
  margin: 16px 0;
}

.error-message {
  padding: 16px;
  text-align: center;
  color: #b91c1c;
  background: #fee2e2;
  border-radius: 8px;
  margin: 16px 0;
}

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  color: #6b7280;
}

.loading-indicator::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-left: 8px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 1200px) {
  .insights-body {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    margin-bottom: 20px;
  }
}


/* ====== Alternative: Footer Outside Container ====== */
.page-insights {
  min-height: calc(100vh - var(--footer-height, 80px));
}

/* Or if you don't know footer height */
.page-insights {
  min-height: 100vh;
  padding-bottom: 100px; /* adjust based on your footer height */
  margin-bottom: -100px; /* negative margin to pull footer up */
}
