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

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent: #0071e3;
    --accent-hover: #0060c0;
    --border: #d2d2d7;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    padding: 40px 20px 20px;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 4px;
    font-size: 1rem;
}

main {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 0 20px 60px;
    flex: 1;
}

/* Form */
form {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 32px;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    background: var(--surface);
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
}

.form-group-btn {
    flex: 0 0 auto;
    justify-content: flex-end;
}

button[type="submit"] {
    padding: 10px 32px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

button[type="submit"]:hover {
    background: var(--accent-hover);
}

button[type="submit"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Autocomplete */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    z-index: 100;
    display: none;
    max-height: 240px;
    overflow-y: auto;
}

.autocomplete-dropdown.active {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--bg);
}

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

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--bg);
}

.autocomplete-item .main-text {
    font-weight: 600;
}

.autocomplete-item .secondary-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Loading */
#loading {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Errors */
#errors {
    background: #fff3f3;
    border: 1px solid #ffcccc;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
    color: #cc0000;
    font-size: 0.9rem;
}

/* Results */
.result-section {
    margin-bottom: 40px;
}

.result-section h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-hover);
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.card .price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.card .tag {
    display: inline-block;
    background: var(--bg);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-right: 4px;
    margin-bottom: 4px;
}

.card .tag.michelin {
    background: #c40d0d;
    color: #fff;
}

.card .links {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.card .links a {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
}

.card .links a:hover {
    text-decoration: underline;
}

.card .detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.card .flight-route {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.card .stops {
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg);
}

.card .stops.nonstop {
    background: #e8f5e9;
    color: #2e7d32;
}

/* Airline header */
.airline-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.airline-info {
    display: flex;
    flex-direction: column;
}

.airline-info h3 {
    margin-bottom: 0;
}

.flight-number {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.airline-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
}

.seatguru-link {
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg);
}

.seatguru-link:hover {
    text-decoration: underline;
    background: #e8e8ed;
}

/* Cabin price tags */
.cabin-prices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.cabin-price {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg);
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    transition: box-shadow 0.2s, background 0.2s;
}

.cabin-price:hover {
    background: #e8e8ed;
    box-shadow: var(--shadow);
}

.cabin-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.cabin-amount {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}

.section-error {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 8px;
    padding: 16px;
    color: #f57f17;
    font-size: 0.9rem;
}

.section-empty {
    color: var(--text-secondary);
    font-style: italic;
    padding: 20px 0;
}

.hidden {
    display: none !important;
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
}

/* Connecting flights toggle */
.connecting-section {
    margin-top: 16px;
    grid-column: 1 / -1;
}

.connecting-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s;
}

.connecting-toggle:hover {
    background: var(--bg);
}

.connecting-arrow {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.connecting-list {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.connecting-list.collapsed {
    display: none;
}

/* Seat Map Modal */
.seatmap-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

.seatmap-overlay.active {
    display: flex;
}

.seatmap-modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    max-width: 720px;
    width: 100%;
    max-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
}

.seatmap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.seatmap-title {
    font-weight: 700;
    font-size: 1.1rem;
}

.seatmap-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    line-height: 1;
}

.seatmap-close:hover {
    color: var(--text);
}

.seatmap-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.seatmap-loading {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
}

.seatmap-error {
    text-align: center;
    color: #cc0000;
    padding: 20px;
}

/* Cabin sections */
.seatmap-cabin {
    margin-bottom: 24px;
}

.seatmap-cabin-header {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

/* Seat grid rows */
.seatmap-row {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 2px;
    position: relative;
}

.seatmap-col-headers {
    margin-bottom: 4px;
}

.seatmap-row-num {
    width: 28px;
    text-align: right;
    font-size: 0.7rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    padding-right: 4px;
}

.seatmap-col-letter {
    width: 36px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.seatmap-seat {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 600;
    flex-shrink: 0;
    cursor: default;
}

.seatmap-available {
    background: #e3f2fd;
    border: 1.5px solid #42a5f5;
    color: #1565c0;
}

.seatmap-occupied {
    background: #e0e0e0;
    border: 1.5px solid #bdbdbd;
    color: #757575;
}

.seatmap-empty {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.seatmap-aisle {
    width: 24px;
    flex-shrink: 0;
}

/* Wing indicators */
.seatmap-wing::before,
.seatmap-wing::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #90a4ae;
    border-radius: 1px;
}

.seatmap-wing::before {
    left: -6px;
}

.seatmap-wing::after {
    right: -6px;
}

/* Facility rows */
.seatmap-facility {
    text-align: center;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    background: var(--bg);
    padding: 4px 8px;
    border-radius: 4px;
    margin: 4px 0;
}

/* Legend */
.seatmap-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-seat {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    display: inline-block;
}

.legend-available {
    background: #e3f2fd;
    border: 1.5px solid #42a5f5;
}

.legend-occupied {
    background: #e0e0e0;
    border: 1.5px solid #bdbdbd;
}

/* Responsive */
@media (max-width: 640px) {
    .form-row {
        flex-direction: column;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .cabin-prices {
        gap: 6px;
    }

    .cabin-price {
        padding: 6px 10px;
    }

    .seatmap-overlay {
        padding: 20px 10px;
    }

    .seatmap-seat {
        width: 28px;
        height: 28px;
        font-size: 0.55rem;
    }

    .seatmap-empty {
        width: 28px;
        height: 28px;
    }

    .seatmap-col-letter {
        width: 28px;
    }

    .seatmap-aisle {
        width: 16px;
    }

    .seatmap-row-num {
        width: 24px;
    }
}
