:root {
    --bg-primary: #f3f6f8;
    --bg-secondary: #ffffff;
    --bg-card: #fcfdff;
    --border-color: #d7e0e6;
    --text-primary: #17222d;
    --text-secondary: #5c6b78;
    --text-muted: #8895a2;
    --accent: #0a8092;
    --accent-strong: #045f6e;
    --accent-soft: #d9f0f3;
    --critical: #d64545;
    --warning: #e08422;
    --good: #1b8f6b;
    --grid-color: #e5edf2;
    --surface-shadow: 0 12px 28px rgba(17, 32, 43, 0.08);
}

[data-theme="dark"] {
    --bg-primary: #101823;
    --bg-secondary: #1a2532;
    --bg-card: #1f2b39;
    --border-color: #2f3d4c;
    --text-primary: #e5ebf2;
    --text-secondary: #b6c0cc;
    --text-muted: #8290a0;
    --accent: #3fb6c8;
    --accent-strong: #58c8da;
    --accent-soft: #243746;
    --critical: #ff7272;
    --warning: #ffc16d;
    --good: #4ad39f;
    --grid-color: #334353;
    --surface-shadow: 0 20px 36px rgba(0, 0, 0, 0.35);
}

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

body {
    font-family: 'Manrope', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 85% -10%, rgba(10, 128, 146, 0.12), transparent 30%),
        radial-gradient(circle at 0% 15%, rgba(4, 95, 110, 0.08), transparent 32%),
        var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

.header {
    background: color-mix(in srgb, var(--bg-secondary) 94%, transparent);
    backdrop-filter: blur(8px);
    padding: 18px 28px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-content h1 {
    font-family: 'Sora', 'Manrope', sans-serif;
    letter-spacing: -0.03em;
    font-size: 28px;
    color: var(--text-primary);
}

.header-content p {
    color: var(--text-secondary);
    margin-top: 6px;
    font-size: 14px;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 10px 14px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(9, 35, 53, 0.12);
}

.theme-toggle .icon {
    font-size: 18px;
}


.container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 26px;
}

.drop-zone {
    border: 2px dashed color-mix(in srgb, var(--accent) 30%, var(--border-color));
    border-radius: 16px;
    padding: 60px;
    text-align: center;
    background: var(--bg-secondary);
    box-shadow: var(--surface-shadow);
    transition: all 0.25s ease;
    cursor: pointer;
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.drop-zone h2 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-family: 'Sora', 'Manrope', sans-serif;
}

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

.file-input {
    display: none;
}

.aircraft-info {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    margin-top: 20px;
    display: none;
    box-shadow: var(--surface-shadow);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.aircraft-info.visible {
    display: block;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 15px;
}

.info-card {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.info-card label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.info-card .value {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 7px;
    line-height: 1.2;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.sort-controls {
    margin-top: 16px;
    display: none;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sort-controls.visible {
    display: flex;
}

.sort-controls label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.sort-controls select {
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 9px 12px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    min-width: 250px;
}

.tab {
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.tab:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.tab.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 10px 24px rgba(10, 128, 146, 0.25);
}

.tab-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 22px;
    margin-top: 20px;
    display: none;
    box-shadow: var(--surface-shadow);
    transition: background 0.3s ease, border-color 0.3s ease;
}

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

.data-table-container {
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: var(--accent-soft);
    padding: 12px 8px;
    text-align: left;
    position: sticky;
    top: 0;
    white-space: nowrap;
    color: var(--text-primary);
}

.data-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--bg-primary);
    white-space: nowrap;
}

.data-table tr:hover {
    background: var(--bg-card);
}

.data-table .invalid {
    color: var(--critical);
}

.chart-container {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

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

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

.stat-card {
    background: var(--bg-card);
    padding: 14px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.stat-card .label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.stat-card .value {
    margin-top: 4px;
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
}

.stat-card .unit {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

h3 {
    color: var(--text-primary);
    margin-bottom: 15px;
    font-size: 18px;
    line-height: 1.35;
}

.health-indicator {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 8px;
}

.health-good { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.health-warning { background: var(--warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 25%, transparent); }
.health-critical { background: var(--critical); box-shadow: 0 0 0 3px color-mix(in srgb, var(--critical) 25%, transparent); animation: pulse-critical 1s infinite; }

@keyframes pulse-critical {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.1); }
}

.health-summary {
    transition: all 0.3s ease;
}

/* Flight Map Styles */
.map-container {
    height: 500px;
    min-height: 500px;
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

#flightMapContainer {
    height: 100%;
    width: 100%;
}

.map-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.flight-info-popup {
    font-size: 13px;
    line-height: 1.5;
}

.flight-info-popup strong {
    color: #0088aa;
}

.marker-start {
    background: var(--good);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.marker-end {
    background: var(--critical);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.heading-arrow {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 16px solid var(--accent);
    transform-origin: center bottom;
}

.flight-map-layout {
    display: flex;
    gap: 20px;
    height: 550px;
}

.flight-list-panel {
    width: 250px;
    min-width: 250px;
    background: var(--bg-card);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.flight-list-header {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-primary);
}

.show-all-btn {
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
}

.show-all-btn:hover {
    opacity: 0.8;
}

.flight-list {
    flex: 1;
    overflow-y: auto;
}

.flight-list-item {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.flight-list-item:hover {
    background: var(--bg-secondary);
}

.flight-list-item.selected {
    background: var(--accent);
    color: var(--bg-primary);
}

.flight-list-item.selected .flight-details {
    color: var(--bg-primary);
    opacity: 0.8;
}

.flight-date {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 4px;
}

.flight-details {
    font-size: 11px;
    color: var(--text-secondary);
    display: flex;
    gap: 10px;
}

.flight-map-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.flight-map-panel .map-container {
    flex: 1;
    margin-bottom: 0;
}

.map-legend {
    display: flex;
    gap: 20px;
    padding: 10px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
}

.legend-line {
    display: inline-block;
    width: 20px;
    height: 3px;
    background: var(--accent);
    margin-right: 5px;
    vertical-align: middle;
}

.flight-list-item.has-anomaly {
    border-left: 3px solid var(--warning);
}

.anomaly-badge {
    display: inline-block;
    background: var(--warning);
    color: #1b1b1b;
    font-size: 10px;
    font-weight: bold;
    width: 14px;
    height: 14px;
    line-height: 14px;
    text-align: center;
    border-radius: 50%;
    margin-left: 6px;
    cursor: help;
}

.anomaly-text {
    color: var(--warning);
}

.flight-list-item.selected .anomaly-text {
    color: #000;
}

.flight-list-item.selected .anomaly-badge {
    background: #0d1115;
    color: var(--warning);
}

.trend-section {
    margin-top: 20px;
}

.owner-hero {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background:
        linear-gradient(140deg, color-mix(in srgb, var(--accent-soft) 80%, transparent), transparent 62%),
        var(--bg-card);
    padding: 20px;
    margin-bottom: 16px;
}

.owner-hero-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.owner-hero-title h2 {
    font-family: 'Sora', 'Manrope', sans-serif;
    font-size: 26px;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.owner-hero-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 820px;
    line-height: 1.5;
}

.owner-status-chip {
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.owner-status-good {
    background: color-mix(in srgb, var(--good) 20%, transparent);
    color: var(--good);
}

.owner-status-warning {
    background: color-mix(in srgb, var(--warning) 20%, transparent);
    color: var(--warning);
}

.owner-status-critical {
    background: color-mix(in srgb, var(--critical) 20%, transparent);
    color: var(--critical);
}

.owner-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.owner-kpi {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
}

.owner-kpi-label {
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
    font-weight: 800;
}

.owner-kpi-value {
    margin-top: 8px;
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.15;
}

.owner-kpi-context {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.owner-block {
    margin-top: 16px;
}

.owner-list {
    display: grid;
    gap: 8px;
}

.owner-list-item {
    border: 1px solid var(--border-color);
    border-left-width: 4px;
    border-radius: 10px;
    background: var(--bg-card);
    padding: 12px 14px;
    font-size: 14px;
    color: var(--text-primary);
}

.owner-list-item.critical { border-left-color: var(--critical); }
.owner-list-item.warning { border-left-color: var(--warning); }
.owner-list-item.info { border-left-color: var(--accent); }
.owner-list-item.good { border-left-color: var(--good); }

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.action-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
}

.action-card h4 {
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.action-card p {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}

.owner-note {
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 12px;
}

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

    .flight-map-layout {
        flex-direction: column;
        height: auto;
    }

    .flight-list-panel {
        width: 100%;
        min-width: 0;
        max-height: 240px;
    }
}

@media (max-width: 720px) {
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
    }

    .header-content h1 {
        font-size: 24px;
    }

    .container {
        padding: 14px;
    }

    .drop-zone {
        padding: 34px 20px;
    }

    .tab {
        padding: 9px 12px;
        font-size: 11px;
    }

    .sort-controls {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .sort-controls select {
        width: 100%;
        min-width: 0;
    }

    .tab-content {
        padding: 16px;
    }

    .owner-hero-title h2 {
        font-size: 22px;
    }

    .owner-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .owner-kpi-value {
        font-size: 20px;
    }
}
