/* Comportamentos visuais do módulo Cronogramas (Gantt, Kanban, reordenação). */

/* ---------- Abas de visualização ---------- */
/* O tema admin define .nav .nav-item a.nav-link com cor clara; força contraste nas abas do projeto. */
.cr-view-tabs.nav-tabs .nav-link {
    font-weight: 600;
    text-transform: none;
    border: 1px solid transparent;
    border-bottom-color: var(--bs-border-color);
}

.cr-view-tabs.nav-tabs .nav-link:not(.active) {
    color: #212529 !important;
    background-color: #e9ecef !important;
    border-color: #ced4da #ced4da var(--bs-border-color) !important;
}

.cr-view-tabs.nav-tabs .nav-link:not(.active):hover {
    color: #0a58ca !important;
    background-color: #fff !important;
    border-color: #86b7fe #86b7fe var(--bs-border-color) !important;
}

.cr-view-tabs.nav-tabs .nav-link:not(.active):focus-visible {
    color: #0a58ca !important;
    outline: 2px solid #86b7fe;
    outline-offset: 2px;
}

.cr-view-tabs.nav-tabs .nav-link.active {
    color: var(--bs-primary, #0d6efd) !important;
    background-color: #fff !important;
    border-color: var(--bs-border-color) var(--bs-border-color) #fff !important;
    border-bottom: 3px solid var(--bs-primary, #0d6efd) !important;
}

/* ---------- Tabela ---------- */
.cr-table {
    --cr-table-line: var(--bs-border-color-translucent, rgba(0, 0, 0, 0.1));
    --cr-table-head-line: var(--bs-border-color, #dee2e6);
    margin-bottom: 0;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
}

.cr-table thead th {
    background-color: var(--bs-tertiary-bg, #f8f9fa);
    border-bottom: 2px solid var(--cr-table-head-line) !important;
    border-right: 1px solid var(--cr-table-line);
    font-size: 0.8125rem;
    font-weight: 600;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;
}

.cr-table thead th:last-child {
    border-right: none;
}

.cr-table tbody td {
    border-bottom: 1px solid var(--cr-table-line) !important;
    border-right: 1px solid var(--cr-table-line);
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
    text-align: center;
    vertical-align: middle;
}

.cr-table tbody td:last-child {
    border-right: none;
}

.cr-table tbody tr:last-child td {
    border-bottom: none !important;
}

.cr-table.table-hover > tbody > tr:hover > * {
    background-color: rgba(var(--bs-primary-rgb, 13, 110, 253), 0.05);
}

.cr-table tbody tr.table-danger > td {
    background-color: rgba(var(--bs-danger-rgb, 220, 53, 69), 0.08);
    border-bottom-color: rgba(var(--bs-danger-rgb, 220, 53, 69), 0.18) !important;
}

.cr-table tbody tr.table-danger:hover > td {
    background-color: rgba(var(--bs-danger-rgb, 220, 53, 69), 0.12);
}

.cr-table .cr-drag-handle {
    cursor: grab;
    text-align: center;
    vertical-align: middle;
    border-right: 1px solid var(--cr-table-line);
}

.cr-table tr.cr-dragging {
    opacity: 0.5;
    background: var(--bs-primary-bg-subtle);
}

.cr-table code {
    color: var(--bs-secondary-color);
}

.cr-table .cr-table-check-col {
    width: 36px;
}

.cr-table .cr-table-drag-col {
    width: 28px;
}

.cr-table .cr-table-progress {
    min-width: 100px;
    height: 8px;
    margin-left: auto;
    margin-right: auto;
}

.cr-table .cr-table-actions-inner {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.cr-table .cr-row-progress-wrap {
    justify-content: center;
    max-width: 12rem;
    margin-left: auto;
    margin-right: auto;
}

.cr-table .cr-row-progress {
    height: 6px;
    min-width: 40px;
}

.cr-table .cr-inline-progress-input {
    width: 70px;
}

.cr-table .form-select-sm {
    margin-left: auto;
    margin-right: auto;
    max-width: 10rem;
}

.cr-table .form-check-input {
    margin-left: 0;
    margin-right: 0;
    float: none;
}

/* Borda externa alinhada ao scroll horizontal */
.table-responsive:has(> .cr-table) {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
}

.table-responsive:has(> .cr-table) > .cr-table {
    border: none;
    border-radius: 0;
}

/* ---------- Gantt v2 ---------- */

/* Container: apenas scroll horizontal; scroll vertical fica na página */
.cr-gantt-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background: var(--bs-body-bg);
    font-size: 0.78rem;
}

/* Wrapper - flex row, mínimo total em px definido via JS */
.cr-gantt-v2 {
    display: flex;
    align-items: flex-start;
}

/* Painel esquerdo: sticky no eixo X para não sumir ao rolar */
.cr-gantt-v2-left {
    position: sticky;
    left: 0;
    z-index: 4;
    flex-shrink: 0;
    background: var(--bs-body-bg);
    border-right: 2px solid #adb5bd;
    box-shadow: 3px 0 8px rgba(0, 0, 0, 0.09);
}

/* Linha de cabeçalho esquerdo */
.cr-gantt-v2-lhdr {
    position: relative;
    display: flex;
    flex-wrap: nowrap;   /* CRÍTICO: impede quebra de linha */
    align-items: center;
    background: #1a3a5c;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: .03em;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

/* Célula de cabeçalho */
.cr-gantt-v2-th {
    position: relative;
    flex: 0 0 auto;   /* tamanho exato via width/max-width no JS */
    display: flex;
    align-items: center;
    padding: 0 6px;
    height: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    border-right: 1px solid rgba(255, 255, 255, 0.15);
}

.cr-gantt-v2-th:last-child { border-right: none; }

.cr-gantt-v2-col-resize {
    position: absolute;
    top: 0;
    right: -3px;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    z-index: 3;
    touch-action: none;
}

.cr-gantt-v2-col-resize:hover,
.cr-gantt-resizing-col .cr-gantt-v2-col-resize:hover {
    background: rgba(255, 255, 255, 0.35);
}

.cr-gantt-v2-row-resize {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -3px;
    height: 7px;
    cursor: row-resize;
    z-index: 6;
    touch-action: none;
}

.cr-gantt-v2-row-resize:hover,
.cr-gantt-resizing-row .cr-gantt-v2-row-resize:hover {
    background: rgba(255, 255, 255, 0.35);
}

.cr-gantt-resizing-col,
.cr-gantt-resizing-row {
    user-select: none;
}

.cr-gantt-v2-td.cr-gantt-td-title {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    white-space: normal;
    padding-top: 4px;
    padding-bottom: 4px;
    overflow: hidden;
}

.cr-gantt-td-title-text {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    word-break: break-word;
    line-height: 1.25;
    width: 100%;
}

/* Linhas do corpo esquerdo */
.cr-gantt-v2-lrow {
    display: flex;
    flex-wrap: nowrap;   /* CRÍTICO */
    align-items: stretch;
    border-bottom: 1px solid var(--bs-border-color);
    background: var(--bs-body-bg);
    overflow: hidden;
}

.cr-gantt-v2-lrow.is-parent {
    background: #d6e8f7;
    font-weight: 600;
    color: #1a3a5c;
}

.cr-gantt-v2-lrow:hover              { background: rgba(91, 155, 213, 0.12) !important; }
.cr-gantt-v2-lrow.is-parent:hover    { background: #c3dcf0 !important; }

/* Célula de dado */
.cr-gantt-v2-td {
    flex: 0 0 auto;   /* tamanho exato via width/max-width no JS */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 6px;
    height: 100%;
    min-height: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    border-right: 1px solid var(--bs-border-color);
}

.cr-gantt-v2-td.cr-gantt-td-center {
    justify-content: center;
    text-align: center;
}

.cr-gantt-v2-td:last-child { border-right: none; }

/* Painel direito (grade de barras) */
.cr-gantt-v2-right {
    flex-shrink: 0;
    position: relative;
}

/* Cabeçalho de meses */
.cr-gantt-v2-ghdr {
    position: relative;
    overflow: hidden;
    background: #1a3a5c;
    color: #fff;
    border-bottom: 2px solid rgba(0, 0, 0, 0.2);
}

.cr-gantt-v2-mcell {
    position: absolute;
    top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
    overflow: hidden;
    box-sizing: border-box;
    padding: 0 4px;
}

/* Corpo da grade */
.cr-gantt-v2-gbody { position: relative; }

.cr-gantt-v2-grow {
    position: relative;
    border-bottom: 1px solid var(--bs-border-color);
}

.cr-gantt-v2-grow.is-parent { background: rgba(214, 232, 247, 0.4); }
.cr-gantt-v2-grow:hover      { background: rgba(91, 155, 213, 0.08); }

/* Listras alternadas de mês */
.cr-gantt-v2-stripe {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.022);
    pointer-events: none;
    z-index: 0;
}

/* Divisórias verticais de mês */
.cr-gantt-v2-mdiv {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--bs-border-color);
    pointer-events: none;
    z-index: 1;
}

/* Linha do hoje */
.cr-gantt-v2-today {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #dc3545;
    z-index: 3;
    pointer-events: none;
}

.cr-gantt-v2-today::before {
    content: '';
    position: absolute;
    top: 0;
    left: -4px;
    width: 10px;
    height: 10px;
    background: #dc3545;
    border-radius: 50%;
}

/* Barras */
.cr-gantt-v2-bar {
    position: absolute;
    top: 5px;
    height: 18px;
    border-radius: 3px;
    background: #5b9bd5;
    overflow: hidden;
    z-index: 2;
    cursor: default;
    min-width: 4px;
    transition: filter .15s;
}

.cr-gantt-v2-bar:hover { filter: brightness(0.88); }

.cr-gantt-v2-bar.g-parent {
    background: #1a3a5c;
    top: 11px;
    height: 6px;
    border-radius: 2px;
    overflow: visible;
}

.cr-gantt-v2-bar.g-parent::before,
.cr-gantt-v2-bar.g-parent::after {
    content: '';
    position: absolute;
    top: -3px;
    width: 12px;
    height: 12px;
    background: #1a3a5c;
    transform: rotate(45deg);
    border-radius: 2px;
}

.cr-gantt-v2-bar.g-parent::before { left: -4px; }
.cr-gantt-v2-bar.g-parent::after  { right: -4px; }

.cr-gantt-v2-bar.g-overdue { background: #dc3545; }
.cr-gantt-v2-bar.g-done    { background: #198754; }

/* Sobreposição de progresso */
.cr-gantt-v2-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: rgba(0, 0, 0, 0.28);
    pointer-events: none;
}

/* Rótulo de % dentro da barra */
.cr-gantt-v2-pct {
    position: absolute;
    right: 4px;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    font-size: 0.62rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.95);
    pointer-events: none;
    white-space: nowrap;
    z-index: 1;
}

/* Legenda */
.cr-gantt-v2-legend-dot {
    display: inline-block;
    width: 14px;
    height: 10px;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 3px;
    flex-shrink: 0;
}

.cr-gantt-v2-legend-today {
    display: inline-block;
    width: 3px;
    height: 14px;
    background: #dc3545;
    border-radius: 1px;
    vertical-align: middle;
    margin-right: 3px;
}

/* ---------- Kanban ---------- */
.cr-kanban-board {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.cr-kanban-col {
    flex: 1 0 220px;
    min-width: 220px;
}

.cr-kanban-column {
    min-height: 140px;
}

.cr-kanban-card {
    cursor: grab;
}

.cr-kanban-card:active {
    cursor: grabbing;
}

.cr-kanban-column.drag-over {
    background: var(--bs-primary-bg-subtle);
    outline: 2px dashed var(--bs-primary);
    outline-offset: -4px;
}

/* ---------- Linha do tempo vertical ---------- */
.cr-timeline {
    position: relative;
    padding-left: 2rem;
}

.cr-timeline::before {
    content: '';
    position: absolute;
    left: 0.6rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--bs-border-color);
}

.cr-timeline-month {
    position: relative;
    margin-bottom: 0.25rem;
    margin-top: 1.5rem;
}

.cr-timeline-month:first-child {
    margin-top: 0;
}

.cr-timeline-month-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color);
    margin-left: -2rem;
    padding-left: 0.25rem;
    background: var(--bs-body-bg);
    display: inline-block;
    position: relative;
    z-index: 1;
}

.cr-timeline-item {
    position: relative;
    margin-bottom: 0.75rem;
}

.cr-timeline-dot {
    position: absolute;
    left: -1.675rem;
    top: 0.65rem;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--bs-border-color);
    z-index: 1;
}

.cr-timeline-card {
    border-left: 3px solid var(--bs-border-color);
    transition: border-color 0.15s;
}

.cr-timeline-item.status-completed .cr-timeline-dot  { background: var(--bs-success); box-shadow: 0 0 0 2px var(--bs-success-border-subtle, #a3cfbb); }
.cr-timeline-item.status-completed .cr-timeline-card { border-left-color: var(--bs-success); }

.cr-timeline-item.status-in_progress .cr-timeline-dot  { background: var(--bs-primary); box-shadow: 0 0 0 2px var(--bs-primary-border-subtle, #9ec5fe); }
.cr-timeline-item.status-in_progress .cr-timeline-card { border-left-color: var(--bs-primary); }

.cr-timeline-item.status-validation .cr-timeline-dot  { background: var(--bs-warning); box-shadow: 0 0 0 2px var(--bs-warning-border-subtle, #ffe69c); }
.cr-timeline-item.status-validation .cr-timeline-card { border-left-color: var(--bs-warning); }

.cr-timeline-item.status-planning .cr-timeline-dot  { background: var(--bs-info); box-shadow: 0 0 0 2px var(--bs-info-border-subtle, #9eeaf9); }
.cr-timeline-item.status-planning .cr-timeline-card { border-left-color: var(--bs-info); }

.cr-timeline-item.status-overdue .cr-timeline-dot  { background: var(--bs-danger); box-shadow: 0 0 0 2px var(--bs-danger-border-subtle, #f1aeb5); }
.cr-timeline-item.status-overdue .cr-timeline-card { border-left-color: var(--bs-danger); }

.cr-timeline-item.status-suspended .cr-timeline-dot,
.cr-timeline-item.status-cancelled .cr-timeline-dot,
.cr-timeline-item.status-not_started .cr-timeline-dot { background: var(--bs-secondary-color); }

/* ---------- Detalhes / badges ---------- */
.cr-badge-comments:empty,
.cr-badge-attachments:empty {
    display: none;
}

.cr-responsible-badges .badge {
    max-width: 100%;
    white-space: normal;
    text-align: left;
    line-height: 1.25;
    font-weight: 400;
}

.cr-gantt-v2-td.cr-gantt-td-responsible {
    align-items: flex-start;
    justify-content: center;
    white-space: normal;
    overflow: visible;
    padding-top: 2px;
    padding-bottom: 2px;
}

.cr-offcanvas-details .list-group-item {
    word-break: break-word;
}

.cr-offcanvas-details {
    width: min(480px, 100%);
}

.cr-progress-h-sm {
    height: 12px;
}

.cr-progress-h-xs {
    height: 4px;
}

.cr-progress-h-kanban {
    height: 5px;
}

.cr-progress-bar-dynamic {
    width: var(--cr-w, 0%);
}

.cr-search-group-max {
    max-width: 28rem;
}

.cr-col-status {
    min-width: 150px;
}

.cr-col-progress {
    min-width: 130px;
}

.cr-depth-1 {
    padding-left: 1.25rem;
}

.cr-kanban-title-max {
    max-width: 55%;
}

.cr-kanban-percent-min {
    min-width: 2.5rem;
    text-align: right;
}

.cr-gantt-legend-macro {
    background: #1a3a5c;
}

.cr-gantt-legend-activity {
    background: #5b9bd5;
}

.cr-gantt-legend-done {
    background: #198754;
}

.cr-gantt-legend-overdue {
    background: #dc3545;
}

/* Colunas de texto livre (Descrição/Observação) na tabela de atividades:
   trunca em uma linha com reticências; o texto completo fica no atributo title. */
.cr-col-longtext {
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Modal de atividade: o <form> envolve header/body/footer dentro do
   .modal-content, o que quebra o layout flex do modal-dialog-scrollable.
   Restaura o comportamento para o corpo rolar e o rodapé (Salvar) ficar fixo. */
#crModalActivity .modal-content {
    overflow: hidden;
}

#crModalActivity .modal-content > form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: 100%;
    flex: 1 1 auto;
}

#crModalActivity .modal-body {
    overflow-y: auto;
    min-height: 0;
}

/* Modal de atividade: responsáveis e predecessoras */
.cr-resp-type-select {
    max-width: 11rem;
}

.cr-pred-list {
    max-height: 12rem;
}

.cr-pred-item {
    cursor: pointer;
}

.cr-pred-item:hover {
    background-color: var(--bs-tertiary-bg, #f8f9fa);
}

.cr-pred-item.cr-pred-checked {
    background-color: var(--bs-primary-bg-subtle, #cfe2ff);
}

.cr-responsible-chip .btn-close {
    font-size: 0.6rem;
}
