/* ThistleNet Logbook styles. One file, no build step.
   The look is monochrome on purpose: black, greys and white only.
   Controls are compact and boxy: 34px high, small radius, quiet borders. */
:root {
  --bg: #0b0b0b;        /* page */
  --surface: #141414;   /* cards, header menus */
  --field: #121212;     /* inside inputs */
  --raised: #1f1f1f;    /* hover, bar tracks */
  --text: #ededed;
  --muted: #9a9a9a;
  --border: #272727;
  --border-strong: #3a3a3a;
  --ink: #ededed;       /* primary buttons and selected choices */
  --on-ink: #0b0b0b;
  --series-1: #c9c9c9;  /* chart bars */
  --map-ink: #f2f2f2;   /* routes and airports on maps */
  --radius: 10px;       /* cards */
  --radius-control: 7px; /* inputs, buttons, chips */
  --control-height: 34px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Views the browser has switched away from stay hidden whatever else styles them. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}
a:hover { text-decoration-color: var(--text); }

/* --- Header bar --- */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-header .brand {
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.93rem;
}
.site-header nav a { color: var(--muted); text-decoration: none; }
.site-header nav a:hover { color: var(--text); }
.site-header nav > a[aria-current="page"] {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--text);
  text-underline-offset: 6px;
}

.site-header form { margin: 0; }

.site-header .brand,
.site-header nav a,
.site-header nav button { white-space: nowrap; }

/* The account menu: the person's name opens it. */
details.menu { position: relative; }
details.menu summary {
  cursor: pointer;
  list-style: none;
  padding: 3px 10px;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  white-space: nowrap;
}
details.menu summary::-webkit-details-marker { display: none; }
details.menu summary::after { content: " \25BE"; color: var(--muted); }
details.menu summary:hover { background: var(--raised); }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 180px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
.menu-items .muted { font-size: 0.8rem; }
.site-header .menu-items a,
.site-header .menu-items button.link { color: var(--text); font-size: 0.93rem; text-align: left; }
.site-header .menu-items a:hover,
.site-header .menu-items button.link:hover { text-decoration: underline; }

/* --- Page --- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 22px 16px 48px;
}

main.narrow { max-width: 400px; }
main.wide { max-width: 980px; }

h1 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 14px; font-weight: 650; }
h2 { font-size: 1rem; margin: 26px 0 10px; font-weight: 600; }
h3 { font-size: 0.87rem; margin: 14px 0 4px; font-weight: 550; color: var(--muted); }
h2 + h3 { margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.muted { color: var(--muted); }

/* --- Forms: compact, boxy controls --- */
form .field,
form > div { margin-bottom: 12px; }

label,
legend { display: block; font-size: 0.87rem; font-weight: 550; margin-bottom: 5px; padding: 0; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
input[type="number"],
select {
  width: 100%;
  height: var(--control-height);
  padding: 0 10px;
  font: inherit;
  font-size: 0.93rem;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
}
input::placeholder { color: #6b6b6b; }

input[type="file"] {
  width: 100%;
  padding: 7px 8px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  background: var(--field);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-control);
}
input[type="file"]::file-selector-button {
  height: 26px;
  margin-right: 10px;
  padding: 0 10px;
  font: inherit;
  font-size: 0.87rem;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  cursor: pointer;
}

input:hover, select:hover { border-color: #555555; }

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

.helptext, .helptext ul { color: var(--muted); font-size: 0.82rem; margin: 4px 0 0; }
.helptext ul { padding-left: 18px; }

/* Errors are marked by weight and a sign, not by colour. */
.errorlist {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  font-size: 0.87rem;
  font-weight: 600;
}
.errorlist li::before { content: "! "; }

fieldset { border: 0; margin: 0 0 12px; padding: 0; min-width: 0; }
/* A fieldset drawn as a card: keep its legend inside the box, not on the border. */
fieldset.card { border: 1px solid var(--border); padding: 16px; }
fieldset.card > legend { float: left; width: 100%; margin-bottom: 10px; font-size: 0.95rem; }
fieldset.card > legend + * { clear: both; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 10px;
}
.field-grid .wide { grid-column: 1 / -1; }

label.checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.93rem; font-weight: 400; margin: 4px 0 0; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--ink); }

/* --- Buttons --- */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-height);
  padding: 0 14px;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 600;
  color: var(--on-ink);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius-control);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover,
.button:hover { background: #ffffff; border-color: #ffffff; }

button.secondary {
  color: var(--text);
  background: var(--raised);
  border-color: var(--border-strong);
  font-weight: 500;
}
button.secondary:hover { background: #2a2a2a; border-color: #555555; }

button.link {
  height: auto;
  padding: 0;
  font-weight: 400;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: none;
}
button.link:hover { color: var(--text); background: none; }

.danger-link { color: var(--muted); }

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.footer-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin-top: 22px; }
.footer-links.tight { margin-top: 10px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 5px 16px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
dl.facts.stacked { grid-template-columns: 1fr; gap: 2px; }
dl.facts.stacked dd { margin-bottom: 8px; }

/* --- Messages and notices --- */
.messages, .problems { list-style: none; margin: 0 0 14px; padding: 0; }
.messages li, .problems li, .notice {
  margin: 0 0 8px;
  padding: 8px 11px;
  font-size: 0.93rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
}
.problems li,
.messages li.error { border-left-color: var(--text); font-weight: 550; }

/* --- Choices shown as chips: radio buttons and filter links --- */
.pills > div { display: flex; flex-wrap: wrap; gap: 6px; }
.pills > div > div { margin: 0; }
.pills label,
.pill-links a {
  display: inline-flex;
  align-items: center;
  height: 30px;
  margin: 0;
  padding: 0 11px;
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--field);
  cursor: pointer;
  text-decoration: none;
}
.pills label:hover,
.pill-links a:hover { background: var(--raised); }
.pills input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.pills label:has(input:checked),
.pill-links a[aria-current="true"] { color: var(--on-ink); background: var(--ink); border-color: var(--ink); }
.pills label:has(input:focus-visible) { outline: 2px solid #ffffff; outline-offset: 1px; }

.pill-links { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }

.inline-filter { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.inline-filter label { margin: 0; }
.inline-filter select { width: auto; }

.pass-card { margin-bottom: 14px; }
.pass-card h2 { margin-top: 0; font-size: 1.1rem; white-space: pre-wrap; }

/* --- Tables --- */
.table-card { padding: 0; overflow-x: auto; }
table.flights { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.flights th, table.flights td { padding: 8px 12px; text-align: left; white-space: nowrap; }
table.flights th { color: var(--muted); font-size: 0.85rem; font-weight: 550; border-bottom: 1px solid var(--border); }
table.flights tr + tr td { border-top: 1px solid var(--border); }
table.flights td:last-child { white-space: normal; }
table.flights tbody tr:hover td { background: var(--raised); }

table.plain { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.plain td { padding: 4px 0; }
table.plain td.number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Hand-entry flight form: details on the left, people on the right --- */
.flight-form .form-columns { display: grid; gap: 22px; }
.flight-form .form-main section { padding: 0 0 6px; }
.flight-form .form-main section + section { margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--border); }
.flight-form h2 { margin: 0 0 10px; }
.flight-form section > .helptext { margin: 0 0 10px; }
.flight-form .form-side h2 { padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.flight-form .actions {
  flex-direction: row-reverse; /* the main button sits on the right */
  position: sticky;
  bottom: 0;
  margin-top: 18px;
  padding: 10px 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

@media (min-width: 860px) {
  .flight-form .form-columns { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  .flight-form .form-side { position: sticky; top: 16px; }
}

/* Airline details do not apply to a private flight. */
.flight-form:has(input[name="kind"][value="private"]:checked) .commercial-only { display: none; }

.airport-field { position: relative; }
.airport-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
}
.airport-results li.muted { padding: 6px 8px; font-size: 0.87rem; }
.airport-results button {
  display: block;
  width: 100%;
  height: auto;
  padding: 6px 8px;
  text-align: left;
  font-weight: 400;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 5px;
  white-space: normal;
}
.airport-results button:hover,
.airport-results button:focus-visible { background: var(--raised); }
.airport-results button strong { display: block; font-weight: 600; font-size: 0.9rem; }
.airport-results button span { color: var(--muted); font-size: 0.82rem; }

details.new-place { margin-top: 6px; }
details.new-place summary { cursor: pointer; color: var(--muted); font-size: 0.87rem; }
details.new-place summary:hover { color: var(--text); }
details.new-place[open] summary { margin-bottom: 10px; }

.who-row + .who-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.who-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 8px; }

/* --- Stats: headline numbers --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.tile-label { color: var(--muted); font-size: 0.85rem; }
.tile-value { font-size: 1.65rem; font-weight: 650; line-height: 1.2; }
.tile-value small { font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.tile-note { color: var(--muted); font-size: 0.8rem; }
.hero-number { margin: 0 0 8px; font-size: 1.5rem; font-weight: 650; line-height: 1.2; }
.hero-number small { font-size: 0.85rem; font-weight: 500; color: var(--muted); }

/* --- Stats: ranked bars in one grey, name and value above each bar --- */
.stat-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 22px; }
.stat-columns .card h2 { margin-top: 0; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { padding: 5px 0; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 0.9rem; }
.bar-value { font-variant-numeric: tabular-nums; }
.bar-track { display: block; height: 8px; margin-top: 4px; background: var(--raised); border-radius: 0 4px 4px 0; }
.bar { display: block; height: 100%; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; }

/* --- Maps --- */
.route-map {
  height: 420px;
  margin: 16px 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}
.route-map.map-failed { display: grid; place-items: center; color: var(--muted); }

/* The map library's own controls, in the same black and greys. */
.route-map .maplibregl-ctrl-group {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  box-shadow: none;
}
.route-map .maplibregl-ctrl-group button + button { border-top-color: var(--border); }
.route-map .maplibregl-ctrl-group button:hover { background: var(--raised); }
.route-map .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1); }
.route-map .maplibregl-ctrl.maplibregl-ctrl-attrib,
.route-map .maplibregl-ctrl-attrib.maplibregl-compact {
  color: var(--muted);
  background: rgba(11, 11, 11, 0.78);
  font-size: 0.6875rem;
}
.route-map .maplibregl-ctrl-attrib a { color: var(--text); }
.route-map .maplibregl-ctrl-attrib-button { filter: invert(1); background-color: transparent; }
.route-map .maplibregl-popup-content {
  padding: 5px 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  box-shadow: none;
  font: 0.85rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.route-map .maplibregl-popup-tip { display: none; }

/* The map library sizes its own buttons; keep our button padding off them. */
.route-map button { padding: 0; }

/* --- The home page: a map filling the page under the header --- */
body.map-page { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
main.map-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}
main.map-main .messages { margin: 12px 16px; }
.map-full { position: relative; flex: 1; min-height: 0; }
.map-full .route-map {
  position: absolute;
  inset: 0;
  height: auto;
  margin: 0;
  border: 0;
  border-radius: 0;
}
.map-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  max-width: min(360px, calc(100% - 24px));
  padding: 11px 13px;
  background: rgba(20, 20, 20, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.map-overlay h1 { margin: 0 0 8px; font-size: 1.05rem; }
.map-overlay .pill-links { margin: 0 0 8px; }
.map-overlay .pill-links a { height: 26px; padding: 0 10px; }
.map-overlay p { margin: 0; font-size: 0.87rem; }

@media (max-width: 480px) {
  .site-header { padding: 10px 12px; }
  .site-header nav { gap: 13px; font-size: 0.9rem; }
  .route-map { height: 300px; }
  .route-map .maplibregl-ctrl-top-right { display: none; } /* pinch to zoom on a phone */
  table.flights { font-size: 0.87rem; }
  table.flights th, table.flights td { padding: 8px 8px; }
  table.flights th:first-child, table.flights td:first-child { padding-left: 12px; }
  table.flights .wide-only { display: none; }
  /* Phones zoom the page when a focused input's text is under 16px. */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="number"],
  select { font-size: 16px; }
}
