/* ========== 1. ROOT VARIABLES (Налаштування теми) ========== */
:root {
  /* Tabler Orange Palette */
  --tblr-primary: #f76707;
  --tblr-primary-hover: #d65600;
  --tblr-primary-rgb: 247, 103, 7;

  /* Інтеграція з bslib/Bootstrap */
  --bs-primary: var(--tblr-primary);
  --bs-primary-rgb: var(--tblr-primary-rgb);
  --bs-body-font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Тіні для кнопок (Tabler style) */
  --btn-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --btn-shadow-hover: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* ========== 2. SIDEBAR (Стиль Tabler, логіка bslib) ========== */

/* Фон та рамка сайдбару */
.bslib-sidebar-layout>.sidebar {
  background-color: #ffffff;
  border-right: 1px solid #e6e7e9;
  padding: 1rem 0.5rem;
  transition: transform 0.2s cubic-bezier(2.4, 0, 0.2, 1) !important;
  will-change: transform;
  z-index: 1000;
}

/* Hamburger menu button */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 9px;
  z-index: 1100;
  background: var(--tblr-primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.2s ease;
}

.sidebar-toggle:hover {
  background: var(--tblr-primary-hover);
  transform: scale(1.05);
}

.sidebar-toggle i {
  font-size: 20px;
}

/* Кнопка закриття sidebar - за замовчуванням сховано (тільки для мобільних) */
.sidebar-close {
  display: none !important;
}

/* Мобільна адаптація sidebar - TABLER STYLE (зверху вниз) */
@media (max-width: 991px) {
  .sidebar-toggle {
    display: block;
  }

  .bslib-sidebar-layout>.sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: auto !important;
    height: auto !important;
    max-height: 70vh !important;
    width: 100% !important;
    overflow-y: auto;
    transform: translateY(-100%) !important;
    transition: transform 0.3s ease-in-out !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-right: none;
    border-bottom: 1px solid #e6e7e9;
    z-index: 1150 !important;
    /* Поверх бургер-кнопки */
  }

  .bslib-sidebar-layout>.sidebar.open {
    transform: translateY(0) !important;
  }


  /* Кнопка закриття sidebar (X) - тільки на мобільних */
  .sidebar-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid #e6e7e9;
    border-radius: 6px;
    color: #656d77;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    padding: 0;
    display: flex !important;
    /* Показуємо на мобільних */
    align-items: center;
    justify-content: center;
  }

  .sidebar-close:hover {
    background: #f3f5f7;
    border-color: var(--tblr-primary);
    color: var(--tblr-primary);
  }

  .sidebar-close i {
    font-size: 18px;
  }

  /* Додаємо padding зверху для sidebar content, щоб не перекривала кнопка */
  .bslib-sidebar-layout>.sidebar .sidebar-content {
    padding-top: 60px !important;
  }

  /* Overlay для закриття sidebar */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  .bslib-sidebar-layout>.main {
    margin-left: 0 !important;
  }

  /* Оптимізація ширини контенту на мобільних - збалансовано */
  .main-content {
    padding: 10px 10px 15px 10px !important;
    /* Комфортні відступи */
  }

  .card {
    margin-bottom: 1rem !important;
    /* Відступи між картками */
  }

  .main-content .row>[class*='col-'] {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  /* Комфортний padding в картках на мобільних */
  .card .card-body {
    padding: 1rem !important;
  }

  .card .card-header {
    padding: 1rem 1rem !important;
    font-size: 1.15rem !important;
  }

  /* Фікси для header на мобільних */

  /* Бургер меню - компактний розмір */
  .sidebar-toggle {
    width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    top: 8px !important;
    left: 10px !important;
    z-index: 1050 !important;
    /* Нижче ніж sidebar (1100), щоб не перекривало */
  }

  .sidebar-toggle i {
    font-size: 20px !important;
  }

  /* Кнопка зміни мови - компактна і видима */
  .lang-toggle-btn {
    min-width: 45px !important;
    height: 36px !important;
    padding: 6px 10px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    border: 2px solid #dee2e6 !important;
    background: #ffffff !important;
  }

  .lang-toggle-btn:hover {
    border-color: #f76707 !important;
    color: #f76707 !important;
  }

  /* Log out кнопка - фіксована висота */
  .auth-btn-logout,
  button[id*="logout"],
  button[class*="auth"] {
    height: 36px !important;
    padding: 6px 12px !important;
    font-size: 14px !important;
    line-height: 1.2 !important;
    white-space: nowrap !important;
  }

  /* Header logo - переконуємось що він правильного розміру */
  .bslib-page-sidebar>div>div>a img {
    height: 50px !important;
  }
}

/* Навігаційні посилання в сайдбарі */
.bslib-sidebar-layout .sidebar-content .nav-link {
  color: #656d77;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.3rem;
  border-radius: 8px;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  position: relative;
  white-space: nowrap;
}

/* Стан наведення (Hover) - легкий сірий */
.bslib-sidebar-layout .sidebar-content .nav-link:hover {
  background-color: #f3f5f7;
  color: #1d273b;
  transform: translateX(2px);
}

/* Активний стан (Active) - помаранчевий акцент */
.bslib-sidebar-layout .sidebar-content .nav-link.active {
  background-color: rgba(247, 103, 7, 0.12);
  color: var(--tblr-primary);
  font-weight: 600;
}

/* Іконки в меню */
.bslib-sidebar-layout .sidebar-content .nav-link i {
  margin-right: 0.75rem;
  font-size: 1.1em;
  opacity: 0.85;
  width: 10px;
  text-align: center;
  transition: opacity 0.15s;
}

.bslib-sidebar-layout .sidebar-content .nav-link.active i {
  opacity: 1;
}

/* Додаткова оптимізація анімації */
.bslib-sidebar-layout>.main {
  transition: margin-left 2.1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Додаткові стилі для sidebar transitioning */
.bslib-sidebar-layout>.sidebar.transitioning {
  transition-duration: 2.2s !important;
}

/* ========== APP LAYOUT (Flexbox для футера внизу) ========== */
html,
body {
  /* ВАЖЛИВО: height: 100% тут часто ламає min-height: 100vh у wrapper'а. 
     Ставимо auto або min-height */
  height: auto;
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  /* Прибирає горизонтальний скрол, якщо вилазить */
}

.app-wrapper {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  /* Додаємо position relative, щоб дочірні елементи знали межі */
  position: relative;
}

/* Виправляємо логіку розтягування */
.bslib-page-sidebar {
  /* flex: 1 0 auto змушує цей блок займати весь вільний простір.
     Це правильно для sticky footer, АЛЕ... */
  flex: 1 0 auto;
  width: 100%;

  /* ВАЖЛИВО: bslib часто ставить тут min-height: 100vh або height: 100%. 
     Ми маємо це скинути, щоб він слухався нашого wrapper'а */
  height: auto !important;
  min-height: auto !important;
}

.app-footer {
  /* Футер не повинен стискатись */
  flex-shrink: 0;
  /* margin-top: auto штовхає футер вниз, якщо контенту мало. 
     Якщо контенту багато - він просто йде слідом. */
  margin-top: auto;
  width: 100%;
  z-index: 10;
}

/* ========== MAIN CONTENT ========== */
.main-content {
  padding: 15px 20px 20px 20px;
  /* top right bottom left */
  transition: margin-left 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
  /* Забороняємо горизонтальну прокрутку */
  max-width: 100%;
}

/* ========== TABLER-STYLE CARDS ========== */
/* Стиль карток як у Tabler - чистий, мінімалістичний */
.bslib-card,
.card {
  margin-bottom: 1.5rem;
  border: 1px solid rgba(98, 105, 118, 0.16);
  border-radius: 8px;
  /* Легка тінь як у Tabler */
  box-shadow: rgba(98, 105, 118, 0.04) 0 0 4px 0;
  background: #ffffff;
  transition: box-shadow 0.2s ease-out;
}

/* Hover ефект для карток */
.bslib-card:hover,
.card:hover {
  box-shadow: rgba(98, 105, 118, 0.16) 0 2px 16px 0;
}

/* Заголовок картки - БЕЗ помаранчевого фону, тільки текст та лінія знизу */
.bslib-card .card-header,
.card .card-header {
  background: #ffffff;
  color: #1e293b;
  font-weight: 900;
  font-size: 1.25rem;
  /* Збільшено з 1rem до 1.25rem */
  padding: 1rem 1rem;
  /* Збільшено padding */
  border-bottom: 1px solid rgba(98, 105, 118, 0.16);
  border-radius: 8px 8px 0 0;
  letter-spacing: -0.01em;
}

/* Тіло картки - білий фон з правильним padding */
.bslib-card .card-body,
.card .card-body {
  padding: 0.25rem;
  background: #ffffff;
  border-radius: 0 0 8px 8px;
}

/* Якщо немає заголовка - округлення зверху */
.bslib-card>.card-body:first-child,
.card>.card-body:first-child {
  border-radius: 8px 8px 0 0;
}

/* Футер картки */
.bslib-card .card-footer,
.card .card-footer {
  padding: 1rem 1.25rem;
  background: #f8f9fa;
  border-top: 1px solid rgba(98, 105, 118, 0.16);
  border-radius: 0 0 8px 8px;
}

/* ========== TABLER-STYLE STAT CARDS ========== */

/* Stat card container - prevent scrolling and ensure proper spacing */
.stat-card {
  padding: 1.25rem;
  border-radius: 8px;
  /* ЛЕГКИЙ ГРАДІЄНТ - змініть тут кольори за потреби */
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  border: 1px solid rgba(98, 105, 118, 0.16);
  box-shadow: rgba(98, 105, 118, 0.08) 0 2px 8px 0;
  margin-bottom: 1rem;
  overflow: visible;
  transition: all 0.2s ease;
}

.stat-card:hover {
  box-shadow: rgba(98, 105, 118, 0.16) 0 4px 12px 0;
  transform: translateY(-2px);
}

/* Subheader - малий текст над великою цифрою */
.subheader {
  font-size: 0.8rem;
  /* Трохи збільшено */
  font-weight: 700;
  /* Жирніше */
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #d65600;
  /* Помаранчевий колір для теми */
  margin-bottom: 0.5rem;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Info icon в stat cards */
.stat-card-info-icon {
  transition: opacity 0.2s ease;
  opacity: 0.6;
}

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

.stat-card-info-icon i {
  transition: color 0.2s ease;
}

.stat-card-info-icon:hover i {
  color: #626976 !important;
}

/* Великі числа в stat картках */
.stat-card .h1,
.stat-card .h2,
.stat-card .h3 {
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  color: #1e293b;
}

.stat-card .h1 {
  font-size: 2.5rem;
}

.stat-card .h2 {
  font-size: 2rem;
}

.stat-card .h3 {
  font-size: 1.75rem;
}

/* Flexbox utilities для stat cards */
.d-flex {
  display: flex !important;
}

.align-items-baseline {
  align-items: baseline !important;
}

.align-items-center {
  align-items: center !important;
}

.justify-content-between {
  justify-content: space-between !important;
}

.me-2 {
  margin-right: 0.5rem !important;
}

.me-auto {
  margin-right: auto !important;
}

.lh-1 {
  line-height: 1 !important;
}

.d-inline-flex {
  display: inline-flex !important;
}

/* Color utilities для growth indicators */
.text-green {
  color: #2fb344 !important;
  font-weight: 600;
}

.text-red {
  color: #d63939 !important;
  font-weight: 600;
}

.text-blue {
  color: #206bc4 !important;
  font-weight: 600;
}

.text-yellow {
  color: #fab005 !important;
  font-weight: 600;
}

/* Progress bars - Tabler style */
.progress {
  height: 0.5rem;
  border-radius: 4px;
  background-color: rgba(98, 105, 118, 0.16);
  overflow: hidden;
  margin-top: 0.75rem;
}

.progress-sm {
  height: 0.375rem;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
}

/* Progress bar colors */
.bg-success,
.progress-bar.bg-success {
  background-color: #2fb344 !important;
}

.bg-danger,
.progress-bar.bg-danger {
  background-color: #d63939 !important;
}

.bg-info,
.progress-bar.bg-info {
  background-color: #4299e1 !important;
}

.bg-warning,
.progress-bar.bg-warning {
  background-color: #f59f00 !important;
}

.bg-primary,
.progress-bar.bg-primary {
  background-color: var(--tblr-primary) !important;
}

/* SVG icons в growth indicators */
.text-green svg,
.text-red svg,
.text-blue svg {
  width: 14px;
  height: 14px;
  margin-left: 2px;
  vertical-align: middle;
}

/* Відступи та spacing для stat cards */
.stat-card+.stat-card {
  margin-top: 1rem;
}

/* Card body має правильно обробляти overflow */
.bslib-card .card-body,
.card .card-body {
  overflow: hidden;
  /* Дозволяємо прокрутку при потребі */
  min-height: auto;
  /* Дозволяємо природну висоту */
}

/* Але для stat cards контейнера - без overflow */
.bslib-card .card-body>.row {
  margin-left: 0px;
  margin-right: 0px;
}

.bslib-card .card-body>.row>[class*='col-'] {
  padding-left: 10px;
  padding-right: 10px;
}

/* Додаткові відступи для fluidRow */
.container-fluid>.row,
.main-content>.row {
  margin-bottom: 1.5rem;
  margin-left: 0;
  margin-right: 0;
}

.main-content>.row:last-child {
  margin-bottom: 1.5rem;
  /* Відступ знизу навіть для останнього елемента */
}

/* Відступи для колонок */
.main-content .row>[class*='col-'] {
  padding-left: 10px;
  padding-right: 10px;
}

/* Забороняємо overflow для всього body */
body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Забороняємо overflow для page-sidebar */
.bslib-page-sidebar {
  overflow-x: hidden;
  max-width: 100%;
}

/* ========== ROUTER FIX ========== */
/* ВАЖЛИВО: Фікс для shiny.router, щоб не показував все одразу */
.router-page {
  display: none;
}

.router-page.active {
  display: block !important;
}

/* ========== 2.5. SELECTIZE FILTERS (Покращені фільтри) ========== */

/* Фікс для стрибання фільтрів при завантаженні */
.filters-box-content {
  /* Видалено min-height щоб фільтри не стрибали */
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
  margin-top: 20px;
  /* Відступ між "Обрані фільтри" та полями фільтрів */
}

.filters-box-content.loaded {
  opacity: 1;
}

/* Відступ для карток "Обрані фільтри" */
#filter_summary_card {
  margin-bottom: 20px;
}

/* Card body для "Обрані фільтри" та "Загальна статистика" - більше padding з правого та лівого боку */
#filter_summary_card .card-body,
#general_stats_container .card-body {
  padding-left: 1.75rem !important;
  padding-right: 1.75rem !important;
}

/* Базовий стиль для selectize input */
.selectize-input {
  border: 1px solid #dce1e7 !important;
  border-radius: 6px !important;
  padding: 8px 12px !important;
  background-color: #ffffff !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
  transition: all 0.2s ease-in-out !important;
  min-height: 42px !important;
  height: auto !important;
  max-height: 200px !important;
  overflow-y: auto !important;
}

/* Фокус стан - помаранчеве обведення */
.selectize-input.focus,
.selectize-input.input-active {
  border-color: var(--tblr-primary) !important;
  box-shadow: 0 0 0 3px rgba(247, 103, 7, 0.1) !important;
  outline: none !important;
}

/* Dropdown меню */
.selectize-dropdown {
  border: 1px solid #dce1e7 !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
  margin-top: 4px !important;
}

/* Опції в dropdown */
.selectize-dropdown .option {
  padding: 8px 12px !important;
  border-radius: 4px !important;
  margin: 2px 4px !important;
  transition: background-color 0.15s ease-in-out !important;
}

.selectize-dropdown .option:hover,
.selectize-dropdown .option.active {
  background-color: rgba(247, 103, 7, 0.08) !important;
  color: var(--tblr-primary) !important;
}

.selectize-dropdown .option.selected {
  background-color: rgba(247, 103, 7, 0.15) !important;
  color: var(--tblr-primary) !important;
  font-weight: 500;
}

/* Вибрані елементи (tags/items) */
.selectize-input .item {
  background-color: rgba(247, 103, 7, 0.1) !important;
  color: var(--tblr-primary) !important;
  border: 1px solid rgba(247, 103, 7, 0.2) !important;
  border-radius: 4px !important;
  padding: 4px 8px !important;
  margin: 2px !important;
  font-weight: 500;
  font-size: 0.9rem;
}

/* Кнопка видалення в tag */
.selectize-input .item .remove {
  color: var(--tblr-primary) !important;
  border-left: 1px solid rgba(247, 103, 7, 0.3) !important;
  padding-left: 6px !important;
  margin-left: 6px !important;
  text-decoration: none !important;
  font-weight: bold;
  transition: color 0.15s ease-in-out !important;
}

.selectize-input .item .remove:hover {
  color: var(--tblr-primary-hover) !important;
  background: none !important;
}

/* Placeholder */
.selectize-input input::placeholder {
  color: #9ca3af !important;
  font-weight: 400;
}

/* Disabled стан */
.selectize-input.disabled {
  background-color: #f3f5f7 !important;
  opacity: 0.6;
  cursor: not-allowed !important;
}

/* ========== 3. BUTTONS (Сучасні, тактильні) ========== */

/* Базовий стиль для всіх кнопок */
.btn {
  font-weight: 500;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  letter-spacing: -0.01em;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--btn-shadow);
  border: 1px solid transparent;
}

/* Ефект натискання для всіх кнопок */
.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* PRIMARY BUTTON (Яскрава, без рамки) */
.btn-primary {
  background-color: var(--tblr-primary);
  border-color: var(--tblr-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--tblr-primary-hover);
  border-color: var(--tblr-primary-hover);
  box-shadow: 0 4px 14px 0 rgba(247, 103, 7, 0.39);
  /* "Світіння" при наведенні */
  transform: translateY(-1px);
}

/* SECONDARY / DEFAULT BUTTON (Біла з рамкою) */
.btn-default,
.btn-secondary,
.btn-light {
  background-color: #ffffff;
  border-color: #dce1e7;
  color: #374151;
}

.btn-default:hover,
.btn-secondary:hover {
  background-color: #ffffff;
  border-color: #b1b7c1;
  color: var(--tblr-primary);
  box-shadow: var(--btn-shadow-hover);
  transform: translateY(-1px);
}

/* Спеціальні кнопки (Logout/Auth) */
.auth-btn-logout {
  background: transparent;
  border: 1px dashed #dce1e7;
  color: #6b7280;
}

.auth-btn-logout:hover {
  border-color: var(--tblr-primary);
  color: var(--tblr-primary);
  background: rgba(247, 103, 7, 0.02);
}

/* ========== 4. HEADER / NAVBAR Fixes ========== */
/* Щоб шапка гармоніювала з сайдбаром */
.navbar {
  background-color: #ffffff !important;
  border-bottom: 1px solid #e6e7e9;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.navbar-brand {
  font-weight: 900;
  color: #1d273b !important;
}

/* ========== ACCORDION STYLES ========== */

/* Accordion panel - такий самий стиль як card header */
.accordion-button {
  font-weight: 700 !important;
  font-size: 1.25rem !important;
  color: #1e293b !important;
  padding: 1.25rem 1.5rem !important;
  /* Збільшено padding для кращого відступу іконок */
  letter-spacing: -0.01em;
  background-color: #ffffff !important;
  border: none !important;
}

/* Відступ для іконок в accordion header */
.accordion-button .header-icon-badge {
  margin-left: 0.25rem;
  /* Відступ від лівого краю */
}

.accordion-button:not(.collapsed) {
  background-color: #ffffff !important;
  color: #1e293b !important;
  box-shadow: none !important;
}

.accordion-button:focus {
  box-shadow: none !important;
  border-color: rgba(98, 105, 118, 0.16) !important;
}

.accordion-item {
  border: 1px solid rgba(98, 105, 118, 0.16) !important;
  border-radius: 8px !important;
  margin-bottom: 1.5rem;
  background: #ffffff;
  box-shadow: rgba(98, 105, 118, 0.04) 0 0 4px 0;
}

.accordion-header {
  border-radius: 8px 8px 0 0 !important;
}

.accordion-body {
  padding: 1.25rem 1.75rem !important;
  /* Більше horizontal padding */
  background: #ffffff;
}

/* Unvisited accordion title link */
.box-title a {
  color: #1e293b;
  text-decoration: none;
  font-weight: 900;
  font-size: 1.25rem;
}

/* Visited accordion title link */
.box-title a:visited {
  color: #1e293b;
}

/* Optional: hover/focus states */
.box-title a:hover,
.box-title a:focus {
  color: #ff6600;
  text-decoration: underline;
}