/* =============================================
   ANALYTICS PAGE STYLES
   ============================================= */

/* =============================================
   SECTION: Selectize & Filters
   ============================================= */

.selectize-input {
  max-height: 150px !important;
  overflow-y: auto !important;
}

/* Optimized filter columns - no fixed height to prevent space */
.filters-box-content .col-md-3 {
  padding-top: 2px;
  padding-bottom: 2px;
}

/* Fixed height for selectize wrapper */
.filters-box-content .form-group {
  margin-bottom: 0;
}

.filters-box-content .selectize-control {
  min-height: 38px;
  max-height: 75px;
}

.filters-box-content .selectize-input {
  min-height: 36px;
  max-height: 75px !important;
  padding: 4px 8px;
  overflow-y: auto !important;
}

/* Fixed height for dropdown */
.selectize-dropdown {
  max-height: 250px;
  overflow-y: auto;
  z-index: 1050;
}

/* Compact filter header */
.filters-box-content .filter-header {
  margin-bottom: 2px;
}

/* Smooth selectize transitions */
.selectize-control {
  transition: opacity 0.15s ease;
}

.selectize-control.loading {
  opacity: 0.6;
}

/* Filter row spacing */
.filters-box-content .row {
  margin-bottom: 0px;
}

.filters-box-content > .row {
  margin-bottom: 3px;
}

/* =============================================
   SECTION: bslib Card Styles
   ============================================= */

.card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid #e2e8f0;
  margin-bottom: 20px;
}

.card-header {
  background-color: #ef6c00;
  color: white;
  font-weight: 600;
  font-size: 16px;
  padding: 12px 16px;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.card-body {
  padding: 20px;
}

/* =============================================
   SECTION: Analytics Table Styles
   ============================================= */

.analytics-table {
  font-size: 0.9375rem;
  border: 1px solid hsl(213, 33%, 93%);
  border-radius: 4px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1);
}

.analytics-table .header {
  background-color: hsl(213, 45%, 97%);
  border-bottom-color: hsl(213, 33%, 93%);
  border-bottom-width: 1px;
  color: #2c3e50;
  font-weight: 700;
  font-size: 0.8125rem;
  padding: 6px 8px;
  line-height: 1.3;
}

.analytics-table .header[aria-sort]:hover,
.analytics-table .header[aria-sort]:focus {
  color: #FF8500;
}

.analytics-table .rt-td {
  border-bottom: 1px solid hsl(213, 33%, 93%);
  vertical-align: middle;
}

.analytics-table .rt-tr:hover {
  background-color: hsl(213, 20%, 99%);
}

/* Keep search bar visible when no results found */
.analytics-table .rt-noData {
  min-height: 60px;
}

/* Highlight found text */
.analytics-table mark {
  background-color: #fff3cd;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 500;
}

/* =============================================
   SECTION: Loading States & Spinners
   ============================================= */

/* Animation for collapse/expand */
#filters_container {
  transition: all 0.3s ease-in-out;
}

/* Loading spinner for charts and tables */
.loading-container {
  position: relative;
  min-height: 200px;
}

.chart-spinner,
.table-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #FF8500;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Overlay for loading state */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  border-radius: 4px;
}

.loading-overlay .spinner {
  width: 50px;
  height: 50px;
}

/* Shiny busy indicator — replaced by global progress bar */

/* echarts loading */
.echarts4r-loading {
  background: rgba(255, 255, 255, 0.9) !important;
}

/* Reactable recalculating — replaced by global progress bar */
.reactable.recalculating {
  opacity: 1 !important;
  pointer-events: none;
}

/* Smooth transition for outputs — replaced by global progress bar */

/* =============================================
   SECTION: Skeleton Loader
   ============================================= */

.skeleton-loader {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  gap: 15px;
}

.skeleton-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-line {
  height: 18px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }
.skeleton-line.long { width: 95%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* =============================================
   SECTION: Filter Summary Wrapper
   ============================================= */

.filter-summary-wrapper {
  position: relative;
  transition: all 0.3s ease;
}

/* Filter summary recalculating — replaced by global progress bar */

/* =============================================
   SECTION: Filters Loading Wrapper
   ============================================= */

.filters-loading-wrapper {
  position: relative;
  transition: all 0.3s ease;
}

.filters-loading-wrapper.is-loading .filters-content {
  filter: blur(2px);
  opacity: 0.6;
  pointer-events: none;
  transition: all 0.3s ease;
}

.filters-loading-wrapper .filters-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  display: none;
}

.filters-loading-wrapper.is-loading .filters-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.filters-loader-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(255, 133, 0, 0.2);
  border-top: 4px solid #FF8500;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.filters-loader-text {
  font-size: 13px;
  color: #FF8500;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.9);
  padding: 4px 12px;
  border-radius: 4px;
}

/* =============================================
   SECTION: Box Loading Wrapper (Universal)
   ============================================= */

.box-loading-wrapper {
  position: relative;
}

.box-loading-wrapper.is-loading {
  pointer-events: none;
}

.box-loading-wrapper.is-loading > *:not(.box-loader-overlay) {
  filter: blur(1px);
  opacity: 0.5;
  transition: all 0.3s ease;
}

.box-loader-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 4px;
}

.box-loading-wrapper.is-loading .box-loader-overlay {
  opacity: 1;
}

.box-loader-spinner {
  width: 45px;
  height: 45px;
  border: 4px solid rgba(255, 133, 0, 0.15);
  border-top: 4px solid #FF8500;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* =============================================
   SECTION: Stat Cards
   ============================================= */

.stat-card {
  background: white;
  padding: 0.85rem 1rem;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: box-shadow 0.2s ease;
  margin-bottom: 0.75rem;
  flex-grow: 0;
}

.stat-card-analytics {
  min-height: 120px;
  max-height: 120px;
  overflow: hidden;
}

/* Prevent Bootstrap columns from stretching stat cards */
[id$='stat_cards_content'] .row {
  align-items: flex-start !important;
}
[id$='stat_cards_content'] [class*='col-'] {
  display: block !important;
}

/* CSS Grid layout for stat cards */
.stat-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 0.75rem;
  align-items: stretch;
}

@media (max-width: 1400px) {
  .stat-cards-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 992px) {
  .stat-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 576px) {
  .stat-cards-grid {
    grid-template-columns: 1fr;
  }
}

.stat-cards-grid .stat-card {
  margin-bottom: 0;
}

.stat-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Dashboard variant - centered values, no info icon */
.stat-card-dashboard {
  justify-content: center;
  text-align: center;
}

.stat-card-dashboard .stat-card-value {
  text-align: center !important;
  max-width: 100% !important;
}

.stat-card .subheader {
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 0;
  line-height: 1.2;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.stat-card .h3 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #1a202c;
  margin: 0;
  line-height: 1.2;
}

/* Ensure info icon is always visible */
.stat-card-info-icon {
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.stat-card-info-icon:hover {
  opacity: 1;
}

/* =============================================
   SECTION: Filter Action Icons
   ============================================= */

.filter-action-icon {
  transition: all 0.2s ease;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.filter-action-icon:hover {
  transform: scale(1.15);
  filter: brightness(1.1);
}

.filter-action-icon:active {
  transform: scale(0.95);
}

/* Remove underline from action links */
a.action-link {
  text-decoration: none !important;
}

a.action-link:hover {
  text-decoration: none !important;
}

/* =============================================
   SECTION: Gender Distribution Chart
   ============================================= */

.gender-stat-chart-outer {
  display: flex;
  gap: 2rem;
  padding: 1.5rem;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.gender-stat-table-panel {
  flex: 1;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.gender-stat-table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 12px;
  margin-bottom: 6px;
}
.gender-stat-table-row:hover { background-color: #f8fafc; transform: translateX(2px); }
.gender-stat-table-row.active { background-color: #f1f5f9; font-weight: 600; }

.gender-table-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}
.gender-table-icon-i {
  font-size: 1.1rem;
  color: #fff;
}

.gender-stat-table-category-name {
  font-size: 0.95rem;
  color: #64748b;
  font-weight: 500;
  flex-grow: 1;
}
.gender-stat-table-row.active .gender-stat-table-category-name { color: #0f172a; }

.gender-stat-table-category-value {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  margin-left: 10px;
  font-variant-numeric: tabular-nums;
}

.gender-stat-chart-panel {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0 auto;
}

.gender-chart-root-block {
  position: relative;
  width: 180px;
  height: 180px;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.05));
}

.gender-chart-path-segment {
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 50% 50%;
  cursor: pointer;
  stroke: #fff;
  stroke-width: 3px;
}
.gender-chart-path-segment:hover { opacity: 0.9 !important; transform: scale(1.03); }

.gender-chart--icon-container {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 80px; height: 80px;
  border-radius: 50%;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.03);
  pointer-events: none;
}

.gender-center-icon-circle {
  width: 55px; height: 55px;
  border-radius: 50%;
  background-color: #ffff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.3s ease;
}

.gender-center-icon-i {
  font-size: 1.3rem !important;
  color: #2B3034 !important;
}

.gender-stat-slider-text-container { margin-top: 10px; text-align: center; }
.gender-pfm-category-title { font-size: 1rem; font-weight: 600; }

/* =============================================
   SECTION: Vulnerability Stats
   ============================================= */

.vuln-stats-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 0.75rem;
  padding: 1rem;
  min-height: 280px;
  height: 280px;
  box-sizing: border-box;
}

.vuln-stat-card {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: all 0.2s ease;
  border: 1px solid #f1f5f9;
  height: 100%;
  margin: 0;
}

.vuln-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.vuln-stat-icon-box {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.85rem;
  flex-shrink: 0;
}
.vuln-stat-icon-box i {
  font-size: 1.1rem;
  color: #fff;
}

.vuln-stat-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

.vuln-stat-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.vuln-stat-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: #1e293b;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.vuln-stat-percentage {
  font-size: 0.95rem;
  font-weight: 700;
  color: #FF8500;
  line-height: 1;
}

.vuln-stat-label {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 600;
  margin-top: 0.4rem;
  line-height: 1.2;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* =============================================
   SECTION: Budget Donut Charts
   ============================================= */

.budget-donut-wrapper {
  display: flex;
  gap: 1.5rem;
  padding: 1.2rem;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 16px;
  max-width: 580px;
  margin: 0 auto;
}

.budget-donut-table-panel {
  flex: 1;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 6px;
}

.budget-donut-table-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 10px;
  margin-bottom: 4px;
}
.budget-donut-table-row:hover { background-color: #f8fafc; transform: translateX(2px); }
.budget-donut-table-row.active { background-color: #f1f5f9; font-weight: 600; }

.budget-donut-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  flex-shrink: 0;
}
.budget-donut-icon-box i {
  font-size: 0.95rem;
  color: #fff;
}

.budget-donut-cat-name {
  font-size: 0.88rem;
  color: #64748b;
  font-weight: 500;
  flex-grow: 1;
}
.budget-donut-table-row.active .budget-donut-cat-name { color: #0f172a; }

.budget-donut-cat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}

.budget-donut-chart-panel {
  flex: 0 0 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  margin: 0 auto;
}

.budget-donut-svg-block {
  position: relative;
  width: 180px;
  height: 180px;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.05));
}

.budget-donut-segment {
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 50% 50%;
  cursor: pointer;
  stroke: #fff;
  stroke-width: 3px;
}
.budget-donut-segment:hover { opacity: 0.9 !important; transform: scale(1.03); }

.budget-donut-icon-container {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 80px; height: 80px;
  border-radius: 50%;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 15px rgba(0,0,0,0.03);
  pointer-events: none;
}

.budget-donut-icon-ring {
  width: 55px; height: 55px;
  border-radius: 50%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.3s ease;
}

.budget-donut-icon-i {
  font-size: 1.3rem !important;
  color: #2B3034 !important;
}

.budget-donut-text-block { margin-top: 10px; text-align: center; }
.budget-donut-center-name { font-size: 0.95rem; font-weight: 600; }

.budget-donut-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #334155;
  text-align: center;
  margin-bottom: 10px;
}

/* =============================================
   SECTION: Mobile Responsive
   ============================================= */

@media (max-width: 991px) {
  .gender-stat-chart-outer {
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
  }

  .gender-stat-table-panel {
    width: 100%;
  }

  .vuln-stats-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    height: auto;
    min-height: 0;
  }
  .vuln-stat-card {
    min-height: 120px;
  }

  .budget-donut-wrapper {
    flex-direction: column-reverse;
    align-items: center;
    gap: 1rem;
  }
  .budget-donut-table-panel { width: 100%; }
  .budget-donut-svg-block { width: 160px; height: 160px; }

  /* Accordion body — менше padding на мобільному */
  .accordion-body {
    padding: 0.75rem 0.5rem !important;
  }

  /* Card body — мінімальний padding для максимальної ширини графіків */
  .card .card-body {
    padding: 0.75rem 0.5rem !important;
  }

  /* Графіки echarts — повна ширина + overflow fix */
  .echarts4r,
  .echarts4r canvas,
  .html-widget,
  [id*="echarts"],
  .highchart,
  [id*="highchart"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Контейнери графіків — без overflow hidden */
  .shiny-html-output,
  .shiny-bound-output {
    overflow-x: visible !important;
    max-width: 100%;
  }

  /* Box loading wrapper — повна ширина */
  .box-loading-wrapper {
    width: 100%;
    overflow: hidden;
  }

  /* Таблиці reactable — горизонтальний скрол */
  .rt-table {
    overflow-x: auto !important;
  }
  .analytics-table {
    font-size: 13px !important;
    width: 100% !important;
  }

  /* Обгортка таблиці — скрол */
  .ReactTable {
    overflow-x: auto !important;
  }

  /* Кнопки експорту — менший розмір */
  .btn-excel-export {
    font-size: 13px !important;
    padding: 6px 12px !important;
  }

  /* Box headers — менший шрифт */
  .box-header-title {
    font-size: 18px !important;
  }

  /* Кнопка копіювання — не перекривати графік */
  .btn-copy-chart {
    position: relative !important;
    margin-top: 8px !important;
  }

  /* Колонки 50% → 100% на мобільному для графіків */
  .box-loading-wrapper .col-sm-6,
  .box-loading-wrapper .col-md-6 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  /* Stat cards: 3 колонки → 1 колонка */
  .box-loading-wrapper .col-md-4,
  .box-loading-wrapper .col-sm-4 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
}

@media (max-width: 576px) {
  .accordion-body {
    padding: 0.5rem 0.25rem !important;
  }

  .card .card-body {
    padding: 0.5rem 0.25rem !important;
  }

  .analytics-table {
    font-size: 12px !important;
  }

  .box-header-title {
    font-size: 16px !important;
  }

  /* Stat cards — компактніше */
  .stat-card {
    padding: 0.6rem 0.75rem !important;
  }
  .stat-card .h3 {
    font-size: 1.25rem !important;
  }
  .stat-card .subheader {
    font-size: 0.75rem !important;
  }
}
