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

:root {
    --bg-top: #dceaff;
    --bg-bottom: #f3f7ff;
    --surface: #ffffff;
    --surface-soft: #edf4ff;
    --surface-hover: #dce9ff;
    --ink: #162a40;
    --muted: #5f7388;
    --line: #c9daef;
    --brand: #0b72b9;
    --brand-deep: #164f7f;
    --warn: #f1a126;
    --danger: #d6455a;
    --success: #1ba667;
    --shadow-lg: 0 26px 64px -42px rgba(17, 41, 67, 0.58);
    --shadow-md: 0 18px 36px -30px rgba(17, 41, 67, 0.42);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 7% 4%, rgba(11, 114, 185, 0.16), transparent 28%),
        radial-gradient(circle at 95% 7%, rgba(241, 161, 38, 0.2), transparent 30%),
        linear-gradient(165deg, var(--bg-top) 0%, var(--bg-bottom) 68%, #e8f2ff 100%);
    color: var(--ink);
    min-height: 100vh;
    padding: 18px;
    line-height: 1.45;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: clamp(1rem, 2vw, 1.45rem);
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
}

header {
    text-align: center;
    margin-bottom: 24px;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: clamp(1rem, 2vw, 1.25rem);
    background:
        linear-gradient(130deg, rgba(255, 255, 255, 0.95), rgba(236, 245, 255, 0.94));
    box-shadow: var(--shadow-md);
}

header h1 {
    font-family: "Sora", sans-serif;
    font-size: clamp(1.5rem, 2.5vw, 2rem);
    color: var(--brand);
    margin-bottom: 0.35rem;
    letter-spacing: 0.02em;
}

header p {
    color: var(--muted);
    font-size: 0.9rem;
}

.drop-zone {
    border: 2px dashed #9bb8d9;
    border-radius: 16px;
    padding: 60px 20px;
    text-align: center;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.93), rgba(240, 247, 255, 0.92));
    transition: all 0.3s ease;
    cursor: pointer;
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--brand);
    background: var(--surface-soft);
    transform: translateY(-1px);
}

.drop-zone-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.drop-zone h2 {
    color: var(--brand);
    margin-bottom: 10px;
    font-family: "Sora", sans-serif;
    font-size: clamp(1.2rem, 2vw, 1.4rem);
}

.drop-zone p {
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #d5e2f1;
    border-top-color: #0b72b9;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.results {
    display: none;
}

.results.show {
    display: block;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--line);
    padding: 20px;
    border-left: 4px solid var(--brand);
    box-shadow: 0 14px 28px -30px rgba(15, 48, 80, 0.92);
}

.card h3 {
    color: var(--muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
}

.card .value {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--brand);
}

.card .sub {
    font-size: 0.8rem;
    color: #6f849a;
    margin-top: 5px;
}

.section {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--line);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 14px 28px -30px rgba(15, 48, 80, 0.92);
}

.section h2 {
    color: var(--brand);
    margin-bottom: 15px;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: "Sora", sans-serif;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.tab {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    color: var(--muted);
    padding: 10px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    font-weight: 600;
}

.tab:hover {
    background: #dce9ff;
    color: #173653;
}

.tab.active {
    background: var(--brand);
    color: #f3f7ff;
    border-color: var(--brand);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--surface);
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

th {
    background: var(--surface-soft);
    color: var(--brand);
    font-weight: 600;
    position: sticky;
    top: 0;
}

tr:hover {
    background: var(--surface-soft);
}

.table-container {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
}

.badge-danger { background: #d6455a; color: #fff; }
.badge-warning { background: #f1a126; color: #4a2a00; }
.badge-info { background: #0b72b9; color: #f3f7ff; }
.badge-success { background: #1ba667; color: #f3f7ff; }

.chart-container {
    position: relative;
    height: 300px;
    margin-bottom: 20px;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 800px) {
    .chart-row {
        grid-template-columns: 1fr;
    }
}

.insight-box {
    background: #edf4ff;
    border-left: 4px solid #f1a126;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 0 8px 8px 0;
}

.insight-box h4 {
    color: #f1a126;
    margin-bottom: 8px;
}

.insight-box ul {
    margin-left: 20px;
    color: #30475f;
}

.insight-box li {
    margin-bottom: 5px;
}

.flight-leg-detail {
    background: #edf4ff;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
}

.flight-leg-detail h4 {
    color: #0b72b9;
    margin-bottom: 10px;
}

.fault-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.fault-tag {
    background: #dce9ff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.fault-detail-panel {
    background: #edf4ff;
    border: 1px solid #c9daef;
    border-radius: 8px;
    padding: 20px;
    margin-top: 15px;
}

.fault-detail-panel h4 {
    color: #0b72b9;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fault-detail-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 8px 15px;
    margin-bottom: 15px;
}

.fault-detail-value { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 600px) {
    .fault-detail-grid { grid-template-columns: 1fr; gap: 4px; }
    .fault-detail-value { margin-bottom: 10px; }
}

.fault-detail-label {
    color: #5f7388;
    font-size: 0.85rem;
}

.fault-detail-value {
    color: #162a40;
}

.pilot-visible {
    color: #d6455a;
    font-weight: bold;
}

.internal-only {
    color: #1ba667;
}

.maintenance-box {
    background: #dce9ff;
    border-left: 3px solid #0b72b9;
    padding: 12px 15px;
    margin-top: 15px;
    border-radius: 0 6px 6px 0;
}

.maintenance-box h5 {
    color: #0b72b9;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.maintenance-box ul {
    margin: 0;
    padding-left: 20px;
    color: #30475f;
    font-size: 0.85rem;
}

.maintenance-box li {
    margin-bottom: 4px;
}

.ata-ref {
    background: #ffffff;
    border: 1px solid #0b72b9;
    color: #0b72b9;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
}

.decode-banner {
    background: linear-gradient(135deg, #edf4ff 0%, #dce9ff 100%);
    border: 1px solid #0b72b9;
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.decode-banner-icon {
    font-size: 2rem;
}

.decode-banner-text h3 {
    color: #0b72b9;
    margin-bottom: 5px;
}

.decode-banner-text p {
    color: #5f7388;
    font-size: 0.85rem;
    margin: 0;
}

.fde-indicator {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.fde-pilot {
    background: rgba(255, 71, 87, 0.2);
    color: #d6455a;
    border: 1px solid #d6455a;
}

.fde-internal {
    background: rgba(46, 213, 115, 0.2);
    color: #1ba667;
    border: 1px solid #1ba667;
}

.clickable-row {
    cursor: pointer;
    transition: background 0.2s;
}

.clickable-row:hover {
    background: #dce9ff !important;
}

/* FDE Popup Modal */
.fde-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.fde-modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.fde-modal {
    background: #ffffff;
    border: 1px solid #0b72b9;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.fde-modal-overlay.show .fde-modal {
    transform: scale(1);
}

.fde-modal-header {
    background: linear-gradient(135deg, #edf4ff 0%, #dce9ff 100%);
    padding: 20px;
    border-bottom: 1px solid #c9daef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fde-modal-header h3 {
    color: #0b72b9;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fde-modal-close {
    background: none;
    border: none;
    color: #5f7388;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

.fde-modal-close:hover {
    color: #d6455a;
}

.fde-modal-body {
    padding: 20px;
}

.fde-cas-message {
    background: #f3f7ff;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    text-align: center;
}

.fde-cas-message .cas-text {
    font-size: 1.5rem;
    font-weight: bold;
    font-family: monospace;
}

.fde-cas-message.warning .cas-text { color: #d6455a; }
.fde-cas-message.caution .cas-text { color: #f1a126; }
.fde-cas-message.advisory .cas-text { color: #0b72b9; }
.fde-cas-message.status .cas-text { color: #173653; }

.fde-severity-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-top: 10px;
}

.fde-severity-badge.warning { background: #d6455a; color: #fff; }
.fde-severity-badge.caution { background: #f1a126; color: #4a2a00; }
.fde-severity-badge.advisory { background: #0b72b9; color: #f3f7ff; }
.fde-severity-badge.status { background: #6f849a; color: #fff; }

/* Fault History Table - Honeywell Style */
.fault-history-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
}
.fault-history-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid #c9daef;
    color: #5f7388;
    font-weight: 500;
    white-space: nowrap;
}
.fault-history-table td {
    padding: 5px 8px;
    border-bottom: 1px solid #e0ebfa;
    white-space: nowrap;
}
.fault-history-table tr:hover {
    background: #e2edff;
    cursor: pointer;
}
.fault-history-table tr.selected {
    background: #d2e2f7;
}
.fault-history-table .severity-warning { color: #e03040; font-weight: bold; }
.fault-history-table .severity-caution { color: #d4a017; font-weight: bold; }
.fault-history-table .severity-advisory { color: #00b4d8; }
.fault-history-table .event-advisory td { background: #d6f5fc; }
.fault-history-table .event-advisory:hover td { background: #bcecf7; }
.fault-history-table .event-advisory .severity-advisory { color: #007b94; font-weight: bold; }
.fault-history-table .severity-status { color: #2a2a2a; }
.fault-history-table .phase-transition td { background: var(--surface-soft); }
.fault-history-table .fault-name { color: #162a40; }
.fault-history-table .fde-name { color: #5f7388; }
.fault-history-table .fault-code { color: #f1a126; font-family: monospace; }
.fault-history-table .leg-header {
    background: #edf4ff !important;
}
.fault-history-table .leg-header:hover {
    background: #d8e7fb !important;
}
.fault-history-table .leg-header td {
    padding: 10px 12px !important;
    border-bottom: 2px solid #c9daef !important;
}

.flm-result-item {
    background: #ffffff !important;
    border: 1px solid #c9daef !important;
    border-radius: 10px !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease !important;
}

.flm-result-item:hover {
    background: #edf4ff !important;
    transform: translateY(-1px);
    box-shadow: 0 10px 20px -18px rgba(16, 49, 80, 0.85);
}

.fde-info-grid {
    display: grid;
    gap: 15px;
}

.fde-info-item {
    background: #edf4ff;
    padding: 12px 15px;
    border-radius: 6px;
}

.fde-info-item label {
    display: block;
    color: #5f7388;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.fde-info-item .value {
    color: #162a40;
}

.fde-related-systems {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 5px;
}

.fde-related-systems span {
    background: #dce9ff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

.fde-manual-ref {
    background: #ffffff;
    border: 1px solid #0b72b9;
    color: #0b72b9;
    padding: 8px 15px;
    border-radius: 6px;
    font-family: monospace;
    display: inline-block;
}

.fde-notes {
    background: rgba(255, 165, 2, 0.1);
    border-left: 3px solid #f1a126;
    padding: 10px 15px;
    border-radius: 0 6px 6px 0;
    margin-top: 15px;
    color: #30475f;
    font-size: 0.9rem;
}

.fde-badge-clickable {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fde-badge-clickable:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 14px rgba(11, 114, 185, 0.24);
}

.clickable {
    cursor: pointer;
    transition: background 0.2s;
}

.clickable:hover {
    background: #dce9ff;
}

.flm-result-item span[style*="color: #fff"] {
    color: #162a40 !important;
}

.fault-history-table .leg-header strong[style*="color: #fff"] {
    color: #173653 !important;
}

#legDetail {
    margin-top: 20px;
}

.reset-btn {
    background: linear-gradient(135deg, #d6455a, #ef677a);
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 20px;
    font-weight: 600;
    box-shadow: 0 12px 22px -18px rgba(130, 28, 42, 0.85);
}

.reset-btn:hover {
    background: linear-gradient(135deg, #db4c60, #ff7f90);
}

.serial-info {
    background: linear-gradient(135deg, #e8f2ff, #dce9ff);
    border: 1px solid var(--line);
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.serial-info-item {
    display: flex;
    flex-direction: column;
}

.serial-info-item label {
    font-size: 0.75rem;
    color: #5f7388;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.serial-info-item span {
    color: #0b72b9;
    font-weight: bold;
    font-size: 1.1rem;
}

input[type="text"],
select {
    background: #f3f7ff !important;
    color: #173653 !important;
    border: 1px solid var(--line) !important;
    border-radius: 8px !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]::placeholder {
    color: #70879e;
}

input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: var(--brand) !important;
    box-shadow: 0 0 0 3px rgba(11, 114, 185, 0.17);
}

a {
    color: var(--brand);
}

@media (max-width: 900px) {
    body {
        padding: 10px;
    }

    .container {
        border-radius: 14px;
        padding: 0.85rem;
    }

    .section,
    .card {
        padding: 14px;
    }

    .tab {
        padding: 9px 14px;
    }
}

@media (max-width: 700px) {
    #faults .section > div:first-child {
        align-items: flex-start !important;
    }

    #faults .section > div:first-child > div {
        width: 100%;
        flex-wrap: wrap;
    }

    #faults .section > div:first-child input[type="text"],
    #faults .section > div:first-child select {
        width: 100% !important;
    }

    #flmref .section > div[style*="display: flex; gap: 10px; margin-bottom: 20px;"] {
        flex-wrap: wrap;
    }

    #flmref .section > div[style*="display: flex; gap: 10px; margin-bottom: 20px;"] select,
    #flmref .section > div[style*="display: flex; gap: 10px; margin-bottom: 20px;"] input[type="text"] {
        width: 100%;
    }
}
