/* === GRID SYSTEM BASE === */
.grid-layout {
  display: grid;
  grid-auto-rows: auto;
  column-gap: 15px;  /* horizontal gap */
  row-gap: 15px;     /* vertical gap */
  box-sizing: border-box;
}

.grid-layout.grid-rows-2 {
  grid-template-rows: auto auto; 
}

.grid-layout.grid-rows-3 {
  grid-template-rows: auto auto auto; 
}

.grid-layout.grid-cols-50-50 {
  width: calc(100% - 15px);
  grid-template-columns: 50% 50%;
}

.grid-layout.grid-cols-35-65 {
  width: calc(100% - 15px);
  grid-template-columns: 35% 65%;
}

.grid-layout.grid-cols-65-35 {
  width: calc(100% - 15px);
  grid-template-columns: 65% 35%;
}

/* Generic row layout for dynamic stacks */
.grid-row-layout { 
  display: grid; 
  grid-auto-flow: row; 
  row-gap: 15px; 
}

/* === CUSTOM GRID USING ATTRIBUTES === */
[data-grid] {
  display: grid;
  gap: 15px;
}
[data-grid-cols] {
  grid-template-columns: var(--grid-cols);
}

/* === GRID ROW HEIGHT PRESETS === */
.grid-auto        { grid-auto-rows: auto; }
.grid-tall        { grid-auto-rows: minmax(300px, auto); }
.grid-even-rows   { grid-auto-rows: 1fr; }

/* === ALIGNMENT UTILITIES === */
.grid-center { align-items: center; justify-items: center; }
.grid-top    { align-items: start; }
.grid-bottom { align-items: end; }

/* === GRID CELL BASE === */
.grid-cell {
  background: #fff;
  border-radius: 10px;
  box-sizing: border-box;
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
  display: flex;
  padding: 10px;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* === SPECIFIC CELL TYPES === */
.grid-cell.video,
.grid-cell.graph,
.grid-cell.text { 
    overflow: hidden; 
}

.grid-cell.video {
  background-color: #0049761a;
  object-fit: cover;
}

.grid-cell.video video,
.grid-cell.video iframe,
.grid-cell.graph img {
  width: auto;
  height: 100%;
  min-height: 250px;
  border-radius: 8px;
  object-fit: cover;
}

/* === GRAPH / VEGA / VEGA-LITE === */
.grid-cell.graph,
.grid-cell.vega-lite,
.grid-cell.mermaid {
  margin: 0;
  overflow: hidden; /* avoid scrollbars inside */
  position: relative;
  width: 100%;
  min-height: 260px; /* slightly more room for axes */
  box-sizing: border-box;
}

/* === Vega & Vega-Lite rendering fixes === */
.grid-cell.graph canvas,
.grid-cell.graph svg,
.grid-cell.vega-lite canvas,
.grid-cell.vega-lite svg {
  width: 100% !important;
  height: auto !important; /* ✅ allow proportional scaling */
  max-height: none !important;
  display: block;
  object-fit: contain; /* ✅ keep axes visible */
  -webkit-transform: translateZ(0); /* Safari: prevent flicker */
}


/* === Mermaid === */
.grid-cell.mermaid {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
  min-height: 250px;
}
.grid-cell.mermaid svg {
  width: 100% !important;
  height: 100% !important;
}

/* === Text Cells === */
.grid-cell.text {
  color: #333;
  font-size: 1em;
  line-height: 1.6;
}
.grid-cell.text h3 {
  color: #004976;
  margin-bottom: 10px;
}

/* === CODE DESCRIPTION CELL === */
.code-description {
  background: #0049761a;
  color: #333;
  padding: 15px;
  border-radius: 10px;
  font-size: 0.95em;
  line-height: 1.5;
}

/* === CODE CELL === */
.grid-cell.code {
  background: #1e1e1e;
  color: #f5f5f5;
  font-family: "Fira Code", monospace;
  font-size: 0.9em;
  line-height: 1.4;
  padding: 12px 12px 12px 12px; /* bottom padding to make room for controls */
  border-radius: 8px;
  overflow: auto;
  position: relative;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 6px rgba(0,0,0,0.15);
  max-height: 520px;
}

.grid-cell.code pre {
  margin: 0;
  overflow-x: auto;
}

.grid-cell.code code {
  display: block;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* === Copy and Code Prompt button styling (your original rules, corrected) */
.code-controls {
  margin-top: 12px;
  position: relative;
  display: flex;
  gap: 3px;
}

/* Use fixed sizes for buttons so they align */
.copy-btn, .popup-btn {
  width: 40px;
  height: 34px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 4px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
}

/* Specific colors you used */
.copy-btn {
  background-color: rgba(0, 126, 204, 0.5);
  transition: background-color 0.3s;
  border: 1px solid #004976;
  margin-left: 10px;
}
.popup-btn {
  background-color: rgba(0, 179, 68, 0.5);
  transition: background-color 0.3s;
  border: 1px solid #487600;
  margin-left: 5px;
}

/* hover / active states */
.copy-btn:hover { background-color: rgba(0, 126, 204, 0.7) !important; }
.copy-btn:active { background-color: rgba(0, 126, 204, 1) !important; }
.popup-btn:hover { background-color: rgba(0, 179, 68, 0.7) !important; }
.popup-btn:active { background-color: rgba(0, 179, 68, 1) !important; }

/* fallback small icon styles */
.copy-btn img, .popup-btn img { width: 18px; height: 18px; filter: invert(1); }

/* === Formula Cells === */
.grid-cell.formula {
  background: #f8fafc;
  border: 1px solid #d0d7de;
  padding: 15px;
  border-radius: 10px;
  color: #333;
  font-size: 0.95em;
  line-height: 1.5;
}

.grid-cell.formula h3 {
  color: #004976;
  font-size: 1.2em;
  margin-bottom: 10px;
}

.grid-cell.formula p {
  margin: 4px 0;
}

.grid-cell.formula code,
.grid-cell.formula pre {
  background: #e8eef5;
  border-radius: 5px;
  padding: 4px 6px;
  font-family: "Fira Code", monospace;
  font-size: 0.9em;
  display: inline-block;
}

/* === Table Cells === */
.grid-cell.table {
  background: #ffffff;
  border: 1px solid slategray;
  border-radius: 10px;
  padding: 15px;
  overflow-x: auto;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.grid-cell.table h3 {
  color: #004976;
  margin-bottom: 10px;
  font-size: 1.2em;
}

.grid-cell.table table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.95em;
}

.grid-cell.table th,
.grid-cell.table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: center;
}

.grid-cell.table thead tr {
  background-color: #0049761a;
}

.grid-cell.table tfoot tr {
  background-color: #0049761a;
  font-weight: bold;
}

.grid-cell.table caption {
  caption-side: top;
  font-weight: bold;
  color: #004976;
  margin-bottom: 8px;
}

.wrapper {
    background-color: #f0f0f0;
    padding: 10px;
    margin: 10px 0;
    border-radius: 5px;
}
.tabs {
    display: flex;
    justify-content: flex-start;
}
.tab {
    cursor: pointer;
    padding: 10px 20px;
    background: #004976;
    color: #fff;
    border-radius: 3px 3px 0 0;
    margin-right: 2px;
}
.tab.active {
    background: slategray;
}
.panels {
    background: slategray;
    padding: 10px 10px 10px 10px;
    border-radius: 0 0 5px 5px;
    position: relative;
}   
.panel {
    display: none;
    max-height: 600px;  /* Changed from height to max-height */
    overflow-y: auto;  /* Add vertical scrollbar when needed */
}
.panel.active {
    display: block;
}

pre.code-example {
    background-color: #2d2d2d;
    color: #ccc;
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-top: 0;
    margin-bottom: 0;
}

/* === BODY + CONTAINER === */
body {
  background: linear-gradient(to bottom, #f9f9fb, #eaeef3);
  color: #333;
}

.insight-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 20px;
  margin: 0 auto;
  gap: 10px;
}

.insight-content {
  flex: 1;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  padding: 20px;
  line-height: 1.6;
  position: relative;
}

.insight-content h1 {
  color: #004976;
  font-size: 1.5em;
  margin-top: 5px;
  margin-bottom: 10px;
  line-height: 1.25;
}

.insight-meta {
  color: #666;
  font-size: 0.9em;
  margin-bottom: 10px;
}

/* === SLIDE HANDLING === */
.slide {
  visibility: hidden;
  position: absolute;
  width: 100%;
  object-fit: cover;
}
.slide.active {
  visibility: visible;
  position: relative;
  object-fit: cover;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === SLIDE NAVIGATION === */
.slide-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
}
.slide-nav button {
  background-color: #00497655;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  width: 40px;
}
.slide-nav button:hover {
  background-color: #004976;
}
.slide-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === SIDEBAR === */
.insight-sidebar {
  width: 25%;
  background-color: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  height: fit-content;
  position: sticky;
  top: 100px;
}
.insight-sidebar h3 {
  color: #004976;
  font-size: 1.2em;
  margin-bottom: 1em;
}
.insight-sidebar ul {
  list-style: none;
  padding: 0;
}
.insight-sidebar li {
  margin-bottom: 0.5em;
}
.insight-sidebar a {
  text-decoration: none;
  color: #0077be;
}

/* === Pagination and Other Buttons === */

.page-btn {
  border: 1px solid #ccc;
  background: #f8f8f8;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95em;
  transition: background 0.2s;
  margin: 2px;
}
.page-btn:hover:not(:disabled) { background: #004976; color: #fff; }
.page-btn.active {
  background: #004976;
  color: #fff;
  font-weight: bold;
}
.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === RESPONSIVE TUNING (≤900px) === */
@media (max-width: 900px) {
  .insight-container {
    flex-direction: column;
  }
  .insight-sidebar {
    margin-top: 5px;    
    width: 100%;
    order: 2;
  }
  
  .grid-layout, [data-grid] {
    grid-template-columns: 1fr !important;
    grid-auto-rows: auto;
    padding-right: 0px;
  }
}

/* === MOBILE OPTIMIZATION (≤768px) === */
@media (max-width: 768px) {
  /* Responsive: collapse to single column on small screens */
  .grid-layout { 
    grid-template-columns: 1fr !important; 
    grid-auto-rows: auto;
    padding-right: 0px !important;
    margin-right: 0px !important;
    column-gap: 0px;
    margin-right: 0px;
  }
  
  .grid-layout.grid-cols-50-50,
  .grid-layout.grid-cols-35-65,
  .grid-layout.grid-cols-65-35
  {
    width: 100%;
  }
  
  .grid-layout h3 {
    color: #004976;
    font-size: 1.4em;
    margin-top: 5px;
    margin-bottom: 10px;
  }
  
   /* === Code Cells on Mobile === */
  .grid-cell {
    font-size: 0.85em;
    margin: 0px !important;
    width: 100% !important;
    overflow-x: auto;
    padding: 8px !important; /* bottom padding to make room for controls */
    border-radius: 8px;
    overflow: auto;
    position: relative;
    white-space: pre-wrap;
    word-break: break-word;
  }
  
  .grid-cell pre {
    white-space: pre-wrap;
    word-break: break-word;
  }

  .section {
    padding: 0px !important;
    margin: 8px !important;
    border-radius: 8px;
  }
  .container {
    padding: 0px !important;
    border-radius: 8px !important;
  }
  
  .insight-container {
    display: flow-root;
    position: relative;
    z-index: 1;
    padding: 5px;
  }

  .insights-layout {
    gap: 5px;
    padding: 2px;
  }

  .insight-content {
    padding: 8px;
  }
  
  .insight-content h1 {
    font-size: 1.4em;
    line-height: 1;
  }

  .insight-main {
    padding: 5px;
  }

  .insight-sidebar {
    padding: 10px;
  }

  .insight-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 10px;
  }

  .insight-item {
    padding: 5px;
  }
  
  .slide h2 {
    font-size: 1.6em;
    line-height: 1.1;
  }

  /* === Tabs === */
  .tab {
    margin-bottom: 10px;
  }
  .tab button {
    padding: 10px 5px;
    font-size: 14px;
    margin-right: 4px;
    width: 80px;
  }
  
  .button-container { 
    right: 8px; 
    bottom: 8px; 
  }

  /* === Search Form === */
  .search-form {
    gap: 5px;
  }
  
  .search-form input {
    padding: 6px;
    font-size: 0.95em;
  }
  
  .search-form button {
    padding: 6px 10px;
    font-size: 0.95em;
  }

}
