* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables for Dark/Light Mode */
:root {
    /* Dark Mode (Default) */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #1a1a1a;
    --text-primary: #e0e0e0;
    --text-secondary: #999999;
    --text-bright: #ffffff;
    --border-color: #404040;
    --accent-color: #cc0000;
    --accent-hover: #ff0000;
    --header-bg: linear-gradient(135deg, #000000, #1a1a1a);
    --control-bg: rgba(255,255,255,0.1);
    --control-hover: rgba(255,255,255,0.2);
    --shadow-color: rgba(0,0,0,0.5);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Light Mode */
body.light-mode {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #fafafa;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-bright: #000000;
    --border-color: #e0e0e0;
    --accent-color: #cc0000;
    --accent-hover: #aa0000;
    --header-bg: linear-gradient(135deg, #ffffff, #f5f5f5);
    --control-bg: rgba(0,0,0,0.05);
    --control-hover: rgba(0,0,0,0.1);
    --shadow-color: rgba(0,0,0,0.1);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header - Schwarz/Rot Theme */
#header {
    background: var(--header-bg);
    color: var(--text-primary);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px var(--shadow-color);
    border-bottom: 2px solid var(--accent-color);
    z-index: 1000;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-bright);
}

.gtfs-period-display {
    background: rgba(255,255,255,0.1);
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    border-left: 3px solid #cc0000;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.language-switcher {
    display: flex;
    gap: 0.2rem;
}

.lang-btn {
    background: rgba(255,255,255,0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.2);
}

.lang-btn.active {
    background: #cc0000;
    border-color: #cc0000;
    color: #ffffff;
}

/* Theme Switcher */
.theme-switcher {
    display: flex;
    gap: 0.2rem;
}

.theme-btn {
    background: rgba(255,255,255,0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    background: rgba(255,255,255,0.2);
}

.theme-btn.active {
    background: #cc0000;
    border-color: #cc0000;
}

.header-stats {
    display: flex;
    gap: 1.5rem;
}

.header-stats span {
    background: rgba(255,255,255,0.1);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    color: #e0e0e0;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Controls Panel - Dunkel Theme */
#controls-panel {
    width: 350px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    box-shadow: 2px 0 10px var(--shadow-color);
    z-index: 500;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

#controls-panel.hidden {
    transform: translateX(-100%);
}

.control-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.control-section.collapsed .section-content {
    display: none;
}

.control-section h3 {
    margin-bottom: 1rem;
    color: var(--text-bright);
    font-size: 1.1rem;
}

.control-section h4 {
    margin-bottom: 0.8rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

/* Collapsible Section Styles */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

.collapsible-header:hover {
    color: #cc0000;
}

.section-toggle-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: #999999;
    transition: all 0.3s ease;
    padding: 0.2rem;
    border-radius: 3px;
}

.section-toggle-btn:hover {
    background: rgba(255,255,255,0.1);
    color: #cc0000;
}

.section-toggle-btn.collapsed {
    transform: rotate(-90deg);
}

.section-content {
    display: block;
}

/* File Upload */
.file-upload {
    text-align: center;
}

.file-info {
    margin-top: 0.5rem;
    color: #999999;
    font-size: 0.8rem;
}

#loaded-files-list {
    margin-top: 1rem;
    padding: 1rem;
    background: #1a1a1a;
    border-radius: 4px;
    border: 1px solid #404040;
}

#files-list {
    margin-bottom: 1rem;
}

.file-item {
    padding: 0.5rem;
    background: #333333;
    border: 1px solid #404040;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-name {
    font-weight: 500;
    color: #e0e0e0;
    flex: 1;
}

.file-remove {
    background: #cc0000;
    color: white;
    border: none;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.7rem;
}

.file-remove:hover {
    background: #aa0000;
}

.btn-primary, .btn-secondary {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background: var(--text-primary);
}

.btn-small {
    padding: 0.4rem 0.8rem !important;
    font-size: 0.8rem !important;
}

#upload-status {
    margin-top: 1rem;
    padding: 0.8rem;
    border-radius: 4px;
    font-size: 0.9rem;
    display: none;
}

#upload-status.success {
    background: rgba(0, 255, 0, 0.1);
    color: #00ff00;
    border: 1px solid rgba(0, 255, 0, 0.3);
}

#upload-status.error {
    background: rgba(204, 0, 0, 0.1);
    color: #ff6666;
    border: 1px solid rgba(204, 0, 0, 0.3);
}

#upload-status.info {
    background: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Date & Time Controls */
.date-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.time-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.8rem;
    background: #1a1a1a;
    border-radius: 4px;
    border: 1px solid #404040;
}

.time-controls label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #e0e0e0;
}

.time-quick-select {
    margin-top: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px solid #404040;
}

.time-period-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.5rem;
}

.time-period-btn {
    flex: 1;
    min-width: 80px;
    background: #666666 !important;
    color: white !important;
}

.time-period-btn:hover {
    background: #555555 !important;
}

.time-period-btn.active {
    background: #cc0000 !important;
}

.date-controls input[type="date"],
.time-controls input[type="time"] {
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Agency Controls */
.agency-controls {
    margin-bottom: 1rem;
}

.agency-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.agency-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #404040;
    border-radius: 4px;
    background: #1a1a1a;
}

.agency-item {
    padding: 0.5rem;
    border-bottom: 1px solid #404040;
    transition: background 0.2s ease;
}

.agency-item:last-child {
    border-bottom: none;
}

.agency-item:hover {
    background: #333333;
}

.agency-item.hidden {
    display: none;
}

.agency-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    width: 100%;
    margin-bottom: 0;
}

.agency-checkbox {
    margin-right: 0.8rem;
    margin-bottom: 0;
}

.agency-info {
    flex: 1;
}

.agency-name {
    font-weight: 500;
    color: #e0e0e0;
    font-size: 0.9rem;
}

.agency-stats {
    font-size: 0.8rem;
    color: #999999;
    margin-top: 0.2rem;
}

.agency-checkbox:checked + .agency-info .agency-name {
    color: #cc0000;
}

/* Route Controls */
.search-box input {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #404040;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    background: #1a1a1a;
    color: #e0e0e0;
}

.quick-select {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #1a1a1a;
    border-radius: 4px;
    border: 1px solid #404040;
}

.route-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #404040;
    border-radius: 4px;
    background: #1a1a1a;
}

.route-item {
    padding: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    min-height: 60px;
    background: var(--bg-secondary);
}

.route-item:last-child {
    border-bottom: none;
}

.route-item:hover {
    background: var(--control-hover) !important;
}

.route-item.selected {
    background: rgba(204, 0, 0, 0.2) !important;
    border-left: 3px solid var(--accent-color);
}

.route-item.hidden {
    display: none !important;
}

.route-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.route-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.2;
    margin-bottom: 0.2rem;
}

.route-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.1;
}

.route-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    box-shadow: 0 1px 3px var(--shadow-color);
    margin: 0 0.5rem;
    flex-shrink: 0;
}

.route-stats {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
    min-width: 60px;
}

.route-stats div {
    line-height: 1.2;
}

/* Radio Controls */
.route-pattern-controls,
.stop-display-controls,
.export-controls {
    margin-top: 1rem;
    padding: 0.8rem;
    background: #1a1a1a;
    border-radius: 4px;
    border: 1px solid #404040;
}

.radio-label {
    display: flex;
    align-items: center;
    margin-bottom: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #e0e0e0;
}

.radio-label input[type="radio"] {
    margin-right: 0.5rem;
}

/* Export Controls */
.export-controls {
    background: rgba(204, 0, 0, 0.1);
    border-color: #cc0000;
}

.export-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.export-buttons button {
    text-align: left;
    justify-content: flex-start;
    background: #cc0000 !important;
    color: white !important;
    border: none !important;
}

.export-buttons button:hover {
    background: #aa0000 !important;
    transform: translateX(2px);
}

/* Enhanced Transport Buttons */
.transport-btn {
    border: 1px solid rgba(255,255,255,0.3) !important;
    font-size: 0.75rem !important;
    font-weight: 500 !important;
    text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}

.transport-btn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5) !important;
}

/* Checkboxes */
.checkbox-label {
    display: flex;
    align-items: center;
    margin-bottom: 0.8rem;
    cursor: pointer;
    color: #e0e0e0;
}

.checkbox-label input {
    margin-right: 0.5rem;
}

/* Display Controls */
.display-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Map Container */
#map-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    z-index: 1;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #404040;
    border-top: 4px solid #cc0000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.1rem;
    color: #e0e0e0;
}

/* Toggle Panel Button */
.toggle-btn {
    position: fixed;
    left: 350px;
    top: 50%;
    transform: translateY(-50%);
    background: #2a2a2a;
    border: 1px solid #404040;
    border-left: none;
    border-radius: 0 6px 6px 0;
    padding: 1rem 0.5rem;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
    color: #e0e0e0;
}

.toggle-btn:hover {
    background: #333333;
}

.toggle-btn.panel-hidden {
    left: 0;
    transform: translateY(-50%) rotate(180deg);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: #2a2a2a;
    border-radius: 8px;
    max-width: 90%;
    max-height: 90%;
    width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    border: 1px solid #404040;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #404040;
    background: #1a1a1a;
}

.modal-header h2 {
    margin: 0;
    color: #e0e0e0;
    font-size: 1.2rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #404040;
    color: #e0e0e0;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    max-height: calc(90vh - 100px);
}

.modal-route-item {
    display: flex;
    align-items: center;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border: 1px solid #404040;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #1a1a1a;
}

.modal-route-item:hover {
    background: #333333;
    border-color: #cc0000;
}

.modal-route-item:last-child {
    margin-bottom: 0;
}

.modal-route-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 0.8rem;
    flex-shrink: 0;
}

.modal-route-info {
    flex: 1;
}

.modal-route-name {
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 0.2rem;
}

.modal-route-desc {
    font-size: 0.8rem;
    color: #999999;
}

/* Stop Popup Styles */
.stop-popup {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.4;
    max-width: 300px;
    color: #e0e0e0;
}

.stop-popup h4 {
    margin: 0 0 10px 0;
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
}

.stop-details {
    margin-bottom: 10px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.stop-details strong {
    word-break: break-word;
    overflow-wrap: break-word;
}

.route-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    max-width: 250px;
}

.route-pill {
    display: inline-block;
    padding: 2px 6px;
    background-color: #666666;
    color: white;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: all 0.2s ease;
}

.route-pill:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    background-color: #555555;
}

.more-routes {
    color: #999999;
    font-size: 11px;
    font-style: italic;
    cursor: pointer;
    text-decoration: underline;
}

.more-routes:hover {
    color: #cccccc;
}

.show-all-routes-btn {
    background: #cc0000;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.show-all-routes-btn:hover {
    background: #aa0000;
    transform: translateY(-1px);
}

.terminal-badge {
    background: #cc0000;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    margin-top: 8px;
}

.interchange-badge {
    background: #000000;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    text-align: center;
    margin-top: 8px;
    border: 1px solid #ffffff;
}

/* Terminal Marker Styling (Rotes Quadrat gedreht) */
.terminal-marker {
    background: transparent !important;
    border: none !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

.terminal-marker div {
    transition: transform 0.2s ease;
}

.terminal-marker:hover div {
    transform: rotate(45deg) scale(1.1);
}

/* Interchange Marker Styling (Schwarzes Dreieck) */
.interchange-marker {
    background: transparent !important;
    border: none !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Terminal + Interchange Marker (Größeres schwarzes Dreieck) */
.terminal-interchange-marker {
    background: transparent !important;
    border: none !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Leaflet Improvements */
.leaflet-popup-content {
    margin: 8px 12px;
    max-width: 280px;
}

.leaflet-popup-content h4 {
    margin: 0 0 8px 0;
    color: #ffffff;
}

.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 3px 14px rgba(0,0,0,0.8);
    background: #2a2a2a;
    color: #e0e0e0;
}

.leaflet-popup-tip {
    box-shadow: 0 3px 14px rgba(0,0,0,0.8);
    background: #2a2a2a;
}

/* Layer Control Styling */
.leaflet-control-layers {
    background: rgba(42, 42, 42, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.5);
    border: 1px solid #404040;
}

.leaflet-control-layers-expanded {
    padding: 8px 12px;
    min-width: 180px;
    color: #e0e0e0;
}

.leaflet-control-layers label {
    font-size: 13px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    color: #e0e0e0;
}

.leaflet-control-layers input[type="radio"] {
    margin-right: 8px;
}

/* MarkerCluster Styles */
.marker-cluster-small {
    background-color: rgba(102, 102, 102, 0.6);
}

.marker-cluster-small div {
    background-color: rgba(102, 102, 102, 0.8);
}

.marker-cluster-medium {
    background-color: rgba(204, 0, 0, 0.6);
}

.marker-cluster-medium div {
    background-color: rgba(204, 0, 0, 0.8);
}

.marker-cluster-large {
    background-color: rgba(170, 0, 0, 0.6);
}

.marker-cluster-large div {
    background-color: rgba(170, 0, 0, 0.8);
}

/* Scrollbar Styling */
.route-list::-webkit-scrollbar, 
#controls-panel::-webkit-scrollbar,
.agency-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.route-list::-webkit-scrollbar-track, 
#controls-panel::-webkit-scrollbar-track,
.agency-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: #1a1a1a;
}

.route-list::-webkit-scrollbar-thumb, 
#controls-panel::-webkit-scrollbar-thumb,
.agency-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: #666666;
    border-radius: 3px;
}

.route-list::-webkit-scrollbar-thumb:hover, 
#controls-panel::-webkit-scrollbar-thumb:hover,
.agency-list::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

/* Input Focus */
input[type="text"]:focus,
input[type="date"]:focus,
input[type="time"]:focus {
    border-color: #cc0000;
    box-shadow: 0 0 0 2px rgba(204, 0, 0, 0.2);
    outline: none;
}

/* Focus States für Accessibility */
.btn-primary:focus,
.btn-secondary:focus,
.route-item:focus,
.agency-item:focus,
.route-pill:focus {
    outline: 2px solid #cc0000;
    outline-offset: 2px;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Text Selection */
::selection {
    background: #cc0000;
    color: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    #controls-panel {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transform: translateX(-100%);
    }
    
    #controls-panel.visible {
        transform: translateX(0);
    }
    
    .toggle-btn {
        left: 20px;
        top: 100px;
        transform: none;
        border-radius: 6px;
        position: fixed;
    }
    
    .header-stats {
        display: none;
    }
    
    .header-right {
        gap: 1rem;
    }
    
    #header h1 {
        font-size: 1.2rem;
    }
    
    .agency-list {
        max-height: 150px;
    }
    
    .route-list {
        max-height: 250px;
    }
    
    .quick-select {
        padding: 0.8rem;
    }
    
    .btn-small {
        padding: 0.3rem 0.6rem !important;
        font-size: 0.75rem !important;
    }
    
    .modal-content {
        width: 95%;
        max-height: 85%;
    }
    
    .time-period-buttons {
        flex-direction: column;
    }
    
    .time-period-btn {
        min-width: auto;
    }
}

/* Collapsible Header Wrapper */
.collapsible-header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    cursor: pointer;
}

.collapsible-header-wrapper:hover h3 {
    color: #cc0000;
}

.collapsible-header {
    margin-bottom: 0 !important;
}

/* ============================================
   MOBILE OPTIMIERUNGEN
   ============================================ */

@media (max-width: 768px) {
    /* Vertikales Layout für Mobile */
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    #app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    /* Header kompakter */
    #header {
        padding: 0.5rem;
        flex-wrap: wrap;
    }
    
    #header h1 {
        font-size: 1rem;
    }
    
    .header-stats {
        display: none; /* Stats verstecken auf Mobile */
    }
    
    .language-switcher {
        order: -1;
        margin-bottom: 0.5rem;
    }
    
    /* Main Content - Vertikales Layout */
    .main-content {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 60px);
    }
    
    /* Controls Panel - Oberer Bereich, einklappbar */
    #controls-panel {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 50vh;
        overflow-y: auto;
        position: relative;
        transform: none;
        border-right: none;
        border-bottom: 2px solid #cc0000;
        order: 1;
    }
    
    #controls-panel.hidden {
        transform: translateY(-100%);
        position: absolute;
        z-index: 1500;
    }
    
    /* Map Container - Unterer Bereich */
    #map-container {
        width: 100%;
        height: 50vh;
        min-height: 400px;
        order: 2;
        flex: 1;
    }
    
    #map {
        height: 100%;
    }
    
    /* Toggle Button - Unten mittig */
    .toggle-btn {
        position: fixed;
        left: 50%;
        top: auto;
        bottom: 20px;
        transform: translateX(-50%);
        border-radius: 50%;
        padding: 1rem;
        width: 50px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 10px rgba(0,0,0,0.5);
        border: 2px solid #cc0000;
        z-index: 2000;
        font-size: 1.2rem;
    }
    
    .toggle-btn.panel-hidden {
        transform: translateX(-50%) rotate(180deg);
    }
    
    /* Control Sections kompakter */
    .control-section {
        padding: 1rem;
    }
    
    .control-section h3 {
        font-size: 1rem;
    }
    
    /* Buttons größer für Touch */
    .btn-primary, .btn-secondary {
        padding: 1rem 1.5rem;
        font-size: 1rem;
        min-height: 44px; /* Apple's empfohlene Touch-Größe */
    }
    
    .btn-small {
        padding: 0.6rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 44px;
    }
    
    /* Inputs größer */
    input[type="text"],
    input[type="date"],
    input[type="time"] {
        padding: 1rem;
        font-size: 16px; /* Verhindert Zoom beim Focus auf iOS */
        min-height: 44px;
    }
    
    /* Checkboxes und Radio Buttons größer */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 1rem;
    }
    
    /* Route List optimiert */
    .route-list {
        max-height: 40vh;
    }
    
    .route-item {
        padding: 1rem;
        min-height: 70px;
    }
    
    .route-name {
        font-size: 1rem;
    }
    
    .route-desc {
        font-size: 0.9rem;
    }
    
    /* Agency List optimiert */
    .agency-list {
        max-height: 30vh;
    }
    
    .agency-item {
        padding: 1rem;
        min-height: 60px;
    }
    
    /* Quick Select Buttons */
    .quick-select {
        padding: 0.8rem;
    }
    
    .transport-btn {
        font-size: 0.85rem !important;
        padding: 0.6rem 0.8rem !important;
        min-width: 100px;
    }
    
    /* Time Period Buttons */
    .time-period-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .time-period-btn {
        min-width: auto;
        width: 100%;
    }
    
    /* Modal optimiert */
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        margin: 5vh auto;
    }
    
    .modal-body {
        max-height: calc(90vh - 80px);
    }
    
    .modal-route-item {
        padding: 1rem;
        min-height: 60px;
    }
    
    /* Export Buttons */
    .export-buttons button {
        padding: 1rem !important;
        font-size: 1rem !important;
    }
    
    /* Leaflet Controls anpassen */
    .leaflet-control-layers {
        max-width: 200px;
    }
    
    .leaflet-control-zoom {
        margin-right: 10px;
        margin-top: 10px;
    }
    
    /* Leaflet Popups */
    .leaflet-popup-content {
        font-size: 14px;
    }
    
    .route-pill {
        padding: 4px 8px;
        font-size: 12px;
        margin: 2px;
    }
    
    .show-all-routes-btn {
        padding: 8px 12px;
        font-size: 13px;
        min-height: 44px;
    }
}

/* Landscape Mode auf Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #controls-panel {
        max-height: 70vh;
    }
    
    #map-container {
        height: 100vh;
        min-height: 300px;
    }
    
    .toggle-btn {
        right: 20px;
        left: auto;
        bottom: 50%;
        transform: translateY(50%);
    }
    
    .toggle-btn.panel-hidden {
        transform: translateY(50%) rotate(180deg);
    }
}

/* Sehr kleine Geräte */
@media (max-width: 480px) {
    #header h1 {
        font-size: 0.9rem;
    }
    
    .lang-btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
    }
    
    .control-section {
        padding: 0.8rem;
    }
    
    .btn-primary, .btn-secondary {
        padding: 0.8rem 1.2rem;
        font-size: 0.9rem;
    }
    
    .route-item {
        min-height: 60px;
        padding: 0.8rem;
    }
    
    .route-name {
        font-size: 0.9rem;
    }
    
    .route-desc {
        font-size: 0.8rem;
    }
}

/* Tablet Portrait */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    #controls-panel {
        width: 400px;
    }
    
    .toggle-btn {
        left: 400px;
    }
}

/* Category Buttons */
.category-btn {
    border: 1px solid rgba(255,255,255,0.3) !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    text-shadow: 0 1px 1px rgba(0,0,0,0.5);
    padding: 0.5rem 0.8rem !important;
    min-width: 120px;
    text-align: center;
}

.category-btn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5) !important;
    filter: brightness(1.1);
}

/* Transport Button Container mit Scrolling */
.quick-select div[style*="max-height"] {
    border: 1px solid #404040;
    border-radius: 4px;
    padding: 0.5rem;
    background: rgba(255,255,255,0.02);
}

.quick-select div[style*="max-height"]::-webkit-scrollbar {
    width: 6px;
}

.quick-select div[style*="max-height"]::-webkit-scrollbar-track {
    background: #1a1a1a;
    border-radius: 3px;
}

.quick-select div[style*="max-height"]::-webkit-scrollbar-thumb {
    background: #666666;
    border-radius: 3px;
}

.quick-select div[style*="max-height"]::-webkit-scrollbar-thumb:hover {
    background: #888888;
}

.leaflet-tile-container img[src*="tracestrack.com"] {
    opacity: 1;
    filter: contrast(0.6) brightness(1.3) saturate(0.5) grayscale(0.3);
}

/* Resize Handle */
#resize-handle {
    width: 5px;
    background: #2a2a2a;
    cursor: ew-resize;
    flex-shrink: 0;
    position: relative;
    transition: background 0.2s ease;
}

#resize-handle:hover {
    background: #cc0000;
}

#resize-handle:active {
    background: #ff0000;
}

/* Ensure controls-panel can be resized */
#controls-panel {
    min-width: 200px;
    max-width: 800px;
    flex-shrink: 0;
}

/* User select none during resize */
body.resizing {
    user-select: none;
    cursor: ew-resize !important;
}

body.resizing * {
    cursor: ew-resize !important;
}

/* ========================================
   LIGHT MODE OVERRIDES
   ======================================== */

body.light-mode {
    /* Agency Items */
    .agency-item {
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
    }

    .agency-item:hover {
        background: var(--control-hover);
    }

    .agency-name {
        color: var(--text-primary);
    }

    /* Route List */
    .route-list {
        background: var(--bg-secondary);
    }

    /* Search Box */
    .search-box input {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
    }

    .search-box input::placeholder {
        color: var(--text-secondary);
    }

    /* Checkboxes and Labels */
    .checkbox-label, .radio-label {
        color: var(--text-primary);
    }

    /* Loading Overlay */
    .loading-overlay {
        background: rgba(255, 255, 255, 0.95);
    }

    .loading-text {
        color: var(--text-primary);
    }

    /* Modals */
    .modal-content {
        background: var(--bg-secondary);
        color: var(--text-primary);
    }

    .modal-header {
        background: var(--bg-tertiary);
        border-bottom: 1px solid var(--border-color);
    }

    .modal-header h2 {
        color: var(--text-bright);
    }

    .modal-body {
        color: var(--text-primary);
    }

    .modal-close {
        color: var(--text-primary);
    }

    .modal-close:hover {
        color: var(--accent-color);
    }

    /* File Upload Area */
    .file-upload {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
    }

    .file-info {
        color: var(--text-secondary);
    }

    /* Toggle Button */
    .toggle-btn {
        background: var(--bg-secondary);
        color: var(--text-primary);
        border-left: 1px solid var(--border-color);
    }

    .toggle-btn:hover {
        background: var(--control-hover);
    }

    /* Collapsible Headers */
    .collapsible-header-wrapper {
        background: var(--bg-tertiary);
    }

    .section-toggle-btn {
        background: var(--control-bg);
        color: var(--text-primary);
    }

    .section-toggle-btn:hover {
        background: var(--control-hover);
    }

    /* Quick Select */
    .quick-select {
        background: var(--bg-tertiary);
    }

    .quick-select div[style*="max-height"] {
        border: 1px solid var(--border-color);
        background: var(--bg-secondary);
    }

    /* Route Pills */
    .route-pill {
        background: var(--control-bg);
        color: var(--text-primary);
        border: 1px solid var(--border-color);
    }

    .route-pill:hover {
        background: var(--control-hover);
    }

    .route-pill.active {
        background: var(--accent-color);
        color: white;
        border-color: var(--accent-color);
    }

    /* Category Buttons */
    .category-btn {
        border: 1px solid var(--border-color);
        color: var(--text-primary);
    }

    .category-btn:hover {
        background: var(--control-hover);
        box-shadow: 0 2px 4px var(--shadow-color) !important;
    }

    .category-btn.active {
        background: var(--accent-color);
        border-color: var(--accent-color);
        color: white;
    }

    /* Resize Handle */
    #resize-handle {
        background: var(--border-color);
    }

    #resize-handle:hover {
        background: var(--accent-color);
    }

    #resize-handle:active {
        background: var(--accent-hover);
    }

    /* Pattern Items */
    .pattern-item {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
    }

    /* Time Period Buttons */
    .time-period-btn {
        background: var(--control-bg);
        color: var(--text-primary);
        border: 1px solid var(--border-color);
    }

    .time-period-btn:hover {
        background: var(--control-hover);
    }

    .time-period-btn.active {
        background: var(--accent-color) !important;
        color: white !important;
    }

    /* Scrollbars for Light Mode */
    ::-webkit-scrollbar-track {
        background: var(--bg-tertiary);
    }

    ::-webkit-scrollbar-thumb {
        background: var(--text-secondary);
    }

    ::-webkit-scrollbar-thumb:hover {
        background: var(--text-primary);
    }

    /* GTFS Period Display */
    .gtfs-period-display {
        background: var(--control-bg);
        border-left-color: var(--accent-color);
    }

    /* Header Stats */
    .header-stats span {
        background: var(--control-bg);
        color: var(--text-primary);
    }

    /* Language & Theme Buttons */
    .lang-btn, .theme-btn {
        background: var(--control-bg);
        color: var(--text-primary);
        border-color: var(--border-color);
    }

    .lang-btn:hover, .theme-btn:hover {
        background: var(--control-hover);
    }

    .lang-btn.active, .theme-btn.active {
        background: var(--accent-color);
        border-color: var(--accent-color);
        color: white;
    }

    /* Focus States */
    input[type="date"]:focus,
    input[type="time"]:focus {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 2px rgba(204, 0, 0, 0.2);
    }

    .btn-primary:focus,
    .btn-secondary:focus,
    .route-item:focus,
    .agency-item:focus,
    .route-pill:focus {
        outline: 2px solid var(--accent-color);
    }

    /* Leaflet Popups */
    .leaflet-popup-content-wrapper {
        background: var(--bg-secondary);
        color: var(--text-primary);
    }

    .leaflet-popup-content {
        color: var(--text-primary);
    }

    .leaflet-popup-content strong {
        color: var(--text-bright);
    }

    .leaflet-popup-tip {
        background: var(--bg-secondary);
    }

    .leaflet-container a.leaflet-popup-close-button {
        color: var(--text-primary);
    }

    .leaflet-container a.leaflet-popup-close-button:hover {
        color: var(--accent-color);
    }

    /* Agency List Items */
    .agency-list {
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
    }

    /* Upload Status */
    #upload-status {
        color: var(--text-primary);
    }

    /* Loaded Files List */
    #loaded-files-list {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }

    #files-list {
        color: var(--text-primary);
    }

    /* Labels */
    label {
        color: var(--text-primary);
    }

    /* Map Container */
    #map-container {
        background: var(--bg-primary);
    }

    /* Stop Routes in Modal */
    #modal-routes-list {
        color: var(--text-primary);
    }

    /* Section Content */
    .section-content {
        color: var(--text-primary);
    }

    /* Date/Time Controls */
    .date-controls, .time-controls {
        color: var(--text-primary);
    }

    /* Display Controls */
    .display-controls {
        color: var(--text-primary);
    }

    /* Export Buttons Container */
    .export-controls {
        color: var(--text-primary);
    }

    .export-buttons {
        color: var(--text-primary);
    }

    /* Stop Display Controls */
    .stop-display-controls {
        color: var(--text-primary);
    }

    /* Route Pattern Controls */
    .route-pattern-controls {
        color: var(--text-primary);
    }

    /* Agency Buttons */
    .agency-buttons {
        color: var(--text-primary);
    }

    /* Route Controls */
    .route-controls {
        color: var(--text-primary);
    }
}