body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #f0f2f5;
    color: #1c1e21;
    display: flex;
    justify-content: center;
}

.main-container {
    max-width: 800px;
    width: 100%;
    margin: 20px;
}

h1 {
    color: #0056b3;
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 20px;
}

/* --- Navigation --- */
.main-nav {
    display: flex;
    background-color: #e9ebee;
    border-radius: 8px;
    margin-bottom: 20px;
    padding: 5px;
}

.nav-link {
    flex-grow: 1;
    text-align: center;
    padding: 10px 15px;
    text-decoration: none;
    color: #606770;
    font-weight: bold;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}

.nav-link:hover {
    background-color: #dddfe2;
}

.nav-link.active {
    background-color: #0056b3;
    color: #fff;
}


/* --- Page switching logic --- */
.page {
    display: none;
}

.page.active {
    display: block;
}


/* --- General Search Containers & Forms --- */
.search-container {
    background: #fff;
    padding: 20px 25px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.25rem;
}

#search-train-form, #search-station-form {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex-grow: 1;
    position: relative; /* For suggestions positioning */
}

.form-group label {
    font-size: 0.875rem;
    color: #606770;
}

input[type="text"], select {
    padding: 10px;
    border: 1px solid #dddfe2;
    border-radius: 6px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box; /* Ensures padding doesn't affect width */
    background-color: #f5f6f7;
}

.form-group-row {
    display: flex;
    gap: 15px;
    width: 100%;
}

#search-train-form button, .form-buttons button {
    padding: 10px 20px;
    border: none;
    background-color: #1877f2;
    color: white;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    height: 42px; /* Align with input height */
}

#search-train-form button:hover, .form-buttons button:hover {
    background-color: #166fe5;
}

.form-buttons {
    display: flex;
    gap: 10px;
}

/* --- Station Autocomplete --- */
#station-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dddfe2;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
}

#station-suggestions div {
    padding: 10px;
    cursor: pointer;
}

#station-suggestions div:hover {
    background-color: #f0f2f5;
}


/* --- Results Containers --- */
.results-container {
    background: #fff;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-height: 50px;
    /* display: none; Rimosso. Ora il suo stato di visibilità sarà controllato dal genitore .page o da JS */
}

/* --- Train Details Layout --- */
.train-details {
    padding: 20px 25px;
}

.train-main-header h2 {
    text-align: center;
    margin-bottom: 20px;
}

.train-journey {
    display: flex;
    justify-content: space-between;
    position: relative;
    padding: 0 10px;
    margin-bottom: 20px;
}

.train-journey::before {
    content: '';
    position: absolute;
    top: 6px; 
    left: 20px;
    right: 20px;
    height: 2px;
    background-image: linear-gradient(to right, #0056b3 33%, rgba(255,255,255,0) 0%);
    background-position: bottom;
    background-size: 8px 2px;
    background-repeat: repeat-x;
}

.journey-point {
    display: flex;
    flex-direction: column;
}
.journey-point--end {
    text-align: right;
}

.journey-point::before {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-bottom: 8px;
}

.journey-point--start::before {
    border: 2px solid #0056b3;
    background-color: #0056b3;
}
.journey-point--end::before {
    border: 2px solid #606770;
    background-color: #fff;
    align-self: flex-end;
}
.journey-point__time {
    font-weight: bold;
}
.journey-point__station {
    font-size: 0.9rem;
    color: #606770;
}

/* --- Status & Info Boxes --- */
.status-box {
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    gap: 15px;
    background: #f0f2f5;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 15px;
}

.info-box {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #f0f2f5;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 15px;
}
.status-box__icon, .info-box__icon {
    font-size: 1.5rem;
    color: #0056b3;
}
.status-box__text, .info-box__text {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.status-box__line1 {
    font-weight: bold;
}
.status-box__line2 {
    font-size: 0.9rem;
    color: #606770;
}
.status-box__help {
    position: relative; /* Contesto per il tooltip */
    font-size: 1.2rem;
    color: #0056b3;
    cursor: pointer;
}

.tooltip-box {
    position: absolute;
    top: 125%; /* Posizionato sotto l'icona */
    left: 50%;
    transform: translateX(-50%); /* Centra orizzontalmente */
    background-color: #333;
    color: #fff;
    padding: 10px 15px;
    border-radius: 6px;
    width: 250px;
    font-size: 0.9rem;
    text-align: left;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 999; /* Assicura che sia sempre sopra */
}

.tooltip-box::after { /* Freccia del tooltip */
    content: '';
    position: absolute;
    bottom: 100%; /* In alto al tooltip */
    left: 50%;
    transform: translateX(-50%); /* Centra la freccia */
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent #333 transparent;
}

.tooltip-box.active {
    visibility: visible;
    opacity: 1;
}

/* --- Stops Timeline --- */
.stops-header {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Assicura l'allineamento verticale */
    font-weight: bold;
    color: #606770;
    padding: 10px 0;
    border-bottom: 1px solid #dddfe2;
    margin-bottom: 10px;
}
.stops-header h3, .stops-header span {
    margin: 0; /* Rimuove i margini di default che causano disallineamento */
}

.stops-timeline {
    list-style-type: none;
    padding-left: 0;
}

.stops-timeline li {
    display: flex;
    position: relative;
    padding: 10px 0 10px 30px;
    align-items: center;
    justify-content: space-between;
}

.stops-timeline li::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 0;
    bottom: 0;
    width: 2px; /* Default solid line */
    background-color: #dddfe2;
}
.stops-timeline li.passed::before {
    background-color: #0056b3; /* Solid blue line for passed */
}
.stops-timeline li.suppressed::before {
    background-color: transparent; /* Nasconde la linea solida */
    border-left: 2px dashed #fa383e; /* Linea tratteggiata rossa */
    width: 0; /* Annulla la width, il bordo la definisce */
}
.stops-timeline li:first-child::before { top: 50%; }
.stops-timeline li:last-child::before { bottom: 50%; }

.timeline-marker {
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    z-index: 1;
}

.stops-timeline li.passed .timeline-marker {
    background-color: #0056b3;
    border: 2px solid #0056b3;
}
.stops-timeline li.future .timeline-marker {
    background-color: #fff;
    border: 2px solid #606770;
}
.stops-timeline li.suppressed .timeline-marker {
    background-color: #fa383e;
    border-color: #fa383e;
}
.stops-timeline li.suppressed .stop-name {
    text-decoration: line-through;
}

.stop-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.stop-name { font-weight: bold; }
.stops-timeline li[onclick] {
    cursor: pointer;
    transition: background-color 0.2s;
}
.stops-timeline li[onclick]:hover {
    background-color: #f5f5f5;
}
.stop-time { font-size: 0.9rem; color: #333; }
.stop-time strong { font-weight: 900; }

.stop-platform {
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 4px;
    min-width: 40px;
    text-align: center;
    margin-left: 10px;
}
.stops-timeline li.passed .stop-platform { background-color: #0056b3; color: #fff; }
.stops-timeline li.future .stop-platform { background-color: #e0e0e0; color: #333; }
.stops-timeline li.suppressed .stop-platform { background-color: #fa383e; color: #fff; }

.delay {
    font-weight: bold;
    color: #fa383e;
}

.error {
    color: #fa383e;
    font-weight: bold;
    padding: 20px 25px;
}

.no-results-message {
    text-align: center;
    padding: 20px;
    color: #606770;
    font-size: 1.1rem;
}

/* --- Train Choices Box --- */
.choices-container {
    padding: 20px 25px;
}
.train-choices {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
.train-choices li {
    margin-bottom: 10px;
}
.choice-button {
    width: 100%;
    padding: 15px;
    font-size: 1rem;
    text-align: left;
    background-color: #f0f2f5;
    border: 1px solid #dddfe2;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}
.choice-button:hover {
    background-color: #e0e0e0;
    border-color: #ccc;
}


/* Station board table */
.station-board h3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0;
    color: #1877f2;
    padding: 10px 15px; /* Aggiungi padding per non attaccare al bordo */
}

.station-board-header-actions {
    display: flex;
    gap: 10px;
}

.switch-board-button, .icon-button {
    padding: 8px 12px;
    border: 1px solid #ccc;
    background-color: #f0f2f5;
    color: #333;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.switch-board-button:hover, .icon-button:hover {
    background-color: #e0e0e0;
}

.icon-button {
    padding: 8px 10px;
}

/* --- Filter Modal --- */
.modal-overlay {
    display: none; /* Nascosto di default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.visible {
    display: flex; /* Mostra il modale */
}

.modal-content {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
}

.board-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
    text-align: left;
    margin-bottom: 20px;
}

.filter-checkbox-label {
    display: block;
    width: calc(50% - 5px); /* Due colonne */
    font-size: 1rem;
}

#apply-filters-btn {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 6px;
    background-color: #1877f2;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s;
}

#apply-filters-btn:hover {
    background-color: #166fe5;
}


.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.results-table th, .results-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid #dddfe2;
}

.results-table th {
    font-weight: bold;
    background-color: #f0f2f5;
}

.results-table tr:hover {
    background-color: #f5f5f5;
}

/* --- New Path Solutions Card Layout --- */
.path-solutions__list {
    padding: 0;
    list-style-type: none;
}

.path-solution__item {
    background: #fff;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
}

.path-solution__body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px; /* Spazio tra le tratte (legs) */
}

.solution-leg {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Allinea tutto a sinistra */
    gap: 4px;
}

.leg__train-info {
    font-weight: bold;
    font-size: 1.1rem;
    color: #1877f2;
    padding: 6px;
    border-radius: 6px;
    transition: background-color 0.2s;
    margin-bottom: 4px;
}

.leg__train-info.clickable {
    cursor: pointer;
}

.leg__train-info.clickable:hover {
    background-color: #e9ebee;
}

.leg__time {
    font-weight: bold;
    font-size: 1rem;
    color: #1c1e21;
}

.leg__station {
    color: #606770;
    padding-left: 5px;
}

.leg__station.clickable-station {
    color: #0056b3;
    cursor: pointer;
    font-weight: 500;
}

.leg__station.clickable-station:hover {
    text-decoration: underline;
}

.wait-time {
    text-align: center;
    font-style: italic;
    color: #606770;
    font-size: 0.9rem;
    padding: 10px 0;
    width: 100%;
    border-top: 1px dashed #ccc;
    border-bottom: 1px dashed #ccc;
    margin-top: 5px;
    margin-bottom: 5px;
}

.path-solution__footer {
    background-color: #f0f2f5;
    padding: 12px 20px;
    text-align: right;
    font-weight: bold;
    color: #333;
    border-top: 1px solid #dddfe2;
}
