/* =============================================================================
   Modern sidebar styling for dashboardr
   Mobile-ready with improved look and feel
   Uses !important to override Quarto dashboard defaults
============================================================================= */

/* -----------------------------------------------------------------------------
   CSS Custom Properties (Design Tokens)
----------------------------------------------------------------------------- */
:root {
  --sidebar-bg: #ffffff;
  --sidebar-border: rgba(0, 0, 0, 0.08);
  --sidebar-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --sidebar-text: #4a4a4a;
  --sidebar-heading: #1a1a2e;
  --sidebar-label: #333333;
  --sidebar-accent: #4361ee;
  --sidebar-transition: 0.25s ease;
  --sidebar-width: 280px;
  --sidebar-padding: 1.5rem;
  --sidebar-radius: 0;
}

/* -----------------------------------------------------------------------------
   Base Sidebar Container
----------------------------------------------------------------------------- */
.dashboard .sidebar,
.quarto-dashboard .sidebar,
.sidebar {
  background-color: var(--sidebar-bg) !important;
  background: var(--sidebar-bg) !important;
  padding: var(--sidebar-padding) !important;
  border-right: 1px solid var(--sidebar-border) !important;
  box-shadow: var(--sidebar-shadow) !important;
  transition: transform var(--sidebar-transition), 
              width var(--sidebar-transition),
              opacity var(--sidebar-transition) !important;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Right sidebar variant */
.sidebar[style*="right"] {
  border-right: none !important;
  border-left: 1px solid var(--sidebar-border) !important;
}

/* Override bslib/bootstrap sidebar backgrounds */
.bslib-sidebar-layout > .sidebar,
.bslib-sidebar-layout > .main-sidebar,
[data-bslib-sidebar-layout] > .sidebar {
  background-color: var(--sidebar-bg) !important;
  background: var(--sidebar-bg) !important;
}

/* -----------------------------------------------------------------------------
   Sidebar Header & Headings
----------------------------------------------------------------------------- */
.sidebar h3,
.sidebar .h3,
.dashboard .sidebar h3 {
  margin-top: 0 !important;
  margin-bottom: 1rem !important;
  font-weight: 600 !important;
  color: var(--sidebar-heading) !important;
  font-size: 1rem !important;
  letter-spacing: -0.01em;
}

.sidebar h4,
.sidebar .h4 {
  font-size: 0.9rem !important;
  font-weight: 600 !important;
  color: var(--sidebar-heading) !important;
  margin-top: 1rem !important;
  margin-bottom: 0.75rem !important;
}

/* -----------------------------------------------------------------------------
   Sidebar Dividers
----------------------------------------------------------------------------- */
.sidebar hr {
  border: none !important;
  border-top: 1px solid var(--sidebar-border) !important;
  margin: 1.25rem 0 !important;
  opacity: 1 !important;
}

/* -----------------------------------------------------------------------------
   Typography - Override Choices.js CDN styles to use dashboard theme font
----------------------------------------------------------------------------- */
.sidebar,
.sidebar *,
.sidebar input,
.sidebar select,
.sidebar label,
.sidebar button,
.sidebar .choices,
.sidebar .choices *,
.sidebar .choices__inner,
.sidebar .choices__list,
.sidebar .choices__item,
.sidebar .choices__placeholder,
.sidebar .choices__input,
.dashboardr-input-label,
.dashboardr-checkbox-label,
.dashboardr-radio-label,
.dashboardr-switch-label {
  font-family: inherit !important;
}

.sidebar p {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--sidebar-text);
  margin-bottom: 0.875rem;
}

.sidebar small,
.sidebar .text-muted {
  font-size: 0.8rem;
  color: #6c757d;
}

/* -----------------------------------------------------------------------------
   Labels
----------------------------------------------------------------------------- */
.sidebar label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--sidebar-heading);
  margin-bottom: 0.5rem;
  display: block;
}

/* -----------------------------------------------------------------------------
   Form Inputs & Controls
----------------------------------------------------------------------------- */
.sidebar .form-group,
.sidebar .input-group {
  margin-bottom: 1.25rem;
}

.sidebar .form-control,
.sidebar select,
.sidebar input[type="text"],
.sidebar input[type="number"] {
  border-radius: 6px;
  border: 1px solid #dee2e6;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sidebar .form-control:focus,
.sidebar select:focus,
.sidebar input:focus {
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
  outline: none;
}

/* -----------------------------------------------------------------------------
   Checkbox and Radio Styling
----------------------------------------------------------------------------- */
.sidebar .form-check {
  margin-bottom: 0.5rem;
  padding-left: 1.75rem;
  position: relative;
}

.sidebar .form-check-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: 0.1em;
  margin-left: -1.75rem;
  border: 2px solid #d1d5db;
  border-radius: 4px;
  background-color: #fff;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
}

.sidebar .form-check-input:hover {
  border-color: var(--sidebar-accent);
}

.sidebar .form-check-input:checked {
  background-color: var(--sidebar-accent);
  border-color: var(--sidebar-accent);
}

/* Custom checkmark */
.sidebar .form-check-input:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.sidebar .form-check-input[type="radio"] {
  border-radius: 50%;
}

/* Custom radio dot */
.sidebar .form-check-input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: white;
  border: none;
  transform: none;
}

.sidebar .form-check-input:focus {
  outline: none;
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

.sidebar .form-check-label {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: color 0.15s ease;
  line-height: 1.4;
}

.sidebar .form-check-label:hover {
  color: var(--sidebar-heading);
}

/* -----------------------------------------------------------------------------
   Checkbox/Radio Grid & Inline Layouts
----------------------------------------------------------------------------- */

/* Inline checkboxes (side by side, wrapping) */
.sidebar .form-check-inline {
  display: inline-flex;
  align-items: center;
  padding-left: 0;
  margin-right: 1rem;
  margin-bottom: 0.5rem;
}

.sidebar .form-check-inline .form-check-input {
  position: relative;
  margin-left: 0;
  margin-right: 0.5rem;
}

/* Checkbox group container - 2 column grid by default */
.sidebar .checkbox-group,
.sidebar .radio-group,
.sidebar .form-check-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.25rem 0.75rem;
}

.sidebar .checkbox-group .form-check,
.sidebar .radio-group .form-check,
.sidebar .form-check-group .form-check {
  margin-bottom: 0.375rem;
}

/* Single column variant */
.sidebar .checkbox-group.single-column,
.sidebar .radio-group.single-column,
.sidebar .form-check-group.single-column {
  grid-template-columns: 1fr;
}

/* Three column variant (for wider sidebars) */
.sidebar .checkbox-group.three-columns,
.sidebar .radio-group.three-columns {
  grid-template-columns: repeat(3, 1fr);
}

/* Compact inline variant (all in one row, wrap if needed) */
.sidebar .checkbox-group.inline,
.sidebar .radio-group.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.sidebar .checkbox-group.inline .form-check,
.sidebar .radio-group.inline .form-check {
  padding-left: 1.5rem;
  margin-bottom: 0;
}

.sidebar .checkbox-group.inline .form-check-input,
.sidebar .radio-group.inline .form-check-input {
  margin-left: -1.5rem;
}

/* Compact styling for grid layouts */
.sidebar .checkbox-group .form-check-label,
.sidebar .radio-group .form-check-label {
  font-size: 0.8rem;
  line-height: 1.3;
}

/* Auto-adjust to single column on narrow sidebars */
@container sidebar (max-width: 220px) {
  .sidebar .checkbox-group,
  .sidebar .radio-group {
    grid-template-columns: 1fr;
  }
}

/* -----------------------------------------------------------------------------
   Buttons
----------------------------------------------------------------------------- */
.sidebar .btn {
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  transition: all 0.2s ease;
}

.sidebar .btn-primary {
  background-color: var(--sidebar-accent);
  border-color: var(--sidebar-accent);
}

.sidebar .btn-primary:hover {
  background-color: #3651d4;
  border-color: #3651d4;
  transform: translateY(-1px);
}

/* -----------------------------------------------------------------------------
   Range Slider Styling
----------------------------------------------------------------------------- */
.sidebar input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  outline: none;
  margin: 0.75rem 0;
  cursor: pointer;
}

/* Track styling for different browsers */
.sidebar input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
}

.sidebar input[type="range"]::-moz-range-track {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  border: none;
}

/* Thumb (handle) styling */
.sidebar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--sidebar-accent);
  border-radius: 50%;
  cursor: pointer;
  margin-top: -6px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(67, 97, 238, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.sidebar input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--sidebar-accent);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(67, 97, 238, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

/* Hover and focus states */
.sidebar input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.1);
  box-shadow: 0 3px 8px rgba(67, 97, 238, 0.4);
}

.sidebar input[type="range"]:hover::-moz-range-thumb {
  transform: scale(1.1);
  box-shadow: 0 3px 8px rgba(67, 97, 238, 0.4);
}

.sidebar input[type="range"]:focus {
  outline: none;
}

.sidebar input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2), 0 2px 6px rgba(67, 97, 238, 0.3);
}

.sidebar input[type="range"]:focus::-moz-range-thumb {
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2), 0 2px 6px rgba(67, 97, 238, 0.3);
}

/* Active state */
.sidebar input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(0.95);
}

.sidebar input[type="range"]:active::-moz-range-thumb {
  transform: scale(0.95);
}

/* Slider value display (if present) */
.sidebar .slider-value,
.sidebar .range-value {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--sidebar-accent);
  margin-left: 0.5rem;
}

/* Slider container */
.sidebar .slider-container,
.sidebar .range-container {
  margin-bottom: 1rem;
}

/* Min/max labels */
.sidebar .slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #9ca3af;
  margin-top: 0.25rem;
}

/* -----------------------------------------------------------------------------
   Badges
----------------------------------------------------------------------------- */
.sidebar .badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.35em 0.65em;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

/* -----------------------------------------------------------------------------
   Callouts
----------------------------------------------------------------------------- */
.sidebar .callout {
  margin: 1rem 0 !important;
  font-size: 0.85rem !important;
  padding: 0.875rem !important;
  border-radius: 6px !important;
  border-left-width: 3px !important;
}

.sidebar .callout-note {
  background-color: #f0f4ff !important;
  border-color: var(--sidebar-accent) !important;
}

.sidebar .callout-tip {
  background-color: #f0fdf4 !important;
  border-color: #22c55e !important;
}

.sidebar .callout-warning {
  background-color: #fffbeb !important;
  border-color: #f59e0b !important;
}

/* -----------------------------------------------------------------------------
   Images
----------------------------------------------------------------------------- */
.sidebar img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

/* -----------------------------------------------------------------------------
   Sidebar Collapse Button
----------------------------------------------------------------------------- */
.sidebar-collapse-button {
  opacity: 0.5;
  transition: all 0.2s ease;
  background: transparent;
  border: none;
  padding: 0.25rem;
  border-radius: 4px;
}

.sidebar-collapse-button:hover {
  opacity: 1;
  background-color: rgba(0, 0, 0, 0.05);
}

/* -----------------------------------------------------------------------------
   Custom Scrollbar (webkit browsers)
----------------------------------------------------------------------------- */
.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.25);
}

/* Firefox scrollbar */
.sidebar {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

/* =============================================================================
   MOBILE RESPONSIVENESS
============================================================================= */

/* Tablet breakpoint */
@media (max-width: 991.98px) {
  .dashboard .sidebar,
  .quarto-dashboard .sidebar,
  .sidebar {
    padding: 1.25rem !important;
  }
  
  .sidebar h3,
  .sidebar .h3 {
    font-size: 0.95rem !important;
  }
  
  .sidebar label {
    font-size: 0.85rem;
  }
}

/* Mobile breakpoint */
@media (max-width: 767.98px) {
  :root {
    --sidebar-padding: 1rem;
  }
  
  /* Make sidebar full width on mobile */
  .dashboard .sidebar,
  .quarto-dashboard .sidebar,
  .sidebar {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    border-right: none !important;
    border-left: none !important;
    border-bottom: 1px solid var(--sidebar-border) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
    padding: var(--sidebar-padding) !important;
  }
  
  /* Right sidebar also gets bottom border on mobile */
  .sidebar[style*="right"] {
    border-top: 1px solid var(--sidebar-border) !important;
    border-bottom: none !important;
  }
  
  /* Adjust heading size */
  .sidebar h3,
  .sidebar .h3,
  .dashboard .sidebar h3 {
    font-size: 0.95rem !important;
    margin-bottom: 1rem !important;
    padding-bottom: 0.5rem;
  }
  
  /* Stack form elements better */
  .sidebar .form-group,
  .sidebar .input-group {
    margin-bottom: 1rem;
  }
  
  /* Larger touch targets for inputs */
  .sidebar .form-check {
    padding: 0.5rem 0 0.5rem 2rem;
    margin-bottom: 0.25rem;
  }
  
  .sidebar .form-check-input {
    width: 20px;
    height: 20px;
    margin-left: -2rem;
  }
  
  .sidebar .form-check-input:checked::after {
    left: 5px;
    top: 2px;
    width: 6px;
    height: 10px;
  }
  
  .sidebar .form-check-input[type="radio"]:checked::after {
    left: 4px;
    top: 4px;
    width: 8px;
    height: 8px;
  }
  
  .sidebar .form-check-label {
    font-size: 0.875rem;
  }
  
  /* Larger slider touch targets */
  .sidebar input[type="range"] {
    height: 8px;
  }
  
  .sidebar input[type="range"]::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -7px;
  }
  
  .sidebar input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }
  
  /* Larger button touch targets */
  .sidebar .btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
  }
  
  /* Adjust callouts */
  .sidebar .callout {
    padding: 0.75rem !important;
    font-size: 0.8rem !important;
    margin: 0.75rem 0 !important;
  }
  
  /* Compact dividers */
  .sidebar hr {
    margin: 1rem 0 !important;
  }
  
  /* Handle inline checkbox groups on mobile */
  .sidebar .form-check-inline {
    display: block;
    margin-right: 0;
  }
}

/* Small mobile breakpoint */
@media (max-width: 575.98px) {
  .sidebar {
    padding: 0.875rem !important;
  }
  
  .sidebar h3,
  .sidebar .h3 {
    font-size: 0.9rem !important;
  }
  
  .sidebar p {
    font-size: 0.8rem;
  }
  
  .sidebar label {
    font-size: 0.8rem;
  }
  
  .sidebar .form-check-label {
    font-size: 0.8rem;
  }
  
  .sidebar .form-control,
  .sidebar select,
  .sidebar input[type="text"],
  .sidebar input[type="number"] {
    font-size: 0.85rem;
    padding: 0.5rem 0.625rem;
  }
}

/* =============================================================================
   COLLAPSIBLE SIDEBAR SUPPORT (Mobile Toggle)
============================================================================= */

/* Mobile sidebar toggle button */
.sidebar-mobile-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1050;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: var(--sidebar-accent);
  color: white;
  border: none;
  box-shadow: 0 4px 12px rgba(67, 97, 238, 0.35);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  align-items: center;
  justify-content: center;
}

.sidebar-mobile-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(67, 97, 238, 0.45);
}

.sidebar-mobile-toggle:active {
  transform: scale(0.95);
}

.sidebar-mobile-toggle svg {
  width: 20px;
  height: 20px;
}

@media (max-width: 767.98px) {
  .sidebar-mobile-toggle {
    display: flex;
  }
}

/* =============================================================================
   DARK MODE SUPPORT (if Quarto dark theme is used)
============================================================================= */

@media (prefers-color-scheme: dark) {
  .quarto-dark .sidebar,
  [data-bs-theme="dark"] .sidebar {
    --sidebar-bg: #1a1a2e;
    --sidebar-border: rgba(255, 255, 255, 0.1);
    --sidebar-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    --sidebar-text: #b8b8c8;
    --sidebar-heading: #ffffff;
    --sidebar-label: #d0d0e0;
    --sidebar-accent: #6366f1;
  }
  
  .quarto-dark .sidebar .form-control,
  .quarto-dark .sidebar select,
  .quarto-dark .sidebar input,
  [data-bs-theme="dark"] .sidebar .form-control,
  [data-bs-theme="dark"] .sidebar select,
  [data-bs-theme="dark"] .sidebar input {
    background-color: #2a2a3e;
    border-color: #3a3a4e;
    color: #e0e0e8;
  }
  
  .quarto-dark .sidebar .form-check-input,
  [data-bs-theme="dark"] .sidebar .form-check-input {
    background-color: #2a2a3e;
    border-color: #4a4a5e;
  }
  
  .quarto-dark .sidebar .callout-note,
  [data-bs-theme="dark"] .sidebar .callout-note {
    background-color: rgba(99, 102, 241, 0.15) !important;
  }
  
  .quarto-dark .sidebar .callout-tip,
  [data-bs-theme="dark"] .sidebar .callout-tip {
    background-color: rgba(34, 197, 94, 0.15) !important;
  }
}

/* =============================================================================
   PRINT STYLES
============================================================================= */

@media print {
  .sidebar {
    display: none !important;
  }
  
  .sidebar-mobile-toggle {
    display: none !important;
  }
}
