:root {
    --br-blue: #003b7a;
    --br-blue-deep: #002a57;
    --br-blue-ink: #0d2340;
    --br-blue-bright: #0f5fb5;
    --br-blue-pale: #d9ebff;
    --br-panel: #ffffff;
    --br-panel-edge: #c2d6ee;
    --br-surface: #edf4fb;
    --br-surface-2: #e2edf8;
    --br-gold: #f1c54b;
    --br-text: #17283d;
    --br-text-soft: #4f6480;
}

body {
    font-family: "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
    line-height: 1.55;
    margin: 0;
    padding: 0;
    background: linear-gradient(180deg, #d4e4f6 0%, #e8f0f9 18%, #f5f9fd 100%);
    color: var(--br-text);
}

header {
    background: linear-gradient(180deg, #0a4d92 0%, var(--br-blue) 38%, var(--br-blue-deep) 100%);
    color: #fff;
    padding: 1.35rem 1.5rem 1.2rem;
    text-align: center;
    border-bottom: 4px solid var(--br-gold);
}

.brand-link {
    display: inline-block;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    font-family: "Arial Rounded MT Bold", "Trebuchet MS", "Gill Sans", sans-serif;
    font-size: clamp(2rem, 5vw, 3.1rem);
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #ffffff;
}

header p {
    margin: 0.45rem 0 0;
    color: rgba(255, 255, 255, 0.82);
}

main {
    max-width: 960px;
    margin: 1.6rem auto 2.5rem;
    padding: 0 1rem;
}

.search-box {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 255, 0.98));
    padding: 1rem;
    border-radius: 14px;
    border: 1px solid var(--br-panel-edge);
    margin-bottom: 1.2rem;
}

.search-form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 0.9rem 0.8rem;
    align-items: end;
}

.search-form-grid .form-group {
    margin: 0;
}

.search-form-grid .autocomplete-container:nth-of-type(3) {
    grid-column: 1 / -1;
}

.autocomplete-container {
    position: relative;
}

.autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--br-panel-edge);
    border-top: none;
    z-index: 99;
    max-height: 200px;
    overflow-y: auto;
    display: none;
}

.autocomplete-suggestion {
    padding: 0.65rem 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid #edf2f8;
}

.autocomplete-suggestion:last-child {
    border-bottom: none;
}

.autocomplete-suggestion:hover {
    background-color: var(--br-surface);
}

.suggestion-crs {
    font-weight: bold;
    color: var(--br-blue-bright);
    margin-right: 10px;
    display: inline-block;
    width: 40px;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

input[type="text"] {
    width: 100%;
    padding: 0.58rem 0.68rem;
    border: 1px solid #a8bfdc;
    border-radius: 8px;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.96);
    color: var(--br-text);
}

select {
    width: 100%;
    padding: 0.58rem 0.68rem;
    border: 1px solid #a8bfdc;
    border-radius: 8px;
    box-sizing: border-box;
    background: #fff;
}

input[type="text"]:focus,
select:focus {
    outline: 2px solid rgba(15, 95, 181, 0.18);
    border-color: var(--br-blue-bright);
}

button {
    background: linear-gradient(180deg, #f5cf63 0%, var(--br-gold) 100%);
    color: #151515;
    border: 1px solid #b68d17;
    padding: 0.48rem 0.88rem;
    font-size: 0.95rem;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    font-weight: 700;
}

button:hover {
    background: linear-gradient(180deg, #f8d879 0%, #e4b734 100%);
}

.secondary-button {
    background: linear-gradient(180deg, #f5cf63 0%, var(--br-gold) 100%);
    color: #151515;
    border: 1px solid #b68d17;
}

.secondary-button:hover {
    background: linear-gradient(180deg, #f8d879 0%, #e4b734 100%);
}

.journey-swap-button {
    width: 3rem;
    min-width: 3rem;
    padding: 0.48rem 0;
    align-self: center;
    margin-top: 1.7rem;
}

.search-submit-button {
    grid-column: 1 / -1;
}

.detail-header {
    justify-content: flex-start;
}

.detail-header button {
    width: auto;
}

.bag-toolbar-row {
    display: flex;
    gap: 1rem;
    align-items: end;
}

.bag-toolbar-row .form-group {
    flex: 1;
    margin: 0;
}

.bag-toolbar-row button {
    width: auto;
}

.filter-box {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(242, 248, 255, 0.96));
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    border: 1px solid var(--br-panel-edge);
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: bold;
    margin-right: 1rem;
}

.filter-box label {
    font-weight: normal;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

.class-filter-option.is-disabled {
    color: #8a8f98;
    cursor: not-allowed;
    opacity: 0.6;
}

.class-filter-option.is-disabled input {
    cursor: not-allowed;
}

.child-toggle {
    margin-left: auto;
}

.fares-group {
    margin-bottom: 2rem;
}

.fares-group h2 {
    color: var(--br-blue-deep);
    border-bottom: 3px solid var(--br-gold);
    padding-bottom: 0.45rem;
    margin-bottom: 0.85rem;
}

table.fares-table {
    width: 100%;
    border-collapse: collapse;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid var(--br-panel-edge);
    border-radius: 12px;
    overflow: hidden;
}

table.fares-table th, table.fares-table td {
    padding: 0.66rem 0.72rem;
    text-align: left;
    border-bottom: 1px solid #d9e4f1;
}

table.fares-table th {
    background: linear-gradient(180deg, #e2eefb 0%, #d4e4f7 100%);
    font-weight: bold;
    color: var(--br-blue-ink);
}

table.fares-table tr:hover {
    background-color: #eef5fd;
}

table.fares-table tr.child-fare-row,
table.fares-table tr.child-fare-row:hover {
    background-color: #fff2cf;
}

table.fares-table tr.reverse-missing-row,
table.fares-table tr.reverse-missing-row:hover {
    background-color: #fff0f0;
}

table.fares-table tr.reverse-different-row,
table.fares-table tr.reverse-different-row:hover {
    background-color: #fff8df;
}

.child-fare-label {
    color: #7a4b00;
    font-weight: 600;
}

.original-fare {
    color: #666;
    display: block;
    margin-top: 0.2rem;
}

.fare-asterisk {
    color: #a55a00;
    font-weight: 700;
    margin-left: 0.15rem;
}

.reverse-note {
    color: #7a2f2f;
    display: block;
    margin-top: 0.2rem;
    font-size: 0.86rem;
}

.reverse-note.is-different {
    color: #8a6200;
}

.fare-detail-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 250, 255, 0.97));
    padding: 1.15rem;
    border-radius: 14px;
    border: 1px solid var(--br-panel-edge);
}

.fare-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.fare-detail-grid div {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.fare-detail-copy h3 {
    margin-top: 0;
    color: var(--br-blue-deep);
}

.restriction-details {
    margin: 0.9rem 0 0;
    padding-left: 1.2rem;
}

.restriction-details li {
    margin-bottom: 0.35rem;
}

.restriction-raw {
    margin-top: 0.6rem;
    padding: 0.75rem;
    background: #edf4fb;
    border: 1px solid #c8d8ea;
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre-wrap;
    font-size: 0.88rem;
    line-height: 1.45;
}

.fare-detail-actions {
    margin-top: 1.5rem;
}

.fare-detail-actions button {
    width: auto;
}

tbody tr.fare-row {
    cursor: pointer;
}

.bag-action-button {
    width: auto;
    padding: 0.28rem 0.55rem;
    font-size: 0.82rem;
    line-height: 1.2;
}

.bag-header-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.bag-header-row h2 {
    margin: 0;
}

.bag-header-row button {
    width: auto;
}

.bag-empty-state {
    color: #666;
}

.bag-group-card {
    border: 1px solid var(--br-panel-edge);
    border-radius: 12px;
    padding: 0.8rem;
    margin-top: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(240, 247, 255, 0.96));
}

.bag-group-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 0.75rem;
}

.bag-group-header h3 {
    margin: 0;
}

.bag-group-actions {
    display: flex;
    gap: 0.5rem;
}

.bag-group-actions button {
    width: auto;
    padding: 0.35rem 0.65rem;
}

.bag-total {
    font-weight: 700;
    color: var(--br-blue-deep);
    margin-bottom: 0.75rem;
}

.bag-items-table {
    width: 100%;
    border-collapse: collapse;
}

.bag-items-table th,
.bag-items-table td {
    padding: 0.65rem 0.5rem;
    text-align: left;
    border-top: 1px solid #d8e4f0;
    vertical-align: top;
}

.bag-remove-button {
    width: auto;
    padding: 0.3rem 0.55rem;
    background-color: #8b1e1e;
}

.bag-remove-button:hover {
    background-color: #6f1717;
}

.bag-ticket-meta {
    color: #666;
    font-size: 0.9rem;
}

@media (max-width: 720px) {
    .search-form-grid {
        grid-template-columns: 1fr;
    }

    .search-form-grid .autocomplete-container:nth-of-type(3),
    .search-submit-button {
        grid-column: auto;
    }

    .journey-swap-button {
        width: auto;
        min-width: 0;
        margin-top: 0;
    }

    .bag-toolbar-row,
    .bag-group-header {
        flex-direction: column;
        align-items: stretch;
    }

    .bag-group-actions {
        flex-wrap: wrap;
    }
}

#loading, #error {
    text-align: center;
    margin-top: 1rem;
    font-weight: bold;
}

@media (max-width: 720px) {
    main {
        margin-top: 1rem;
        padding: 0 0.75rem 1.5rem;
    }

    .filter-box {
        gap: 0.75rem;
    }
}
