/* Styles for field analysis */
.plot-row, .owner-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

.plot-row:hover, .owner-row:hover {
    background-color: rgba(40, 167, 69, 0.1);
}

.table-responsive {
    max-height: 300px;
    overflow-y: auto;
}

/* Custom scrollbar for tables */
.table-responsive::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Collapsible sections */
[data-bs-toggle="collapse"] {
    padding: 8px;
    border-radius: 4px;
    background-color: rgba(0,0,0,0.02);
}

[data-bs-toggle="collapse"]:hover {
    background-color: rgba(0,0,0,0.05);
}

[data-bs-toggle="collapse"] .bi {
    transition: transform 0.2s;
}

[data-bs-toggle="collapse"][aria-expanded="true"] .bi {
    transform: rotate(180deg);
}

/* Highlight for selected rows */
.plot-row.selected, .owner-row.selected {
    background-color: rgba(40, 167, 69, 0.2);
    font-weight: bold;
}

/* Modal accessibility improvements */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

.modal:focus {
    outline: none; /* Remove outline but maintain focus capability */
}

.modal-dialog {
    position: relative;
    margin: 1.75rem auto;
    pointer-events: none;
}

.modal-content {
    pointer-events: auto;
    outline: 0; /* Remove outline but maintain focus capability */
}

/* Ensure buttons are keyboard-navigable */
.btn:focus, 
.form-check-input:focus,
.btn-close:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Ensure focus is visible for keyboard users */
:focus-visible {
    outline: 3px solid #0d6efd !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25) !important;
}

/* Inert element handling */
[inert] {
    pointer-events: none;
    cursor: default;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Modal focus handling updates */
.modal-dialog:focus,
.modal-content:focus,
.modal:focus {
    outline: none;
}

/* Add CSS smooth transitions for focus visibility */
button:focus-visible, 
input:focus-visible, 
select:focus-visible, 
textarea:focus-visible {
    transition: outline-color 0.15s ease-in-out;
}

/* Fix for Bootstrap modals */
.modal-open {
    overflow: hidden;
    padding-right: 0 !important; /* Prevent page shift */
}

/* Additional modal accessibility improvements */
.modal-dialog {
    margin: 1.75rem auto !important;
    max-width: 95% !important; /* More responsive on mobile */
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: 500px !important; /* Standard size for desktop */
    }
}

/* Fix for ARIA hidden warning */
.modal.fade {
    transition: opacity 0.15s linear;
}

.modal.fade:not(.show) {
    opacity: 0;
    /* Don't use aria-hidden, use visibility instead */
    visibility: hidden;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

/* Updated legend styles for better visibility */
.info.legend {
    padding: 10px !important;
    background-color: white !important;
    border-radius: 5px !important;
    box-shadow: 0 0 5px rgba(0,0,0,0.3) !important;
    font-size: 14px;
    line-height: 1.5;
}

.info.legend h6 {
    margin-top: 0;
    margin-bottom: 10px;
    font-weight: bold;
}

/* Style for the perfect match alert */
.info.legend .alert-success {
    background-color: rgba(25, 135, 84, 0.15);
    border-color: rgba(25, 135, 84, 0.3);
    color: #155724;
}

/* Improved analysis results display */
.analysis-results .alert-success {
    background-color: rgba(25, 135, 84, 0.15);
    border-color: rgba(25, 135, 84, 0.3);
    color: #155724;
}

/* Improved loading overlay for longer operations */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.loading-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.loading-spinner-container {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    max-width: 90%;
    width: 300px;
}

.loading-text {
    margin-top: 10px;
    color: #333;
    font-weight: bold;
    white-space: normal; /* Allow text wrapping */
    word-break: break-word; /* Allow breaking at any point if needed */
}

/* Add a progress indicator style */
.loading-progress {
    width: 100%;
    height: 8px;
    background-color: #f0f0f0;
    border-radius: 4px;
    margin-top: 10px;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background-color: #28a745;
    width: 0%;
    transition: width 0.3s ease;
}

/* No plots found indicator */
.no-plots-message {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
    color: #721c24;
}

.no-plots-message h5 {
    margin-top: 0;
    margin-bottom: 10px;
}

.no-plots-message ul {
    margin-bottom: 0;
}

/* Custom alert style for import suggestion */
.custom-alert-import {
    background-color: #f8f9fa;
    border-left: 4px solid #28a745;
    padding: 15px;
    margin-bottom: 20px;
    position: relative;
}

.custom-alert-import .alert-icon {
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 24px;
    color: #28a745;
}

.custom-alert-import .alert-content {
    margin-left: 40px;
}

.custom-alert-import h5 {
    margin-top: 0;
    color: #28a745;
}

.custom-alert-import p {
    margin-bottom: 10px;
}

.custom-alert-import .btn {
    margin-top: 5px;
}

/* Shadow styles */
.field-boundary-layer {
    filter: drop-shadow(2px 2px 3px rgba(0, 0, 0, 0.5));
}

/* Prevent text selection on map elements */
.leaflet-container {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Set proper cursor for interactive elements */
.leaflet-interactive {
    cursor: pointer !important;
}

/* Remove outline on click */
.leaflet-interactive:focus {
    outline: none !important;
}

/* Prevent blue highlight on mobile */
.leaflet-container {
    -webkit-tap-highlight-color: transparent;
}

/* Contractor Analysis Styles */
.contractor-analysis-item {
    border: 1px solid #e0e6ed;
    border-radius: 8px;
    margin-bottom: 12px;
    transition: all 0.2s ease;
}

.contractor-analysis-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.1);
}

.contractor-main-info {
    flex: 1;
}

.contractor-stats .stat-card {
    background: rgba(0, 123, 255, 0.05);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    border: 1px solid rgba(0, 123, 255, 0.1);
}

.contractor-stats .stat-value {
    font-size: 1.1em;
    font-weight: 600;
    color: #007bff;
}

.contractor-stats .stat-label {
    font-size: 0.75em;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.best-worst-fields .field-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}

.best-field {
    color: #28a745;
}

.worst-field {
    color: #ffc107;
}

/* Contractor Detail Card */
.contractor-detail-card .card {
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.contractor-detail-card .card-header {
    background: linear-gradient(45deg, #007bff, #0056b3);
    color: white;
    border-bottom: none;
}

.contractor-detail-card .stat-card {
    background: rgba(0, 123, 255, 0.05);
    border: 1px solid rgba(0, 123, 255, 0.2);
    border-radius: 8px;
    padding: 15px;
    transition: all 0.2s ease;
}

.contractor-detail-card .stat-card:hover {
    background: rgba(0, 123, 255, 0.1);
    transform: translateY(-2px);
}

.contractor-detail-card .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.contractor-detail-card .stat-label {
    font-size: 0.8rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Contractor Summary Toast */
.contractor-summary-toast {
    min-width: 350px;
    max-width: 400px;
}

.contractor-summary-toast .toast-header {
    background: linear-gradient(45deg, #007bff, #0056b3);
    color: white;
    border-bottom: none;
}

.contractor-summary-toast .toast-body {
    background: white;
    border: 1px solid #dee2e6;
    border-top: none;
}

.best-worst-summary {
    font-size: 0.9rem;
}

.best-worst-summary .badge {
    font-size: 0.75rem;
}

/* Analysis Tab Content */
.contractor-analysis-section {
    background: rgba(248, 249, 250, 0.5);
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    margin-top: 15px;
}

.contractor-analysis-section h6 {
    color: #495057;
    margin-bottom: 15px;
    font-weight: 600;
}

.contractor-analysis-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.contractor-analysis-buttons .btn {
    flex: 1;
    min-width: 140px;
    font-size: 0.875rem;
}

/* Fields list in contractor details */
.fields-list .table th {
    background-color: #f8f9fa;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 8px 12px;
}

.fields-list .table td {
    padding: 8px 12px;
    font-size: 0.875rem;
}

.fields-list .table tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .contractor-analysis-buttons {
        flex-direction: column;
    }
    
    .contractor-analysis-buttons .btn {
        min-width: auto;
    }
    
    .contractor-stats .row {
        text-align: center;
    }
    
    .contractor-summary-toast {
        min-width: 300px;
        max-width: 350px;
    }
}

@media (max-width: 576px) {
    .contractor-detail-card .stat-card {
        padding: 10px;
    }
    
    .contractor-detail-card .stat-value {
        font-size: 1.2rem;
    }
    
    .contractor-stats .stat-value {
        font-size: 1rem;
    }
}

/* Rent Analysis Styles */
.rent-analysis-section {
    background: rgba(52, 58, 64, 0.03);
    border: 1px solid rgba(52, 58, 64, 0.1);
    border-radius: 6px;
    padding: 12px;
    margin-top: 10px;
}

.rent-section-title {
    font-size: 0.9rem;
    color: #495057;
    margin-bottom: 8px;
    font-weight: 600;
}

.rent-stat-mini {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.rent-value {
    font-size: 1rem;
    font-weight: 600;
    color: #007bff;
}

.rent-label {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.rent-distribution {
    margin: 8px 0;
}

.rent-progress-container {
    margin-bottom: 6px;
}

.rent-progress {
    display: flex;
    height: 8px;
    border-radius: 4px;
    background-color: #e9ecef;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.rent-segment {
    transition: all 0.3s ease;
}

.rent-segment.own-fields {
    background: linear-gradient(45deg, #28a745, #20c997);
}

.rent-segment.foreign-fields {
    background: linear-gradient(45deg, #fd7e14, #ffc107);
}

.rent-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    margin-top: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-color {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

.legend-color.own-fields-color {
    background: linear-gradient(45deg, #28a745, #20c997);
}

.legend-color.foreign-fields-color {
    background: linear-gradient(45deg, #fd7e14, #ffc107);
}

.rent-pie-chart {
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

.rent-pie-svg {
    filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.1));
}

/* Hover effects for rent analysis */
.rent-segment:hover {
    opacity: 0.8;
    cursor: pointer;
}

.rent-pie-svg path:hover {
    opacity: 0.8;
    cursor: pointer;
}

/* Responsive adjustments for rent analysis */
@media (max-width: 768px) {
    .rent-stat-mini .rent-value {
        font-size: 0.9rem;
    }
    
    .rent-legend {
        font-size: 0.65rem;
    }
    
    .rent-pie-chart {
        margin-top: 6px;
    }
}

@media (max-width: 576px) {
    .rent-analysis-section {
        padding: 8px;
    }
    
    .rent-section-title {
        font-size: 0.8rem;
    }
    
    .rent-stat-mini {
        padding: 4px;
    }
    
    .rent-value {
        font-size: 0.85rem;
    }
    
    .rent-label {
        font-size: 0.65rem;
    }
}
