/* --- GRUNDLÄGGANDE --- */
* { box-sizing: border-box; }

body {
    margin: 0; padding: 0;
    background-color: #fff; color: #333;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.map-container { position: relative; width: 100vw; height: 100vh; }
#map { width: 100%; height: 100%; background-color: #ddd; z-index: 1; }

/* --- KONTROLLPANEL --- */
.controls-container {
    position: absolute; top: 15px; right: 15px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 1000; width: 180px;
}

.search-row { display: flex; gap: 5px; }

.map-input {
    flex: 1; background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc; border-radius: 8px; padding: 10px;
    font-size: 13px; color: #333; outline: none; width: 100%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.map-input:focus { border-color: #007bff; }

.map-btn {
    background-color: #007bff; color: #fff; border: none;
    border-radius: 8px; padding: 0 14px; font-size: 14px; cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.map-select {
    background-color: rgba(255, 255, 255, 0. 95);
    border: 1px solid #ccc; border-radius: 8px; padding: 10px;
    font-size: 13px; font-weight: 500; color: #333; width: 100%;
    outline: none; cursor: pointer; -webkit-appearance: none;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww. w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23333%22%20d%3D%22M287%2069.4a17. 6%2017. 6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12. 9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205. 4%2012. 8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205. 4-7.8%205.4-12.8%200-5-1. 9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat; background-position: right . 7em top 50%;
    background-size: . 65em auto; padding-right: 1. 5em;
}

.toggle-row {
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc; border-radius: 8px; padding: 8px 10px;
    font-size: 13px; font-weight: 500; color: #333;
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* --- STATUSRUTAN --- */
.status-box {
    position: absolute; bottom: 30px; left: 15px;
    background-color: rgba(255, 255, 255, 0.95); backdrop-filter: blur(4px);
    color: #000; padding: 10px 15px; border-radius: 20px; border: 1px solid #ddd;
    z-index: 1000; display: flex; align-items: center; gap: 10px;
    font-size: 13px; font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

. spinner {
    width: 14px; height: 14px; border: 2px solid #ccc;
    border-top: 2px solid #007bff; border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- TÅGMARKÖRERNA (FÖRSTORADE) --- */
.train-marker-icon {
    border: 2px solid #fff;
    border-radius: 50% ! important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    display: flex ! important; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-family: sans-serif;
    text-shadow: 0 0 2px rgba(0,0,0,0.7);
    
    /* NY STORLEK: 30px (var 22px) */
    width: 30px ! important;
    height: 30px !important;
    font-size: 13px; /* Större text */
    
    transition: background-color 0. 3s ease, transform 0.2s ease;
}

.icon-text { position: relative; z-index: 10; line-height: 1; margin-top: 1px; }

/* Pilen anpassad för 30px */
.direction-wrapper {
    position: absolute; top: -2px; left: -2px;
    width: 30px; height: 30px; /* Matcha markörens storlek */
    border-radius: 50%; pointer-events: none; z-index: 5;
}

.arrow-tip {
    position: absolute; top: -6px; left: 50%; transform: translateX(-50%);
    width: 0; height: 0; 
    border-left: 5px solid transparent; border-right: 5px solid transparent;
    border-bottom: 7px solid #333; /* Lite större pil */
    filter: drop-shadow(0 -1px 0 #fff);
}

.marker-unknown { background-color: #f5a623; }
.marker-ontime  { background-color: #28a745; }
.marker-delayed { background-color: #dc3545; }

/* VALT TÅG (Extra stort) */
.marker-highlighted {
    border: 3px solid #ffeb3b ! important;
    width: 44px ! important;
    height: 44px ! important;
    z-index: 10000 !important;
    box-shadow: 0 0 20px rgba(255, 235, 59, 0.9) !important;
}
.marker-highlighted .icon-text { font-size: 18px; }
.marker-highlighted . direction-wrapper { width: 44px; height: 44px; top: -3px; left: -3px; }

/* Plankorsningar */
.crossing-marker {
    background-color: #fff; border: 2px solid #555;
    width: 10px ! important; height: 10px !important;
    transform: rotate(45deg); box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* --- POPUP (Card) --- */
.leaflet-popup-content-wrapper {
    background-color: #fff; border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3); padding: 0; overflow: hidden;
}
.leaflet-popup-content { margin: 0; width: 260px ! important; font-family: -apple-system, sans-serif; }
.leaflet-popup-tip { background-color: #fff; box-shadow: 0 10px 25px rgba(0,0,0,0.3); }

.popup-header {
    background-color: #f9f9f9; padding: 12px 15px;
    border-bottom: 1px solid #eaeaea; display: flex;
    justify-content: space-between; align-items: center;
}
.popup-train-id { font-size: 16px; font-weight: 800; color: #2c3e50; }
.popup-dest { font-size: 11px; color: #7f8c8d; font-weight: 600; text-transform: uppercase; }

.status-badge {
    padding: 4px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap;
}
.status-ontime { background-color: #d4edda; color: #155724; }
.status-delayed { background-color: #f8d7da; color: #721c24; }
.status-early { background-color: #cce5ff; color: #004085; }
.status-unknown { background-color: #fff3cd; color: #856404; }

.popup-body { padding: 15px; }
.info-row { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.info-label { color: #95a5a6; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.info-value { color: #34495e; font-weight: 600; text-align: right; }

.popup-btn {
    display: block; margin-top: 15px; padding: 10px;
    background-color: #007bff; color: #fff ! important; text-align: center;
    text-decoration: none; font-size: 13px; font-weight: 600;
    border-radius: 8px; transition: background-color 0.2s;
}
.popup-btn:hover { background-color: #0056b3; }

/* --- MOBIL-LAYOUT --- */
@media (max-width: 450px) {
    .controls-container { 
        width: auto; 
        left: 10px; 
        right: 10px; 
        top: 10px; 
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .search-row { 
        flex: 1 1 auto;
        min-width: 120px;
        max-width: 50%;
    }
    
    .map-input {
        padding: 8px;
        font-size: 12px;
    }
    
    .map-btn {
        padding: 0 10px;
        font-size: 12px;
    }
    
    .map-select { 
        flex: 1 1 auto;
        min-width: 100px;
        padding: 8px;
        font-size: 12px;
    }
    
    .toggle-row {
        flex: 1 1 100%;
        padding: 6px 10px;
        font-size: 12px;
        justify-content: center;
    }
    
    .toggle-row span {
        font-size: 11px !important;
        margin-left: 5px;
    }
}