/*
 * App Version: 1.0 (Sidebar Layout)
 * Reorganized by Aldebran for improved structure and maintainability.
 */

/* --- 1. GLOBAL STYLES & ROOT CONFIGURATION --- */

html, body {
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%; /* The JS will set the height on the HTML element */
    overflow: hidden;
    font-family: sans-serif;
}

/* Default Light Theme Styles */
body {
    display: flex;
    flex-direction: column; /* Mobile-first: stack header and map */
    background-color: #f9fafb; /* gray-50 */
    color: #1f2937; /* gray-800 */
}

/* Universal Scrollbar Styling */
/* For Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9; /* gray-100 */
}
::-webkit-scrollbar-thumb {
    background-color: #9ca3af; /* gray-400 */
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background-color: #6b7280; /* gray-500 */
}

/* For Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #9ca3af #f1f5f9; /* thumb track */
}


/* --- 2. MAIN LAYOUT & RESPONSIVENESS --- */

/* Mobile-First Containers */
#mobile-header {
    background-color: #ffffff;
    z-index: 50;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    flex-shrink: 0;
    border-bottom: 1px solid #e5e7eb;
}

#map-container {
    position: relative; /* Positioning context for the sidebar */
    flex-grow: 1; /* Fills remaining space */
    overflow: hidden;
}

#viewDiv {
    height: 100%;
    width: 100%;
}

.app-footer-base {
    background-color: #ffffff;
    z-index: 50;
    padding: 0.5rem 1rem;
    display: flex;
    font-size: 0.875rem;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.1);
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #e5e7eb;
}

#app-footer {
    flex-shrink: 0;
}

/* Sidebar (Mobile Hidden) */
#sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 320px;
    background-color: #ffffff;
    color: #1f2937;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    z-index: 60; /* Slides over everything */
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    border-right: 1px solid #e5e7eb; /* gray-200 */
}

#sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    padding: 1rem;
    flex-shrink: 0;
}

#sidebar-controls {
    display: flex;
    flex-direction: column;
    overflow: auto; /* Key for child scrolling */
    flex-grow: 1;
    min-height: 0; /* Key for child scrolling */
}

#analysis-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    overflow-y: auto;
    flex-shrink: 0; /* Don't shrink, let it scroll */
    border-bottom: 1px solid #e5e7eb;
}

#legend-controls {
    overflow-y: auto;
    flex-grow: 1; /* Take up remaining space */
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#sidebar-footer {
    display: none; /* Hidden on mobile by default */
}

#report-disclaimer {
	/* position: static; /* Move out of absolute positioning into the flow */
	width: 30%;      /* Reset width from w-1/3 */
	margin-top: 0rem;
}

@media (max-width: 768px) {
	#report-disclaimer {
		/* position: static; /* Move out of absolute positioning into the flow */
		margin-top: 0rem;
		max-height: 200px;
		overflow-y: auto;
	}
	#report-header-container .text-left {
		max-width: 70%; /* Wrap title if it gets too long */
	}
}

/* Desktop Layout (for screens 768px and wider) */
@media (min-width: 768px) {
    body {
        flex-direction: row; /* Side-by-side layout */
    }
    #mobile-header, #app-footer {
        display: none;
    }
    #sidebar {
        position: relative;
        transform: translateX(0);
        flex-shrink: 0;
        width: 350px;
        z-index: 20; /* Reset z-index */
    }
    #sidebar-footer {
        display: flex;
        flex-shrink: 0;
    }
    #map-container {
        display: flex;
    }
    #viewDiv {
        flex-grow: 1;
    }
}


/* --- 3. UI COMPONENTS --- */

/* Modals & Popups */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #ffffff;
    color: #1f2937;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    position: relative;
    max-width: 500px;
    width: 90%;
    display: flex;
    flex-direction: column;
    max-height: 95vh;
}

#results-popup .modal-content {
    max-width: 1000px;
    width: 95%;
}

/* Inputs & Search */
#species-select {
    background-color: #f3f4f6;
    color: #1f2937;
    border: 1px solid #d1d5db;
}

#unified-search-input {
	background-color: #e5e7eb;
	border: 1px solid #d1d5db;
}

.suggestions-container {
    position: relative;
}

.suggestions {
    position: absolute;
    width: 100%;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}
.suggestions li {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #e5e7eb;
    color: #1f2937;
}
.suggestions li:last-child {
    border-bottom: none;
}
.suggestions li:hover {
    background-color: #f3f4f6;
}

/* Buttons */
.icon-button {
    background: none;
    border: none;
    color: #6b7280; /* gray-500 */
    cursor: pointer;
    transition: color 0.2s;
}
.icon-button:hover {
    color: #1f2937; /* gray-800 */
}
.remove-parcel-button:hover {
    color: #ef4444; /* red-500 */
}

#info-button {
	background-color: #2563eb; /* blue-600 */
}
#info-button:hover {
	background-color: #1d4ed8; /* blue-700 */
}
#info-button:disabled {
	background-color: #9ca3af; /* gray-400 */
}

/* Parcel List */
#parcel-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background-color: #e5e7eb; /* gray-200 */
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

#parcel-input-area {
    background-color: #f9fafb;
    border: 1px solid #d1d5db;
    color: #1f2937;
}

/* Legends */
.legend-item:hover {
    background-color: #f3f4f6;
}

.species-legend-item {
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    padding: 0.75rem;
}
.species-legend-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.species-legend-item-title {
    font-weight: bold;
}
.species-legend-item-body {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	gap: 0.75rem;
	padding-top: 0.25rem;
}

/* Analyze User Layer Toggle Container */
#analyze-user-layer-container {
    background-color: #e5e7eb; /* gray-200 */
}

/* Report-Specific Components */
#printable-report {
    overflow-y: hidden;
    padding-right: 0;
    margin-right: 0;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
}
#report-map-image {
    width: 100%;
    background-color: #e5e7eb;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
	min-height:80px;
}
#report-map-image img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}
.report-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
.report-table th, .report-table td {
    border: 1px solid #d1d5db;
    padding: 0.75rem;
    text-align: left;
}
.report-table th {
    background-color: #f3f4f6;
    font-weight: bold;
}
.report-table tbody tr:nth-child(even) {
    background-color: #f9fafb;
}
.report-table td.text-right {
    text-align: right;
    font-family: monospace;
}
#species-report-table th:nth-child(1) { width: 30%; min-width: 180px; }
#species-report-table th:nth-child(n+2) { width: 17.5%; min-width: 100px; }

/* Metadata Popup (Prose) */
#info-description h4 {
    font-weight: bold;
    border-bottom: 1px solid #d1d5db;
    padding-bottom: 0.5rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}
#info-description h4:first-child {
    margin-top: 0;
}


/* --- 4. STATE & UTILITY CLASSES --- */

/* Sidebar State */
#sidebar.is-open {
    transform: translateX(0);
}

/* Drag & Drop State */
#viewDiv.drag-over::after {
    content: 'Drop file to load layer';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    color: white;
    background-color: rgba(0, 122, 194, 0.7);
    border: 4px dashed #007ac2;
    box-sizing: border-box;
    pointer-events: none;
    z-index: 100;
}

/* Loading Spinner */
.loading-spinner {
    border: 4px solid #e5e7eb;
    border-top: 4px solid #3b82f6;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: none;
    margin-left: 0.5rem;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Custom Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute; content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: #3b82f6; }
input:focus + .slider { box-shadow: 0 0 1px #3b82f6; }
input:checked + .slider:before { transform: translateX(20px); }

/* Slashed Icon Utility */
.fa-object-group-slashed {
  position: relative;
}
.fa-object-group-slashed::after {
  content: "/";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(20deg);
  font-size: 2.5em;
  color: inherit;
}


/* --- 5. DARK THEME OVERRIDES --- */

.dark body {
    background-color: #1e1e1e;
    color: #f0f0f0;
}

/* Layout */
.dark #mobile-header {
    background-color: #2a2a2a;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    border-bottom: 1px solid #444;
	color: #f0f0f0;
}
.dark #mobile-header h1 {
	color: #f0f0f0;
}
.dark .app-footer-base {
    background-color: #2a2a2a;
    color: #f0f0f0;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.5);
    border-top: 1px solid #444;
}
.dark #sidebar {
    background-color: #2a2a2a;
    color: #f0f0f0;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
    border-right: 1px solid #444;
}
.dark #sidebar-header {
    border-bottom: 1px solid #444;
}
@media (min-width: 768px) {
    .dark #sidebar-footer {
        border-top: 1px solid #444;
    }
}
.dark #analysis-controls {
    border-bottom: 1px solid #444;
}

/* Components */
.dark .modal-content {
    background-color: #2a2a2a;
    color: #f0f0f0;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}
.dark #species-select {
    background-color: #333;
    color: #f0f0f0;
    border: 1px solid #555;
}
.dark #info-button:disabled {
	background-color: #4b5563; /* gray-600 */
}
.dark #unified-search-input {
	background-color: #374151; /* gray-700 */
	border: 1px solid #4b5563; /* gray-600 */
}
.dark .suggestions {
    background-color: #2d3748;
    border: 1px solid #4a5568;
}
.dark .suggestions li {
    border-bottom: 1px solid #4a5568;
    color: #f0f0f0;
}
.dark .suggestions li:hover {
    background-color: #4a5568;
}
.dark #parcel-list li {
    background-color: #374151; /* gray-700 */
}
.dark .icon-button {
     color: #9ca3af; /* gray-400 */
}
.dark .icon-button:hover {
    color: #f0f0f0;
}
.dark #parcel-input-area {
    background-color: #1f2937;
    border: 1px solid #4b5563;
    color: #f0f0f0;
}
.dark #analyze-user-layer-container {
    background-color: #374151; /* gray-700 */
}
.dark .legend-item:hover {
    background-color: #374151;
}
.dark .species-legend-item {
    border-color: #4b5563;
}
.dark #report-map-image {
    background-color: #333;
    border: 1px solid #555;
}
.dark .report-table {
    color: #f0f0f0;
}
.dark .report-table th, .dark .report-table td {
    border: 1px solid #444;
}
.dark .report-table th {
    background-color: #333;
}
.dark .report-table tbody tr:nth-child(odd) {
    background-color: #2a2a2a;
}
.dark .report-table tbody tr:nth-child(even) {
    background-color: #1e1e1e;
}

/* Dark Mode Prose (Metadata) */
.dark #info-description h4 {
    color: #ffffff;
    border-bottom: 1px solid #444;
}
.dark .modal-content .prose h4,
.dark .modal-content .prose p,
.dark .modal-content .prose li {
	color: #f9fafb;
}
.dark strong {
	color: #999999;
}

/* Dark Mode Utilities */
.dark .loading-spinner {
     border: 4px solid #4b5563;
     border-top: 4px solid #3498db;
}
.dark .slider {
    background-color: #4b5563;
}
.dark input:checked + .slider {
    background-color: #3b82f6;
}

/* Dark Mode Scrollbars */
.dark ::-webkit-scrollbar-track {
    background: #2a2a2a;
}
.dark ::-webkit-scrollbar-thumb {
    background-color: #555;
}
.dark ::-webkit-scrollbar-thumb:hover {
    background-color: #777;
}
.dark * {
    scrollbar-color: #555 #2a2a2a;
}


/* This is in your style.css file - No changes needed, for confirmation only */
/* --- 6. PRINT STYLES --- */

/* PDF Generation Helpers (Off-screen rendering) */
.pdf-container {
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    background-color: #fff;
}
/* ... (other helper rules remain the same) ... */
.pdf-container .report-table tbody tr:nth-of-type(odd) {
    background-color: #f8f9fa;
}

/* --- Final PDF Legend Styles --- */
#pdf-legend-box {
    border: 1px solid #dee2e6;
    background-color: #f8f9fa;
    padding: 10px;
    font-size: 14px;
    color: #000;
}
#pdf-legend-box h4 {
    margin-top: 0;
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid #dee2e6;
    font-size: 22px;
    font-weight: bold;
}

/* Base style for ALL legend items (default horizontal/inline layout) */
#pdf-legend-box .print-legend-item {
	display: flex;
    align-items: center; /* Vertically center content */
    gap: 5px;
}

/* Style for the text label within any legend item */
#pdf-legend-box .print-legend-item span {
    /*border: 1px solid #dee2e6;*/
	word-break: break-word;
    flex: 1; /* Allow text to take up space and wrap */
	display:flex;
	align-items: center;
}

/* Style for the symbol within any legend item */
#pdf-legend-box .print-legend-item .esri-legend__symbol {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
}

/* --- Layout for STACKED items (Species) --- */
/* This modifier class overrides the base style to create a vertical layout */
#pdf-legend-box .print-legend-item .print-stacked {
    flex-direction: column; /* Stack symbol and text vertically */
    text-align: center;     /* Horizontally center the text */
    margin-bottom: 8px;
    gap: 2px;
}

/* --- Layout for GRID items (Species Container) --- */
#pdf-legend-box .print-legend-layer-title {
    font-weight: bold;
    margin-top: 8px;
    margin-bottom: 5px;
    width: 100%;
}
#pdf-legend-box .print-legend-item-group {
    display: flex;
    flex-wrap: wrap;
    row-gap: 5px;
    column-gap: 15px;
    padding-left: 10px;
}
#pdf-legend-box .print-legend-item-group .print-legend-item {
    flex-grow: 1;
    flex-basis: calc(33.333% - 16px); /* 3-column layout */
}

/* General style for the text label in any legend item 
#pdf-legend-box span {
    line-height: 1; /* Helps with precise alignment 
}

/* Ensure the Esri symbol div doesn't shrink 
#pdf-legend-box .esri-legend__symbol {
    flex-shrink: 0;
}

/* Main Print Media Query */
@media print {
    /* Hide UI elements */
    .no-print, .esri-ui-corner, .esri-view-surface:not(#report-map-image) {
        display: none !important;
    }

    /* Reset base styles for printing */
    html, body {
        height: auto !important;
        overflow: visible !important;
        background: #fff !important;
        color: #000 !important;
        font-family: sans-serif !important;
    }

    /* Override modal and report container styles */
    .modal-overlay {
        display: block !important;
        position: static !important;
    }
    .modal-content {
        box-shadow: none !important;
        color: #000 !important;
        max-width: none !important;
        width: auto !important;
        max-height: none !important;
        background-color: #fff !important;
        border: none !important;
        padding: 0 !important;
    }
    #results-popup .modal-content,
    #printable-report,
    #report-main-content,
    #report-data-column {
		display: block !important;
		height: auto !important;
		overflow: visible !important;
	}

    /* Help Popup */
    #help-popup {
        display: block !important;
        position: static !important;
    }

    /* Table headers repeating on new pages */
    .report-table thead {
        display: table-header-group;
    }
    .report-table tbody {
        display: table-row-group;
    }
    .report-table {
        page-break-inside: auto;
    }

    /* Report Layout & Typography */
    .report-table {
        margin-top: 0.25rem;
        color: #000;
        font-size: 0.8em;
    }
    .report-table th, .report-table td {
        border: 1px solid #ccc;
        padding: 0.15rem 0.5rem;
        text-align: left;
    }
    .report-table th {
        background-color: #eee;
    }
    .report-table tbody tr:nth-child(odd) {
        background-color: #f9f9f9;
    }
    .print-data-container h3 {
        margin-top: 0.75rem !important;
        margin-bottom: 0.25rem !important;
    }
	
	#report-disclaimer { display: none !important; }
    .no-print { display: none !important; }
}