:root {
  --bg: #f3f5f1;
  --card: #fff;
  --ink: #1d2420;
  --muted: #5d6a63;
  --line: #d9dfd8;
  --brand: #1f6f4a;
  --brand-ink: #fff;
  --brand-soft: #e3f1e9;
  --danger: #b3261e;
  --warn: #a15c00;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
body.public .wrap { max-width: 560px; }
h1 { font-size: 1.6rem; margin: 0.4em 0 0.3em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 0.7em; }
h3 { font-size: 1rem; margin: 1em 0 0.5em; }
a { color: var(--brand); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { background: #e9ede7; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* nav */
.nav { background: #17382a; color: #fff; }
.nav-in { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.brand { margin-right: 4px; }
.nav nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: #d6e8dd; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav a:hover { background: rgba(255,255,255,.12); }
.nav a.active { background: rgba(255,255,255,.2); color: #fff; }
.linklike { background: none; border: 0; color: #d6e8dd; cursor: pointer; font: inherit; text-decoration: underline; padding: 6px; }
.logout { margin: 0; }
.who { display: flex; align-items: center; gap: 6px; }
.role-tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; background: rgba(255,255,255,.18); color: #fff; padding: 1px 7px; border-radius: 999px; }

/* cards & layout */
.card, .panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 16px 0;
}
.panel h1, .panel h2 { margin-top: 0; }
.login-box { max-width: 380px; margin: 60px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.grid4 { display: grid; grid-template-columns: 1fr 1fr 1.2fr 0.7fr; gap: 14px; }
@media (max-width: 800px) { .grid4 { grid-template-columns: 1fr; } }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 14px; }
@media (max-width: 800px) { .grid3 { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 14px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat b { display: block; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 0.875rem; }
.steps { padding-left: 1.2em; margin: 0; }
.steps li { margin: 0.4em 0; }

/* forms */
label { display: block; font-weight: 600; margin: 0 0 12px; }
label small { font-weight: 400; color: var(--muted); }
label.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 10px; font: inherit; color: inherit;
  background: #fff; border: 1px solid #b9c3bb; border-radius: 8px;
}
input[type=checkbox] { width: auto; margin: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 3px solid #8cc9a8; outline-offset: 1px; }
textarea { resize: vertical; }
.hint { display: block; font-size: 0.85rem; font-weight: 400; color: var(--muted); min-height: 1.2em; margin-top: 3px; }
.hint.ok { color: var(--brand); }
.hint.bad { color: var(--danger); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.toolbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0; }
.toolbar label { margin: 0; }
.toolbar select { min-width: 200px; }

.btn {
  display: inline-block; padding: 9px 16px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--ink); background: #fff; border: 1px solid #b9c3bb; border-radius: 8px;
}
.btn:hover { background: #f0f4ef; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { background: #185a3c; }
.btn.danger { color: var(--danger); border-color: #e2b5b1; }
.btn.sm { padding: 4px 10px; font-size: 0.85rem; }
.btn.block { display: block; width: 100%; }
.btn.big { padding: 14px; font-size: 1.15rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* tables */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tbl th, .tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl input, .tbl select { margin: 0; min-width: 140px; }
.tbl .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell .btn { margin-left: 4px; }
.code-chip { background: var(--brand-soft); color: #11402b; padding: 3px 9px; border-radius: 6px; font-weight: 700; letter-spacing: .08em; }
.seq { margin: 6px 0 0; padding-left: 1.3em; font-size: 0.85rem; font-weight: 400; }
details summary { cursor: pointer; color: var(--brand); font-size: 0.85rem; margin-top: 4px; }

/* maps */
.map { height: 440px; border: 1px solid var(--line); border-radius: 8px; z-index: 0; }
.map-caption { margin: 8px 0 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.map.form-map { height: 380px; }
.map-field { margin: 4px 0 12px; }
.pin { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff;
  font: 700 12px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); }
.pin.start { background: #1a7f37; }
.pin.finish { background: #b3261e; }
.pin.pending { background: #f5a300; color: #3a2600; }
.pin.done { background: #1a7f37; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -1px; border: 1px solid rgba(0,0,0,.3); }
.key.amber { background: #f5a300; }
.key.green { background: #1a7f37; }
.map.tall { height: 70vh; min-height: 420px; }
.pt-shownext { margin-top: 6px; }
.pin.unused { background: #6b7a72; }
.pin.preview { background: #fff; color: var(--brand); border: 3px dashed var(--brand); }
.leaflet-popup-content { margin: 12px 14px; font: 14px/1.4 system-ui, sans-serif; }
.leaflet-popup-content .btn { margin: 6px 6px 0 0; }
.leaflet-popup-content .small { color: var(--muted); }

/* live progress: click-to-expand scan list */
.route-toggle { background: none; border: 0; padding: 2px 0; font: inherit; color: var(--brand); cursor: pointer; text-align: left; text-decoration: underline dotted; }
.route-toggle:hover { text-decoration: underline; }
.route-toggle:focus-visible { outline: 3px solid #8cc9a8; outline-offset: 2px; border-radius: 3px; }
.tbl tr.detail-row td { background: #f6f9f5; padding: 6px 12px 12px; }
.scan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.scan-list li { display: grid; grid-template-columns: 7.5em minmax(8em, 1fr) 8.5em minmax(9em, auto); gap: 10px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.scan-list li:last-child { border-bottom: 0; }
.scan-list .sc-role { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: .05em; }
.scan-list .sc-name { font-weight: 600; }
.scan-list .sc-time { text-align: right; font-variant-numeric: tabular-nums; }
.scan-list li.pending { color: var(--muted); }
.scan-list li.pending .sc-name { font-weight: 400; }
@media (max-width: 700px) { .scan-list li { grid-template-columns: 1fr auto; } .scan-list .sc-role, .scan-list .mono { grid-column: 1 / -1; } }

/* route editor */
.pt { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 12px 0; background: #fafcf9; }
.pt-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.pt-tools { display: flex; gap: 4px; }
.pt-new { display: grid; gap: 8px; margin-top: 8px; }
.mids { margin: 10px 0; }
.pt-note { margin: 10px 0 0; }
.pt-note textarea, .pt-note input { margin-top: 8px; }
.video { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* badges, bars, messages */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: #e9ede7; color: var(--muted); white-space: nowrap; }
.badge.ok { background: #d5efe0; color: #11402b; }
.badge.warn { background: #fdebc8; color: var(--warn); }
.pbar-wrap { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.pbar { flex: 1; height: 10px; background: #e4e9e2; border-radius: 99px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.pbar.big { height: 14px; margin: 10px 0 6px; }
.msg { min-height: 1.4em; margin: 6px 0 10px; }
.msg.bad { color: var(--danger); font-weight: 600; }
.msg.ok { color: var(--brand); font-weight: 600; }
.narrow { max-width: 420px; }
.inline-forms { display: flex; gap: 18px; flex-wrap: wrap; }
.inline-forms form { margin: 0; }
.linklike.dark { color: var(--brand); padding: 4px 0; }
.role-tag.dark { background: var(--brand-soft); color: #11402b; }
#toasts { position: fixed; right: 14px; bottom: 14px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 28px); }
.toast { background: #17382a; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
.toast.err { background: var(--danger); }

/* public scan page – built for bright sun and wet fingers */
.code-input { font-size: 2rem; text-align: center; letter-spacing: .15em; text-transform: uppercase; padding: 14px 10px; }
.banner { text-align: center; background: var(--brand-soft); border-color: #b8dcc8; }
.banner.done { background: #fff4d6; border-color: #ecd391; }
.banner h1 { margin-bottom: 4px; }
.next { border: 2px solid var(--brand); }
.gridref { font-size: 2.1rem; font-weight: 800; letter-spacing: .04em; margin: 4px 0; overflow-wrap: anywhere; }
.big-time { font-size: 1.6rem; font-weight: 700; }

/* printable QR sheet */
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.qr-card { background: #fff; border: 1px dashed #8a948c; border-radius: 8px; padding: 14px; text-align: center; break-inside: avoid; page-break-inside: avoid; }
.qr svg { width: 100%; max-width: 220px; height: auto; display: block; margin: 0 auto; }
.qr-cap { margin: 6px 0; font-weight: 700; }
.qr-meta { display: grid; gap: 2px; }
.qr-url { font-size: 0.62rem; color: var(--muted); overflow-wrap: anywhere; margin: 6px 0 0; }
body.hide-meta .qr-meta { visibility: hidden; }

/* printable route cards */
.route-card { background: #fff; border: 2px solid #222; border-radius: 10px; padding: 18px 22px; margin: 0 0 18px; break-inside: avoid; page-break-inside: avoid; }
.route-card header { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; border-bottom: 2px solid #222; padding-bottom: 8px; }
.route-card h2 { margin: 0; font-size: 1.5rem; flex: 1; }
.rc-event, .rc-route { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.rc-code { text-align: center; margin: 14px 0; }
.rc-code span { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.rc-code b { display: block; font-size: 2.6rem; letter-spacing: .18em; }
.rc-code small { color: var(--muted); }
.rc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.rc-grid div { border: 1px solid #222; border-radius: 8px; padding: 10px; text-align: center; }
.rc-grid span { display: block; font-size: .75rem; letter-spacing: .1em; color: var(--muted); }
.rc-grid b { font-size: 1.5rem; }
.rc-steps { margin: 0; padding-left: 1.3em; font-size: .9rem; }

/* printable route card (legs, distance, bearing, remarks) */
.leg-card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; }
.leg-card header h1 { margin: 0 0 2px; }
.leg-table { width: 100%; border-collapse: collapse; margin: 12px 0 8px; }
.leg-table th, .leg-table td { border: 1px solid #222; padding: 6px 8px; vertical-align: top; text-align: left; }
.leg-table thead th { background: #f0f3f1; font-size: .85rem; }
.leg-table .c-leg { width: 3.2rem; text-align: center; }
.leg-table .c-num { width: 7rem; text-align: right; white-space: nowrap; }
.leg-table .c-rem { width: 38%; }
.leg-remark-print { display: none; }
.leg-table td strong + br + .mono, .leg-table .mono { white-space: nowrap; }
.leg-table tfoot td { background: #f0f3f1; }
.leg-remark { width: 100%; box-sizing: border-box; min-height: 44px; resize: vertical; font: inherit; border: 1px dashed var(--line); border-radius: 4px; padding: 4px 6px; background: #fff; }
.leg-remark[readonly] { border-color: transparent; resize: none; }
@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .no-print, .nav, #toasts { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .qr-sheet { grid-template-columns: repeat(3, 1fr); gap: 8mm; }
  .route-card { margin-bottom: 8mm; }
  .leg-card { border: 0; padding: 0; }
  .leg-remark { display: none; }
  .leg-remark-print { display: block; white-space: pre-wrap; min-height: 1.4em; }
  .leg-table .c-rem { width: 40%; }
  .leg-table tr { break-inside: avoid; }
}
