/* Data Table Component */

.datatable-wrapper {
    background: white;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.datatable-container {
    overflow-y: auto;
}

.datatable-table {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    width: 100%;
}

/* Table Header (Sticky) */
.datatable-table th {
    background: #f7fafc;
    position: sticky;
    top: 0;
    z-index: 2;
    color: #4a5568;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 10px 12px;
    border-bottom: 2px solid #e2e8f0;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.datatable-table th:hover {
    background: #edf2f7;
}

/* Table Body */
.datatable-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.85rem;
    color: #2d3748;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.datatable-table tbody tr {
    transition: background 0.1s;
}

.datatable-table tbody tr:hover {
    background: #ebf8ff;
}

/* Column Resize Handle */
.col-resize {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 6;
}

.col-resize:hover,
.col-resize.active {
    background: #3b82f6;
    opacity: 0.4;
}

/* Filter Row (Sticky, above header) */
.filter-row th {
    background: #edf2f7;
    padding: 6px 4px;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 3;
    cursor: default;
}

/* Header row sits below filter row */
.datatable-table thead tr:nth-child(2) th {
    top: 34px;
    z-index: 2;
}

/* Filter Inputs & Selects */
.col-filter-input,
.col-filter-select {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #2d3748;
    background: white;
    outline: none;
    transition: border-color 0.15s;
}

.col-filter-input:focus,
.col-filter-select:focus {
    border-color: #4299e1;
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.15);
}

.col-filter-input::placeholder {
    color: #cbd5e0;
}

.col-filter-select {
    cursor: pointer;
    -webkit-appearance: auto;
    appearance: auto;
}

/* Multi-Select Checkbox Filter */
.col-filter-multi {
    position: relative;
    width: 100%;
}

.col-filter-multi-btn {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.75rem;
    color: #2d3748;
    background: white;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.15s;
}

.col-filter-multi-btn:hover {
    border-color: #cbd5e0;
}

.col-filter-multi-btn.active {
    border-color: #4299e1;
    color: #2b6cb0;
    background: #ebf8ff;
}

.col-filter-multi-dd {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    min-width: 100%;
    max-height: 60vh;
    overflow-y: auto;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 50;
    padding: 4px 0;
}

.col-filter-multi-dd.show {
    display: block;
}

.col-filter-multi-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    font-size: 0.75rem;
    color: #4a5568;
    cursor: pointer;
    white-space: nowrap;
}

.col-filter-multi-item:hover {
    background: #edf2f7;
}

.col-filter-multi-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.col-filter-multi-all {
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 2px;
    padding-bottom: 4px;
    font-weight: 600;
    color: #2d3748;
}

/* Date Filter Trigger & Dropdown */
.date-filter-wrap {
    position: relative;
}

.date-filter-trigger {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.75rem;
    background: #fff;
    color: #718096;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.date-filter-trigger.has-filter {
    color: #2d3748;
    border-color: #4299e1;
    background: #ebf8ff;
}

.date-range-filter-dropdown {
    position: fixed;
    z-index: 9999;
    min-width: 220px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    padding: 10px;
}

.date-range-filter-dropdown .date-range-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.date-range-filter-dropdown .date-preset-btn {
    padding: 4px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    background: #f7fafc;
    font-size: 0.75rem;
    cursor: pointer;
    color: #4a5568;
}

.date-range-filter-dropdown .date-preset-btn:hover {
    background: #edf2f7;
}

.date-range-filter-dropdown .date-preset-btn.active {
    background: #4299e1;
    color: #fff;
    border-color: #4299e1;
}

.date-range-divider {
    font-size: 0.7rem;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 8px 0 6px;
    border-top: 1px solid #e2e8f0;
    padding-top: 8px;
}

.date-range-filter-dropdown .date-range-fields {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.date-range-filter-dropdown .date-range-group {
    flex: 1;
}

.date-range-filter-dropdown .date-range-group label {
    display: block;
    font-size: 0.7rem;
    color: #718096;
    margin-bottom: 2px;
}

.date-range-filter-dropdown .date-range-input {
    width: 100%;
    box-sizing: border-box;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.75rem;
}

.date-range-btn-row {
    display: flex;
    justify-content: space-between;
    gap: 6px;
}

.date-range-clear-btn,
.date-range-apply-btn {
    flex: 1;
    padding: 5px 0;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.date-range-clear-btn {
    background: #edf2f7;
    color: #4a5568;
}

.date-range-clear-btn:hover {
    background: #e2e8f0;
}

.date-range-apply-btn {
    background: #4299e1;
    color: #fff;
}

.date-range-apply-btn:hover {
    background: #3182ce;
}

/* Filter Pills Bar */
.filter-pills-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 0 4px;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    font-size: 0.7rem;
    font-weight: 500;
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    border-radius: 9999px;
    white-space: nowrap;
}

.filter-pill-label {
    color: #3b82f6;
}

.filter-pill-x {
    background: none;
    border: none;
    cursor: pointer;
    color: #93c5fd;
    padding: 0;
    margin-left: 2px;
    font-size: 1rem;
    line-height: 1;
    transition: color 0.15s;
}

.filter-pill-x:hover {
    color: #1e40af;
}

.filter-clear-all {
    font-size: 0.7rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 9999px;
    padding: 2px 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-clear-all:hover {
    background: #f3f4f6;
    color: #374151;
}

/* Column Picker (Gear Icon) */
.col-picker-wrap {
    position: relative;
}

.col-picker-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 1.1rem;
    cursor: pointer;
    color: #718096;
    transition: all 0.15s;
}

.col-picker-btn:hover {
    background: #edf2f7;
    color: #4a5568;
    border-color: #cbd5e0;
}

.col-picker-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    min-width: 180px;
    max-height: 70vh;
    overflow-y: auto;
    z-index: 200;
    padding: 6px 0;
}

.col-picker-dropdown.show {
    display: block;
}

.col-picker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #2d3748;
    transition: background 0.1s;
    user-select: none;
}

.col-picker-item:hover {
    background: #f7fafc;
}

.col-picker-item.disabled {
    opacity: 0.45;
    cursor: default;
}

.col-picker-item input[type="checkbox"] {
    accent-color: #4299e1;
}

.col-picker-handle {
    cursor: grab;
    color: #a0aec0;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 2px;
}

.col-picker-item.dragging {
    opacity: 0.4;
}

.col-picker-item.drag-over {
    border-top: 2px solid #4299e1;
}

/* View Selector */
.view-selector-wrap {
    position: relative;
}

.view-selector-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    color: #718096;
    transition: all 0.15s;
    white-space: nowrap;
}

.view-selector-btn:hover {
    background: #edf2f7;
    color: #4a5568;
    border-color: #cbd5e0;
}

.view-selector-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 100;
    min-width: 200px;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px 0;
}

.view-selector-dropdown.show {
    display: block;
}

.view-selector-item {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #4a5568;
    white-space: nowrap;
}

.view-selector-item:hover {
    background: #edf2f7;
}

.view-selector-item.active {
    font-weight: 600;
    color: #2d3748;
}

.view-selector-divider {
    border-top: 1px solid #e2e8f0;
    margin: 4px 0;
}

.view-selector-action {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #4299e1;
    white-space: nowrap;
}

.view-selector-action:hover {
    background: #ebf8ff;
}

/* View Manage Overlay */
.view-manage-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-manage-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    min-width: 320px;
    max-width: 420px;
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.view-manage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.view-manage-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #2d3748;
}

.view-manage-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: #a0aec0;
    padding: 0 4px;
    line-height: 1;
}

.view-manage-close:hover {
    color: #4a5568;
}

.view-manage-body {
    padding: 8px;
    overflow-y: auto;
}

.view-manage-row {
    padding: 8px;
    border-radius: 6px;
}

.view-manage-row:hover {
    background: #f7fafc;
}

.view-manage-row-header {
    display: flex;
    align-items: center;
}

.view-manage-name {
    flex: 1;
    font-size: 0.9rem;
    color: #2d3748;
}

.view-manage-details {
    padding: 4px 0 2px 4px;
    font-size: 0.78rem;
    color: #a0aec0;
    line-height: 1.5;
}

.view-manage-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: #a0aec0;
    padding: 2px 6px;
    border-radius: 4px;
}

.view-manage-btn:hover {
    background: #edf2f7;
    color: #4a5568;
}

.view-manage-btn-danger:hover {
    background: #fff5f5;
    color: #e53e3e;
}

/* Export CSV Button */
.export-csv-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: #718096;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.export-csv-btn:hover {
    background: #edf2f7;
    color: #4a5568;
    border-color: #cbd5e0;
}

/* Pagination */
.datatable-bottom {
    padding: 12px 0 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #718096;
    flex-wrap: wrap;
    gap: 8px;
}

.datatable-bottom .datatable-info { order: 1; }
.datatable-bottom .datatable-pagination { order: 2; }
.datatable-bottom .datatable-dropdown { order: 3; margin-left: auto; }

.datatable-pagination .datatable-pagination-list {
    display: flex;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.datatable-pagination .datatable-pagination-list li a,
.datatable-pagination .datatable-pagination-list li button {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    background: white;
    color: #4a5568;
    cursor: pointer;
    font-size: 0.8rem;
    text-decoration: none;
}

.datatable-pagination .datatable-pagination-list li.datatable-active a,
.datatable-pagination .datatable-pagination-list li.datatable-active button {
    background: #4299e1;
    color: white;
    border-color: #4299e1;
}

/* Center all columns except name and client */
.datatable-table th,
.datatable-table td {
    text-align: center;
}

.datatable-table th.col-name,
.datatable-table td.col-name,
.datatable-table th.col-client,
.datatable-table td.col-client {
    text-align: left;
}

/* Drag and Drop */
.drag-handle {
    display: inline-block;
    cursor: grab;
    color: #cbd5e0;
    font-size: 0.85rem;
    letter-spacing: -3px;
    margin-right: 6px;
    vertical-align: middle;
    user-select: none;
    transition: color 0.15s;
}

.drag-handle:hover {
    color: #718096;
}

.datatable-table tbody tr[draggable="true"]:active .drag-handle,
.datatable-table tbody tr.dragging .drag-handle {
    cursor: grabbing;
}

.datatable-table tbody tr.dragging {
    opacity: 0.4;
    background: #f7fafc;
}

.datatable-table tbody tr.drag-over-above {
    box-shadow: inset 0 2px 0 0 #4299e1;
}

.datatable-table tbody tr.drag-over-below {
    box-shadow: inset 0 -2px 0 0 #4299e1;
}

/* Status Badges in datatable */
.datatable-table .status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Row name links */
.datatable-table td a[data-route] {
    color: #3182ce;
    text-decoration: none;
}
.datatable-table td a[data-route]:hover {
    text-decoration: underline;
}

/* Row actions column */
.col-actions {
    width: 40px;
    text-align: center;
}
.row-actions-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #a0aec0;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    letter-spacing: 1px;
}
.row-actions-btn:hover {
    background: #edf2f7;
    color: #4a5568;
}
.row-actions-dd {
    display: none;
    position: fixed;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 1000;
    min-width: 120px;
    padding: 4px 0;
}
.row-actions-dd.show {
    display: block;
}
.row-actions-dd button {
    display: block;
    width: 100%;
    padding: 6px 12px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.85rem;
    color: #2d3748;
}
.row-actions-dd button:hover {
    background: #edf2f7;
}
