* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f8f9fa;
    height: 100vh;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    position: relative;
}

.header h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.header .subtitle {
    margin: 5px 0 0 0;
    opacity: 0.9;
    font-size: 14px;
}

.main-container {
    display: flex;
    height: calc(100vh - 80px);
}

.sidebar {
    width: 400px;
    background: white;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    background: #ecf0f1;
    border-bottom: 1px solid #ddd;
}

.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    margin: 10px 0;
    width: 100%;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-export, .btn-import {
    background: #27ae60;
    color: white;
}

.btn-export:hover, .btn-import:hover {
    background: #229954;
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
    width: auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
}

.stat-card {
    background: white;
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.stat-card.clickable:hover {
    background: #e3f2fd;
    border-color: #2196f3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    cursor: pointer;
}

.stat-card.clickable:active {
    transform: translateY(0);
}

.stat-number { 
    font-size: 24px; 
    font-weight: bold; 
    color: #2c3e50; 
}

.stat-label { 
    font-size: 12px; 
    color: #7f8c8d; 
    margin-top: 4px; 
}

.search-bar {
    margin: 15px 20px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    width: calc(100% - 40px);
}

.filters {
    padding: 0 20px 15px;
    border-bottom: 1px solid #eee;
}

.filter-group {
    margin-bottom: 10px;
}

.filter-group label {
    display: block;
    font-size: 12px;
    color: #7f8c8d;
    margin-bottom: 5px;
}

.filter-group select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.snag-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.snag-item {
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

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

.snag-item.selected {
    background-color: #e3f2fd;
    border-left: 4px solid #2196f3;
}

.snag-item.no-location {
    border-left: 4px solid #ff9800;
}

.snag-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.snag-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

.snag-location {
    font-size: 13px;
    color: #7f8c8d;
    margin-bottom: 3px;
}

.snag-status {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-outstanding { 
    background: #ffebee; 
    color: #c62828; 
}

.status-completed { 
    background: #e8f5e8; 
    color: #2e7d32; 
}

.status-no-location { 
    background: #fff3e0; 
    color: #ef6c00; 
}

.snag-actions {
    display: flex;
    gap: 10px;
    padding: 0 20px 15px;
    opacity: 0;
    transition: opacity 0.2s;
}

.snag-item:hover .snag-actions {
    opacity: 1;
}

.action-btn {
    padding: 5px 10px;
    font-size: 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f8f9fa;
    border-color: #3498db;
    color: #3498db;
}

.what3words-badge {
    background: #3498db;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-family: monospace;
    margin-left: 5px;
}

.map-container {
    flex: 1;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
    position: relative; /* Added */
    z-index: 1; /* Added */
}

.legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
}

.legend h4 {
    margin: 0 0 10px 0;
    color: #2c3e50;
    font-size: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin: 6px 0;
    font-size: 12px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 8px;
}

.outstanding-marker { 
    background-color: #e74c3c; 
}

.completed-marker { 
    background-color: #27ae60; 
}

.map-info {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    max-width: 300px;
    font-size: 13px;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid #eee;
    background: #ecf0f1;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 9999; /* Increased from 2000 */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 0;
    border: none;
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    position: relative; /* Added */
    z-index: 10000; /* Added */
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    padding: 20px;
    background: #2c3e50;
    color: white;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.close {
    color: white;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
}

.close:hover {
    opacity: 0.8;
}

#snag-form, #notes-form {
    padding: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #3498db;
}

.coordinates-input {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
}

.modal-footer {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #eee;
    border-radius: 0 0 8px 8px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.notes-history {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 0 20px;
}

.note-item {
    background: #f8f9fa;
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    border-left: 3px solid #3498db;
}

.note-date {
    font-size: 11px;
    color: #7f8c8d;
    margin-bottom: 5px;
}

.note-text {
    font-size: 13px;
    color: #2c3e50;
}

/* Responsive */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    
    .map-container {
        height: 50vh;
    }
}

/* Custom marker styles */
.snag-marker {
    background-color: #e74c3c;
    width: 24px;
    height: 24px;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.snag-marker.completed {
    background-color: #27ae60;
}

.snag-marker:hover {
    transform: scale(1.2);
}

/* Image Gallery Styles */
.image-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.image-upload-area {
    border: 2px dashed #3498db;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    background-color: #f8f9fa;
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-upload-area:hover {
    background-color: #e3f2fd;
    border-color: #2196f3;
}

.image-upload-area.drag-over {
    background-color: #e3f2fd;
    border-color: #2196f3;
    border-style: solid;
}

.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.image-item {
    position: relative;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.2s ease;
}

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

.image-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    cursor: pointer;
}

.image-caption {
    padding: 10px;
    font-size: 0.9em;
    color: #2c3e50;
    background: #f8f9fa;
}

.image-caption input {
    width: 100%;
    border: 1px solid #ddd;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
}

.image-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    gap: 5px;
}

.image-delete-btn {
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
}

.image-delete-btn:hover {
    background: #c0392b;
}

.image-counter {
    background: #3498db;
    color: white;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 0.8em;
    margin-left: 5px;
}

/* Image Modal */
.image-viewer-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
}

.image-viewer-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    margin: auto;
    display: block;
    top: 50%;
    transform: translateY(-50%);
}

.image-viewer-caption {
    text-align: center;
    color: white;
    padding: 10px;
    font-size: 1.1em;
}

.image-viewer-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

.image-viewer-close:hover {
    color: #3498db;
}

/* File input styling */
input[type="file"] {
    display: none;
}

.upload-button {
    display: inline-block;
    padding: 8px 16px;
    background: #3498db;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.upload-button:hover {
    background: #2980b9;
}