:root{
  --sidebar-width: 220px;
  --sidebar-bg: #003964;
  --accent: #007BFF;
  --muted: #666;
  --max-content-width: 1100px;
  --gap: 16px;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: #222;
  background: #fff;
  overflow: hidden; /* Prevent body scroll */
}

.layout {
  display: flex;
  height: 100vh; /* Full viewport height */
  gap: var(--gap);
  overflow: hidden; /* Prevent layout scroll */
}

/* Sidebar */
nav.sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  padding: 20px;
  box-sizing: border-box;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  overflow-y: auto; /* Enable sidebar scrolling */
  height: 100vh; /* Full height */
  display: flex;
  flex-direction: column;
}


nav.sidebar p {
  margin: 0 0 12px 0;
  font-size: 14px;
  word-break: break-all;
  color: #AEC0CE;
}

nav.sidebar h2 {
  margin: 0 0 12px 0;
  font-size: 18px;
  color: #AEC0CE;
}

nav.sidebar h2.myrustic-sidebar-title {
  color: #FFFFFF;
}

nav.sidebar .section {
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 6px;
  margin-top: 6px;
}

nav.sidebar .section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

nav.sidebar .section:nth-of-type(2) {
  margin-top: 0;
  padding-top: 0;
}

nav.sidebar .section:nth-of-type(3) {
  margin-top: 0;
  padding-top: 0;
}

nav.sidebar .section-title {
  margin-top: 9px; /* Reduced by half from 18px */
  margin-bottom: 0; /* No bottom margin - spacing handled by sub-subheader */
  font-size: 12px;
  text-transform: uppercase;
  color: #AEC0CE;
  letter-spacing: 0.6px;
  padding-left: 0; /* Align with MyPortal */
}
nav.sidebar .section > a:first-of-type {
  display: block;
  margin-bottom: 0; /* Remove default margin from <a> tag wrapping section-title */
}

nav.sidebar .subheader { 
    margin-top: 2px; /* Further reduced spacing */
    margin-bottom: 2px; /* Further reduced spacing */
    margin-left: 12px; /* Slight indent from section */
    font-weight: 600; 
    font-size: 12px; 
    color: #AEC0CE; 
    text-transform: uppercase; 
}
nav.sidebar a .subheader {
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    margin-top: 1px; /* Further reduced spacing */
    margin-bottom: 1px; /* Further reduced spacing */
}
nav.sidebar a .subheader:first-of-type {
    margin-top: 2px; /* First subheader keeps reduced spacing */
}
nav.sidebar a .subheader:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #AEC0CE;
}
nav.sidebar .sub-subheader { 
    margin-top: 8px; 
    margin-left: 24px; /* Indent from sub-section */
    margin-bottom: 4px;
    font-weight: 500; 
    font-size: 11px; 
    color: #AEC0CE; 
    text-transform: uppercase; 
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
}
/* First sub-subheader after section-title - ensure consistent 2px spacing */
/* Cosmos: <a> wrapping section-title, then <a class="sub-subheader"> */
/* Logos/Providence: <div class="section-title">, then <a class="sub-subheader"> */
/* Use a consistent approach: set margin-top to 2px for first sub-subheader after any section-title */
nav.sidebar .section > a:first-of-type + a.sub-subheader,
nav.sidebar .section > .section-title + a.sub-subheader {
    margin-top: 2px !important; /* Consistent 2px spacing - override default 8px */
}
/* Ensure consistent spacing between all sub-subheaders (all should have same 8px spacing) */
nav.sidebar .section a.sub-subheader + a.sub-subheader {
    margin-top: 8px !important; /* Consistent spacing between all sub-subheaders */
}
nav.sidebar .sub-subheader:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #AEC0CE;
}
nav.sidebar a.sub-subheader {
    text-decoration: none;
    display: block;
}

/* Hide post-trip section on all devices */
nav.sidebar .post-trip-section {
    display: none !important;
}

nav.sidebar a,
nav.sidebar .placeholder {
  display: block;
  margin-bottom: 8px;
  text-decoration: none;
  color: #AEC0CE;
  padding: 6px 8px;
  border-radius: 4px;
}

nav.sidebar a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #AEC0CE;
}

nav.sidebar a.active {
  background: var(--accent);
  color: #FFFFFF;
}

nav.sidebar .placeholder {
  color: #AEC0CE;
  padding-left: 6px;
  font-style: italic;
}

/* Main content */
main.content {
  flex: 1;
  padding: 8px;
  box-sizing: border-box;
  max-width: none;
  margin: 0;
  width: calc(100% - var(--sidebar-width));
  overflow-y: auto; /* Enable main content scrolling */
  height: 100vh; /* Full height */
}

/* Cosmos page standard styling */
.cosmos-body-header {
  font-size: 16px;
  font-weight: bold;
  border-bottom: 1px solid #ddd;
  margin-bottom: 8px;
  padding-bottom: 2px;
  width: 100%;
  grid-column: 1 / -1; /* Span all columns - exempt from column distribution */
}

.cosmos-body-content {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  width: 100%;
  grid-auto-flow: row; /* Allow headers to span columns */
  max-width: 100%; /* Ensure grid doesn't exceed container */
}

.cosmos-body-column {
  min-width: 0; /* Allow content to wrap */
  word-wrap: break-word;
  overflow-wrap: break-word;
  width: 100%; /* Ensure columns fill their allocated space */
  box-sizing: border-box; /* Include padding in width calculation */
}

.cosmos-body-column .layout-section {
  margin-bottom: 16px;
}

.cosmos-related-body {
  grid-column: 1 / -1; /* Span all 4 columns */
  margin-top: 24px;
}

.cosmos-related-body h2 {
  font-size: 16px;
  font-weight: bold;
  border-bottom: 1px solid #ddd;
  margin-bottom: 8px;
  padding-bottom: 2px;
}

/* simple table styles for search results */
table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 12px;
}
table th, table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}
table th {
  background: #fafafa;
  font-weight: 600;
}

/* flash messages */
.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.flash.info { background: #e7f3ff; color: #045; border: 1px solid #cfe8ff; }
.flash.success { background: #e6ffef; color: #064; border: 1px solid #c8f2d6; }
.flash.warn { background: #fff8e6; color: #6a4a00; border: 1px solid #ffeebc; }
.flash.error { background: #ffecec; color: #6a0000; border: 1px solid #ffd6d6; }

/* Mobile menu header */
.mobile-menu-header {
  display: none; /* Hidden on desktop */
}

.mobile-menu-title {
  margin: 0;
  font-size: 18px;
}

.mobile-menu-toggle {
  display: none; /* Hidden on desktop */
  background: none !important;
  border: none !important;
  padding: 8px;
  cursor: pointer;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  transition: opacity 0.2s;
  color: #222 !important;
}

.mobile-menu-toggle:hover {
  opacity: 0.7;
}

.mobile-menu-toggle .hamburger-icon {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 24px;
}

.mobile-menu-toggle .hamburger-icon span {
  display: block;
  height: 2px;
  width: 100%;
  background-color: #222;
  border-radius: 2px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon span:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

/* responsive: collapse sidebar under 720px */
@media (max-width: 720px) {
  html, body {
    overflow: auto; /* Allow scrolling on mobile */
  }
  .layout { 
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible; /* Allow sticky to work */
  }
  
  /* Show mobile menu header */
  .mobile-menu-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: #fff;
    border-bottom: 1px solid #e6e6e6;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* Show mobile menu toggle button */
  .mobile-menu-toggle {
    display: flex !important;
    background: none !important;
    border: none !important;
    color: #222 !important;
    order: 2; /* Ensure button is on the right */
  }
  
  .mobile-menu-title {
    order: 1; /* Ensure title is on the left */
    margin: 0;
    font-size: 18px;
    color: #222;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .mobile-menu-title .page-title {
    font-weight: 400;
    color: #666;
  }
  
  .mobile-menu-title .page-title::before {
    content: "|";
    margin-right: 8px;
    color: #ccc;
  }
  
  /* Hide page headers on mobile for MyRustic pages */
  .page-header,
  .invoice-header {
    display: none !important;
  }
  
  /* Hide desktop sidebar on mobile */
  nav.sidebar:not(.mobile-menu) {
    display: none;
  }
  
  /* Sidebar collapsed by default on mobile */
  nav.sidebar.mobile-menu {
    width: 100% !important;
    border-right: none !important;
    height: 0 !important;
    max-height: 0 !important;
    overflow: hidden !important;
    padding: 0 20px !important;
    margin: 0 !important;
    position: fixed !important;
    top: 60px !important; /* Below fixed header */
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 999 !important;
    background-color: #fff !important;
    flex-shrink: 1 !important;
    border: none !important;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    display: flex !important;
    flex-direction: column !important;
  }
  
  /* Sidebar expanded state on mobile */
  nav.sidebar.mobile-menu.expanded {
    height: calc(100vh - 60px) !important; /* Full height minus header */
    max-height: calc(100vh - 60px) !important;
    overflow-y: auto !important; /* Allow scrolling within menu */
    padding: 20px !important;
    margin: 0 !important;
    position: fixed !important;
    top: 60px !important; /* Below fixed header */
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 999 !important;
    background-color: #fff !important;
    flex-shrink: 1 !important;
    border: none !important;
    transition: max-height 0.3s ease-in, padding 0.3s ease-in;
    display: flex !important;
    flex-direction: column !important;
  }
  
  /* Make menu font black on mobile */
  nav.sidebar.mobile-menu p,
  nav.sidebar.mobile-menu h2,
  nav.sidebar.mobile-menu .section-title,
  nav.sidebar.mobile-menu .subheader,
  nav.sidebar.mobile-menu .sub-subheader,
  nav.sidebar.mobile-menu a {
    color: #000 !important;
  }
  
  nav.sidebar.mobile-menu a:hover {
    color: #000 !important;
  }
  
  nav.sidebar.mobile-menu .subheader:hover,
  nav.sidebar.mobile-menu .sub-subheader:hover {
    color: #000 !important;
  }
  
  /* Hide post-trip section on mobile */
  nav.sidebar.mobile-menu .post-trip-section {
    display: none !important;
  }
  
  /* Prevent body scroll when menu is open */
  body.menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
  }
  
  main.content {
    width: 100%;
    margin-top: 60px; /* Account for fixed header height */
    padding: 16px;
    height: auto;
    overflow-y: visible;
  }
}
