/**
 * Excel Table Resizer - Global Styles
 * Applied to all Django admin tabular inline forms
 * Version 1.0 - VinFast Showroom
 */

/* Global table positioning for resize functionality */
.inline-group .tabular th,
.inline-group .tabular td,
.tabular.inline-related th,
.tabular.inline-related td,
.module.aligned .tabular th,
.module.aligned .tabular td {
    position: relative;
    overflow: visible;
}

/* Column Resize Handles - Global */
.column-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 15;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: transparent;
}

.column-resizer:hover,
th:hover .column-resizer {
    opacity: 1;
}

.column-resizer .resize-handle {
    width: 2px;
    height: 100%;
    background: #007cba;
    margin: 0 auto;
    border-radius: 1px;
    box-shadow: 0 0 2px rgba(0, 124, 186, 0.3);
}

/* Row Resize Handles - Global */
.row-resizer {
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 6px;
    cursor: row-resize;
    z-index: 15;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: transparent;
}

.row-resizer:hover,
td:hover .row-resizer {
    opacity: 1;
}

.row-resizer .resize-handle {
    width: 100%;
    height: 2px;
    background: #007cba;
    border-radius: 1px;
    margin-top: 2px;
    box-shadow: 0 0 2px rgba(0, 124, 186, 0.3);
}

/* Resizing State Visual Feedback - Global */
th.resizing {
    background-color: #e3f2fd !important;
    box-shadow: inset 0 0 0 2px #007cba;
    position: relative;
}

tr.resizing {
    background-color: #e3f2fd !important;
}

tr.resizing td {
    background-color: #e3f2fd !important;
    box-shadow: inset 0 0 0 1px #007cba;
}

/* Enhanced Hover Effects for Resize Areas - Global */
.inline-group .tabular th:hover,
.tabular.inline-related th:hover,
.module.aligned .tabular th:hover {
    background-color: #f0f8ff !important;
}

.inline-group .tabular td:hover,
.tabular.inline-related td:hover,
.module.aligned .tabular td:hover {
    background-color: #f9f9f9 !important;
}

/* Smooth Transitions for Resize Operations - Global */
.inline-group .tabular th,
.inline-group .tabular td,
.tabular.inline-related th,
.tabular.inline-related td,
.module.aligned .tabular th,
.module.aligned .tabular td {
    transition: width 0.15s ease, height 0.15s ease, background-color 0.2s ease;
}

/* Prevent text selection during resize - Global */
body.resizing,
body.resizing * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    cursor: inherit !important;
}

/* Enhanced resize cursor visibility - Global */
.column-resizer:active,
.row-resizer:active {
    opacity: 1 !important;
}

/* Resize handle active state - Global */
.column-resizer:active .resize-handle {
    background: #0056b3;
    width: 3px;
    box-shadow: 0 0 4px rgba(0, 86, 179, 0.5);
}

.row-resizer:active .resize-handle {
    background: #0056b3;
    height: 3px;
    box-shadow: 0 0 4px rgba(0, 86, 179, 0.5);
}

/* Reset button styling - Global */
.table-resize-reset {
    background: #6c757d;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 10px;
    transition: background-color 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

.table-resize-reset:hover {
    background: #5a6268;
    color: white;
    text-decoration: none;
}

/* Improved column border visibility during resize - Global */
.inline-group .tabular th,
.tabular.inline-related th,
.module.aligned .tabular th {
    border-right: 1px solid #dee2e6;
}

.inline-group .tabular td,
.tabular.inline-related td,
.module.aligned .tabular td {
    border-right: 1px solid #dee2e6;
}

/* Last column special handling - Global */
.inline-group .tabular th:last-child,
.inline-group .tabular td:last-child,
.tabular.inline-related th:last-child,
.tabular.inline-related td:last-child,
.module.aligned .tabular th:last-child,
.module.aligned .tabular td:last-child {
    border-right: none;
}

/* Enhanced table container for better resize experience - Global */
.inline-group .tabular,
.tabular.inline-related,
.module.aligned .tabular {
    position: relative;
    overflow: visible;
}

/* Ensure proper z-index stacking - Global */
.inline-group .tabular thead,
.tabular.inline-related thead,
.module.aligned .tabular thead {
    z-index: 12;
}

.inline-group .tabular tbody,
.tabular.inline-related tbody,
.module.aligned .tabular tbody {
    z-index: 11;
}

/* Specific enhancements for different admin modules */

/* CRM Tables */
.module[id*="crm"] .tabular th,
.module[id*="crm"] .tabular td {
    position: relative;
}

/* Vehicle Management Tables */
.module[id*="vehicle"] .tabular th,
.module[id*="vehicle"] .tabular td {
    position: relative;
}

/* Warehouse Management Tables */
.module[id*="warehouse"] .tabular th,
.module[id*="warehouse"] .tabular td {
    position: relative;
}

/* Task Management Tables */
.module[id*="task"] .tabular th,
.module[id*="task"] .tabular td {
    position: relative;
}

/* Responsive adjustments for resize functionality */
@media (max-width: 1200px) {
    .column-resizer {
        width: 8px;
        right: -4px;
    }
    
    .row-resizer {
        height: 8px;
        bottom: -4px;
    }
}

@media (max-width: 768px) {
    .column-resizer {
        width: 10px;
        right: -5px;
    }
    
    .row-resizer {
        height: 10px;
        bottom: -5px;
    }
    
    .column-resizer .resize-handle {
        width: 3px;
    }
    
    .row-resizer .resize-handle {
        height: 3px;
    }
}

/* Print styles - hide resize handles */
@media print {
    .column-resizer,
    .row-resizer,
    .table-resize-reset {
        display: none !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .column-resizer .resize-handle,
    .row-resizer .resize-handle {
        background: #4fc3f7;
        box-shadow: 0 0 2px rgba(79, 195, 247, 0.3);
    }
    
    .column-resizer:active .resize-handle,
    .row-resizer:active .resize-handle {
        background: #29b6f6;
        box-shadow: 0 0 4px rgba(41, 182, 246, 0.5);
    }
    
    th.resizing {
        background-color: #1e3a5f !important;
        box-shadow: inset 0 0 0 2px #4fc3f7;
    }
    
    tr.resizing td {
        background-color: #1e3a5f !important;
        box-shadow: inset 0 0 0 1px #4fc3f7;
    }
}
