/**
 * Activity Table View Styles
 * Spreadsheet-like editing interface for project activities
 */

/* Container */
.activity-table-container {
    position: relative;
    min-height: 400px;
}

/* Toolbar */
.activity-table-toolbar {
    margin-bottom: 15px;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.activity-table-toolbar .btn-group {
    margin-right: 10px;
}

.activity-table-toolbar .badge {
    background-color: #5bc0de;
    margin-left: 5px;
}

/* Loading Overlay */
.activity-table-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
}

.loading-spinner p {
    margin-top: 15px;
    color: #666;
    font-size: 14px;
}

/* Table Grid Container */
.activity-table-grid {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 350px);
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Table Styles. Every column has a width of its own (see Column Widths): the table is as wide as they
   add up to, and the grid scrolls sideways, instead of squeezing the number columns. Separate borders
   keep the sticky header and the frozen columns whole: with collapsed borders a row shows through the gap. */
.activity-table {
    margin-bottom: 0;
    table-layout: fixed;
    width: 100%;
    min-width: 1800px;
    border-collapse: separate;
    border-spacing: 0;
}

/* The modern theme sets border-collapse on .ditio-modern-enabled .table; this must win over it (0,3,0 against 0,2,0, and ditio-modern.css loads later) */
.ditio-modern-enabled .table.activity-table {
    border-collapse: separate;
    border-spacing: 0;
}

.activity-table thead th {
    position: sticky;
    top: 0;
    background: #f5f5f5;
    border-bottom: 2px solid #ddd;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: #555;
    padding: 10px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10;
}

.activity-table tbody tr {
    background-color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.activity-table tbody tr:hover {
    background-color: #f0f7ff !important;
}

.activity-table tbody td {
    padding: 6px 8px;
    vertical-align: middle;
    font-size: 13px;
    border-right: 1px solid #eee;
}

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

/* Column Widths */
.col-select {
    width: 35px;
    text-align: center;
}

/* The tick column is frozen with the name, so nothing scrolls into the gap left of the name */
.activity-table .col-select {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 5;
}

.activity-table thead .col-select {
    z-index: 16;
}

.col-name {
    width: 280px;
    min-width: 200px;
}

.col-parent {
    width: 180px;
}

.col-chapter {
    width: 100px;
}

.col-external-id {
    width: 120px;
}

.col-dim01,
.col-dim02 {
    width: 100px;
}

.col-date {
    width: 110px;
}

.col-hours {
    width: 110px;
    text-align: right;
}

/* The budget columns: wide enough for "1 234,50" and the header, never squeezed */
.col-unit {
    width: 90px;
}

.col-qty,
.col-cost-price,
.col-price {
    width: 120px;
    text-align: right;
}

.col-total {
    width: 120px;
    text-align: right;
}

.col-active {
    width: 90px;
    text-align: center;
}

/* A column that is not edited here says so under its name, in plain small grey text (D332) */
.activity-table thead th .read-only-mark {
    display: block;
    font-size: 11px;
    font-weight: normal;
    text-transform: none;
    color: #666;
}

/* A header with a tooltip: the pointer and a small icon before the name say there is one (the name stays flush with the numbers) */
.activity-table thead th.has-header-tip {
    cursor: help;
}

.activity-table thead th .header-tip-icon {
    margin-right: 3px;
    color: #777;
}

.col-active .active-word {
    margin-left: 4px;
}

/* A number typed wrong stays in the cell, marked, with its error under it */
.activity-table tbody td .cell-invalid {
    color: #a94442;
    font-weight: bold;
}

.activity-table tbody td .cell-error {
    white-space: normal;
}

/* Frozen Column (Name) */
.frozen-col {
    position: sticky;
    left: 35px;
    background: inherit;
    z-index: 5;
}

.activity-table thead .frozen-col {
    z-index: 15;
}

/* Row States */
.activity-table tbody tr.is-folder {
    background-color: #fafafa;
}

.activity-table tbody tr.is-folder td {
    font-weight: 500;
}

.activity-table tbody tr.is-selected {
    background-color: #d9edf7 !important;
}

.activity-table tbody tr.is-dirty {
    background-color: #fcf8e3 !important;
}

.activity-table tbody tr.is-new {
    background-color: #dff0d8 !important;
}

.activity-table tbody tr.preview-insert {
    box-shadow: inset 4px 0 0 #5cb85c;
}

.activity-table tbody tr.preview-update td .preview-old {
    display: block;
    color: #a94442;
    font-size: 11px;
}

.activity-table tbody td .preview-check {
    display: block;
    font-size: 11px;
    font-weight: bold;
}

.activity-table tbody tr.preview-error {
    background-color: #f2dede !important;
}

.activity-table .preview-new-label {
    margin-left: 6px;
}

.activity-table-preview-bar {
    margin-bottom: 10px;
}

.activity-table tbody tr.is-inactive {
    opacity: 0.6;
}

.activity-table tbody tr.is-inactive td {
    color: #999;
}

/* Cell Content */
.cell-content {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Editable Cells */
.editable-cell {
    cursor: text;
}

.editable-cell:hover {
    background-color: #fff8e1;
}

.editable-cell.editing {
    padding: 2px;
}

.editable-cell.editing .cell-content {
    display: none;
}

.editable-cell input,
.editable-cell select {
    width: 100%;
    border: 2px solid #337ab7;
    border-radius: 3px;
    padding: 4px 6px;
    font-size: 13px;
    outline: none;
}

.editable-cell input:focus,
.editable-cell select:focus {
    box-shadow: 0 0 0 2px rgba(51, 122, 183, 0.25);
}

/* Folder Toggle */
.folder-toggle {
    display: inline-block;
    width: 18px;
    text-align: center;
    cursor: pointer;
    color: #666;
    margin-right: 3px;
}

.folder-toggle:hover {
    color: #333;
}

.folder-toggle-placeholder {
    display: inline-block;
    width: 18px;
    margin-right: 3px;
}

/* Row Icon */
.row-icon {
    margin-right: 6px;
    color: #888;
}

.is-folder .row-icon {
    color: #f0ad4e;
}

/* Child Count Badge */
.child-count-badge {
    font-size: 11px;
    color: #888;
    margin-left: 2px;
    margin-right: 4px;
}

/* Description Text */
.description-text {
    display: inline;
}

/* Inherited Values */
.inherited {
    color: #888;
    font-style: italic;
}

.inherited-icon {
    font-size: 10px;
    color: #5bc0de;
    margin-left: 4px;
    vertical-align: super;
}

/* Empty State */
.empty-state {
    padding: 60px 20px;
    color: #999;
}

.empty-state i {
    margin-bottom: 15px;
}

.empty-state h4 {
    color: #666;
    margin-bottom: 10px;
}

/* Status Bar */
.activity-table-status {
    padding: 8px 12px;
    background: #f8f8f8;
    border-top: 1px solid #ddd;
    font-size: 12px;
}

/* Alert Overrides */
.activity-table-container .alert {
    margin-bottom: 15px;
}

/* Typeahead Dropdown */
.parent-typeahead + .typeahead.dropdown-menu {
    max-height: 300px;
    overflow-y: auto;
}

/* Datepicker Positioning */
.datepicker-edit + .datepicker {
    z-index: 1100;
}

/* Print Styles */
@media print {
    .activity-table-toolbar,
    .activity-table-status {
        display: none !important;
    }
    
    .activity-table-grid {
        max-height: none;
        overflow: visible;
        border: none;
    }
    
    .activity-table {
        font-size: 10px;
    }
    
    .activity-table thead th,
    .activity-table tbody td {
        padding: 4px 6px;
    }
}

/* Responsive Adjustments */
@media (max-width: 992px) {
    .activity-table-toolbar .btn span {
        display: none;
    }
    
    .activity-table-toolbar .btn i {
        margin-right: 0;
    }
    
    .col-parent,
    .col-dim02 {
        display: none;
    }
}

/* Keyboard Focus Indicators */
.activity-table tbody tr:focus,
.activity-table tbody td:focus {
    outline: 2px solid #337ab7;
    outline-offset: -2px;
}

/* Checkbox Styling */
.activity-table input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* Active/Inactive Icons */
.text-success {
    color: #5cb85c;
}

.text-muted {
    color: #999;
}

/* Scrollbar Styling */
.activity-table-grid::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.activity-table-grid::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 5px;
}

.activity-table-grid::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
}

.activity-table-grid::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Required Field Styling */
.required-field {
    background-color: #fff8e1 !important;
}

.required-field::after {
    content: '*';
    color: #d9534f;
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 10px;
}

/* Dropdown in cell */
.activity-table .cell-select {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid #66afe9;
    border-radius: 2px;
    font-size: 12px;
    background-color: #fff;
}

.activity-table .cell-select:focus {
    outline: none;
    border-color: #337ab7;
    box-shadow: 0 0 3px rgba(66, 139, 202, 0.3);
}

/* Additional column widths */
.col-external-proj {
    min-width: 120px;
    width: 120px;
}

.col-external-sub-proj {
    min-width: 120px;
    width: 120px;
}


/* Yes/no cell editor: an on/off switch, not a list */
.editable-cell .cell-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    margin: 2px 4px;
    vertical-align: middle;
}

.editable-cell .cell-switch .cell-switch-input {
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.editable-cell .cell-switch .cell-switch-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 22px;
    background-color: #bbb;
    transition: background-color 0.15s;
}

.editable-cell .cell-switch .cell-switch-slider:before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #fff;
    transition: transform 0.15s;
}

.editable-cell .cell-switch .cell-switch-input:checked + .cell-switch-slider {
    background-color: #5cb85c;
}

.editable-cell .cell-switch .cell-switch-input:checked + .cell-switch-slider:before {
    transform: translateX(18px);
}

.editable-cell .cell-switch .cell-switch-input:focus + .cell-switch-slider {
    box-shadow: 0 0 0 2px rgba(51, 122, 183, 0.4);
}
