/* Structural Fallbacks (Prevents collapse if main.css fails to load) */
html, body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--main-background, #f4f4f4);
}

/* Guarantee the main content area pushes the footer to the bottom */
main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Accessibility Focus Styles */
#app-container *:focus-visible,
.content-section *:focus-visible {
    outline: 3px solid var(--secondary-color, #008AFF) !important;
    outline-offset: 2px !important;
    border-radius: 2px !important;
}

/* Screen Reader Only - Visually hides elements but keeps them accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* App Container Layout (Co-exists with global header) */
#app-container {
    display: flex;
    flex-direction: row;
    height: 75vh;
    min-height: 600px;
    width: calc(100% - 30px); 
    margin: 20px auto 40px auto; 
    border-radius: 8px; 
    box-shadow: 2px 2px 12px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    z-index: 1; 
    isolation: isolate; 
    background-color: var(--main-background, #f4f4f4);
    box-sizing: border-box;
}

#app-container *, #app-container *::before, #app-container *::after {
    box-sizing: border-box;
}

@media screen and (min-width: 1281px) {
    #app-container {
        margin-top: 0;
        margin-left: 315px; /* 285px global sidebar + 30px gap */
        width: calc(100% - 315px - 30px); /* Adjusts width to maintain the 30px right gutter */
    }
}

/* Sidebar Styling */
#sidebar {
    width: 320px;
    background-color: var(--color-white, #ffffff);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    z-index: 2000; 
    height: 100%;
    overflow-y: auto;
    border-right: 1px solid var(--border-color, #e2e8f0);
    flex-shrink: 0;
}

.sidebar-header {
    background-color: var(--main-color, #1A48EE);
    color: var(--color-white, #ffffff);
    padding: 20px;
    text-align: center;
}

#sidebar h1.sidebar-title {
    font-size: 1.2rem;
    letter-spacing: 1px;
    color: var(--color-white, #ffffff); 
    margin: 0;
}

/* Semantic Fieldsets replacing generic div controls */
fieldset.control-group {
    padding: 20px;
    border: none;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    margin: 0;
    min-width: 0;
}

legend.group-legend {
    font-size: 0.9rem;
    color: var(--main-color, #1A48EE);
    margin: 0 0 15px 0;
    text-transform: uppercase;
    font-weight: bold;
    display: table;
    width: 100%;
    padding: 0;
}

.input-row {
    margin-bottom: 15px;
}

.input-row label {
    display: block;
    font-size: 0.85rem;
    color: var(--color-gray, #4a5568);
    font-weight: bold;
    margin-bottom: 5px;
}

#app-container input[type="text"], 
#app-container select, 
#app-container textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 4px;
    font-size: 0.9rem;
    background-color: var(--color-white, #ffffff);
    color: var(--color-gray, #4a5568);
    transition: border-color 0.2s, box-shadow 0.2s;
    margin: 0;
}

#app-container input[type="text"]:focus, 
#app-container select:focus, 
#app-container textarea:focus {
    outline: none;
    border-color: var(--main-color, #1A48EE);
    box-shadow: 0 0 0 3px rgba(26, 72, 238, 0.2);
}

#app-container input[type="color"] {
    width: 100%;
    height: 40px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

#app-container input[type="range"] {
    width: 100%;
    margin-top: 5px;
    cursor: pointer;
}
#sidebar > .sidebar-header > .sidebar-title{
    color:var(--color-white);
}
.btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
    text-align: center;
}

.btn-export { 
    background-color: var(--color-contrast-green, #065F46); 
    color: #ffffff !important; 
}
.btn-export:hover { background-color: #04402e; }

.btn-import { 
    background-color: var(--secondary-color, #008AFF); 
    color: #ffffff !important; 
}
.btn-import:hover { background-color: var(--main-color, #1A48EE); }

/* Embedded Tools Styling - Refactored as Semantic List */
ul.tools-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    list-style: none;
    padding: 0;
    margin: 0;
}

ul.tools-grid li {
    display: block;
}

.tool-btn {
    display: flex;
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    background-color: var(--secondary-background, #f9f9f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--color-gray, #4a5568);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    gap: 8px;
    text-align: center;
}

.tool-btn i {
    font-size: 1.15rem;
    color: var(--main-color, #1A48EE);
    transition: color 0.2s;
}

.tool-btn:hover {
    background-color: var(--main-background, #e5f3ff);
    border-color: var(--secondary-color, #008AFF);
    color: var(--main-color, #1A48EE);
}

.tool-btn.active {
    background-color: var(--main-color, #1A48EE);
    color: var(--color-white, #ffffff);
    border-color: var(--main-color, #1A48EE);
}

.tool-btn.active i {
    color: var(--color-white, #ffffff);
}

.tool-btn-danger i {
    color: var(--color-error-dark, #c53030);
}
.tool-btn-danger:hover {
    background-color: #fde8e8;
    border-color: var(--color-error-dark, #c53030);
    color: var(--color-error-dark, #c53030);
}
.tool-btn-danger.active {
    background-color: var(--color-error-dark, #c53030) !important;
    border-color: var(--color-error-dark, #c53030) !important;
    color: var(--color-white, #ffffff) !important;
}
.tool-btn-danger.active i {
    color: var(--color-white, #ffffff) !important;
}

/* Marked Places List */
.places-container {
    display: flex;
    flex-direction: column;
    padding: 20px 20px 10px 20px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.places-container h3 {
    font-size: 0.9rem;
    color: var(--main-color, #1A48EE);
    margin: 0 0 15px 0;
    text-transform: uppercase;
}

#places-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.place-item {
    padding: 5px;
    background: var(--secondary-background, #f9f9f9);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 4px;
    margin-bottom: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.place-item:hover, .place-item:focus-within {
    background: var(--main-background, #e5f3ff);
    border-color: var(--secondary-color, #008AFF);
}

.place-main-click {
    display: flex;
    align-items: center;
    flex-grow: 1;
    overflow: hidden;
    background: none;
    border: none;
    text-align: left;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    color: inherit;
}

.place-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white, #ffffff);
    font-size: 11px;
    margin-right: 12px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.place-color i {
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.place-info {
    display: flex;
    flex-direction: column;
}

.place-name {
    font-weight: bold;
    font-size: 0.85rem;
    color: var(--main-color, #1A48EE);
}

.place-desc {
    font-size: 0.75rem;
    color: var(--color-gray, #4a5568);
}

.place-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    flex-shrink: 0;
    margin-left: 8px;
    padding-right: 5px;
}

.place-item:hover .place-actions,
.place-item:focus-within .place-actions {
    opacity: 1;
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    font-size: 0.9rem;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
}

.action-btn-edit { color: var(--secondary-color, #008AFF); }
.action-btn-edit:hover, .action-btn-edit:focus-visible {
    background-color: var(--tertiary-background, #e6e5ea);
    color: var(--main-color, #1A48EE);
}

.action-btn-delete { color: var(--color-error-dark, #c53030); }
.action-btn-delete:hover, .action-btn-delete:focus-visible {
    background-color: #fde8e8;
    color: #9b2c2c;
}

/* Leaflet Overrides */
.custom-marker {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
}

.leaflet-popup-content {
    margin: 12px !important;
    line-height: 1.4;
}
.pop-edit-btn {
    width: 100% !important;
    padding: 8px !important;
    background-color: var(--main-color, #1A48EE) !important;
    color: var(--color-white, #ffffff) !important;
    border: none !important;
    border-radius: 4px !important;
    font-size: 0.8rem !important;
    font-weight: bold !important;
    cursor: pointer !important;
    transition: background 0.2s !important;
    margin-top: 8px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.pop-edit-btn:hover, .pop-edit-btn:focus-visible {
    background-color: var(--secondary-color, #008AFF) !important;
}

/* Modal Styles */
.modal-overlay {
    position: absolute; 
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease-in-out;
    backdrop-filter: blur(2px);
}
.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--color-white, #ffffff);
    padding: 24px;
    border-radius: 8px;
    width: 380px;
    max-width: 90%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    transform: scale(0.9);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-overlay.show .modal-content {
    transform: scale(1);
}
.modal-header {
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h4 {
    font-size: 1.15rem;
    color: var(--main-color, #1A48EE);
    font-weight: bold;
    margin: 0;
}
.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-gray, #4a5568);
    line-height: 1;
    border-radius: 4px;
    padding: 0 4px;
}
.modal-close-btn:hover, .modal-close-btn:focus-visible {
    color: var(--color-error-dark, #c53030);
    background-color: var(--tertiary-background, #e6e5ea);
}

/* Map Container */
#map {
    flex-grow: 1; 
    height: 100%;
    width: 100%;
    z-index: 0;
}

.leaflet-container {
    font-family: inherit;
}

/* Toast Notification System */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 3000;
}

.toast {
    background-color: var(--main-color, #1A48EE);
    color: var(--color-white, #ffffff);
    padding: 12px 24px;
    border-radius: 4px;
    margin-top: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s;
    font-weight: 500;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.instructions {
    font-size: 0.85rem;
    color: var(--color-gray, #4a5568);
    line-height: 1.5;
    padding: 20px;
    background: var(--secondary-background, #f9f9f9);
    margin: 0;
}

/* Mobile Responsive Layout & Toggle */
#mobile-menu-btn {
    display: none;
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 2001;
    background-color: var(--main-color, #1A48EE);
    color: var(--color-white, #ffffff);
    border: none;
    border-radius: 4px;
    padding: 10px 14px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

#mobile-menu-btn:focus-visible {
    outline: 3px solid var(--secondary-color, #008AFF);
}

#sidebar-backdrop {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1900;
    backdrop-filter: blur(1px);
}

.sidebar-close-btn {
    display: none;
    background: none;
    border: none;
    color: var(--color-white, #ffffff);
    font-size: 1.5rem;
    cursor: pointer;
    position: absolute;
    top: 15px;
    right: 15px;
}

@media (max-width: 1280px) {
    #sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        visibility: hidden; /* Removes off-screen sidebar from keyboard tab order */
        transition: transform 0.3s ease-in-out, visibility 0s 0.3s;
        box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    }
    #sidebar.open {
        transform: translateX(0);
        visibility: visible; /* Restores sidebar to keyboard tab order */
        transition: transform 0.3s ease-in-out, visibility 0s 0s;
    }
    #mobile-menu-btn {
        display: block;
    }
    .sidebar-close-btn {
        display: block;
    }
    #sidebar-backdrop.show {
        display: block;
    }
    .leaflet-top.leaflet-left {
        top: 60px;
    }
}

/* Typography Content Adjustments */
.content-section {
    width: calc(100% - 30px);
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 3rem;
}
.content-section h2 {
    border-bottom: 2px solid var(--secondary-color, #008AFF);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}
.content-section p {
    line-height: 1.6;
    color: var(--color-gray, #4a5568);
}
.content-section ol li {
    margin-bottom: 1rem;
    line-height: 1.6;
    color: var(--color-gray, #4a5568);
}
@media screen and (min-width: 1281px) {
    .content-section {
        margin-left: 315px; /* Aligns perfectly with the map container's new gap */
        width: calc(100% - 315px - 30px);
    }
}