/* Custom CSS for VK Phone Pricing System */

/* Professional notification system */
.custom-notification {
    animation: slideInRight 0.3s ease-out;
    border: none;
    border-radius: 8px;
    font-weight: 500;
}

.custom-notification.alert-success {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    color: #155724;
    border-left: 4px solid #28a745;
}

.custom-notification.alert-danger {
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    color: #721c24;
    border-left: 4px solid #dc3545;
}

.custom-notification.alert-info {
    background: linear-gradient(135deg, #d1ecf1, #bee5eb);
    color: #0c5460;
    border-left: 4px solid #17a2b8;
}

.custom-notification .btn-close {
    filter: invert(1);
    opacity: 0.7;
}

.custom-notification .btn-close:hover {
    opacity: 1;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Enhanced button styling */
.btn-test-flow {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-test-flow:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    color: white;
}

.btn-test-flow:active {
    transform: translateY(0);
}

/* Professional form styling */
.form-control:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.form-select:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Enhanced card styling */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.card-header {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-bottom: 1px solid #dee2e6;
    border-radius: 12px 12px 0 0 !important;
    font-weight: 600;
}

/* Professional table styling */
.table {
    border-radius: 8px;
    overflow: hidden;
}

.table thead th {
    background: linear-gradient(135deg, #495057, #6c757d);
    color: white;
    border: none;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.table tbody tr:hover {
    background-color: rgba(102, 126, 234, 0.05);
    transition: all 0.2s ease;
}

/* Loading states */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    z-index: 1000;
}

/* Responsive improvements */
@media (max-width: 768px) {
    .custom-notification {
        right: 10px;
        left: 10px;
        min-width: auto;
    }
    
    .btn-test-flow {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

/* Dark theme enhancements */
[data-bs-theme="dark"] .custom-notification.alert-success {
    background: linear-gradient(135deg, #1e4d2b, #2d5a3d);
    color: #d4edda;
}

[data-bs-theme="dark"] .custom-notification.alert-danger {
    background: linear-gradient(135deg, #4d1e1e, #5a2d2d);
    color: #f8d7da;
}

[data-bs-theme="dark"] .custom-notification.alert-info {
    background: linear-gradient(135deg, #1e4d5a, #2d5a6a);
    color: #d1ecf1;
}

[data-bs-theme="dark"] .card-header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: #ecf0f1;
}

[data-bs-theme="dark"] .table thead th {
    background: linear-gradient(135deg, #2c3e50, #34495e);
}

/* Pagination styling improvements */
.justify-content-center {
    justify-content: center !important;
    align-items: center;
}

/* Consistent pagination input and button styling */
#pageJump {
    border-radius: 0.375rem !important;
    height: 31px !important;
    line-height: 1.5;
}

#paginationJump .btn {
    border-radius: 0.375rem !important;
    height: 31px !important;
    line-height: 1.5;
    padding: 0.25rem 0.5rem;
    display: inline-flex;
    align-items: center;
}

/* Ensure all form controls have consistent styling */
.form-control-sm {
    border-radius: 0.375rem !important;
    height: 31px !important;
    line-height: 1.5;
}

.btn-sm {
    border-radius: 0.375rem !important;
    height: 31px !important;
    line-height: 1.5;
    padding: 0.25rem 0.5rem;
    display: inline-flex;
    align-items: center;
}

/* Compact action buttons in table */
.table .btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    margin: 0 1px;
}

.table .btn-sm {
    padding: 0.15rem 0.35rem;
    font-size: 0.75rem;
    height: 24px !important;
}

/* Responsive table design */
.table-responsive-custom {
    position: relative;
}

/* Hide some columns on medium-large screens */
@media (max-width: 1199px) {
    .table th:nth-child(5),
    .table th:nth-child(6),
    .table td:nth-child(5),
    .table td:nth-child(6) {
        display: none;
    }
}

/* Hide more columns on medium screens */
@media (max-width: 991px) {
    .table th:nth-child(5),
    .table th:nth-child(6),
    .table th:nth-child(7),
    .table td:nth-child(5),
    .table td:nth-child(6),
    .table td:nth-child(7) {
        display: none;
    }
}

/* Hide non-essential columns on small screens */
@media (max-width: 768px) {
    .table th:nth-child(n+6):not(:last-child),
    .table td:nth-child(n+6):not(:last-child) {
        display: none;
    }
    
    .table th:nth-child(1),
    .table th:nth-child(2), 
    .table th:nth-child(3),
    .table th:nth-child(4),
    .table th:last-child,
    .table td:nth-child(1),
    .table td:nth-child(2),
    .table td:nth-child(3), 
    .table td:nth-child(4),
    .table td:last-child {
        display: table-cell;
    }
}

@media (max-width: 576px) {
    .table th:nth-child(n+4):not(:last-child),
    .table td:nth-child(n+4):not(:last-child) {
        display: none;
    }
    
    .table th:nth-child(1),
    .table th:nth-child(2), 
    .table th:nth-child(3),
    .table th:last-child,
    .table td:nth-child(1),
    .table td:nth-child(2),
    .table td:nth-child(3),
    .table td:last-child {
        display: table-cell;
    }
}


/* Expandable row styles - only when columns are hidden */
@media (max-width: 1199px) {
    .expandable-row {
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .expandable-row:hover {
        background-color: rgba(0, 123, 255, 0.1) !important;
    }
    
    /* Style for expanded main row */
    .expandable-row.expanded {
        background-color: rgba(0, 123, 255, 0.05) !important;
        border-left: 4px solid #007bff !important;
    }
}

/* Disable expandable functionality on large screens where all columns are visible */
@media (min-width: 1200px) {
    .expandable-row {
        cursor: default;
    }
    
    .expandable-row:hover {
        background-color: transparent;
    }
    
    .expanded-details {
        display: none !important;
    }
}

.expanded-details {
    background-color: #f8f9fa;
    border-left: 3px solid #007bff;
}

.expanded-details-content {
    padding: 0.5rem 1rem;
    background: white;
}

.detail-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important;
    gap: 0.5rem !important;
    padding: 0.25rem 0 !important;
    width: 100% !important;
}

.detail-item {
    display: flex !important;
    flex-direction: column !important;
    padding: 0.1rem 0 !important;
    box-sizing: border-box !important;
}

.detail-label {
    font-weight: 600;
    color: #495057 !important;
    font-size: 0.8rem !important;
    margin-bottom: 0.1rem !important;
    line-height: 1.2 !important;
}

.detail-value {
    font-size: 0.85rem !important;
    color: #212529 !important;
    word-break: break-word;
    line-height: 1.2 !important;
}

/* Responsive detail content */
.detail-missing-only {
    display: block;
}

/* On large screens (1000px-1199px), show only Year and Color in details */
@media (max-width: 1199px) and (min-width: 992px) {
    /* Show only Year and Color for large screens */
    .detail-missing-only .detail-item:nth-child(1), /* Year */
    .detail-missing-only .detail-item:nth-child(2)  /* Color */
    {
        display: flex;
    }
    
    .detail-missing-only .detail-item:nth-child(n+3) {
        display: none;
    }
}

/* On medium screens (769px-991px), show Year, Color, and Prices in details */
@media (max-width: 991px) and (min-width: 769px) {
    /* Show Year, Color, and Price Records for medium screens */
    .detail-missing-only .detail-item:nth-child(1), /* Year */
    .detail-missing-only .detail-item:nth-child(2), /* Color */
    .detail-missing-only .detail-item:nth-child(3)  /* Price Records */
    {
        display: flex;
    }
    
    .detail-missing-only .detail-item:nth-child(n+4) {
        display: none;
    }
}

/* On medium screens (≤768px), show only missing columns in details */
/* Hidden columns: Year, Color, Prices, 100% Price, 70% Price, 40% Price, Override */
@media (max-width: 768px) {
    /* Adjust detail grid for smaller screens */
    .detail-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
        gap: 0.4rem !important;
    }
    
    /* Update missing details for medium screens */
    .detail-missing-only .detail-item:nth-child(1), /* Year */
    .detail-missing-only .detail-item:nth-child(2), /* Color */
    .detail-missing-only .detail-item:nth-child(3), /* Price Records */
    .detail-missing-only .detail-item:nth-child(4), /* 100% Price */
    .detail-missing-only .detail-item:nth-child(5), /* 70% Price */
    .detail-missing-only .detail-item:nth-child(6), /* 40% Price */
    .detail-missing-only .detail-item:nth-child(7)  /* Has Override */
    {
        display: flex;
    }
}

/* On small screens (≤576px), show only most essential missing info */
/* Hidden columns: Storage, Year, Color, Prices, 100% Price, 70% Price, 40% Price, Override */
@media (max-width: 576px) {
    .detail-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.3rem !important;
    }
    
    .expanded-details-content {
        padding: 0.4rem 0.75rem !important;
    }
    
    .detail-item {
        padding: 0.05rem 0 !important;
    }
    
    .detail-label {
        font-size: 0.75rem !important;
    }
    
    .detail-value {
        font-size: 0.8rem !important;
    }
    
    /* Show only pricing info on very small screens */
    .detail-missing-only .detail-item:nth-child(1), /* Year */
    .detail-missing-only .detail-item:nth-child(2)  /* Color */
    {
        display: none;
    }
    
    .detail-missing-only .detail-item:nth-child(3), /* Price Records */
    .detail-missing-only .detail-item:nth-child(4), /* 100% Price */
    .detail-missing-only .detail-item:nth-child(5), /* 70% Price */
    .detail-missing-only .detail-item:nth-child(6), /* 40% Price */
    .detail-missing-only .detail-item:nth-child(7)  /* Has Override */
    {
        display: flex;
    }
}

/* Three-dot menu styles */
.actions-dropdown {
    position: relative;
    display: inline-block;
    /* Ensure dropdown container doesn't get clipped */
    overflow: visible;
}

/* Create strong stacking context when menu is shown */
.actions-dropdown:has(.actions-menu.show) {
    z-index: 999999;
    position: relative;
    isolation: isolate;
}

/* Fallback for browsers that don't support :has() */
.actions-dropdown.menu-open {
    z-index: 999999;
    position: relative;
    isolation: isolate;
}

.three-dots-btn {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: #6c757d;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.three-dots-btn:hover {
    background-color: #e9ecef;
    color: #495057;
}

.three-dots-btn i {
    font-size: 1rem;
}

/* Dropdown menu */
.actions-menu {
    position: absolute;
    right: 0;
    top: 100%;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.3);
    z-index: 10000000; /* Increased z-index for better layering */
    min-width: 140px;
    display: none;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 2px;
    isolation: isolate;
    transform: translateZ(0);
    /* Ensure dropdown is always visible */
    pointer-events: auto;
    white-space: nowrap;
}

.actions-menu.show {
    display: block;
}

.actions-menu-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    color: #212529;
    text-decoration: none;
    border: none;
    background: none;
    text-align: left;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

.actions-menu-item:hover {
    background-color: #f8f9fa;
    color: #16181b;
}

.actions-menu-item:first-child {
    border-radius: 0.375rem 0.375rem 0 0;
}

.actions-menu-item:last-child {
    border-radius: 0 0 0.375rem 0.375rem;
}

.actions-menu-item i {
    margin-right: 0.5rem;
    width: 14px;
}

/* Ensure table cells don't clip dropdown menus */
.table td:last-child {
    overflow: visible;
    position: relative;
}

/* Improve table responsive behavior for dropdowns */
.table-responsive-custom {
    overflow: visible;
}

/* Ensure card body allows context menus */
.card-body {
    position: relative;
    overflow: visible;
}

/* Ensure card container doesn't clip context menus */
.card {
    overflow: visible;
}

/* Ensure table container allows context menus to overflow */
.table-responsive-custom {
    overflow: visible;
    position: static;
}

/* Fix for dropdown menus being clipped with few records - removed auto positioning 
   to let JavaScript handle it dynamically */

/* Additional fixes for context menu visibility */
.main-content,
.container-fluid,
.row,
.col-12 {
    position: relative;
    overflow: visible;
}

/* Ensure table and its containers allow dropdowns */
#variantsTable,
.table,
.table-responsive,
.table-responsive-custom {
    position: static;
    overflow: visible !important;
}

/* Ensure main content container doesn't clip dropdowns */
.container-fluid {
    overflow: visible;
}

/* Ensure card containers don't interfere with dropdowns */
.card .card-body {
    overflow: visible;
    position: relative;
    z-index: auto;
}

/* Strong stacking context for active menu rows */
.table tbody tr.menu-active {
    position: relative;
    z-index: 999999;
}

/* Special handling for tables with few rows - ensure last row menu is visible */
.table tbody:has(tr:nth-child(-n+5)) tr:last-child .actions-menu {
    /* Give extra room for menus in sparse tables */
    z-index: 20000000;
}

/* Fallback for browsers without :has() support */
.table tbody tr:last-child .actions-menu {
    z-index: 15000000;
}

/* Global body class when any menu is open to manage stacking */
body.menu-open {
    overflow-x: visible;
}

/* Ensure table wrapper doesn't clip */
.table-responsive {
    overflow: visible !important;
}

/* Force table to allow context menus */
#variantsTable {
    position: static;
}

#variantsTable tbody {
    position: static;
}

#variantsTable tbody tr {
    position: static;
}

/* Ensure the last column can show dropdowns */
#variantsTable tbody tr td:last-child {
    position: relative;
    overflow: visible;
    z-index: 1;
}

/* Fix for dark theme dropdown menu */
[data-bs-theme="dark"] .actions-menu {
    background: #2d3748;
    border-color: #4a5568;
    color: #e2e8f0;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] .actions-menu-item {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .actions-menu-item:hover {
    background-color: #4a5568;
    color: #ffffff;
}

/* Prevent menu flickering on hover - but ensure button remains clickable */
.actions-dropdown:hover .actions-menu:not(.show) {
    pointer-events: none;
}

.actions-menu.show {
    pointer-events: all;
}

/* Ensure the three-dots button always remains clickable */
.three-dots-btn {
    pointer-events: auto !important;
    position: relative;
    z-index: 50000000;
}

/* Prevent other table row interactions when menu is open */
.table tbody:has(.actions-menu.show) tr:not(:has(.actions-menu.show)) {
    pointer-events: none;
    opacity: 0.7;
}

/* More specific fallback for table row interactions when menu is open */
.table tbody tr.menu-active {
    position: relative;
    z-index: 30000000;
}

.table tbody tr.menu-active * {
    pointer-events: auto;
}

/* Fallback for browsers without :has() support */
body.menu-open .table tbody tr:not(.menu-active) {
    pointer-events: none;
    opacity: 0.7;
}

body.menu-open .table tbody tr:hover {
    transform: none !important;
    background-color: transparent !important;
}

body.menu-open .table tbody tr:not(.menu-active):hover {
    background-color: transparent !important;
    pointer-events: none;
}