:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #132033;
  --muted: #5f6f86;
  --border: #d7dfe8;
  --primary: #0b6ef3;
  --primary-dark: #084fb0;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}
button, input { font: inherit; }

/* Keyboard focus: a clearly visible ring on every interactive element when
   tabbing (mouse clicks don't trigger :focus-visible, so it stays clean). */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}
/* Checkboxes are small, so give their ring a touch more breathing room. */
input[type='checkbox']:focus-visible { outline-offset: 3px; }

.app-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  overflow: hidden;
}
.sidebar {
  padding: 16px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

/* --- Map + ad ------------------------------------------------------------- */
.map-area { position: relative; height: 100vh; overflow: hidden; }
#map { width: 100%; height: calc(100vh - 90px); }
.ad-slot-top {
  height: 90px;
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  position: relative;
  z-index: 1000;
}

/* Sidebar footer (about / faq / privacy links). */
.sidebar-footer { margin-top: 14px; font-size: 0.76rem; display: flex; gap: 12px; flex-wrap: wrap; }
.sidebar-footer a { color: var(--muted); }

/* Content-page top nav (about / faq / privacy). */
.legal-nav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.legal-nav span { display: flex; gap: 14px; }

/* Standalone legal page (privacy policy) - allow normal page scroll. */
body.legal-page { height: auto; overflow: auto; }
.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 48px;
  line-height: 1.55;
}
.legal h1 { font-size: 1.5rem; }
.legal h2 { font-size: 1.05rem; margin-top: 22px; }
.legal a { color: var(--primary); }
.legal .legal-note { margin-top: 24px; color: var(--muted); font-size: 0.85rem; }

/* --- Top bar: brand + language switch ------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
}
.brand h1 { margin: 0; font-size: 1.15rem; }
.lang-switch { display: flex; gap: 4px; }
.lang-btn {
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  background: var(--surface);
}
.lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* --- Form fields --------------------------------------------------------- */
.field { margin-bottom: 10px; }
.field > label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
  font-size: 0.82rem;
}
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-head label { margin-bottom: 0; font-weight: 600; font-size: 0.82rem; }
#waypointBody { margin-top: 8px; }
.link-btn {
  background: none;
  border: 0;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 2px 4px;
}
input[type='text'], input[type='number'] {
  width: 100%;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.port-coordinates {
  margin-top: 6px;
  text-align: right;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: monospace;
}
.port-coordinates:empty { display: none; }

/* --- Search dropdown ----------------------------------------------------- */
.search-results { margin-top: 6px; display: grid; gap: 5px; }
.search-item {
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
}
.search-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Actions ------------------------------------------------------------- */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}
.primary, .secondary {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}
.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.secondary { background: var(--surface); color: var(--text); }

/* --- Results: stacked rows (nmi / km / ETA), label left, value right ------ */
.results-strip {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 12px;
  box-shadow: var(--shadow);
}
.results-strip .metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
}
/* Horizontal divider between each stacked row. */
.results-strip .metric + .metric { border-top: 1px solid var(--border); }
.results-strip .metric span {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
.results-strip .metric strong {
  font-size: 1.1rem;
  line-height: 1.2;
  word-break: break-word;
  text-align: right;
}
.route-note { margin: 6px 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.35; }
.route-note:empty { display: none; }

/* --- Settings: speed field (with km/h hint) + 2-col mini fields ---------- */
.settings { margin: 10px 0; }
.settings > .mini-field { margin-bottom: 8px; }
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mini-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-field > span { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
/* The km/h conversion: a quiet helper line, not an editable-looking field. */
.field-hint { margin-top: 2px; font-size: 0.74rem; color: var(--muted); }

/* --- Checkboxes: two labelled categories, each a 2-col grid -------------- */
.checks-group { margin-top: 10px; }
.checks-heading {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}
.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 10px;
}
.checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 500;
}
.checks .pct {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
}

/* --- Mobile: vertical stack (ad -> map -> controls), scrolls -------------- */
@media (max-width: 980px) {
  body { height: auto; overflow: auto; }
  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  /* order: -1 pulls the ad+map block above the sidebar; the ad already
     precedes #map inside .map-area, so the final order is ad -> map -> settings. */
  .map-area { order: -1; height: auto; overflow: visible; }
  #map { height: 55vh; }
  .sidebar {
    order: 0;
    height: auto;
    overflow: visible;
    border-right: 0;
    /* Center the controls so they don't stretch edge-to-edge on wide tablets. */
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
  }
  /* Roomier touch targets on phones/tablets. */
  .lang-btn { padding: 6px 12px; }
  .checks { gap: 8px 10px; }
}

/* Phones: long passage labels need the full width, so stack the controls. */
@media (max-width: 480px) {
  .settings-grid, .checks { grid-template-columns: 1fr; }
  /* Content pages (about/faq/privacy): tighter padding and a stacked top nav. */
  .legal { padding: 18px 16px 36px; }
  .legal h1 { font-size: 1.3rem; }
  .legal-nav { flex-direction: column; gap: 6px; }
}
