/**
 * CircuitJS Documentation Styles
 * 
 * Common styles for CircuitJS documentation pages:
 * - Split-panel layout (CircuitJS iframe + content)
 * - Toast notifications
 * - Slider buttons
 * - Real-time data tables
 * - Mobile responsive layout
 * - Compact table formatting
 * 
 * Usage:
 * - Include in split-panel pages (money-first-principles.qmd)
 * - Include in embedded content pages (money-content.qmd)
 */

/* ============================================================================
   COMPACT TABLE FORMATTING
   ============================================================================ */

/* Compact table rows for all standard tables */
table {
  font-size: 0.85em;
}

table th, table td {
  padding: 0.2em 0.5em !important;
  line-height: 1.2;
}

/* ============================================================================
   SPLIT PANEL LAYOUT
   ============================================================================ */

/* Hide default Quarto footer and prevent body scroll for split pages */
.split-container ~ .page-footer,
.split-container ~ footer {
  display: none !important;
}

/* Main split container */
.split-container {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  height: calc(100vh - 60px); /* Account for navbar */
}

/* Left panel - CircuitJS iframe */
.split-left {
  flex: 0 0 60%;
  position: sticky;
  top: 0;
  height: 100%;
  min-width: 200px;
}

.split-left iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Draggable resizer between panels */
.split-resizer {
  flex: 0 0 8px;
  background: linear-gradient(180deg, #e0e0e0 0%, #f5f5f5 50%, #e0e0e0 100%);
  cursor: col-resize;
  position: relative;
  transition: background 0.2s;
}

.split-resizer:hover,
.split-resizer.dragging {
  background: linear-gradient(180deg, #667eea 0%, #764ba2 50%, #667eea 100%);
}

/* Grip indicator on resizer */
.split-resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 40px;
  background: repeating-linear-gradient(180deg, #999 0px, #999 2px, transparent 2px, transparent 6px);
  border-radius: 2px;
}

.split-resizer:hover::after,
.split-resizer.dragging::after {
  background: repeating-linear-gradient(180deg, white 0px, white 2px, transparent 2px, transparent 6px);
}

/* Overlay to prevent iframe capturing mouse during resize */
.resize-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  cursor: col-resize;
  display: none;
}

.resize-overlay.active {
  display: block;
}

/* Right panel - scrolling content */
.split-right {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px 40px 12px;
  min-width: 200px;
}

/* When split-right contains an iframe, remove padding */
.split-right:has(iframe) {
  padding: 0;
  overflow: hidden;
}

.split-right > iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Footer within split layout */
.split-footer {
  margin-top: 40px;
  padding: 20px 0;
  border-top: 1px solid #e0e0e0;
  font-size: 0.85em;
  color: #666;
  text-align: center;
}

/* Circuit section markers for scroll detection */
.circuit-section {
  scroll-margin-top: 100px;
}

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  pointer-events: none;
}

.toast {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  margin-bottom: 10px;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.hide {
  opacity: 0;
  transform: translateX(100%);
}

.toast-icon {
  width: 20px;
  height: 20px;
  animation: toast-spin 1s linear infinite;
}

.toast.success .toast-icon {
  animation: none;
}

.toast.error {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

@keyframes toast-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ============================================================================
   SLIDER BUTTONS
   ============================================================================ */

.slider-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  margin: 4px 8px 4px 0;
  font-size: 14px;
  font-weight: 500;
  color: white;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.slider-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
  background: linear-gradient(135deg, #5a6fd6 0%, #6a4190 100%);
  color: white;
  text-decoration: none;
}

.slider-toggle-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.slider-toggle-btn .btn-icon {
  font-size: 16px;
}

/* Secondary/outline variant */
.slider-toggle-btn.secondary {
  background: transparent;
  color: #667eea;
  border: 2px solid #667eea;
  box-shadow: none;
}

.slider-toggle-btn.secondary:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

/* Button container for grouping */
.slider-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

/* ============================================================================
   REAL-TIME DATA TABLES
   ============================================================================ */

.realtime-table {
  width: 100%;
  max-width: 350px;
  border-collapse: collapse;
  margin: 12px 0;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 12px;
  background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.realtime-table thead {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.realtime-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.realtime-table th:last-child {
  text-align: right;
}

.realtime-table tbody tr {
  border-bottom: 1px solid #e9ecef;
  transition: background 0.15s ease;
}

.realtime-table tbody tr:hover {
  background: rgba(102, 126, 234, 0.05);
}

.realtime-table tbody tr:last-child {
  border-bottom: none;
}

.realtime-table td {
  padding: 6px 12px;
}

.realtime-table .rt-label {
  font-weight: 500;
  color: #495057;
}

.realtime-table .rt-value {
  text-align: right;
  font-weight: 600;
  color: #667eea;
  font-variant-numeric: tabular-nums;
}

/* Animated value indicator */
.realtime-table .rt-value::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #28a745;
  border-radius: 50%;
  margin-right: 8px;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================================
   MOBILE RESPONSIVE - Vertical split layout
   ============================================================================ */

@media (max-width: 768px) {
  .split-container {
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  .split-left {
    flex: 0 0 60%;
    height: auto;
    width: 100%;
    min-height: 150px;
    overflow: hidden;
  }

  .split-resizer {
    flex: 0 0 8px;
    width: 100%;
    height: 8px;
    cursor: row-resize;
    background: linear-gradient(90deg, #e0e0e0 0%, #f5f5f5 50%, #e0e0e0 100%);
  }

  .split-resizer:hover,
  .split-resizer.dragging {
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
  }

  .split-resizer::after {
    width: 40px;
    height: 4px;
    background: repeating-linear-gradient(90deg, #999 0px, #999 2px, transparent 2px, transparent 6px);
  }

  .split-resizer:hover::after,
  .split-resizer.dragging::after {
    background: repeating-linear-gradient(90deg, white 0px, white 2px, transparent 2px, transparent 6px);
  }

  .split-right {
    flex: 1;
    padding: 10px;
    min-height: 200px;
  }

  .split-footer {
    display: none;
  }

  .resize-overlay {
    cursor: row-resize;
  }

  /* Toast adjustments for mobile */
  .toast-container {
    left: 20px;
    right: 20px;
  }

  .toast {
    transform: translateY(-100%);
  }

  .toast.show {
    transform: translateY(0);
  }

  .toast.hide {
    transform: translateY(-100%);
  }
}

/* ============================================================================
   EMBEDDED CONTENT OVERRIDES
   For money-content.html loaded in iframe
   ============================================================================ */

/* When this CSS is loaded in an embedded iframe, ensure scrolling works */
html.embedded-content,
html.embedded-content body {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  height: auto !important;
}

/* Hide navbar in embedded content */
.embedded-content .navbar {
  display: none !important;
}

.embedded-content #quarto-content {
  margin-top: 0 !important;
  padding-top: 20px !important;
}

/* ============================================================================
   FULL-PAGE SPLIT LAYOUT OVERRIDES
   For money-first-principles.html (top-level split page)
   ============================================================================ */

/* Full viewport layout - hide scrollbars and chrome */
.split-page-layout html,
.split-page-layout body {
  overflow: hidden !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Hide Quarto footer and navbar for split pages */
.split-page-layout .page-footer,
.split-page-layout footer,
.split-page-layout #quarto-footer,
.split-page-layout #quarto-header,
.split-page-layout .navbar,
.split-page-layout header.navbar {
  display: none !important;
}

/* Split container fills viewport */
.split-page-layout .split-container {
  height: 100vh !important;
  margin: 0 !important;
}

/* Remove content area margins/padding */
.split-page-layout #quarto-content,
.split-page-layout .quarto-container,
.split-page-layout main,
.split-page-layout .content {
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
}

/* ============================================================================
   FLOATING CONTROL BUTTONS & SLIDE-OUT PANEL
   ============================================================================ */

/* Container for floating buttons */
.floating-controls {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10001;
  display: flex;
  gap: 8px;
}

/* Shared floating button style */
.floating-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.floating-btn:hover {
  background: #667eea;
  color: white;
  transform: scale(1.05);
}

.floating-btn svg {
  width: 20px;
  height: 20px;
}

/* Fullscreen button specific */
.fullscreen-btn.is-fullscreen .expand-icon {
  display: none;
}

.fullscreen-btn.is-fullscreen .collapse-icon {
  display: block !important;
}

/* Legacy support for standalone menu button */
.menu-toggle-btn:not(.floating-btn) {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 10001;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.menu-toggle-btn:not(.floating-btn):hover {
  background: #667eea;
  color: white;
  transform: scale(1.05);
}

.menu-toggle-btn:not(.floating-btn) svg {
  width: 20px;
  height: 20px;
}

/* Slide-out menu panel */
.menu-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 220px;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  z-index: 10000;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  overflow-y: auto;
  padding: 50px 5px 15px;
}

.menu-panel.open {
  transform: translateX(0);
}

/* Overlay behind menu panel */
.menu-panel-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.menu-panel-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Menu panel content styling */
.menu-panel h3 {
  margin: 0 0 15px;
  font-size: 18px;
  color: #333;
}

.menu-panel a {
  display: block;
  padding: 10px 12px;
  margin: 4px 0;
  color: #555;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.2s;
}

.menu-panel a:hover {
  background: #f0f0f0;
  color: #667eea;
}

.menu-panel .menu-section {
  margin-bottom: 20px;
}

/* TOC list styling in menu panel */
.menu-panel .toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.menu-panel .toc-item {
  margin: 2px 0;
}

.menu-panel .toc-item a {
  padding: 8px 12px;
  font-size: 14px;
}

.menu-panel .toc-h1 a {
  font-weight: 600;
  color: #333;
}

.menu-panel .toc-h2 a {
  padding-left: 20px;
  font-size: 13px;
}

.menu-panel .toc-h3 a {
  padding-left: 32px;
  font-size: 12px;
  color: #777;
}

/* Quarto TOC styling when cloned */
.menu-panel #TOC,
.menu-panel .toc {
  border: none;
  background: transparent;
}

.menu-panel #TOC ul,
.menu-panel .toc ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.menu-panel #TOC li,
.menu-panel .toc li {
  margin: 2px 0;
}

.menu-panel #TOC a,
.menu-panel .toc a {
  display: block;
  padding: 8px 12px;
  color: #555;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.2s;
  font-size: 14px;
}

.menu-panel #TOC a:hover,
.menu-panel .toc a:hover {
  background: #f0f0f0;
  color: #667eea;
}

.menu-panel #TOC ul ul a,
.menu-panel .toc ul ul a {
  padding-left: 24px;
  font-size: 13px;
}

.menu-panel #TOC ul ul ul a,
.menu-panel .toc ul ul ul a {
  padding-left: 36px;
  font-size: 12px;
  color: #777;
}

/* Menu navigation links section */
.menu-panel .menu-nav-links {
  border-top: 1px solid #e0e0e0;
  padding-top: 15px;
  margin-top: 15px;
}

/* Hover trigger zone on right edge */
.menu-hover-trigger {
  position: fixed;
  top: 0;
  right: 0;
  width: 5px;
  height: 20vh;
  z-index: 9998;
  cursor: pointer;
}

.menu-hover-trigger::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 4px;
  height: 40px;
  background: rgba(102, 126, 234, 0.3);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.menu-hover-trigger:hover::after {
  opacity: 1;
}

/* Hide hover trigger when panel is open */
.menu-panel.open ~ .menu-hover-trigger,
.menu-panel-overlay.open ~ .menu-hover-trigger {
  display: none;
}
