* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100%;
    width: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Top Header with Container and Direction */
#top-header {
    position: absolute;
    top: 0;
    left: 380px;
    right: 0;
    background: #ffffff;
    padding: 12px 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 4;
}

#top-header .header-content {
    display: flex;
    align-items: center;
    gap: 30px;
}

#top-header .container-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

#top-header .container-label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#top-header #container-number-text {
    font-size: 14px;
    font-weight: 700;
    color: #2a467c;
    letter-spacing: 0.3px;
}

#top-header .direction-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

#top-header .direction-selector label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#top-header .direction-selector select {
    padding: 6px 12px;
    border: 2px solid #2a467c;
    border-radius: 6px;
    background: #ffffff;
    color: #2a467c;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}

#top-header .direction-selector select:hover {
    background: #f5f5f5;
}

/* Top Controls (Centered) */
#top-controls {
    position: absolute;
    top: 60px;
    left: 380px;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 3;
    padding: 0 20px;
}

#top-controls .control-buttons {
    display: flex;
    gap: 10px;
    background: #ffffff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

#top-controls button {
    padding: 8px 16px;
    border: 2px dashed rgba(42, 70, 124, 0.6);
    border-radius: 999px;
    background: #ffffff;
    color: #2a467c;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    white-space: nowrap;
}

#top-controls button .label {
    letter-spacing: 0.2px;
}

#top-controls button.active {
    background: #2a467c;
    color: #ffffff;
    border-style: solid;
    border-color: #2a467c;
}

#top-controls button:not(.active):hover {
    border-style: solid;
    border-color: rgba(42, 70, 124, 0.8);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#top-controls button .check {
    width: 0;
    font-size: 12px;
    line-height: 1;
    text-align: center;
    color: inherit;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s ease, transform 0.2s ease, width 0.2s ease;
    overflow: hidden;
}

#top-controls button.active .check {
    width: 1em;
    opacity: 1;
    transform: scale(1);
}

#top-controls button.reset-btn {
    border: 2px solid #2a467c;
    background: #2a467c;
    color: #ffffff;
}

#top-controls button.reset-btn:hover {
    background: #1e3459;
    border-color: #1e3459;
}

/* Timeline Panel - Fixed Left */
#timeline-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 380px;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid #e0e0e0;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.08);
    z-index: 5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.timeline-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.timeline-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #2a467c;
}

.timeline-list {
    overflow-y: auto;
    padding: 20px;
    flex: 1;
}

.timeline-item {
    position: relative;
    padding-left: 50px;
    padding-bottom: 28px;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item:last-child .timeline-icon-line {
    display: none;
}

.timeline-icon {
    position: absolute;
    left: 0;
    top: 0;
}

.timeline-icon-container {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e0e0e0;
    position: relative;
    z-index: 2;
    border: 3px solid #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.timeline-icon-container svg {
    width: 18px;
    height: 18px;
    fill: #666;
}

.timeline-icon-line {
    position: absolute;
    left: 17px;
    top: 36px;
    width: 2px;
    height: calc(100% + 28px);
    background: #e0e0e0;
    z-index: 1;
}

.timeline-item.timeline-completed .timeline-icon-container {
    background: #4caf50;
}

.timeline-item.timeline-completed .timeline-icon-container svg {
    fill: #ffffff;
}

.timeline-item.timeline-delayed .timeline-icon-container {
    background: #ff9800;
}

.timeline-item.timeline-delayed .timeline-icon-container svg {
    fill: #ffffff;
}

.timeline-item.timeline-early .timeline-icon-container {
    background: #4caf50;
}

.timeline-item.timeline-early .timeline-icon-container svg {
    fill: #ffffff;
}

/* Pending/Future stops - grey and dotted */
.timeline-item.timeline-pending .timeline-icon-container {
    background: #9e9e9e;
}

.timeline-item.timeline-pending .timeline-icon-container svg {
    fill: #ffffff;
}

.timeline-item.timeline-pending .timeline-icon-line {
    background: transparent;
    border-left: 2px dotted #bdbdbd;
}

.timeline-item.timeline-pending .timeline-title {
    color: #666;
}

.timeline-item.timeline-pending .timeline-eta,
.timeline-item.timeline-pending .timeline-datetime {
    color: #999;
}

/* Expected delays on pending stops - still grey icon but show badge */
.timeline-item.timeline-expected-delayed .timeline-icon-container {
    background: #9e9e9e;
}

.timeline-item.timeline-expected-early .timeline-icon-container {
    background: #9e9e9e;
}

.timeline-content {
    padding-top: 2px;
}

.timeline-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    line-height: 1.4;
}

.timeline-item.timeline-completed .timeline-title {
    font-weight: 700;
}

.timeline-datetime {
    font-size: 12px;
    color: #999;
    margin-bottom: 4px;
}

.timeline-eta {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.timeline-delay-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 6px;
}

.timeline-delay-tag.delay {
    background: #fff3cd;
    color: #856404;
}

.timeline-delay-tag.early {
    background: #d4edda;
    color: #155724;
}

.timeline-delay-tag.expected-delay {
    background: #fff3cd;
    color: #856404;
}

.timeline-delay-tag.expected-early {
    background: #d4edda;
    color: #155724;
}

/* Map */
#map {
    position: absolute;
    top: 0;
    left: 380px;
    right: 0;
    bottom: 0;
    width: calc(100% - 380px);
    height: 100%;
}

#map-key {
    position: absolute;
    top: 130px;
    right: 20px;
    background: #ffffff;
    padding: 16px 24px;
    border-radius: 8px;
    color: #000000;
    font-size: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 2;
    pointer-events: none;
}

#map-key h3 {
    margin: 0 0 12px 0;
    font-size: 12px;
    font-weight: 700;
    color: #2a467c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#map-key div {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

#map-key div:last-child {
    margin-bottom: 0;
}

#map-key span {
    display: inline-block;
    width: 32px;
    height: 10px;
    border-radius: 4px;
    background: #ccc;
}

#map-key span.optimal {
    background: linear-gradient(90deg, #ffc107 0, #ffc107 50%, transparent 50%, transparent 100%);
    background-size: 8px 100%;
}

#railx-logo {
    position: absolute;
    bottom: 20px;
    left: 400px;
    background: #ffffff;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 2;
    pointer-events: auto;
    transition: box-shadow 0.2s ease;
}

#railx-logo:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

#railx-logo a {
    cursor: pointer;
}

#railx-logo img {
    display: block;
    height: 28px;
    width: auto;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.7;
    }
    100% {
        transform: translate(-50%, -50%) scale(3);
        opacity: 0;
    }
}

/* Loader overlay */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #2a467c;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loader-content p {
    color: #2a467c;
    font-size: 16px;
    font-weight: 600;
}

/* Container input modal */
#container-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(42, 70, 124, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Error modal */
#error-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(139, 0, 0, 0.95);
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-content {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.error-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.error-content h2 {
    color: #c41e3a;
    margin-bottom: 16px;
    font-size: 24px;
}

.error-content p {
    color: #666;
    margin-bottom: 12px;
    font-size: 16px;
}

.error-detail {
    color: #999;
    font-size: 14px;
    margin-bottom: 24px;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 90%;
    text-align: center;
}

.modal-logo {
    height: 40px;
    margin-bottom: 24px;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.modal-content h2 {
    color: #2a467c;
    margin-bottom: 16px;
    font-size: 28px;
}

.modal-content p {
    color: #666;
    margin-bottom: 24px;
    font-size: 16px;
}

#container-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#container-input {
    padding: 14px 18px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: border-color 0.2s ease;
}

#container-input:focus {
    outline: none;
    border-color: #2a467c;
}

.btn-primary {
    padding: 14px 24px;
    background: #2a467c;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-primary:hover {
    background: #1e3350;
}

/* Responsive styles for smaller screens */
@media (max-width: 1024px) {
    #timeline-panel {
        width: 320px;
    }
    
    #top-header {
        left: 320px;
    }
    
    #top-controls {
        left: 320px;
    }
    
    #map {
        left: 320px;
        width: calc(100% - 320px);
    }
    
    #railx-logo {
        left: 340px;
    }
}

@media (max-width: 768px) {
    #timeline-panel {
        width: 100%;
        height: 40vh;
        top: auto;
        bottom: 0;
        border-right: none;
        border-top: 1px solid #e0e0e0;
    }
    
    #top-header {
        left: 0;
        top: 0;
    }
    
    #top-controls {
        left: 0;
        top: 55px;
        padding: 0 10px;
    }
    
    #top-controls .control-buttons {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }
    
    #top-controls button {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    #map {
        left: 0;
        top: 115px;
        bottom: 40vh;
        width: 100%;
        height: auto;
    }
    
    #map-key {
        top: 125px;
        right: 10px;
        font-size: 10px;
        padding: 12px 16px;
    }
    
    #railx-logo {
        display: none;
    }
}
