/* layouts/dashboard-layout.css */

/* ======= BASE STYLES & LAYOUT ======= */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background-color: var(--light-bg, var(--myceo-surface-1));
  color: var(--myceo-text-primary);
  min-height: 100vh;
}

/* Ensure the app wrapper takes full height */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
}

/* Ensure sidebar is always visible and fixed */
.sidebar {
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
  width: 210px !important;
  height: 100vh !important;
  background: var(--myceo-surface-2) !important;
  z-index: 1000 !important;
  overflow-y: auto !important;
  display: block !important;
  visibility: visible !important;
}

/* Main content wrapper should account for fixed sidebar */
.main-content-wrapper {
  margin-left: 210px !important;
  flex: 1;
  width: calc(100% - 210px) !important;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--myceo-surface-1);
}

/* Ensure content container fills available space */
.content-container {
  flex: 1;
  padding: 0;
  background: var(--myceo-surface-1);
}

/* Main content area */
.main-content {
  padding: 20px;
  min-height: calc(100vh - 140px); /* Account for header and footer */
}

/* Dashboard container */
.dashboard-container {
  padding: 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

/* Dashboard header */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.dashboard-header h1 {
  color: var(--primary-color, var(--myceo-accent-blue));
  margin: 0;
  font-size: 1.8rem;
}

/* Dashboard charts layout - full width for all charts */
.dashboard-charts {
  display: grid;
  grid-template-columns: 1fr; /* Always full width single column */
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  width: 100%;
}

/* Class for when we want to explicitly show multiple charts in a row */
.dashboard-charts.multi-column {
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}

/* Chart container base styles */
.chart-container {
  width: 100%;
  height: auto;
  min-height: 300px;
  position: relative;
  margin-bottom: 1.5rem;
  background-color: var(--myceo-surface-1);
  border-radius: 8px;
  box-shadow: var(--card-shadow, 0 2px 4px rgba(0,0,0,0.1));
  padding: 1.5rem;
  box-sizing: border-box;
}

.chart-container .chart-placeholder {
  width: 100%;
  height: 100%;
  min-height: 250px;
}

/* Chart container specifically for the first row of charts */
.dashboard-charts.full-width-charts .chart-container {
  width: 100%;
}

/* Loading spinner */
.loading-spinner {
  border: 3px solid var(--myceo-border-mid);
  border-top: 3px solid var(--myceo-accent-blue);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  display: inline-block;
}

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

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  justify-content: flex-end;
}

/* ======= MOBILE NAV (VERITAS-102) ======= */
/* Hamburger — hidden on desktop, shown ≤768px where the sidebar
   slides off-canvas. Toggles .sidebar.mobile-open via main.js. */
#mobile-nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  margin-right: 4px;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
}
#mobile-nav-toggle:active { background: rgba(10, 36, 87, 0.08); }
#mobile-nav-toggle .mnt-bar {
  display: block;
  width: 100%;
  height: 2.5px;
  border-radius: 2px;
  /* These bars are the ICON's strokes, not a surface. They are drawn with
     background-color because that is how a CSS hamburger works, which fooled
     the theme conversion into treating them as a panel and painting them
     near-black on a near-black header - technically themed, practically
     invisible. Marks wear ink colours. */
  background: var(--myceo-text-primary);
  transition: transform 0.25s ease, opacity 0.2s ease;
}
/* Morph to an X while the nav is open */
#mobile-nav-toggle.open .mnt-bar:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
#mobile-nav-toggle.open .mnt-bar:nth-child(2) { opacity: 0; }
#mobile-nav-toggle.open .mnt-bar:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

/* Scrim behind the open sidebar */
#sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(6, 15, 34, 0.5);
  z-index: 999; /* under .sidebar (1000) */
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ======= RESPONSIVE DESIGN ======= */
@media (max-width: 992px) {
  .dashboard-charts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  /* Mobile: Hide sidebar by default */
  .sidebar {
    width: 240px !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  }

  #mobile-nav-toggle { display: flex; }
  #sidebar-scrim.open { display: block; opacity: 1; }

  /* Don't scroll the page behind an open nav */
  body.nav-open { overflow: hidden; }

  .main-content-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Header: hamburger · title (truncates) · year toggle · user chip */
  header {
    gap: 0.5rem;
    padding: 0 0.75rem;
  }
  .header-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metric-card {
    padding: 1rem;
  }

  .chart-container, .orders-table-container {
    padding: 1rem;
  }

  /* Dashboard page header: title stacks above the filter controls */
  .dashboard-header {
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .dashboard-header h1 {
    font-size: 1.4rem;
  }

  /* Explicit multi-column chart rows: minmax(400px, 1fr) can't fit a
     phone column — collapse to one */
  .dashboard-charts.multi-column {
    grid-template-columns: 1fr;
  }

  /* Reclaim horizontal space on small screens */
  .main-content {
    padding: 12px;
  }
  .dashboard-container {
    padding: 0.85rem;
  }
}

@media (max-width: 520px) {
  .user-profile > div:not(.user-avatar) { display: none; }
}

/* ======= COHORT HEATMAP SPECIFIC STYLES ======= */
.chart-container.full-width {
  width: 100%;
  height: auto;
  min-height: 500px;
  max-height: calc(100vh - 200px);
  position: relative;
  overflow: hidden;
  margin-bottom: 30px;
}

.chart-container.full-width .chart-placeholder {
  width: 100%;
  height: auto;
  min-height: 450px;
  max-height: calc(100vh - 220px);
  position: relative;
  overflow: auto;
}

/* Style the cohort heatmap table */
.cohort-heatmap {
  width: auto;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 0.9rem;
  margin-top: 1px;
}

.cohort-heatmap th,
.cohort-heatmap td {
  padding: 8px;
  white-space: nowrap;
  min-width: 80px;
  width: 80px;
  position: relative;
  text-align: center;
}

.cohort-heatmap th {
  position: sticky;
  top: 0;
  background-color: var(--myceo-surface-1);
  z-index: 10;
  font-weight: bold;
  box-shadow: 0 2px 3px rgba(0,0,0,0.1);
}

.cohort-heatmap th:first-child {
  position: sticky;
  left: 0;
  z-index: 20;
  box-shadow: 2px 0 3px rgba(0,0,0,0.1);
}

.cohort-heatmap td:first-child {
  position: sticky;
  left: 0;
  background-color: var(--myceo-surface-1);
  z-index: 5;
  font-weight: bold;
  text-align: center;
  box-shadow: 2px 0 3px rgba(0,0,0,0.1);
}

/* Ensure scrollable container takes full width */
.cohort-heatmap-container,
.chart-container.full-width .chart-placeholder > div {
  width: 100%;
  max-width: 100%;
}

/* Add custom scrollbar styles for better visibility */
.chart-container.full-width .chart-placeholder::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.chart-container.full-width .chart-placeholder::-webkit-scrollbar-track {
  background: var(--myceo-surface-1);
  border-radius: 5px;
}

.chart-container.full-width .chart-placeholder::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 5px;
}

.chart-container.full-width .chart-placeholder::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Empty cells in cohort table */
.cohort-heatmap td:empty {
  border: none;
  background-color: transparent;
}

/* ======= SANKEY DIAGRAM SPECIFIC STYLES ======= */
.sankey-dashboard {
  position: relative !important;
  overflow: visible !important;
}

.sankey-dashboard .chart-container,
.sankey-dashboard .chart-container.full-width {
  height: auto !important;
  min-height: 600px !important;
  max-height: none !important; 
  overflow: visible !important;
  position: relative !important;
}

.sankey-dashboard .chart-placeholder,
.sankey-dashboard #chart {
  height: auto !important;
  min-height: 600px !important;
  overflow: visible !important;
  position: relative !important;
}

/* Configuration panel for Sankey */
.sankey-dashboard #configPanel {
  position: absolute !important;
  top: 60px !important;
  right: 20px !important;
  background-color: var(--myceo-surface-1) !important;
  border: 1px solid var(--myceo-border-mid) !important;
  border-radius: 5px !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
  padding: 15px !important;
  z-index: 1000 !important;
  width: 350px !important;
  max-width: 90% !important;
  margin-bottom: 0 !important;
}

.sankey-dashboard .dashboard-charts {
  display: block !important; 
  grid-template-columns: none !important;
}

.sankey-dashboard svg,
.sankey-dashboard .node rect,
.sankey-dashboard .link path {
  overflow: visible !important;
  clip-path: none !important;
}

.sankey-dashboard .chart-header,
.sankey-dashboard .chart-controls {
  position: relative !important;
  z-index: 50 !important;
}

.sankey-dashboard .custom-dropdown {
  position: relative !important;
  z-index: 100 !important;
}

.sankey-dashboard #labelDropdownContent {
  z-index: 1001 !important;
}

/* ======= COHORT ANALYSIS SPECIFIC STYLES ======= */
.cohort-dashboard {
  position: relative !important;
  overflow: visible !important;
}

.cohort-dashboard .chart-container,
.cohort-dashboard .chart-container.full-width {
  height: auto !important;
  min-height: 600px !important;
  max-height: none !important; 
  overflow: visible !important;
  position: relative !important;
  width: 100% !important;
}

.cohort-dashboard .chart-placeholder,
.cohort-dashboard #cohort-retention-chart {
  height: auto !important;
  min-height: 600px !important;
  overflow: visible !important;
  position: relative !important;
  width: 100% !important;
}

.cohort-dashboard .dashboard-charts {
  display: block !important; 
  grid-template-columns: none !important;
  width: 100% !important;
}

.cohort-dashboard .cohort-heatmap th,
.cohort-dashboard .cohort-heatmap td:first-child {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  z-index: 1 !important;
  box-shadow: none !important;
}

.cohort-dashboard .cohort-heatmap {
  width: 100% !important;
  table-layout: fixed !important;
  border-collapse: separate !important;
  border-spacing: 2px !important;
  margin: 0 auto !important;
}

.cohort-dashboard .cohort-heatmap-container {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: auto !important;
  padding: 0 !important;
}

.cohort-dashboard .chart-container.full-width .chart-placeholder {
  overflow: auto !important;
  max-width: 100% !important;
}

.cohort-dashboard .chart-header,
.cohort-dashboard .chart-controls {
  position: relative !important;
  z-index: 50 !important;
}

.cohort-dashboard .cohort-period-filter {
  z-index: 100 !important;
  position: relative !important;
}