:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --bg-dark: #0f172a;
    --glass-bg: rgba(15, 23, 42, 0.75);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* Glassmorphism Header */
.glass-header {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    width: 90%;
    max-width: 800px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo svg {
    color: var(--primary);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.logo span {
    font-weight: 300;
    color: var(--text-muted);
}

.badge {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
}

/* Map Container */
main {
    flex: 1;
    height: 100%;
}

#map {
    height: 100%;
    width: 100%;
    z-index: 1;
}

/* Leaflet Customizations for Premium Look */
.leaflet-control-layers {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid var(--glass-border) !important;
    border-radius: 12px !important;
    color: var(--text-main) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
    padding: 8px !important;
}

.leaflet-control-layers-list {
    font-family: 'Inter', sans-serif;
}

.leaflet-control-layers-separator {
    border-top: 1px solid var(--glass-border) !important;
    margin: 10px 0 !important;
}

.leaflet-bar {
    border: none !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-bar a {
    background-color: var(--glass-bg) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--glass-border) !important;
    backdrop-filter: blur(12px) !important;
}

.leaflet-bar a:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

/* Popup Customization */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: var(--glass-bg) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
    border-radius: 12px !important;
}

.leaflet-popup-content {
    font-family: 'Inter', sans-serif;
    margin: 16px;
}

.leaflet-popup-content h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--primary);
    font-weight: 600;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 8px;
}

.popup-table {
    width: 100%;
    border-collapse: collapse;
}

.popup-table th, .popup-table td {
    padding: 6px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.popup-table th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    width: 40%;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Animations */
@keyframes slideDown {
    from { transform: translate(-50%, -20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.glass-header {
    animation: slideDown 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* PDF Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease, visibility 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.modal-content {
    background: var(--bg-dark);
    width: 90%;
    max-width: 1000px;
    height: 85vh;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #ef4444;
}

.modal-body {
    flex: 1;
    background: #525659; /* Standard PDF viewer background */
}

#pdf-iframe {
    width: 100%;
    height: 100%;
    display: block;
}

/* Button in popup */
.ficha-btn {
    display: inline-block;
    margin-top: 4px;
    padding: 6px 14px;
    background-color: var(--primary);
    color: white !important;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    border: none;
}

.ficha-btn:hover {
    background-color: var(--primary-dark);
}

/* Coordinates Control */
.coordinates-control {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 6px 12px;
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    font-family: 'Inter', sans-serif;
    pointer-events: none; /* Allows clicking through it if necessary */
    margin-bottom: 20px !important;
    margin-left: 20px !important;
}

/* Floating Logo */
.floating-logo {
    position: absolute;
    top: 20px;
    left: 20px;
    height: 100px; /* Increased size */
    width: auto;
    z-index: 2000;
    object-fit: contain;
    background: transparent;
    pointer-events: none;
}

/* Legend Control */
.legend-control {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 16px;
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    font-family: 'Inter', sans-serif;
    margin-bottom: 20px !important;
    margin-right: 20px !important;
}

.legend-control h4 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: var(--primary);
    font-weight: 600;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-right: 10px;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.5);
}

.legend-line {
    width: 16px;
    height: 4px;
    margin-right: 8px;
    display: inline-block;
}

.legend-poly {
    width: 14px;
    height: 14px;
    margin-right: 10px;
    display: inline-block;
    border: 2px solid #a855f7;
    background-color: rgba(168, 85, 247, 0.3);
}

/* Floating Sidebar Filters */
.floating-sidebar {
    position: absolute;
    top: 140px; /* Below the logo */
    left: 20px;
    width: 280px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
    color: var(--text-main);
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    font-family: 'Inter', sans-serif;
}

.floating-sidebar h3 {
    margin: 0 0 16px 0;
    font-size: 1.1rem;
    color: var(--primary);
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 8px;
}

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

.filter-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
    padding: 8px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

/* Custom Scrollbar for the checkbox groups */
.checkbox-group::-webkit-scrollbar {
    width: 6px;
}
.checkbox-group::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}
.checkbox-group::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}
.checkbox-group::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.4);
}

.check-container {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    font-weight: 400;
}

.check-container input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    accent-color: var(--primary);
}

.filter-stats {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px dashed var(--glass-border);
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.filter-stats span {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

/* Login Modal */
.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: url('https://images.unsplash.com/photo-1451187580459-43490279c0fa?q=80&w=2072&auto=format&fit=crop') no-repeat center center;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
}

.login-box {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 40px;
    width: 350px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
}

.login-logo {
    height: 60px;
    margin-bottom: 20px;
}

.login-box h2 {
    margin-bottom: 10px;
    color: var(--primary);
    font-size: 1.5rem;
}

.login-box p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 25px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-form input {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.login-form input:focus {
    border-color: var(--primary);
}

.login-form button {
    padding: 12px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s;
    margin-top: 5px;
}

.login-form button:hover {
    background: var(--primary-dark);
}

.error-msg {
    color: #ef4444 !important;
    font-size: 0.85rem !important;
    margin-bottom: 0 !important;
    margin-top: -5px;
}
