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

/* Offline banner */
.offline-banner {
    background: #e65100;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 0.85em;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2000;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Login */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 360px;
    border-top: 6px solid #FFCC00;
}

.login-logo img {
    width: 120px;
    margin-bottom: 20px;
}

.login-box h2 {
    color: #D40511;
    margin-bottom: 20px;
    font-size: 1.4em;
}

.login-box input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1em;
    margin-bottom: 15px;
    transition: border-color 0.3s;
}

.login-box input:focus {
    outline: none;
    border-color: #FFCC00;
}

.login-box button {
    width: 100%;
    padding: 12px;
    background: #D40511;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.login-box button:hover {
    background: #b00410;
}

.login-error {
    color: #D40511;
    margin-top: 10px;
    font-size: 0.9em;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    background: #FFFFFF;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    border-left: 8px solid #FFCC00;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.logo img {
    width: 120px;
    height: auto;
}

header h1 {
    color: #D40511;
    font-size: 2.2em;
    font-weight: 700;
    margin-bottom: 10px;
}

.update-time {
    color: #666;
    font-size: 0.95em;
}

/* Duty Manager Display */
.header-right-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.header-right-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logged-in-as {
    font-size: 0.85em;
    color: #888;
}

.btn-logout {
    padding: 5px 14px;
    background: #c62828;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-logout:hover {
    background: #a02020;
}

.duty-manager-display {
    text-align: right;
    flex-shrink: 0;
}

.duty-manager-header {
    font-weight: 700;
    color: #D40511;
    font-size: 0.9em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.duty-manager-entry {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-bottom: 6px;
}

.duty-manager-entry .duty-manager-name {
    font-weight: 600;
    font-size: 1em;
    color: #333;
}

.duty-manager-entry .duty-manager-dates {
    font-size: 0.85em;
    color: #888;
}

.fleet-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.fleet-card {
    background: #FFFFFF;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-top: 5px solid #FFCC00;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.fleet-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.15);
}

.fleet-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.fleet-card h3 {
    color: #D40511;
    font-size: 1.4em;
    font-weight: 700;
    margin: 0;
}

.fleet-bookmark-btn {
    background: none;
    border: none;
    font-size: 1.3em;
    cursor: pointer;
    color: #ccc;
    transition: color 0.2s;
    padding: 2px 5px;
}

.fleet-bookmark-btn:hover {
    color: #D40511;
}

.fleet-bookmark-btn.bookmarked {
    color: #FFCC00;
}

.stats {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.stats.stats-pw {
    margin-top: 0;
}

.stat-serviceable {
    background: #4CAF50;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

.stat-total {
    background: #666;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

.aircraft-selector {
    background: #FFFFFF;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.aircraft-selector label {
    display: block;
    color: #D40511;
    font-weight: 600;
    font-size: 1.1em;
    margin-bottom: 12px;
}

#aircraft-select {
    width: 100%;
    padding: 15px;
    padding-right: 40px;
    border: 2px solid #FFCC00;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='10'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23D40511' stroke-width='2.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
}

#aircraft-select:hover {
    border-color: #D40511;
}

.bookmarks-section {
    margin-bottom: 30px;
}

.bookmarks-section h3 {
    color: #D40511;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 12px;
}

.bookmarks-list {
    display: grid;
    gap: 10px;
}

.bookmark-card {
    background: #FFFFFF;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    border-left: 4px solid #FFCC00;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    container-type: inline-size;
}

.bookmark-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

.bookmark-card-info {
    display: flex;
    flex-direction: column;
}

.bookmark-card-reg {
    font-weight: 700;
    color: #333;
    font-size: 1em;
}

.bookmark-card-type {
    font-size: 0.8em;
    color: #777;
}

.bookmark-card-status {
    font-size: 0.75em;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.bookmark-card-status .short-label { display: none; }
.bookmark-card-status .full-label { display: inline; }

@container (max-width: 230px) {
    .bookmark-card-status .short-label { display: inline; }
    .bookmark-card-status .full-label { display: none; }
}

.bookmark-card-status-S { background: #e8f5e9; color: #2e7d32; }
.bookmark-card-status-M { background: #fff3e0; color: #e65100; }
.bookmark-card-status-W { background: #e3f2fd; color: #1565c0; }
.bookmark-card-status-A { background: #ffebee; color: #c62828; }

.bookmark-remove {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 5px;
    margin-left: 8px;
}

.bookmark-remove:hover {
    color: #c62828;
}

#aircraft-select:focus {
    outline: none;
    border-color: #D40511;
    box-shadow: 0 0 0 3px rgba(212, 5, 17, 0.1);
}

.aircraft-details {
    background: #FFFFFF;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 3px solid #FFCC00;
    flex-wrap: wrap;
    gap: 15px;
}

.detail-header h2 {
    color: #D40511;
    font-size: 2em;
    font-weight: 700;
}

.detail-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.detail-bookmark-btn {
    background: none;
    border: 2px solid #FFCC00;
    border-radius: 8px;
    font-size: 1.4em;
    padding: 5px 12px;
    cursor: pointer;
    color: #999;
    transition: all 0.3s ease;
}

.detail-bookmark-btn:hover {
    border-color: #D40511;
    color: #D40511;
}

.detail-bookmark-btn.bookmarked {
    color: #FFCC00;
    background: #fff8e1;
}

.detail-close-btn {
    background: none;
    border: 2px solid #ccc;
    border-radius: 8px;
    font-size: 1.4em;
    padding: 5px 12px;
    cursor: pointer;
    color: #999;
    transition: all 0.3s ease;
    line-height: 1;
}

.detail-close-btn:hover {
    border-color: #D40511;
    color: #D40511;
}

.status-badge {
    padding: 10px 20px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.95em;
    text-transform: uppercase;
}

.status-serviceable {
    background: #4CAF50;
    color: white;
}

.status-maintenance {
    background: #FF9800;
    color: white;
}

.status-workshop {
    background: #1565c0;
    color: white;
}

.status-aog {
    background: #D40511;
    color: white;
    animation: aogPulse 2s ease-in-out infinite;
}

@keyframes aogPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(212, 5, 17, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(212, 5, 17, 0); }
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.detail-item {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #FFCC00;
    overflow: hidden;
    word-wrap: break-word;
}

.detail-item .label {
    display: block;
    color: #D40511;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9em;
}

.detail-item .value {
    display: block;
    color: #333;
    font-size: 1.1em;
    font-weight: 500;
    word-break: break-word;
}

.defects-section {
    margin-top: 30px;
}

.defects-section h3 {
    color: #D40511;
    font-size: 1.5em;
    margin-bottom: 20px;
    font-weight: 700;
}

.defect-row {
    display: flex;
    gap: 0;
    padding: 20px 0;
}

.defect-row-border {
    border-top: 1px solid #ddd;
}

.defect-row .defect-card {
    flex: 1;
    min-width: 0;
    padding: 20px;
    background: #fff3cd;
    border-left: 5px solid #ff9800;
    border-radius: 8px;
    margin-right: 20px;
}

.defect-row .limitation-card {
    flex: 0 0 38%;
    padding: 20px;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #ffebee;
    border-radius: 8px;
}

.defect-row .limitation-card.limitation-none {
    background: #e8f5e9;
}

.defect-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.defect-card .defect-id {
    color: #D40511;
    font-weight: 700;
    font-size: 1.1em;
    white-space: nowrap;
}

.defect-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.defect-pill {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.88em;
    font-weight: 600;
    white-space: nowrap;
}

.defect-pill-mel {
    background: #e8eaf6;
    color: #283593;
}

.defect-pill-mel .defect-pill-link {
    color: #283593;
    text-decoration: underline;
    cursor: pointer;
}

.defect-pill-mel .defect-pill-link:hover {
    color: #1a237e;
}

.defect-pill-expiry {
    background: #e8f5e9;
    color: #2e7d32;
}

.defect-pill-expired {
    background: #ffebee;
    color: #c62828;
}

.defect-pill-est {
    background: #e3f2fd;
    color: #1565c0;
}

.defect-pill .pill-short { display: none; }
.defect-pill .pill-full { display: inline; }

.defect-header.compact .defect-pill .pill-short { display: inline; }
.defect-header.compact .defect-pill .pill-full { display: none; }

.defect-card .defect-description {
    color: #333;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-line;
}

.limitation-card .limitation-label {
    color: #D40511;
    font-weight: 700;
    font-size: 0.85em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.limitation-card .limitation-text {
    color: #333;
    line-height: 1.6;
    font-weight: 500;
    word-break: break-word;
    white-space: pre-line;
}

.limitation-card.limitation-none .limitation-text {
    color: #2e7d32;
    font-weight: 500;
}

.limitation-card.limitation-none .limitation-label {
    display: none;
}

.no-defects {
    background: #e8f5e9;
    border-left: 5px solid #4CAF50;
    padding: 20px;
    border-radius: 8px;
    color: #2e7d32;
    font-weight: 500;
}

/* MEL Modal */
.mel-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mel-modal-content {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 550px;
    width: 90%;
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    border-top: 5px solid #FFCC00;
    animation: fadeIn 0.3s ease;
}

.mel-modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.8em;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

.mel-modal-close:hover {
    color: #D40511;
}

.mel-modal-content h3 {
    color: #D40511;
    font-size: 1.4em;
    margin-bottom: 20px;
    padding-right: 30px;
}

.mel-detail-row {
    display: flex;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

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

.mel-detail-label {
    font-weight: 600;
    color: #555;
    min-width: 140px;
    font-size: 0.9em;
    text-transform: uppercase;
}

.mel-detail-value {
    color: #333;
    font-weight: 500;
}

.mel-rect-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9em;
    color: white;
}

.mel-rect-A { background: #D40511; }
.mel-rect-B { background: #e65100; }
.mel-rect-C { background: #FF9800; }
.mel-rect-D { background: #4CAF50; }

.mel-pdf-link {
    display: block;
    width: 100%;
    text-align: center;
    margin-top: 20px;
    padding: 12px 20px;
    background: #D40511;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9em;
    transition: background 0.3s;
}

.mel-pdf-link:hover {
    background: #b00410;
}

.mel-link {
    color: #D40511;
    text-decoration: underline;
    cursor: pointer;
    font-weight: 600;
}

.mel-link:hover {
    color: #b00410;
}

/* Lock body scroll when PDF modal is open */
body.pdf-modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* PDF Viewer Modal (full-screen) */
.pdf-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #222;
    z-index: 2000;
    display: flex;
    flex-direction: column;
}

.pdf-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: #333;
    color: white;
    flex-shrink: 0;
}

.pdf-modal-header span {
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pdf-modal-close-btn {
    background: #D40511;
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 15px;
}

.pdf-modal-close-btn:hover {
    background: #b00410;
}

.pdf-modal-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: white;
}

/* MEL Modal enhancements */
.mel-modal-content.modal-wide {
    max-width: 900px;
}

.mel-modal-buttons {
    margin-top: 20px;
}

.mel-limitations {
    color: #c62828;
    font-weight: 600;
}

/* Fleet Detail Table */
.fleet-detail-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -10px;
    padding: 0 10px;
}

.fleet-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    min-width: 600px;
}

.fleet-detail-table th {
    background: #333;
    color: white;
    padding: 8px 8px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em;
    white-space: nowrap;
}

.fleet-detail-table td {
    padding: 8px 8px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
}

.fleet-detail-table td:nth-child(7) {
    white-space: normal;
    min-width: 120px;
}

.fleet-detail-row:hover {
    background: #fffde7;
}

.status-cell-S { color: #2e7d32; font-weight: 600; }
.status-cell-M { color: #e65100; font-weight: 600; }
.status-cell-W { color: #1565c0; font-weight: 600; }
.status-cell-A { color: #D40511; font-weight: 600; }

/* ADDs/P/W stat badges */
.stat-adds-label {
    color: #333;
    font-size: 0.9em;
    font-weight: 600;
    padding: 8px 0;
}

.stat-planned {
    background: #1565c0;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

.stat-work {
    background: #e65100;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

/* AOG stat badge */
.stat-aog {
    background: #D40511;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
}

/* ==========================================================================
   iPad (portrait & landscape) — up to 1024px
   ========================================================================== */
@media (max-width: 1024px) {
    body {
        padding: 10px;
    }

    /* --- Header: stack into clean rows --- */
    header {
        padding: 15px 18px;
    }

    .header-top {
        flex-direction: column;
        gap: 10px;
    }

    .header-left {
        gap: 12px;
        align-items: center;
    }

    .logo img {
        width: 70px;
    }

    header h1 {
        font-size: 1.25em;
        margin-bottom: 2px;
    }

    .update-time {
        font-size: 0.82em;
    }

    .header-right-group {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        width: 100%;
        flex-shrink: 1;
        border-top: 1px solid #eee;
        padding-top: 10px;
    }

    .duty-manager-display {
        text-align: left;
        font-size: 0.85em;
    }

    .duty-manager-entry {
        align-items: flex-start;
    }

    .header-right-actions {
        flex-shrink: 0;
    }

    /* --- Fleet cards: 2 per row on iPad --- */
    .fleet-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 20px;
    }

    .fleet-card {
        padding: 15px;
    }

    .fleet-card h3 {
        font-size: 1.15em;
    }

    .fleet-card-header {
        margin-bottom: 10px;
    }

    .stats {
        gap: 8px;
    }

    .stat-serviceable,
    .stat-total,
    .stat-planned,
    .stat-work,
    .stat-aog {
        padding: 5px 10px;
        font-size: 0.82em;
    }

    .stat-adds-label {
        font-size: 0.82em;
        padding: 5px 0;
    }

    /* --- Bookmarks: 2 per row --- */
    .bookmarks-list {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .bookmark-card {
        padding: 10px;
    }

    .bookmarks-section {
        margin-bottom: 20px;
    }

    /* --- Fleet detail modal --- */
    .mel-modal-content.modal-wide {
        width: 95%;
        padding: 15px;
    }

    .fleet-detail-table {
        font-size: 0.82em;
    }

    .fleet-detail-table th,
    .fleet-detail-table td {
        padding: 6px 6px;
    }

    /* --- Detail view --- */
    .detail-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .detail-header h2 {
        font-size: 1.5em;
    }

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

    .aircraft-details {
        padding: 20px;
    }

    .aircraft-selector {
        padding: 15px;
    }

    .defect-row {
        flex-direction: column;
    }

    .defect-row .defect-card {
        margin-right: 0;
        margin-bottom: 10px;
    }

    .defect-row .limitation-card {
        flex: none;
        border-left: none;
    }
}

/* ==========================================================================
   Phone — up to 480px
   ========================================================================== */
@media (max-width: 480px) {
    header {
        padding: 12px;
        border-left-width: 5px;
    }

    .header-left {
        gap: 10px;
    }

    .logo img {
        width: 50px;
    }

    header h1 {
        font-size: 1.05em;
    }

    .update-time {
        font-size: 0.75em;
    }

    .header-right-group {
        flex-direction: column;
        gap: 8px;
    }

    .header-right-actions {
        width: 100%;
        justify-content: space-between;
    }

    /* Fleet cards: 1 per row on phone */
    .fleet-summary {
        grid-template-columns: 1fr;
    }

    .fleet-card {
        padding: 12px;
    }

    /* Bookmarks: 2 per row still works on phone */
    .bookmarks-list {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

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

    .aircraft-details {
        padding: 15px;
    }

    .aircraft-selector {
        padding: 12px;
    }
}
