/* One stylesheet, mobile first. Dark by default because half of this is read
   at 5 a.m. in a car, and light when the system asks for it. */

:root {
  --bg: #12151a;
  --bg-soft: #181c23;
  --card: #1d222b;
  --line: #2b323e;
  --text: #e8ecf2;
  --muted: #98a2b3;
  --accent: #5aa9e6;
  --accent-soft: #1e3a52;
  --ok: #57c98a;
  --warn: #e8b84b;
  --err: #e8695a;
  --radius: 10px;
  --gap: 12px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --bg-soft: #eceff4;
    --card: #ffffff;
    --line: #d9dee7;
    --text: #1a1f27;
    --muted: #5c6675;
    --accent: #1d6fb8;
    --accent-soft: #dcebf8;
    --ok: #1f8a53;
    --warn: #9a6b06;
    --err: #b8352a;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

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

h1, h2, h3, h4 {
  line-height: 1.25;
  margin: 0 0 8px;
  /* The header is sticky, so a heading scrolled to would hide under it. */
  scroll-margin-top: 60px;
}
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
h4 { font-size: .92rem; color: var(--muted); }
p { margin: 0 0 10px; }
a { color: var(--accent); }

/* --- shell ---------------------------------------------------------------- */

header.app {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 10px 14px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}

header.app .brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
}

header.app .spacer { flex: 1; }

header.app button.nav {
  padding: 5px 9px;
  border-radius: 7px;
  font-size: .92rem;
}
header.app button.nav.active {
  color: var(--text);
  background: var(--card);
  border-color: var(--line);
}

@media (max-width: 560px) {
  .hide-narrow { display: none; }
  header.app { padding: 8px 10px; gap: 6px; }
}
header.app .who { color: var(--muted); font-size: .85rem; }

main { padding: 14px; max-width: 1100px; margin: 0 auto; }

/* --- tabs ----------------------------------------------------------------- */

nav.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  padding-bottom: 2px;
}
nav.tabs::-webkit-scrollbar { display: none; }

nav.tabs button {
  flex: 0 0 auto;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 10px;
  font: inherit;
  font-size: .92rem;
  cursor: pointer;
  white-space: nowrap;
}
nav.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
nav.tabs button .count {
  font-size: .75rem;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 0 5px;
  margin-left: 4px;
}

.panel { animation: fade .12s ease-out; }
@keyframes fade { from { opacity: .4; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

nav.days {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 12px;
  scrollbar-width: none;
}
nav.days::-webkit-scrollbar { display: none; }
nav.days button {
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 6px 12px;
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
  text-align: left;
}
nav.days button.active { border-color: var(--accent); color: var(--text); }
nav.days button small { display: block; font-size: .72rem; opacity: .75; }

/* --- cards and lists ------------------------------------------------------ */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: var(--gap);
}

.card > h3 { display: flex; align-items: center; gap: 8px; }
.card > h3 .spacer { flex: 1; }

.grid { display: grid; gap: var(--gap); }
@media (min-width: 720px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
/* A dot between facts: "-238 m · 180 m de corde · 6 h" reads as a list, where
   the same values separated by whitespace read as one run-on number. */
.row.stats > span + span::before { content: '·'; margin-right: 5px; opacity: .6; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.empty { color: var(--muted); font-style: italic; margin: 6px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: none; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 550; }
.item .sub { color: var(--muted); font-size: .85rem; }

/* --- controls ------------------------------------------------------------- */

input, select, textarea, button {
  font: inherit;
  color: var(--text);
}

input[type=text], input[type=date], input[type=time], input[type=number],
input[type=password], input[type=email], input[type=url], select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

input.live, select.live, textarea.live { background: transparent; border-color: transparent; }
input.live:hover, select.live:hover, textarea.live:hover { border-color: var(--line); }
input.live:focus, select.live:focus, textarea.live:focus { background: var(--bg-soft); }
.live.read-only, input.live[readonly], textarea.live[readonly] {
  border-color: transparent;
  background: transparent;
  cursor: default;
  opacity: .85;
}
span.live.read-only { padding: 7px 0; display: inline-block; }

.live.saving { opacity: .6; }
.live.saved { border-color: var(--ok); }
.live.failed { border-color: var(--err); }

button {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.icon { padding: 4px 8px; line-height: 1; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field-label { font-size: .82rem; color: var(--muted); }
.field-hint { font-size: .78rem; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; }

form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
form.inline .field { margin-bottom: 0; flex: 1 1 140px; }
form.inline button { flex: 0 0 auto; }

/* --- badges --------------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: .75rem;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge-ok { color: var(--ok); border-color: var(--ok); }
.badge-warn { color: var(--warn); border-color: var(--warn); }
.badge-err { color: var(--err); border-color: var(--err); }
.badge-accent { color: var(--accent); border-color: var(--accent); }

/* --- tables --------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 550; font-size: .8rem; }

/* --- schedule ------------------------------------------------------------- */

.event {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.event:last-child { border-bottom: none; }
.event .when { font-variant-numeric: tabular-nums; font-size: .88rem; }
/* Inputs default to full width, which inside a flex row makes every control
   claim its own line. In the event header they share one. */
.event .row select, .event .row input { width: auto; }
.event .row > select { flex: 1 1 110px; }
.event .body { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.event .body > .row { width: 100%; }
.event .kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.event .callout { color: var(--warn); font-size: .82rem; }
.people-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.chip {
  font-size: .78rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1px 8px;
}
.chip button { all: unset; cursor: pointer; margin-left: 4px; color: var(--muted); }

h4.objective {
  color: var(--accent);
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 6px;
  font-size: .88rem;
}
h4.objective:first-child { border-top: none; padding-top: 0; }

/* --- rigging sheets ------------------------------------------------------ */

.card.route { border-left: 3px solid var(--accent); }
.card.route > summary {
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  list-style: none;
}
.card.route > summary::-webkit-details-marker { display: none; }
.card.route > summary::before { content: '▸'; color: var(--muted); }
.card.route[open] > summary::before { content: '▾'; }
.card.route[open] > summary { margin-bottom: 10px; }
.card.route > summary .route-name { font-weight: 600; }
.card.route > summary .sub { flex: 1 1 100%; color: var(--muted); font-size: .85rem; }

details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 10px; }

.warn-note {
  color: var(--warn);
  font-size: .85rem;
  border-left: 3px solid var(--warn);
  padding-left: 8px;
  margin: 6px 0;
}

.obstacles { margin-top: 10px; }
.obstacles > h4 { margin-bottom: 4px; }

.obstacle {
  border-top: 1px solid var(--line);
  padding: 8px 0 6px;
}
.obstacle .num {
  flex: 0 0 18px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
/* An obstacle that needs rope and has none recorded is the one thing on this
   page that must not be missed. */
.obstacle.missing { background: color-mix(in srgb, var(--err) 8%, transparent); }

.riggings {
  margin: 4px 0 0 26px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rigging { padding: 2px 0; }
/* The one to take unless there is a reason not to. */
.rigging.preferred { border-left: 2px solid var(--ok); margin-left: -12px; padding-left: 10px; }
.rigging-form { gap: 6px; }
.rigging-form input { font-size: .88rem; }

.map {
  height: 260px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin: 10px 0;
  z-index: 0;
}
.leaflet-container { background: var(--bg-soft); border-radius: var(--radius); }
.map-tall { height: 340px; }
.map-empty { display: flex; align-items: center; justify-content: center; height: 100%; }
button.locate { padding: 0 4px; font-size: .95rem; line-height: 1; }

/* --- a cave's notes and files -------------------------------------------- */

.card.note { border-left: 3px solid var(--line); }
.share-banner { border-left: 3px solid var(--accent); }
.item.dead { opacity: .55; }
/* A ticked-off line stays readable but stops competing for attention. */
.item.done .title { text-decoration: line-through; opacity: .6; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.gallery figure { margin: 0; }
.gallery img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  display: block;
}
.gallery figcaption {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  color: var(--muted);
  margin-top: 3px;
}
.gallery figcaption span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-frame { position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 0; }

/* --- markdown ------------------------------------------------------------- */

.md { font-size: .93rem; }
.md p { margin: 0 0 8px; }
.md ul { margin: 0 0 8px; padding-left: 20px; }
.md table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .88rem; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; }
.md th { color: var(--muted); font-weight: 550; }
.md blockquote {
  border-left: 3px solid var(--warn);
  margin: 8px 0;
  padding-left: 10px;
  color: var(--warn);
}

.md code {
  background: var(--bg-soft);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: .88em;
}
pre.brief {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
  max-height: 340px;
  font-size: .82rem;
  white-space: pre-wrap;
}

/* --- toasts --------------------------------------------------------------- */

#toasts {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
  width: min(560px, calc(100vw - 24px));
}
.toast {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .9rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
  transition: opacity .4s, transform .4s;
}
.toast-error { border-left-color: var(--err); }
.toast-ok { border-left-color: var(--ok); }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* --- login / setup -------------------------------------------------------- */

.centered {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.centered .card { width: min(380px, 100%); }

/* --- gate ----------------------------------------------------------------- */

.gate {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-left: 3px solid var(--warn);
  padding-left: 10px;
}
.gate.passed { border-left-color: var(--ok); }
