:root {
    --bg: #ffffff;
    --surface: rgba(255, 255, 255, 0.96);
    --surface-2: #f3f5f8;
    --text: #18202b;
    --muted: #5d6877;
    --border: #dfe3e9;
    --accent: #2f6fde;
    --accent-soft: rgba(47, 111, 222, 0.12);
    --origin: #d6336c;
    --seasonal: #e8890c;
    --seasonal-soft: rgba(232, 137, 12, 0.15);
    --old: #98a2b3;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235d6877' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    --shadow: 0 6px 24px rgba(20, 30, 45, 0.16);
    --radius: 12px;
    --panel-w: 400px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151b;
        --surface: rgba(24, 29, 37, 0.96);
        --surface-2: #232a35;
        --text: #e7ebf0;
        --muted: #9aa5b4;
        --border: #313a47;
        --accent: #5b93f5;
        --accent-soft: rgba(91, 147, 245, 0.16);
        --origin: #f06595;
        --seasonal: #f5a524;
        --seasonal-soft: rgba(245, 165, 36, 0.18);
        --old: #6b7686;
        --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239aa5b4' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
        --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
#map { position: absolute; inset: 0; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- Barre du haut ---------- */
.topbar {
    position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3;
    display: flex; gap: 10px; align-items: center; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand, .search input {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); height: 44px;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 0 14px; font-weight: 650; white-space: nowrap; }
.brand svg { width: 20px; height: 20px; fill: var(--accent); }
.search { position: relative; flex: 0 1 380px; min-width: 0; }
.search input {
    width: 100%; padding: 0 14px; font-size: 15px; color: var(--text); outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
#search-results {
    position: absolute; top: 50px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto;
}
#search-results li {
    display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: center;
    padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--accent-soft); }
#search-results .code { font-weight: 700; font-variant-numeric: tabular-nums; }
#search-results .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search-results .name small { display: block; color: var(--muted); }
#search-results .count { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- Panneau ---------- */
.panel {
    position: absolute; z-index: 2; top: 68px; left: 12px; max-height: calc(100% - 104px); width: var(--panel-w);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
.panel[hidden] { display: none; }
#panel-body { overflow-y: auto; flex: 1; padding: 18px 18px 12px; }
.icon-btn {
    border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%;
    font-size: 20px; line-height: 1; cursor: pointer;
}
.panel-close { position: absolute; top: 12px; right: 12px; z-index: 1; }
.back-btn {
    border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; margin-bottom: 10px;
    font-size: 14px;
}

.ap-head { padding-right: 36px; }
.ap-code { font-size: 34px; font-weight: 750; letter-spacing: 0.5px; line-height: 1; }
.ap-code small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.ap-name { margin: 6px 0 2px; font-size: 16px; font-weight: 600; }
.ap-place { color: var(--muted); font-size: 14px; }
.stats { display: flex; gap: 8px; margin: 14px 0; }
.stat { flex: 1; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }
.note { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 0 0 12px; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.tools input, .tools select {
    height: 36px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px;
    background-color: var(--bg); color: var(--text); font: inherit; font-size: 14px; min-width: 0;
    outline: none; transition: border-color .15s, box-shadow .15s;
}
.tools input:focus, .tools select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tools input:hover, .tools select:hover { border-color: var(--muted); }
/* Menus déroulants : flèche maison, texte tronqué proprement */
.tools select {
    appearance: none; -webkit-appearance: none; cursor: pointer;
    padding-right: 30px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
    background-image: var(--chevron); background-repeat: no-repeat;
    background-position: right 11px center; background-size: 10px 6px;
}
.tools select::-ms-expand { display: none; }

.dest-list { list-style: none; margin: 0; padding: 0; }
.dest {
    display: grid; grid-template-columns: 46px 1fr auto; gap: 4px 10px; align-items: baseline;
    padding: 10px 8px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.dest:hover, .dest.hover { background: var(--accent-soft); }
.dest .code { font-weight: 700; font-variant-numeric: tabular-nums; }
.dest .city { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest .km { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dest .airlines { grid-column: 2 / -1; color: var(--muted); font-size: 13px; line-height: 1.35; }
.empty { color: var(--muted); padding: 20px 4px; text-align: center; }

.route-head { display: flex; align-items: center; gap: 10px; font-size: 28px; font-weight: 750; padding-right: 36px; }
.route-head .arrow { color: var(--muted); font-weight: 400; }
.route-cities { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.airline { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.airline-name { font-weight: 650; }
button.airline-name.link { border: 0; background: none; padding: 0; cursor: pointer; font-size: 15px; color: var(--text); text-align: left; }
button.airline-name.link:hover { color: var(--accent); text-decoration: underline; }
#search-results .code.cie { color: var(--accent); }
.airline-codes { color: var(--muted); font-size: 12px; margin-left: 6px; font-weight: 400; }
.period-line { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 14px; }
.badge {
    font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 999px;
    background: var(--accent-soft); color: var(--accent); white-space: nowrap;
}
.badge.seasonal { background: var(--seasonal-soft); color: var(--seasonal); }
.badge.old { background: var(--surface-2); color: var(--muted); }
.badge.neutral { background: var(--surface-2); color: var(--text); }
.dest .tags { grid-column: 2 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.dest.old .code, .dest.old .city { color: var(--muted); }

.legend {
    position: absolute; z-index: 2; right: 56px; bottom: 30px; display: flex; gap: 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
    box-shadow: var(--shadow); padding: 7px 14px; font-size: 12px; color: var(--text);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.sw { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--accent); border-radius: 2px; }
.sw.sea { border-color: var(--seasonal); }
.sw.old { border-top: 3px dashed var(--old); }
.src { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Divers ---------- */
.hint, .loading {
    position: absolute; z-index: 2; left: 50%; transform: translateX(-50%); bottom: 44px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
    box-shadow: var(--shadow); padding: 9px 16px; font-size: 14px; white-space: nowrap;
}
.hint[hidden], .loading[hidden] { display: none; }
.credits { position: absolute; z-index: 2; left: 12px; bottom: 8px; }
.link-btn { border: 0; background: var(--surface); border-radius: 6px; padding: 3px 8px; font-size: 12px; color: var(--muted); cursor: pointer; }
dialog {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text);
    max-width: 560px; width: calc(100% - 32px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin-top: 0; font-size: 18px; }
.hublot-logo { display: inline-block; margin: 2px 0 4px; }
.hublot-logo img { display: block; height: 34px; width: auto; }
dialog li { margin-bottom: 6px; font-size: 14px; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 8px 16px; cursor: pointer; }

.maplibregl-popup-content {
    background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 10px;
    box-shadow: var(--shadow); font-size: 13px;
}
.maplibregl-popup-tip { display: none; }
.maplibregl-ctrl-group { background: var(--surface); }
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ---------- Mobile : panneau en bas ---------- */
@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; top: 8px; left: 8px; right: 8px; gap: 6px; }
    .brand { display: none; }
    .search { flex: 1 1 100%; }
    .panel {
        top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55%;
        border-radius: var(--radius) var(--radius) 0 0;
    }
    .hint { bottom: 76px; white-space: normal; width: calc(100% - 32px); text-align: center; }
    .legend { left: 8px; right: auto; bottom: 30px; gap: 10px; padding: 6px 10px; }
    .panel:not([hidden]) ~ .legend { display: none; }
    .credits { bottom: 4px; left: 8px; }
    .panel:not([hidden]) ~ .credits { display: none; }
}
