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

#app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

#sidebar {
    width: 350px;
    background: #252525;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #333;
    z-index: 1000;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.3);
}

#map {
    flex: 1;
    background: #111;
}

.header {
    padding: 15px;
    background: #333;
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
}

.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.control-group {
    margin-bottom: 20px;
    background: #2a2a2a;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #333;
}

.control-group h3 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 0.9rem;
    text-transform: uppercase;
    color: #888;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-section-btn {
    background: transparent;
    border: none;
    padding: 0;
    color: #888;
    cursor: pointer;
    font-size: 0.9rem;
    transition: transform 0.3s;
}

.toggle-section-btn:hover {
    color: #fff;
    background: transparent;
}

.group-content {
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    max-height: 1000px;
    /* Arbitrary large height */
    opacity: 1;
    /* overflow: hidden; */
    margin-top: 10px;
}

.group-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.toggle-section-btn.rotated {
    transform: rotate(-90deg);
}

label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.85rem;
    color: #ccc;
}

select,
input[type="text"] {
    width: 100%;
    padding: 8px;
    background: #333;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    box-sizing: border-box;
}

select:focus,
input:focus {
    border-color: #007acc;
    outline: none;
}

button {
    background: #333;
    border: 1px solid #444;
    color: #eee;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    white-space: nowrap;
    /* Prevent text wrapping */
}

button:hover {
    background: #444;
    border-color: #666;
}

button:active {
    background: #222;
    transform: translateY(1px);
}

button.primary {
    background: #0066cc;
    border-color: #0055aa;
    width: 100%;
    margin-top: 10px;
    font-weight: bold;
}

button.primary:hover {
    background: #0077ee;
}

button.active,
button.active-mode {
    background: #0066cc;
    border-color: #0088ff;
    box-shadow: 0 0 8px rgba(0, 102, 204, 0.5);
}

button.active-action {
    background: #27ae60;
    border-color: #2ecc71;
    box-shadow: 0 0 8px rgba(46, 204, 113, 0.5);
    color: #fff;
}

button.active-warning {
    background: #d35400;
    /* Orange */
    border-color: #e67e22;
    box-shadow: 0 0 8px rgba(230, 126, 34, 0.5);
    color: #fff;
}

.status-icon {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
    margin-left: auto;
    color: #00ff00;
    /* Push to right if needed, or specific placement */
}

button.active .status-icon {
    background: #00ff00;
    box-shadow: 0 0 5px #00ff00;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #222;
    border-color: #333;
}

.icon-btn {
    padding: 6px;
    /* slightly smaller padding for icon-only/compact buttons */
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.slider-row label {
    flex: 0 0 60px;
    margin: 0;
}

.slider-row input[type="range"] {
    flex: 1;
}

.slider-row span {
    flex: 0 0 40px;
    text-align: right;
    font-family: monospace;
    font-size: 0.8rem;
}

.feature-item {
    font-size: 0.85rem;
    padding: 5px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.feature-item:last-child {
    border-bottom: none;
}

.feature-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 0;
}

.feature-row input {
    margin-bottom: 0;
    flex: 1;
}

.feature-row button.icon-btn {
    width: 32px;
    padding: 0;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0;
    font-size: 1.2rem;
}

.feature-row-separator {
    margin-top: 5px;
    border-top: 1px solid #444;
    padding-top: 10px;
}

.feature-item .tag {
    font-size: 0.7rem;
    padding: 2px 5px;
    border-radius: 3px;
    background: #444;
    color: #aaa;
}

.feature-item .tag {
    font-size: 0.7rem;
    padding: 2px 5px;
    border-radius: 3px;
    background: #333;
    cursor: default;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #222;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #444;
    width: 300px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
    margin-top: 0;
    color: #fff;
}

.modal-content p {
    color: #ccc;
    font-size: 14px;
    margin-bottom: 15px;
}

.import-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.import-options label {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #eee;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.flat-btn {
    background: transparent;
    border: 1px solid #444;
    color: #ccc;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
}

.flat-btn:hover {
    background: #333;
    color: #fff;
}

.primary-btn {
    background: #0088ff;
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
}

.primary-btn:hover {
    background: #0077ee;
}

/* Leaflet Dark Mode Overrides (Basic) */
.leaflet-container {
    background: #111;
}

/* Tools Grid */
.tools-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 5px 0;
}

.tools-grid button {
    margin-bottom: 0;
    width: 100%;
    padding: 8px 12px;
    /* Tighter padding for grid items */
    font-size: 12px;
}

#btn-add-curb,
#btn-edit-trace {
    justify-content: flex-start;
    text-align: left;
}

/* Ensure icons in buttons are nicely sized */
button i {
    font-size: 14px;
}

/* Specific tweaks for text overflow */
button {
    text-overflow: ellipsis;
    overflow: hidden;
}

/* Reference Window */
#ref-window {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 300px;
    /* Default width */
    min-width: 150px;
    background: #252525;
    /* border: 1px solid #444; handled by window logic? Ensure visibility */
    border: 1px solid #444;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    /* Above Leaflet controls */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Changed from auto to hidden for container, content scrolls */
    resize: both;
    /* Allow resizing */
}

/* Make sure ref-content scrolls */
.ref-content {
    flex: 1;
    overflow: auto;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

#ref-window.hidden {
    display: none;
}

#ref-window.size-xl {
    width: 800px !important;
    height: 600px !important;
    max-width: 90vw;
    max-height: 80vh;
}

#ref-window.size-l {
    width: 600px !important;
    height: 450px !important;
}

#ref-window.size-m {
    width: 400px !important;
    height: 300px !important;
}

#ref-window.size-s {
    width: 250px !important;
    height: 180px !important;
}

#ref-window.size-collapsed {
    height: auto !important;
    /* Header only */
    width: 200px !important;
    resize: none;
}

#ref-window.size-collapsed .ref-content {
    display: none;
}

.ref-header {
    background: #333;
    padding: 8px 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    /* Header shouldn't shrink */
}

.ref-header button {
    width: auto;
    padding: 2px 8px;
    margin: 0;
    font-size: 1rem;
    line-height: 1;
    background: transparent;
    border: none;
    color: #ccc;
    display: inline-block;
    /* Reset from flex default of button */
}

.ref-header button:hover {
    color: #fff;
    background: #444;
}

.ref-content img {
    width: 100%;
    height: auto;
    display: block;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #444;
    /* Slightly lighter than bg */
    color: #fff;
    padding: 10px 20px;
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 3000;
    font-size: 14px;
    border: 1px solid #666;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

.toast.hidden {
    display: none;
}

/* Typeahead Results */
.results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #252525;
    border: 1px solid #444;
    border-top: none;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    border-radius: 0 0 4px 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.results-dropdown.hidden {
    display: none;
}

.result-item {
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid #333;
    color: #eee;
    font-size: 0.9rem;
}

.result-item:last-child {
    border-bottom: none;
}

.result-item:hover {
    background: #333;
    color: #fff;
}

/* Full Page Loader */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

#loader-overlay.hidden {
    display: none !important;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #00ff00;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 15px;
}

.loader-text {
    color: #fff;
    font-size: 1.2rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: bold;
    letter-spacing: 1px;
}

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

/* Status Toggle */
.toggle-switch {
    position: relative;
    width: 140px;
    height: 30px;
    background: #222;
    border-radius: 15px;
    border: 1px solid #444;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px;
    box-sizing: border-box;
    cursor: pointer;
    overflow: hidden;
}

.toggle-switch input {
    display: none;
}

.toggle-switch-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 50%;
    /* roughly */
    width: calc(50% - 4px);
    height: calc(100% - 4px);
    background: #d35400;
    /* Default WIP Orange */
    border-radius: 13px;
    transition: all 0.3s ease;
    z-index: 1;
}

.toggle-switch input:checked~.toggle-switch-slider {
    left: 50%;
    background: #27ae60;
    /* DONE Green */
}

.toggle-label {
    flex: 1;
    text-align: center;
    font-size: 0.75rem;
    font-weight: bold;
    color: #666;
    z-index: 2;
    transition: color 0.3s;
    user-select: none;
}

/* WIP Label state */
.toggle-switch input:not(:checked)~.label-wip {
    color: #fff;
}

/* DONE Label state */
/* Import Visualization */
.modal-content {
    width: 500px;
    /* Widen modal to fit side-by-side */
    max-width: 90vw;
}

.import-layout {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.import-form-column {
    flex: 1;
}

.import-viz-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #1a1a1a;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #333;
    /* Fixed width for viz column */
}

.viz-track {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 100%;
}

.viz-track img {
    width: 200px;
    /* Larger images */
    object-fit: contain;
    border: 1px solid #444;
    background: #000;
    border-radius: 4px;
}

.viz-track span {
    font-size: 0.75rem;
    color: #aaa;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.viz-arrow {
    font-size: 1.2rem;
    color: #0088ff;
    padding: 5px 0;
}

/* Drag and Drop Styles */
.drag-handle {
    cursor: grab;
    color: #666;
    padding: 4px;
}

.drag-handle:hover {
    color: #ddd;
}

.feature-row {
    transition: background 0.2s, transform 0.2s;
    user-select: none;
    /* Prevent text selection while dragging */
}

.feature-row.dragging {
    opacity: 0.5;
    background: #333;
    border: 1px dashed #666;
}

.feature-row.drag-over {
    border-top: 2px solid #00ff00;
}