/* Доработки поверх Bootstrap */

/* Боковое меню фиксированной ширины на всю высоту экрана (на широких экранах) */
@media (min-width: 992px) {
  .sidebar {
    flex: 0 0 230px;
    max-width: 230px;
    min-height: calc(100vh - 56px);
  }
}

/* Основная область может сжиматься: широкие таблицы прокручиваются внутри, а не уезжают под меню */
.main-content {
  min-width: 0;
}

.sidebar .badge {
  font-weight: 400;
}

.sidebar .nav-link {
  color: var(--bs-body-color);
  padding: .5rem 1rem;
}

.sidebar .nav-link.active {
  font-weight: 600;
  color: var(--bs-primary);
  background-color: var(--bs-secondary-bg);
}

.sidebar .nav-link.disabled {
  color: var(--bs-secondary-color);
}

.sidebar-heading {
  font-size: .75rem;
}

/* Дерево отделов */
.dept-tree,
.dept-tree ul {
  list-style: none;
  padding-left: 0;
}

.dept-tree ul {
  margin-left: 1.25rem;
  padding-left: 1rem;
  border-left: 1px solid var(--bs-border-color);
}

/* Индикатор загрузки HTMX */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}

/* --- CRM --- */

/* Канбан сделок: колонки фиксированной ширины, прокрутка вбок */
.kanban {
  overflow-x: auto;
  align-items: flex-start;
}

.kanban-col {
  flex: 0 0 260px;
  background: var(--bs-tertiary-bg);
  border-radius: .5rem;
}

.kanban-head {
  padding: .5rem .75rem;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-top: 4px solid var(--bs-secondary);
  border-radius: .5rem .5rem 0 0;
}

.kanban-list {
  min-height: 90px; /* чтобы можно было бросить карточку в пустую колонку */
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.kanban-card {
  cursor: grab;
}

.kanban-ghost {
  opacity: .4;
}

/* Цветные стадии: бейдж и полоса стадий в карточке сделки */
.stage-badge {
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, .5);
}

.stage-btn {
  border: 1px solid var(--stage-color);
  color: var(--bs-body-color);
  background: transparent;
}

.stage-btn.filled {
  background: var(--stage-color);
  color: #fff;
  text-shadow: 0 0 2px rgba(0, 0, 0, .5);
}

.stage-btn.current {
  font-weight: 600;
  box-shadow: 0 0 0 2px var(--bs-body-bg), 0 0 0 4px var(--stage-color);
}

.stage-btn:disabled {
  opacity: 1; /* текущая стадия и режим «только просмотр» — не бледнеют */
}

/* --- Проекты и задачи --- */

/* Цвет верхней полосы колонок канбана задач — по статусу */
.task-col-new { border-top-color: var(--bs-secondary) !important; }
.task-col-in_progress { border-top-color: var(--bs-primary) !important; }
.task-col-review { border-top-color: var(--bs-warning) !important; }
.task-col-done { border-top-color: var(--bs-success) !important; }
.task-col-deferred { border-top-color: var(--bs-gray-400) !important; }

/* --- Документы --- */

/* Значок типа файла: PDF, DWG, DOCX… */
.doc-ext {
  display: inline-block;
  flex-shrink: 0;
  min-width: 2.75rem;
  padding: .15rem .3rem;
  border-radius: .25rem;
  font-size: .7rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  text-transform: uppercase;
  color: #fff;
  background: var(--bs-gray-600);
}
.doc-ext-pdf { background: #c0392b; }
.doc-ext-dwg, .doc-ext-dxf, .doc-ext-rvt, .doc-ext-ifc, .doc-ext-nwd { background: #1f6f8b; }
.doc-ext-doc, .doc-ext-docx, .doc-ext-rtf, .doc-ext-odt { background: #2b579a; }
.doc-ext-xls, .doc-ext-xlsx, .doc-ext-csv, .doc-ext-ods { background: #217346; }
.doc-ext-png, .doc-ext-jpg, .doc-ext-jpeg, .doc-ext-gif, .doc-ext-webp, .doc-ext-tif, .doc-ext-tiff { background: #8e44ad; }
.doc-ext-zip, .doc-ext-rar, .doc-ext-7z { background: #7f6a00; }

/* --- Учёт времени --- */

.timesheet td, .timesheet th { white-space: nowrap; }
.timesheet td:first-child { white-space: normal; }
.timesheet .ts-weekend { background: var(--bs-tertiary-bg); }
.timesheet .ts-today { box-shadow: inset 0 -3px 0 var(--bs-primary); }

/* --- Диаграмма Ганта (frappe-gantt): цвет полосы по статусу ---
   У полосы один класс вида g-<статус>[__late][__ro] (см. projects/gantt.py), поэтому селекторы по части имени */

.gantt .bar-wrapper[class*="g-new"] .bar { fill: #e9ecef; }
.gantt .bar-wrapper[class*="g-new"] .bar-progress { fill: #ced4da; }
.gantt .bar-wrapper[class*="g-in-progress"] .bar { fill: #cfe2ff; }
.gantt .bar-wrapper[class*="g-in-progress"] .bar-progress { fill: #8bb9fe; }
.gantt .bar-wrapper[class*="g-review"] .bar { fill: #fff3cd; }
.gantt .bar-wrapper[class*="g-review"] .bar-progress { fill: #ffda6a; }
.gantt .bar-wrapper[class*="g-done"] .bar { fill: #d1e7dd; }
.gantt .bar-wrapper[class*="g-done"] .bar-progress { fill: #75b798; }
.gantt .bar-wrapper[class*="g-deferred"] .bar { fill: #f8f9fa; stroke: #adb5bd; stroke-dasharray: 4; stroke-width: 1; }
/* Просрочено — красная рамка */
.gantt .bar-wrapper[class*="__late"] .bar { stroke: var(--bs-danger); stroke-width: 2; }
/* Задачи, которые сотрудник не вправе переносить, — без «ручек» растягивания */
.gantt .bar-wrapper[class*="__ro"] .handle { display: none; }

.gantt-legend {
  display: inline-block;
  width: 1.4rem;
  height: .75rem;
  vertical-align: middle;
  border-radius: 2px;
  border: 1px solid #ced4da;
}
.gantt-legend.g-new { background: #e9ecef; }
.gantt-legend.g-in-progress { background: #cfe2ff; }
.gantt-legend.g-review { background: #fff3cd; }
.gantt-legend.g-done { background: #d1e7dd; }
.gantt-legend.g-deferred { background: #f8f9fa; border-style: dashed; }
.gantt-legend.g-overdue-legend { background: #fff; border: 2px solid var(--bs-danger); }

/* --- Календарь --- */

.calendar-grid { table-layout: fixed; }
.calendar-grid td { height: 7.5rem; vertical-align: top; padding: .25rem; overflow: hidden; }
.calendar-grid .cal-other { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }
.calendar-grid .cal-weekend .cal-day { color: var(--bs-danger); }
.calendar-grid .cal-today { box-shadow: inset 0 0 0 2px var(--bs-primary); }
.calendar-grid .cal-day { font-weight: 600; font-size: .85rem; }
.calendar-grid .cal-add { visibility: hidden; text-decoration: none; font-weight: 600; padding: 0 .3rem; }
.calendar-grid td:hover .cal-add { visibility: visible; }

/* Пункт календаря: цветная полоска слева — тип */
.cal-item {
  display: block;
  margin-top: 2px;
  padding: 0 .3rem;
  border-left: 3px solid var(--bs-secondary);
  border-radius: 2px;
  background: var(--bs-light);
  color: var(--bs-body-color);
  font-size: .75rem;
  line-height: 1.35;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-item:hover { filter: brightness(.95); }
.cal-legend .cal-item { display: inline-block; margin-right: .5rem; }
.cal-item.done { text-decoration: line-through; opacity: .6; }
.cal-item.overdue { background: #f8d7da; border-left-color: var(--bs-danger); }
.cal-task { border-left-color: var(--bs-primary); background: #e7f1ff; }
.cal-activity { border-left-color: #6f42c1; background: #f1ebfa; }
.cal-section { border-left-color: #fd7e14; background: #fff0e1; }
.cal-project { border-left-color: var(--bs-danger); background: #fde8ea; font-weight: 600; }
.cal-event-meeting, .cal-event-other { border-left-color: #198754; background: #e3f4ec; }
.cal-event-customer { border-left-color: #6f42c1; background: #f1ebfa; }
.cal-event-site { border-left-color: #795548; background: #efebe9; }
.cal-event-expertise, .cal-event-handover { border-left-color: #0dcaf0; background: #e2f8fc; }

/* --- Отчёты --- */

/* Шкала в ячейке таблицы: ширина = доля от максимума */
.report-bar {
  height: .55rem;
  min-width: 2px;
  border-radius: 2px;
  background: var(--bs-primary);
  opacity: .75;
}
.report-bar.bg-danger { background: var(--bs-danger); }
.report-table td { white-space: nowrap; }
.report-table th { vertical-align: bottom; }  /* заголовки переносятся — таблица уже */
.report-table td.wrap { white-space: normal; }
.report-group td { background: var(--bs-tertiary-bg) !important; font-weight: 600; }

/* Печать и сохранение в PDF: без меню, шапки и кнопок */
@media print {
  header.navbar, .sidebar, .no-print, .btn, .breadcrumb { display: none !important; }
  .main-content { width: 100% !important; max-width: 100% !important; flex: 0 0 100% !important; padding: 0 !important; }
  .card { break-inside: avoid; }
  a { color: inherit !important; text-decoration: none !important; }
  .table-responsive { overflow: visible !important; }
}

/* --- Уведомления --- */

.notif-menu { width: min(380px, 92vw); max-height: 70vh; overflow-y: auto; }
.notif-item.unread { background: #e7f1ff; border-left: 3px solid var(--bs-primary); }
