/* ippiPlot - Main Styles */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
}

.navbar-brand {
    font-weight: 600;
}

.card {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: none;
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
    font-weight: 500;
}

#deedTextInput {
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.list-group-item {
    transition: background-color 0.2s;
}

.list-group-item:hover {
    background-color: #f8f9fa;
}

.deed-call-item {
    font-size: 14px;
    transition: background-color 0.2s;
}

.deed-call-item:hover {
    background-color: #f8f9fa;
}

#plotContainer {
    position: relative;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0;
    width: 100%;
    height: max(400px, 72vh);
    min-width: 0;
    overflow: hidden;
}

#plotCanvas {
    background-color: white;
    cursor: crosshair;
    display: block;
    border: 0;
    margin: 0;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#plotWorkspace > .card-body { padding: 8px; min-width: 0; }
#plotWorkspace.map-expanded {
    position: fixed;
    inset: 8px;
    z-index: 1040;
    margin: 0;
}
#plotWorkspace.map-expanded > .card-body {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
#plotWorkspace.map-expanded #plotContainer {
    flex: 1;
    height: auto;
    min-height: 0;
}
body.map-expanded { overflow: hidden; }

.badge {
    font-weight: 500;
}

.btn-group .btn {
    border-radius: 0;
}

.btn-group .btn:first-child {
    border-top-left-radius: 0.25rem;
    border-bottom-left-radius: 0.25rem;
}

.btn-group .btn:last-child {
    border-top-right-radius: 0.25rem;
    border-bottom-right-radius: 0.25rem;
}

.form-check-input {
    cursor: pointer;
}

.form-check-label {
    cursor: pointer;
    user-select: none;
}

/* Loading spinner */
.spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

/* Tooltips */
.tooltip {
    font-size: 12px;
}

/* Modal improvements */
.modal-header {
    background-color: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

.modal-footer {
    background-color: #f8f9fa;
    border-top: 2px solid #dee2e6;
}

/* Table styling */
.table-hover tbody tr:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}

/* Status indicators */
#connectionStatus {
    min-width: 100px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
    100% {
        opacity: 1;
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .col-md-4, .col-md-8 {
        margin-bottom: 1rem;
    }
    
    #plotContainer {
        touch-action: none;
        -webkit-overflow-scrolling: touch;
    }
    
    
    /* Larger touch targets for mobile */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 15px;
    }
    
    .form-check-input {
        width: 24px;
        height: 24px;
        margin-top: 0;
    }
    
    .form-check-label {
        padding-left: 10px;
        line-height: 24px;
    }
    
    /* Improve mobile navigation */
    .navbar {
        padding: 0.75rem 1rem;
    }
    
    .navbar-brand {
        font-size: 1rem;
    }
    
    /* Stack buttons on mobile */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        border-radius: 0.25rem !important;
        margin-bottom: 5px;
    }
    
    /* Improve modal on mobile */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    /* Interactive mode button */
    #interactiveModeBtn {
        width: 100%;
        margin-top: 10px;
    }
}

/* Print styles */
@media print {
    .navbar,
    .btn,
    .form-check,
    .card-header {
        display: none !important;
    }
    
    #plotContainer {
        border: none;
        box-shadow: none;
    }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

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

/* Alert positioning */
.alert {
    min-width: 300px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Color picker styling */
input[type="color"] {
    width: 50px;
    height: 38px;
    padding: 2px;
    cursor: pointer;
}

/* Tract visibility checkbox */
.form-check-input:checked {
    background-color: #28a745;
    border-color: #28a745;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3em;
    color: white;
}

/* Touch-friendly enhancements */
@supports (-webkit-touch-callout: none) {
    /* iOS specific styles */
    #plotCanvas {
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    input, textarea, select {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Improve touch interaction feedback */
.tract-item:active,
.deed-call-item:active,
.btn:active {
    transform: scale(0.98);
    opacity: 0.8;
}

/* Better scrolling for mobile */
.card-body {
    -webkit-overflow-scrolling: touch;
}

/* Pinch zoom indicator */
.pinch-zoom-hint {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

/* Zoom Controls Styling */
#plotZoomControls {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#plotZoomControls button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    transition: background-color 0.2s, transform 0.1s;
}

#plotZoomControls button:active {
    transform: scale(0.95);
    background-color: #f0f0f0 !important;
}

#plotZoomControls button:hover {
    background-color: #f8f8f8;
}

/* Zoom slider styling */
#zoomSlider {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    outline: none;
    touch-action: manipulation;
}

#zoomSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
}

#zoomSlider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #007bff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Mobile-specific zoom control adjustments */
@media (max-width: 768px) {
    #plotZoomControls {
        top: 5px;
        right: 5px;
        padding: 8px;
    }
    
    #plotZoomControls button {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    #zoomSlider {
        width: 140px;
    }
    
    #zoomSlider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    #zoomSlider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
}

.pinch-zoom-hint.visible {
    opacity: 1;
}

/* Label Clustering Styles */
.label-cluster-popup {
    position: fixed;
    background: white;
    border: 2px solid #4682B4;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 280px;
    max-height: 350px;
    overflow-y: auto;
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.label-cluster-popup .cluster-popup-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 25px;
    height: 25px;
    line-height: 20px;
    text-align: center;
    transition: color 0.2s;
}

.label-cluster-popup .cluster-popup-close:hover {
    color: #000;
}

.label-cluster-content {
    margin-top: 10px;
}

.cluster-type-group {
    margin-bottom: 15px;
}

.cluster-type-group:last-child {
    margin-bottom: 0;
}

.cluster-type-group h4 {
    font-size: 13px;
    font-weight: 600;
    color: #4682B4;
    margin-bottom: 5px;
    padding-bottom: 3px;
    border-bottom: 1px solid #e0e0e0;
}

.cluster-type-group ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.cluster-type-group li {
    padding: 3px 8px;
    font-size: 12px;
    color: #333;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.cluster-type-group li:hover {
    background: #f5f5f5;
    border-left-color: #4682B4;
}

/* Cluster indicator on canvas */
.cluster-indicator {
    cursor: pointer;
}
/* Deed ordering: a dedicated touch/mouse handle leaves fields and map movement alone. */
.batch-drag-handle { cursor: grab; touch-action: none; user-select: none; }
.batch-drag-handle:active { cursor: grabbing; }
#batchRows .batch-dragging { opacity: .55; }
#batchRows .batch-drop-before { box-shadow: 0 -4px 0 #0d6efd; }
#batchRows .batch-drop-after { box-shadow: 0 4px 0 #0d6efd; }

/* Keep the integrated deed list bounded so calls and the map stay usable. */
#batchRows { max-height: 460px; overflow-y: auto; overscroll-behavior: contain; padding: 5px; }
#batchRows .form-label { display: block; }
#batchRows .batch-preview { overflow-wrap: anywhere; }
#batchRows .tract-name { overflow-wrap: anywhere; }

/* One compact row per tract; letters are fields, never parent rows. */
#batchRows .batch-tract-row { display: flex; align-items: center; gap: 5px; padding: 7px; }
.batch-tract-controls { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.batch-tract-controls .batch-drag-handle { padding: 2px; }
.batch-tract-controls .tract-letter { width: 42px; text-align: center; padding: 3px; }
#batchRows .batch-tract-row > .d-flex { flex: 1; min-width: 0; }
#batchRows .batch-tract-row small { display: none; }
#batchRows .batch-tract-row .badge { font-size: 9px; }

/* Keep tract review inside the sidebar without changing map dimensions. */
.tract-editor-fields { max-height: 52vh; overflow-y: auto; overflow-x: hidden; padding: 0 4px 4px; }
#tractEditorPanel .form-label { margin-bottom: .25rem; }
#tractEditorPanel .form-control { min-width: 0; }
#tractListActions[hidden] { display: none !important; }

/* Native disclosure keeps pasted deed text intact while reclaiming sidebar space. */
#deedTextPanel > summary { cursor: pointer; display: list-item; list-style-position: inside; }
#deedTextPanel:not([open]) > summary { border-bottom: 0; border-radius: inherit; }

/* Alignment controls float over the plat so opening them never resizes its camera. */
#plotContainer > .parcel-background-controls {
    position: absolute;
    z-index: 1001;
    top: .5rem;
    left: .5rem;
    max-height: calc(100% - 1rem);
    max-width: min(27rem, calc(100% - 1rem));
    overflow: auto;
    padding: .6rem;
    border: 1px solid #9bb2c7;
    border-radius: .35rem;
    background: #fff;
    box-shadow: 0 2px 8px #0002;
    font-size: .875rem;
}
.parcel-background-controls summary { cursor: pointer; font-weight: 600; color: #174a78; }
.parcel-background-controls fieldset { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .6rem 0; }
.parcel-background-controls fieldset legend,
.parcel-background-controls fieldset p { grid-column: 1 / -1; font-size: inherit; }
.parcel-background-controls fieldset label { display: flex; flex-direction: column; min-width: 0; }
.parcel-background-controls input,
.parcel-background-controls select { max-width: 100%; }
.parcel-background-controls p { margin: .5rem 0; }
.parcel-background-controls [data-selected-point] { grid-column: 1 / -1; }
.parcel-background-controls button {
    border: 1px solid #9bb2c7;
    border-radius: .25rem;
    background: #f5f8fb;
    color: #174a78;
    padding: .3rem .5rem;
}
/* Screen privacy after session changes; unsaved editor state remains in memory. */
html.ippiplot-session-locked body > :not(#editorSignInNotice) { display: none !important; }
