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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #333;
}

/* Navbar */
.navbar {
    background: #1a3a5c;
    color: #fff;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-links a {
    color: #cde;
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-links a:hover {
    color: #fff;
}

.nav-user {
    font-size: 0.85rem;
    color: #aac;
}

.btn-logout {
    background: transparent;
    border: 1px solid #557;
    color: #cde;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-logout:hover {
    background: #2a4a6c;
}

/* Container */
.container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Messages */
.messages {
    margin-bottom: 1rem;
}

.message {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.message-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.message-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.message-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.message-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1.1rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
}

.btn-primary {
    background: #1a3a5c;
    color: #fff;
}

.btn-primary:hover {
    background: #244e7a;
}

.btn-secondary {
    background: #6c757d;
    color: #fff;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-download {
    background: #28a745;
    color: #fff;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
}

.btn-download:hover {
    background: #218838;
}

.btn-map {
    background: #17a2b8;
    color: #fff;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    margin-right: 0.4rem;
}

.btn-map:hover {
    background: #138496;
}

/* Map page */
.map-info-bar {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    font-size: 0.95rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.map-info-label {
    color: #555;
}

.map-info-sep {
    color: #aaa;
}

#route-map {
    width: 100%;
    height: 500px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: #1a3a5c;
}

/* File table */
.file-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.file-table th,
.file-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.9rem;
}

.file-table th {
    background: #e9ecef;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
}

.file-table tr:last-child td {
    border-bottom: none;
}

.file-table tr:hover td {
    background: #f8f9fa;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #888;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Login */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.login-container h2 {
    margin-top: 0;
    color: #1a3a5c;
}

/* Upload */
.upload-container {
    max-width: 600px;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.upload-container h2 {
    margin-top: 0;
    color: #1a3a5c;
}

/* Forms */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    color: #444;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.95rem;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-errors {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Edit Airports button */
.btn-edit {
    background: #6610f2;
    color: #fff;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
}

.btn-edit:hover {
    background: #560bd0;
}

/* Airport table section on map page */
.airport-table-section {
    margin-top: 2rem;
}

.airport-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.airport-table-header h3 {
    margin: 0;
    color: #1a3a5c;
    font-size: 1.2rem;
}

.airport-table-section > h3 {
    color: #1a3a5c;
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}

/* Airport edit page container */
.airport-edit-container {
    max-width: 900px;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.airport-edit-hint {
    color: #555;
    font-size: 0.9rem;
    margin-top: 0;
    margin-bottom: 1.5rem;
}

/* Airport row layout */
.airport-row {
    display: grid;
    grid-template-columns: 110px 1fr 1fr;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e9ecef;
}

.airport-row:last-child {
    border-bottom: none;
}

.airport-icao-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.airport-icao-group .icao-input {
    width: 80px;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.airport-row .name-input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Role badge */
.role-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.role-badge-origin {
    background: #d4edda;
    color: #155724;
}

.role-badge-destination {
    background: #f8d7da;
    color: #721c24;
}

.role-badge-alternate {
    background: #fde8cc;
    color: #7d4000;
}

/* Lookup button */
.btn-lookup {
    background: #1a3a5c;
    color: #fff;
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn-lookup:hover {
    background: #244e7a;
}

/* Lookup status feedback */
.lookup-status {
    font-size: 0.8rem;
    white-space: nowrap;
}

.lookup-ok {
    color: #28a745;
    font-weight: 600;
}

.lookup-err {
    color: #dc3545;
}

/* Remove alternate button */
.btn-remove-alt {
    background: #dc3545;
    color: #fff;
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}

.btn-remove-alt:hover {
    background: #c82333;
}

/* Add alternate / form actions spacing */
.airport-edit-actions {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

/* Waypoint table section on map page */
.waypoint-table-section {
    margin-top: 2rem;
}

.waypoint-table-section h3 {
    color: #1a3a5c;
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}

/* Leaflet waypoint divIcon marker */
.wp-marker {
    background: #1a3a5c;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    line-height: 1;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

/* Scrollable wrapper for wide tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 6px;
}
/* Let the table inside take full width but not force the page wider */
.table-responsive .file-table {
    min-width: 480px;
}

@media (max-width: 768px) {
    /* Navbar: wrap onto two lines if needed */
    .navbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.65rem 1rem;
    }
    .nav-links {
        flex-wrap: wrap;
        gap: 0.5rem 0.75rem;
        width: 100%;
    }
    .nav-user {
        font-size: 0.8rem;
    }

    /* Container: tighter margins */
    .container {
        margin: 1rem auto;
        padding: 0 0.75rem;
    }

    /* Page header: stack title and button */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.6rem;
        margin-bottom: 1rem;
    }

    /* Airport table header: stack h3 and Edit button */
    .airport-table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }

    /* Map: shorter on tablet */
    #route-map {
        height: 340px;
    }

    /* Airport edit grid: compress to badge + ICAO + name (2-col) */
    .airport-row {
        grid-template-columns: 100px 1fr;
        row-gap: 0.4rem;
    }

    /* Containers: reduce padding */
    .login-container,
    .upload-container,
    .airport-edit-container {
        padding: 1.25rem 1rem;
    }

    /* Table cells: slightly tighter */
    .file-table th,
    .file-table td {
        padding: 0.6rem 0.75rem;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    /* Navbar brand: slightly smaller */
    .nav-brand {
        font-size: 1rem;
    }

    /* Map: compact on phones */
    #route-map {
        height: 260px;
    }

    /* Airport edit grid: single column */
    .airport-row {
        grid-template-columns: 1fr;
    }

    /* Table cells: compact */
    .file-table th,
    .file-table td {
        padding: 0.5rem 0.6rem;
        font-size: 0.82rem;
    }

    /* Login: less top margin on small phones */
    .login-container {
        margin: 1.5rem auto;
    }

    /* Map info bar: allow wrapping */
    .map-info-bar {
        flex-wrap: wrap;
    }

    /* Form actions: stack buttons */
    .form-actions {
        flex-direction: column;
    }
    .form-actions .btn {
        width: 100%;
        text-align: center;
    }
}

/* Warning button */
.btn-warning { background: #fd7e14; color: #fff; padding: 0.35rem 0.8rem; font-size: 0.85rem; }
.btn-warning:hover { background: #e0690b; }

/* Version / status badges */
.badge { display: inline-block; padding: 0.2rem 0.55rem; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-current    { background: #d4edda; color: #155724; }
.badge-superseded { background: #e9ecef; color: #6c757d; }

/* Form hint text */
.form-hint { font-size: 0.82rem; color: #666; margin-top: 0.25rem; }

/* Section heading (e.g. Archived Routes) */
.section-heading { color: #1a3a5c; font-size: 1.2rem; margin: 2rem 0 0.75rem; }

/* Leaflet divIcon for alternate distance midpoint label */
.alt-label {
    background: rgba(255,255,255,0.85);
    border: 1px solid #fd7e14;
    border-radius: 4px;
    padding: 2px 5px;
    font-size: 0.75rem;
    color: #7d4000;
    white-space: nowrap;
    pointer-events: none;
}

.us-flag { font-size: 1.1rem; vertical-align: middle; margin-left: 0.3rem; }

/* Schedule app */
.container.container-wide { max-width: 1400px; }
.status-badge { display:inline-block; padding:.25rem .65rem; border-radius:12px; font-size:.8rem; font-weight:700; }
.status-draft { background:#fff3cd; color:#856404; border:1px solid #ffeeba; }
.status-published { background:#d4edda; color:#155724; border:1px solid #c3e6cb; }
.btn-danger { background:#dc3545; color:#fff; border:none; }
.btn-danger:hover { background:#c82333; }
