/* activity-table.css */
/* Activity table: columns, widths, sticky headers, sorting, mobile */

.competencies-table thead {
    background-color: transparent;
}

.competencies-table th {
    color: var(--text-secondary);
    font-weight: var(--font-weight-semibold);
    background-color: var(--bg-primary);
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: none;
}

.competencies-table thead th::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background-color: var(--border-color);
    pointer-events: none;
}

/* === BASE TABLE LAYOUT (applies to all screen sizes) === */
.competencies-table {
    table-layout: fixed;
    width: 100%;
}

/* Prevent text selection on row click */
.competencies-table tbody tr {
    user-select: none;
}

/* === COLUMN WIDTHS (applies to all screen sizes) === */
/* Столбцы: dragHandle(1), checkbox(2), sequenceNumber(3), name(4), ... */

/* Column 1: Drag Handle */
.competencies-table thead tr th:nth-child(1),
.competencies-table tbody tr td:nth-child(1) {
    width: 24px;
    min-width: 24px;
    max-width: 24px;
    padding: 0 !important;
    text-align: center;
}

/* Column 2: Checkbox */
.competencies-table thead tr th:nth-child(2),
.competencies-table tbody tr td:nth-child(2) {
    width: 32px;
    min-width: 32px;
    max-width: 32px;
    padding: 0 !important;
    text-align: center;
}

/* Column 3: Sequence Number */
.competencies-table thead tr th:nth-child(3),
.competencies-table tbody tr td:nth-child(3) {
    width: 60px;
    min-width: 60px;
    max-width: 60px;
    text-align: left;
    padding-left: 0.5rem !important;
}

/* Align header with cell content (compensate for .sequence-number-cell padding) */
.competencies-table thead tr th:nth-child(3) {
    padding-left: calc(0.5rem + 4px) !important;
}

/* Vertical centering for first 3 columns */
.competencies-table tbody tr td:nth-child(1),
.competencies-table tbody tr td:nth-child(2),
.competencies-table tbody tr td:nth-child(3) {
    vertical-align: middle !important;
    line-height: 1;
}

.competencies-table tbody tr td:nth-child(1),
.competencies-table tbody tr td:nth-child(2) {
    text-align: center;
}

/* Column 4: Name - с actions внутри */
.competencies-table thead tr th:nth-child(4),
.competencies-table tbody tr td:nth-child(4) {
    width: 300px;
    min-width: 300px;
}

/* Column 5: Current Step */
.competencies-table thead tr th:nth-child(5),
.competencies-table tbody tr td:nth-child(5) {
    width: 250px;
    min-width: 250px;
}

/* Column 6: Assigned */
.competencies-table thead tr th:nth-child(6),
.competencies-table tbody tr td:nth-child(6) {
    width: 180px;
    min-width: 180px;
}

/* Column 7: Progress */
.competencies-table thead tr th:nth-child(7),
.competencies-table tbody tr td:nth-child(7) {
    width: 120px;
    min-width: 120px;
    text-align: left !important;
}

/* Column 8: Start */
.competencies-table thead tr th:nth-child(8),
.competencies-table tbody tr td:nth-child(8) {
    width: 130px;
    min-width: 130px;
    padding: 0.5rem;
}

/* Column 9: Finish */
.competencies-table thead tr th:nth-child(9),
.competencies-table tbody tr td:nth-child(9) {
    width: 130px;
    min-width: 130px;
    padding: 0.5rem;
}

/* Column 10: Author */
.competencies-table thead tr th:nth-child(10),
.competencies-table tbody tr td:nth-child(10) {
    width: 150px;
    min-width: 150px;
}

/* --- ИСПРАВЛЕННЫЕ СТИЛИ: Десктопная таблица с правильными ширинами --- */
/* === ИСПРАВЛЕННЫЕ СТИЛИ: Десктопная таблица с 9 столбцами === */
@media (min-width: 769px) {
    .competencies-table th,
    .competencies-table td {
        padding: 0.75rem;
        text-align: left !important;
        vertical-align: middle;
    }

    /* Для данных - обрезка с многоточием */
    .competencies-table td {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Перенос текста для Assigned (столбец 6) */
    .competencies-table tbody tr td:nth-child(6) {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        overflow-wrap: break-word;
        max-width: 180px;
    }

    /* Заголовки - однострочные, компактные, одинаковый padding как у td */
    .competencies-table th {
        white-space: nowrap;
        font-size: var(--font-size-xs);
        padding: 0.75rem;
    }

    /* Липкие (sticky) столбцы: dragHandle(1), checkbox(2), sequenceNumber(3), name(4) */
    /* Данные (tbody) */

    /* Column 1: Drag Handle - sticky at left: 0 */
    .competencies-table tbody tr td:nth-child(1) {
        position: sticky !important;
        left: 0 !important;
        z-index: 3;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 2: Checkbox - sticky at left: 24px */
    .competencies-table tbody tr td:nth-child(2) {
        position: sticky !important;
        left: 24px !important;
        z-index: 3;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 3: Sequence Number - sticky at left: 56px (24 + 32) */
    .competencies-table tbody tr td:nth-child(3) {
        position: sticky !important;
        left: 56px !important;
        z-index: 3;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 4: Name - sticky at left: 116px (24 + 32 + 60) */
    .competencies-table tbody tr td:nth-child(4) {
        position: sticky !important;
        left: 116px !important;
        z-index: 3;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Заголовки (thead) - нужны и top, и left для двойного sticky */
    /* z-index: 4 выше чем у обычных заголовков (z-index: 2) */

    /* Column 1 Header: Drag Handle */
    .competencies-table thead tr th:nth-child(1) {
        position: sticky !important;
        left: 0 !important;
        top: 0 !important;
        z-index: 4;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 2 Header: Checkbox */
    .competencies-table thead tr th:nth-child(2) {
        position: sticky !important;
        left: 24px !important;
        top: 0 !important;
        z-index: 4;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 3 Header: Sequence Number */
    .competencies-table thead tr th:nth-child(3) {
        position: sticky !important;
        left: 56px !important;
        top: 0 !important;
        z-index: 4;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Column 4 Header: Name */
    .competencies-table thead tr th:nth-child(4) {
        position: sticky !important;
        left: 116px !important;
        top: 0 !important;
        z-index: 4;
        background-color: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    /* Поддержка hover для липких столбцов */
    .competencies-table tbody tr:hover td:nth-child(1),
    .competencies-table tbody tr:hover td:nth-child(2),
    .competencies-table tbody tr:hover td:nth-child(3),
    .competencies-table tbody tr:hover td:nth-child(4) {
        background-color: var(--bg-hover);
    }

    /* Поддержка для строк на hold */
    .competencies-table tbody tr[data-on-hold='true'] td:nth-child(1),
    .competencies-table tbody tr[data-on-hold='true'] td:nth-child(2),
    .competencies-table tbody tr[data-on-hold='true'] td:nth-child(3),
    .competencies-table tbody tr[data-on-hold='true'] td:nth-child(4) {
        background-color: var(--color-warning-bg) !important;
    }

    .competencies-table tbody tr[data-on-hold='true']:hover td:nth-child(1),
    .competencies-table tbody tr[data-on-hold='true']:hover td:nth-child(2),
    .competencies-table tbody tr[data-on-hold='true']:hover td:nth-child(3),
    .competencies-table tbody tr[data-on-hold='true']:hover td:nth-child(4) {
        background-color: var(--bg-hover) !important;
    }

    /* Поддержка для highlight анимации */
    .competencies-table tbody tr.row-highlight td:nth-child(1),
    .competencies-table tbody tr.row-highlight td:nth-child(2),
    .competencies-table tbody tr.row-highlight td:nth-child(3),
    .competencies-table tbody tr.row-highlight td:nth-child(4) {
        background-color: var(--color-success-bg);
    }

    /* Для Name (столбец 4) разрешаем перенос в данных */
    .competencies-table tbody tr td:nth-child(4) {
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Стили для многострочных дат (P/F/A) */
    .multiline-date-cell {
        display: flex;
        flex-direction: column;
        gap: 2px;
        line-height: 1.3;
    }

    .date-line {
        font-size: 10px;
        white-space: nowrap;
    }

    .date-label {
        font-weight: var(--font-weight-semibold);
        color: var(--text-secondary);
        min-width: 12px;
        display: inline-block;
    }

    /* Цветовое кодирование префиксов дат P/F/A */
    .date-label-p {
        color: var(--text-tertiary, #999); /* План: серый (базовый) */
    }

    .date-label-f {
        color: var(--info-color, #2196f3); /* Прогноз: синий (изменение) */
    }

    .date-label-a {
        color: var(--success-dark, #2e7d32); /* Факт: темно-зеленый (завершено) */
        font-weight: var(--font-weight-bold, 700);
    }

    /* --- СТИЛИ СОРТИРОВКИ --- */
    .competencies-table th.sortable {
        cursor: pointer;
        user-select: none;
    }

    .competencies-table th.sortable:hover {
        background-color: var(--bg-tertiary);
    }

    /* Индикатор сортировки рядом с текстом */
    .competencies-table th .sort-indicator {
        display: inline-block;
        margin-left: 4px;
        vertical-align: middle;
        opacity: 0.3;
        transition: opacity 0.2s ease;
    }

    .competencies-table th.sortable:hover .sort-indicator {
        opacity: 0.6;
    }

    .competencies-table th.sorted .sort-indicator {
        opacity: 1;
    }

    .sort-indicator .material-icons {
        font-size: 18px;
        line-height: 1;
        color: var(--primary-color);
        vertical-align: middle;
    }

    .sort-indicator .sort-asc,
    .sort-indicator .sort-desc {
        display: none;
    }

    .competencies-table th.sorted-asc .sort-indicator .sort-asc {
        display: inline-block;
    }

    .competencies-table th.sorted-desc .sort-indicator .sort-desc {
        display: inline-block;
    }
}

/* --- МОБИЛЬНАЯ АДАПТИВНОСТЬ --- */
@media (max-width: 768px) {
    /* Mobile-specific table styles if needed */
}

/* Hold indicator */
tr[data-on-hold='true'] {
    background-color: var(--color-warning-bg);
}

tr[data-on-hold='true']:hover {
    background-color: var(--bg-hover);
}

/* Подсветка новой активности */
@keyframes highlightRow {
    0% {
        background-color: var(--color-success-bg);
        box-shadow: 0 0 10px var(--color-success-bg);
    }
    100% {
        background-color: transparent;
        box-shadow: none;
    }
}

.row-highlight {
    animation: highlightRow 2.5s ease-out;
}

/* Activity row styles when locked */
.competencies-table tbody tr.activity-locked {
    background-color: var(--color-lock-bg);
}

/* Sticky columns for locked rows need explicit background */
.competencies-table tbody tr.activity-locked td:nth-child(1),
.competencies-table tbody tr.activity-locked td:nth-child(2),
.competencies-table tbody tr.activity-locked td:nth-child(3),
.competencies-table tbody tr.activity-locked td:nth-child(4) {
    background-color: var(--color-lock-bg) !important;
}

/* Hover effect for locked rows */
.competencies-table tbody tr.activity-locked:hover {
    background-color: var(--bg-hover);
}

/* Hover effect for sticky columns in locked rows */
.competencies-table tbody tr.activity-locked:hover td:nth-child(1),
.competencies-table tbody tr.activity-locked:hover td:nth-child(2),
.competencies-table tbody tr.activity-locked:hover td:nth-child(3),
.competencies-table tbody tr.activity-locked:hover td:nth-child(4) {
    background-color: var(--bg-hover) !important;
}

/* Dim row when locked by another user */
.competencies-table tbody tr.locked-by-other {
    opacity: 0.6;
    pointer-events: none;
}

.competencies-table tbody tr.locked-by-other:hover {
    background-color: var(--bg-secondary) !important;
}

/* Disable action buttons when locked by another user */
.competencies-table tbody tr.locked-by-other .btn-icon {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}
