:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4aa8ff;
  --accent-2: #f5a524;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  --radius: 10px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------ Sidebar ------------------------------ */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0 16px 16px;
}

.brand {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 14px;
  margin-bottom: 4px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), #2d7fd6);
  border-radius: 10px;
  color: #04121f;
}
.brand-text { flex: 1; }
.brand-text h1 { margin: 0; font-size: 18px; letter-spacing: 0.2px; }
.brand-text p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

/* Bottom-sheet chrome (mobile only; hidden on desktop by default) */
.sheet-handle, .sheet-close, .results-chevron, #mobileBar, #backdrop { display: none; }
.sheet-close {
  width: 34px; height: 34px; border-radius: 8px; background: #222b38;
  border: 1px solid var(--border); place-items: center; font-size: 15px; color: var(--muted);
}

.panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12px; color: var(--text); display: flex; justify-content: space-between; }
.field > span em { color: var(--muted); font-style: normal; font-size: 11px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input, select, button {
  font: inherit;
  color: var(--text);
}
input[type="number"], input[type="text"], select {
  background: #0e141c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input[type="number"]:focus, select:focus { border-color: var(--accent); }

.slider-field input[type="range"] { width: 100%; accent-color: var(--accent); }

.checkbox-field { flex-direction: row; align-items: flex-start; gap: 8px; }
.checkbox-field input { margin-top: 2px; }
.checkbox-field span { font-size: 12px; line-height: 1.35; }

.hint { font-size: 11px; color: var(--muted); line-height: 1.45; margin: 6px 0 0; }

.btn-row { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.btn-row button { flex: 1; min-width: 90px; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: #222b38;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #2b3646; }
.btn-primary { background: var(--accent); color: #04121f; border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: #63b4ff; }
.btn-primary.active { background: var(--accent-2); }
.btn-secondary { background: #222b38; }

.side-footer { margin-top: 16px; font-size: 10.5px; color: var(--muted); line-height: 1.5; }

/* ------------------------------ Map ------------------------------ */
#main { position: relative; }
#map { position: absolute; inset: 0; background: #0a0e14; }

.leaflet-container { background: #0a0e14; font-family: inherit; }

/* ------------------------------ Results card ------------------------------ */
.results-card {
  position: absolute;
  top: 12px; right: 12px;
  width: 320px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: rgba(22, 27, 34, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 500;
}
.results-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.results-header h3 { margin: 0; font-size: 14px; }

.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.pill-muted { background: #2a3441; color: var(--muted); }
.pill-good { background: rgba(63,185,80,0.18); color: var(--good); }

.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-primary { grid-column: 1 / -1; background: linear-gradient(135deg, rgba(74,168,255,0.16), rgba(74,168,255,0.04)); border-color: rgba(74,168,255,0.4); }
.stat-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat-value { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-primary .stat-value { font-size: 24px; }
.stat-sub { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.warnings { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.warn-item {
  font-size: 11.5px; line-height: 1.4;
  padding: 8px 10px; border-radius: 8px;
  display: flex; gap: 8px; align-items: flex-start;
}
.warn-item.warn { background: rgba(210,153,34,0.14); border: 1px solid rgba(210,153,34,0.4); color: #f0c674; }
.warn-item.bad { background: rgba(248,81,73,0.14); border: 1px solid rgba(248,81,73,0.4); color: #ff8b84; }
.warn-item.info { background: rgba(74,168,255,0.12); border: 1px solid rgba(74,168,255,0.3); color: #9dcbff; }

/* ------------------------------ Toast ------------------------------ */
.toast {
  position: absolute;
  bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #222b38; border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 600;
  font-size: 13px;
}

/* Map labels for flight-line direction / numbering */
.line-label {
  background: rgba(13,17,23,0.8);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  font-size: 11px; font-weight: 600;
  padding: 1px 5px;
  white-space: nowrap;
}
.leaflet-div-icon.line-label { line-height: 1.2; }

/* ------------------------------ Responsive (phone-first) ------------------------------ */
@media (max-width: 820px) {
  #app { display: block; height: 100dvh; }

  /* ---- Mobile top bar ---- */
  #mobileBar {
    display: flex; align-items: center; justify-content: space-between;
    position: fixed; top: 0; left: 0; right: 0; height: 54px; z-index: 700;
    padding: 0 12px;
    background: rgba(13, 17, 23, 0.94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top, 0);
    height: calc(54px + env(safe-area-inset-top, 0));
  }
  .mb-brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
  .mb-mark { color: var(--accent); }
  .mb-actions { display: flex; gap: 8px; }
  .mb-btn { padding: 0 14px; font-size: 13px; border-radius: 9px; min-height: 40px; }
  .mb-btn-primary { background: var(--accent); color: #04121f; border-color: transparent; font-weight: 600; }
  .mb-btn.active { background: var(--accent-2); color: #04121f; }

  /* ---- Full-screen map under the bar ---- */
  #main { position: absolute; inset: 0; }
  #map { top: calc(54px + env(safe-area-inset-top, 0)); }

  /* ---- Backdrop for the controls sheet ---- */
  #backdrop {
    display: block; position: fixed; inset: 0; z-index: 800;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  #backdrop.show { opacity: 1; pointer-events: auto; }

  /* ---- Controls become a slide-up bottom sheet ---- */
  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; height: 88dvh; max-height: 88dvh;
    border-right: none; border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    padding: 0 16px calc(24px + env(safe-area-inset-bottom, 0));
    transform: translateY(100%); transition: transform 0.28s ease;
    z-index: 900; box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.55);
  }
  #sidebar.open { transform: translateY(0); }
  .sheet-handle {
    display: block; width: 42px; height: 4px; border-radius: 2px;
    background: var(--border); margin: 10px auto 2px;
  }
  #sidebar .brand { padding-top: 6px; }
  .sheet-close { display: grid; }

  /* ---- Results become a collapsible bottom sheet ---- */
  .results-card {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; max-width: none;
    border-radius: 18px 18px 0 0;
    max-height: calc(56px + env(safe-area-inset-bottom, 0));
    overflow: hidden;
    padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0));
    transition: max-height 0.3s ease;
    z-index: 600;
  }
  .results-card.expanded { max-height: 74dvh; overflow-y: auto; }
  .results-header {
    position: sticky; top: 0; z-index: 1;
    background: rgba(22, 27, 34, 0.98);
    padding: 12px 2px; margin: 0 -2px 10px; cursor: pointer;
  }
  .results-chevron { display: inline-block; color: var(--muted); transition: transform 0.25s; }
  .results-card.expanded .results-chevron { transform: rotate(180deg); }

  /* ---- Larger touch targets ---- */
  input[type="number"], select { padding: 12px; font-size: 16px; min-height: 48px; }
  button { min-height: 44px; }
  input[type="range"] { height: 30px; }
  .field > span { font-size: 13px; }
  .btn-row button { min-width: 44%; }
  .stat-value { font-size: 20px; }
  .stat-primary .stat-value { font-size: 26px; }
}

/* Short-and-wide phones (landscape): let the sheets use more height sparingly */
@media (max-width: 820px) and (max-height: 480px) {
  #sidebar { height: 92dvh; max-height: 92dvh; }
  .results-card.expanded { max-height: 82dvh; }
}
