:root {
  /* Light theme (default). --cave stays dark in both themes (text on amber, photo placeholders). */
  --cave: #1b2428;
  --bg: #fafbfb;
  --surface: #ffffff;
  --text: #1b2428;
  --header: #1b2428;
  --rock: #66727a;
  --mist: #f0f2f3;
  --lamp-text: #b0690d;
  --chip: #e2e7ea;
  --band: #f7eedf;
  --line: #dde1e4;
  --lamp: #e09a2b;
  --alert: #c8473a;
  --moss: #3f8f7f;
  --ok-bg: #e7f3ef;
  --err-bg: #f8e8e6;
  --radius: 8px;
  color-scheme: light;
  font-family: "Fira Sans", -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--text);
  background: var(--bg);
}
/* Dark theme: chosen with the button, or the computer's setting if no choice was made. */
:root[data-theme="dark"] {
  --bg: #11171a;
  --surface: #1a2226;
  --text: #e3e8ea;
  --header: #0b1012;
  --rock: #9aa7ae;
  --mist: #232d32;
  --lamp-text: #eaa645;
  --chip: #303d44;
  --band: #2b2a22;
  --line: #34414a;
  --alert: #e8776b;
  --moss: #63b9a6;
  --ok-bg: #1d3530;
  --err-bg: #3a2321;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11171a;
    --surface: #1a2226;
    --text: #e3e8ea;
    --header: #0b1012;
    --rock: #9aa7ae;
    --mist: #232d32;
    --lamp-text: #eaa645;
  --lamp-text: #eaa645;
    --chip: #303d44;
    --band: #2b2a22;
  --band: #2b2a22;
    --line: #34414a;
    --alert: #e8776b;
    --moss: #63b9a6;
    --ok-bg: #1d3530;
    --err-bg: #3a2321;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; line-height: 1.45; }
a { color: inherit; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 120px; }
h1 { font-size: 1.8rem; margin: 0.2rem 0; }
h2 { font-size: 1.15rem; margin: 0 0 0.8rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.3rem; }
.muted { color: var(--rock); }
.small, small { font-size: 0.85rem; }
.lead { font-size: 1.1rem; margin: 0.2rem 0; color: var(--rock); }
.pre { white-space: pre-line; }
.nowrap { white-space: nowrap; }
.error { color: var(--alert); display: block; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--header); color: white; flex-wrap: wrap; }
.theme-toggle { background: none; border: 1px solid #ffffff33; color: white; padding: 4px 9px; font-size: 1rem; line-height: 1; }
.theme-toggle:hover { border-color: var(--lamp); }
.brand { text-decoration: none; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.brand img { height: 34px; display: block; }
.login-logo { display: block; width: 180px; max-width: 70%; margin: 0 auto 12px; }
.topbar nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; }
.topbar nav a:hover { color: var(--lamp); }
.topbar .muted { color: #b8c0c5; }
.topbar form { margin: 0; }

.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

button, .button { font: inherit; display: inline-block; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
button:hover, .button:hover { border-color: var(--rock); }
.primary { background: var(--lamp); border-color: var(--lamp); color: var(--cave); font-weight: 600; }
.primary:hover { filter: brightness(0.95); border-color: var(--lamp); }
.danger { color: var(--alert); }
button.danger { border-color: var(--alert); }
button.link { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline; }

.msg { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; background: var(--mist); }
.msg.success { background: var(--ok-bg); }
.msg.error { background: var(--err-bg); color: var(--alert); }
.msg.warning { background: var(--mist); border-left: 3px solid var(--lamp); }
.msg .button { margin-left: 8px; padding: 4px 10px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.panel.narrow { max-width: 460px; margin: 30px auto; }
details.panel summary { cursor: pointer; font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 160px; }
.field label { font-size: 0.85rem; color: var(--rock); }
.field small { color: var(--rock); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--alert); }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=url], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--lamp) 50%, transparent); border-color: var(--lamp); }
.file-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-top: 6px; }
.file-preview:empty { display: none; }
.file-preview figure { margin: 0; }
.file-preview img, .file-preview .noprev { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; background: var(--mist); color: var(--rock); font-size: 0.8rem; }
.file-preview input[type=text] { margin-top: 4px; padding: 5px 7px; font-size: 0.85rem; }
.cover-label { display: block; font-size: 0.8rem; margin-top: 4px; color: var(--text); }
.file-preview figcaption { font-size: 0.75rem; color: var(--rock); overflow-wrap: anywhere; margin-top: 2px; }
.date-wrap { position: relative; display: flex; gap: 6px; align-items: center; }
.date-wrap input.date { flex: 1; min-width: 0; }
.date-button { padding: 6px 9px; line-height: 1; }
.calendar { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); padding: 8px; width: 260px; }
.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.calendar-head button { padding: 2px 10px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.calendar-grid .weekday { font-size: 0.75rem; color: var(--rock); padding: 2px 0; }
.calendar-grid button { padding: 5px 0; border: 0; background: none; color: inherit; border-radius: 6px; font-size: 0.85rem; }
.calendar-grid button:hover { background: var(--mist); }
.calendar-grid button.today { outline: 1px solid var(--line); }
.calendar-grid button.chosen { background: var(--lamp); color: #fff; }
/* Same crop as in the PDF: which part of the photo is kept. */
img.focus-t { object-position: 50% 0; }
img.focus-c { object-position: 50% 50%; }
img.focus-b { object-position: 50% 100%; }
.strength { margin-top: 4px; }
.strength-track { height: 6px; background: var(--mist); border-radius: 3px; overflow: hidden; }
.strength-fill { height: 100%; width: 0; background: var(--alert); transition: width 0.2s; }
.strength-fill[data-score="2"] { background: var(--lamp); }
.strength-fill[data-score="3"], .strength-fill[data-score="4"] { background: var(--moss); }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-start; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filters input, .filters select { width: auto; min-width: 160px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; text-decoration: none; display: flex; flex-direction: column; }
.card:hover { border-color: var(--rock); }
.card img, .card .noimg { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; background: linear-gradient(var(--rock), var(--cave)); display: block; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.card .body strong { color: var(--lamp-text); }  /* the cave's name */
.title-link { color: inherit; text-decoration: none; }
.title-link:hover { text-decoration: underline; }

.rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.formrow { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 10px; background: var(--mist); border-radius: var(--radius); }
.formrow.day { flex-direction: column; align-items: stretch; }
.formrow .field { margin-bottom: 0; }
.del { font-size: 0.85rem; color: var(--rock); white-space: nowrap; align-self: center; }
.deleted { opacity: 0.45; }

.codes { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 8px 0 10px; }
.code { padding: 3px 9px; font-size: 0.85rem; }
.code b { font-weight: 700; margin-right: 2px; }
.codes-label { font-size: 0.8rem; color: var(--rock); min-width: 80px; }
.rig-head, .rig-row { display: grid; grid-template-columns: 92px 80px 80px 2fr 1.5fr 92px; gap: 6px; align-items: center; }
/* ↑ ↓ ✕ on one line; ✕ is the label of a hidden checkbox (the form's DELETE). */
.row-tools { display: inline-flex; gap: 3px; align-items: center; white-space: nowrap; }
.row-tools button, .row-tools .del-icon { padding: 2px 7px; font-size: 0.85rem; line-height: 1.3; border: 1px solid var(--line, #ccc);
  border-radius: 6px; background: none; color: inherit; cursor: pointer; }
.row-tools .del-icon input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.row-tools .del-icon:hover { color: var(--alert); border-color: var(--alert); }
.deleted .row-tools .del-icon { color: var(--alert); border-color: var(--alert); }
.rig-row { border-radius: 6px; outline: 2px solid transparent; }
.rig-row.selected { outline-color: var(--lamp); }
.pitch-label { font-weight: 700; padding-left: 4px; }
.anchor-chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 32px; align-items: center; }

/* Anchor chips: code, condition, note, remove. Colour = condition. */
.chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 4px 2px 7px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--chip); font-size: 0.85rem; white-space: nowrap; }
.chip b { margin-right: 2px; }
.chip select { width: auto; padding: 1px 2px; font-size: 0.75rem; border: 0; background: transparent; }
.chip button { border: 0; background: none; padding: 0 3px; font-size: 0.8rem; color: var(--rock); }
.chip button:hover { color: var(--alert); }
.chip.cond-worn { border-color: var(--lamp); }
.chip.cond-missing { border-color: var(--alert); background: var(--err-bg); text-decoration: line-through; }
.chip.static { padding: 2px 8px; margin: 1px 2px; }
button.code.group { border-style: dashed; }
.rig-help ul { margin: 4px 0 8px; padding-left: 1.2em; }
.rig-help summary { cursor: pointer; }
/* The code buttons stay in view while scrolling through a long rigging. */
.rig-toolbar { position: sticky; top: 0; z-index: 4; background: var(--surface); padding: 6px 0; border-bottom: 1px solid var(--line); }
.rig-row .pitch-label { white-space: nowrap; }
/* A branch row: name and starting point instead of depth, rope, anchors, comments. */
.rig-row .branch-name, .rig-row .branch-from { display: none; }
.rig-row.branch .branch-name { display: block; grid-column: 2 / 5; }
.rig-row.branch .branch-from { display: block; grid-column: 5; }
.rig-row.branch input[name$="-depth"], .rig-row.branch input[name$="-rope"],
.rig-row.branch .anchor-chips, .rig-row.branch input[name$="-comments"] { display: none; }
/* A branch is one block: a tinted heading, then its rows with a coloured edge. */
.rig-row.branch { margin-top: 14px; background: var(--ok-bg); border-left: 4px solid var(--moss); border-radius: 6px 6px 0 0; }
.rig-row.branch .pitch-label { font-weight: bold; color: var(--moss); }
.rig-row.in-branch { border-left: 4px solid var(--moss); border-radius: 0; }
.rigging-table tr.branch td { background: var(--surface); font-weight: bold; padding-top: 14px; border-bottom: 2px solid var(--rock); }
.rig-row.sub .pitch-label { padding-left: 2em; font-weight: normal; }
.rig-row.sub .pitch-label::before { content: "↳ "; color: var(--rock); }
.rigging-table tr.sub td:first-child { padding-left: 3.2em; font-weight: normal; }
.chip.marked { outline: 2px solid var(--lamp); }
.rigging-table td { vertical-align: top; }
/* Each point with its RB / Dev / Mid / End rows shares one shade, alternating. */
.rig-row.band, .rigging-table tr.band td { background: var(--band); }
.rig-row { padding-top: 4px; padding-bottom: 4px; }
.rigging-table tr.sub td { border-top-color: transparent; }
.rigging-table tr.is-new td:first-child, .rigging-table tr.is-changed td:first-child { color: var(--lamp); }
.mark { color: var(--lamp); font-weight: 600; }
.rigging-left ul { list-style: none; padding: 0; margin: 4px 0; display: flex; gap: 16px; flex-wrap: wrap; }
.rigging-left label { color: var(--text); font-size: 0.95rem; }
.rig-head { font-size: 0.8rem; color: white; background: var(--header); padding: 6px; border-radius: 6px 6px 0 0; }
.rig-row { padding: 0 6px; }
.rig-row .error { grid-column: 1 / -1; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 14px; }
.photo-item { background: var(--mist); border-radius: var(--radius); padding: 8px; }
.photo-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; display: block; margin-bottom: 8px; }
.photo-item .field { min-width: 0; margin-bottom: 6px; }
.photo-item > input[type=text] { margin-bottom: 6px; }
.photo-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 0.8rem; color: var(--rock); margin-top: 4px; }
.photo-meta select, .photo-meta input { width: auto; padding: 3px 6px; font-size: 0.85rem; }
.photo-meta input.short { width: 4.5em; }
input[name="files"] + .file-preview { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 10px; }
.file-preview figure.photo-item img { aspect-ratio: 4 / 3; margin-bottom: 8px; }
.file-preview figure.photo-item figcaption { margin: 0 0 6px; }
.photo-wait { aspect-ratio: 4 / 3; border-radius: 6px; margin-bottom: 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; background: linear-gradient(var(--rock), var(--cave));
  color: white; padding: 10px; }
.photo-wait.error { background: var(--err-bg); color: var(--alert); }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; display: block; }

.cave-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.cave-photos figure { margin: 0; border-radius: 8px; padding: 4px; }
.cave-photos figure.is-cover { outline: 2px solid var(--lamp); }
.cave-photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; display: block; }
.cave-photos figcaption { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin-top: 4px; }
.cave-photos form { margin: 0; }
.cover-mark { color: var(--lamp); font-size: 0.85rem; }
.attachments { list-style: none; padding: 0; }
.attachments li { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.attachments form { margin: 0; }

.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); z-index: 5; }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.list th { background: var(--mist); font-size: 0.85rem; color: var(--rock); }

dl.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin: 0 0 8px; }
dl.facts div { background: var(--mist); border-radius: var(--radius); padding: 8px 12px; }
dl.facts dt { font-size: 0.8rem; color: var(--rock); }
dl.facts dd { margin: 0; font-weight: 600; }
img.map { max-width: 100%; border-radius: var(--radius); margin-top: 10px; }
img.map.small { max-width: 300px; display: block; margin-bottom: 8px; }

.danger-zone { margin-top: 30px; color: var(--rock); }
.danger-zone summary { cursor: pointer; }

@media (max-width: 700px) {
  .rig-head { display: none; }
  .rig-row { grid-template-columns: 1fr 1fr 1fr; background: var(--mist); padding: 8px; border-radius: 6px; }
  .rig-row .anchor-chips, .rig-row input[name$="-comments"] { grid-column: 1 / -1; }
}

/* Map of all caves */
.cave-map { height: 70vh; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--line); }
.leaflet-tooltip.cave-label { background: rgba(255, 255, 255, 0.85); border: 0; box-shadow: none; padding: 1px 5px;
  font-weight: 600; color: #1b2428; }
.leaflet-tooltip.cave-label::before { display: none; }

/* Cave page: observations gathered from the reports */
.observation { border-left: 3px solid var(--line); padding-left: 10px; margin: 6px 0 12px; }
.observation p:first-of-type { margin-top: 2px; }

/* PDF build in progress */
.spinner { display: none; width: 0.9em; height: 0.9em; margin-right: 6px; vertical-align: -0.1em;
  border: 2px solid var(--line); border-top-color: var(--lamp); border-radius: 50%; animation: spin 0.8s linear infinite; }
.pdf-live .spinner, #pdf-panel[data-status="queued"] .spinner, #pdf-panel[data-status="building"] .spinner { display: inline-block; }
.pdf-live { display: inline-flex; align-items: center; font-size: 0.9rem; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Draft reports */
.badge { display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; padding: 1px 7px;
  border-radius: 10px; vertical-align: middle; }
.badge.draft { background: var(--lamp); color: #fff; }
.card .badge.draft { align-self: flex-start; }
.history form { display: inline; margin-left: 6px; }
.formrow .check { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; font-size: 0.9rem; }
.upload-progress { font-size: 0.9rem; color: var(--rock); align-self: center; }
