:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --border: #ddd;
  --text: #222;
  --muted: #666;
  --accent: #2a5db0;
  --accent-hover: #1f4788;
  --error: #b00020;
  --success: #1a7a3c;

  /* Spacing scale, 0.25rem (4px) steps. Every margin/padding/gap in this
     file snaps to the nearest step *except*: values under 4px (badge/stack
     "fine chrome" like 0.1rem/0.15rem/0.2rem — snapping these up would
     visibly inflate tightly-packed pill/stack UI), fixed component
     dimensions that aren't spacing rhythm at all (.icon-button's 2.25rem
     diameter, .danger-zone's 3rem "false floor", .filter-row-label's
     5.5rem text column), and 0.35rem (2 call sites, not worth a coin-flip
     snap between steps) — those stay as commented-in-place literals rather
     than being forced onto the scale. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;

  /* Type scale. form.stack input/select/textarea font-size is deliberately
     NOT on this scale — see comment at that rule. */
  --text-xs: 0.75rem;
  --text-sm: 0.85rem;
  --text-base: 0.95rem;
  --text-lg: 1.15rem;
  --text-xl: 1.4rem;

  /* RGB channels shared by the dark canvas-chrome overlays (tooltip,
     icon-button). Alphas vary meaningfully by state (base/hover/disabled)
     and stay inline at each call site — only the color itself is shared. */
  --overlay-dark: 20, 20, 20;

  color-scheme: light;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-header .brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--text);
  text-decoration: none;
}
.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.site-nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.site-nav a:hover {
  text-decoration: underline;
}
.site-nav .inline-form {
  display: contents;
}
.site-nav .link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.site-nav .link-button:hover {
  text-decoration: underline;
  background: none;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-5);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

h1 { font-size: var(--text-xl); margin: 0; }
h2 { font-size: var(--text-lg); }

.button, button, input[type="submit"] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: var(--space-2) var(--space-4);
  border-radius: 6px;
  text-decoration: none;
  font-size: var(--text-base);
  cursor: pointer;
}
.button:hover, button:hover, input[type="submit"]:hover { background: var(--accent-hover); }
.button.secondary, button.secondary { background: #888; }
.button.danger, button.danger { background: var(--error); }

.flashes { list-style: none; padding: 0; margin: 0 0 var(--space-4); }
.flash { padding: var(--space-2) var(--space-4); border-radius: 6px; margin-bottom: var(--space-2); }
.flash-error { background: #fde8e8; color: var(--error); border: 1px solid #f3b8b8; }
.flash-success { background: #e7f6ec; color: var(--success); border: 1px solid #b9e6c6; }

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

.target-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-4); }
.target-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.target-card a { color: inherit; text-decoration: none; display: block; }
.target-card .thumb { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #eee; }
.target-card-body { padding: var(--space-2) var(--space-3); display: flex; flex-direction: column; gap: var(--space-1); }
.target-name { font-weight: 600; }
.group-count { color: var(--muted); font-size: var(--text-sm); }

/* Wider, horizontal variant of .target-card — thumbnail left, metadata
   (status, groups, rifles/ammo used, notes) to the right — used by the
   trip timeline's target card and the home page's trip card, instead of
   the narrow vertical tile layout used elsewhere (rifles index, account
   page). */
.target-card.preview-card { max-width: 640px; display: flex; }
.target-card.preview-card .target-card-thumb { flex: 0 0 160px; }
.target-card.preview-card .thumb { width: 160px; height: 100%; aspect-ratio: auto; }
.target-card.preview-card .target-name { display: block; }
.target-card-rifles,
.target-card-notes {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.15rem; /* below the 4px scale floor — see :root comment */
}
.target-card-notes { font-style: italic; }

.trip-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--space-4); }

/* " · "-joined inline meta spans (date, location, ...) — a CSS-generated
   separator rather than a literal space in the template, which djlint's
   whitespace-collapsing reformatter would otherwise eat. Same idea as
   .trip-meta's own separator on the trip detail page, just scoped smaller
   for reuse inside a card. */
.meta-line span:not(:last-child)::after { content: " · "; }

.badge { display: inline-block; font-size: var(--text-xs); padding: 0.1rem var(--space-2); border-radius: 999px; width: fit-content; }
.badge-uploaded { background: #fdf1d6; color: #8a6100; }
.badge-deskewed { background: #dceeff; color: #0a5aa8; }
.badge-calibrated { background: #dcf5e2; color: var(--success); }

form.stack { display: flex; flex-direction: column; gap: var(--space-3); max-width: 420px; }
form.stack label { font-weight: 600; font-size: var(--text-base); }
form.stack input[type="text"],
form.stack input[type="email"],
form.stack input[type="password"],
form.stack input[type="number"],
form.stack input[type="date"],
form.stack input[type="time"],
form.stack input[type="file"],
form.stack select,
form.stack textarea {
  padding: var(--space-2) var(--space-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  /* Deliberately 1rem (16px), not var(--text-base)/0.95rem: sub-16px input
     font-size triggers iOS Safari's auto-zoom-on-focus, a real mobile-UX
     regression, not a cosmetic nit. */
  font-size: 1rem;
  width: 100%;
  font-family: inherit;
}
form.stack textarea { resize: vertical; }
.field-row { display: flex; gap: var(--space-2); align-items: flex-end; }
.field-row > div { flex: 1; }

.canvas-wrap { position: relative; max-width: 100%; touch-action: none; }
.canvas-wrap canvas { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 4px; display: block; background: #111; cursor: crosshair; }
.thumb-large { width: 100%; max-width: 500px; }

/* Read-only target-overview hover tooltip (see target-overview.js's
 * TargetOverview._initTooltip) — floats next to the cursor over whichever
 * summary shape (extreme spread, mean radius, POA/calculated-zero lines) it
 * currently hovers. Positioned absolutely within .canvas-wrap. */
.canvas-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(var(--overlay-dark), 0.9);
  color: #fff;
  font-size: 0.8rem; /* between --text-xs/--text-sm, kept literal */
  padding: var(--space-1) var(--space-2);
  border-radius: 4px;
  white-space: nowrap;
}

/* Fixed-size zoom/pan viewport — used only on the interactive canvases
 * (deskew, calibrate, group editor, compare-groups overlay). Width fills
 * whatever container it's placed in (the page's 900px .container on its
 * own, or the narrower first column of .two-col's grid on calibrate/group
 * editor) rather than sizing off the raw browser viewport — a vw-based
 * width would overflow .container and, worse, blow out .two-col's grid
 * track (a fixed-width child forces a grid item wider than its track
 * unless the item's min-width shrinks to fit, which browsers don't do by
 * default), pushing the second column (rifle/caliber/firing-solution
 * fields) out of view. Height is fixed (viewport-relative, capped) and
 * does NOT change with zoom — ZoomPanController (zoom-pan.js)
 * positions/scales the canvas inside it entirely via a CSS transform, so
 * the canvas's own width/height attributes (its native pixel resolution)
 * are never touched here; the canvas being position:absolute also means it
 * contributes no intrinsic width to this element, which is what makes
 * width:100% safe inside a grid column. touch-action:none keeps native
 * browser touch-scroll/pinch off the canvas so pointer events receive raw
 * touch input for ZoomPanController's own pan/pinch handling.
 *
 * There's no explicit "pan mode" — every draggable point/corner/shot gets a
 * grab cursor, and dragging empty space simply pans (see zoom-pan.js's
 * hitTest coordination), so one grab/grabbing cursor pair covers both. */
.canvas-viewport { position: relative; width: 100%; height: min(78vh, 700px); overflow: hidden; border: 1px solid var(--border); border-radius: 4px; background: #111; }
.canvas-viewport canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; display: block; cursor: grab; touch-action: none; }
.canvas-viewport.dragging canvas { cursor: grabbing; }

.canvas-overlay-toolbar { position: absolute; top: var(--space-2); right: var(--space-2); display: flex; gap: var(--space-2); z-index: 2; }
.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem; /* fixed circular diameter, not spacing rhythm */
  height: 2.25rem;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(var(--overlay-dark), 0.65);
  color: #fff;
}
.icon-button:hover { background: rgba(var(--overlay-dark), 0.85); }
.icon-button:disabled { opacity: 0.35; cursor: default; background: rgba(var(--overlay-dark), 0.65); }

.zoom-controls { display: flex; gap: 0.35rem; align-items: center; } /* between --space-1/--space-2, kept literal */
.zoom-controls button { padding: var(--space-1) var(--space-3); }
.zoom-level { color: var(--muted); font-size: var(--text-sm); min-width: 3em; text-align: center; }

.toolbar { display: flex; gap: var(--space-2); align-items: center; margin: var(--space-3) 0; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: var(--text-base); }

.danger-zone { margin-top: 3rem; padding-top: var(--space-4); border-top: 1px solid var(--border); } /* 3rem is a deliberate oversized "false floor" before a destructive action, not spacing rhythm */

.stats-table { border-collapse: collapse; width: 100%; margin: var(--space-2) 0; }
.stats-table th, .stats-table td { border: 1px solid var(--border); padding: 0.35rem var(--space-2); text-align: right; font-size: var(--text-base); } /* 0.35rem between --space-1/--space-2, kept literal */
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { background: #f0f0ee; }

.group-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: var(--space-4) var(--space-4); margin-bottom: var(--space-4); } /* padding-y was 0.9rem, snapped up to the --space-4 step */
.group-panel-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.group-legend { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; min-width: 0; }
.swatch { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 50%; }
/* Hover affordance for the Compare Groups picker (see group-overlay.js's
 * hoveredGroupId) — a subtle background so hovering a row visibly connects
 * to highlighting that group's shots on the canvas. Harmless no-op on other
 * pages' .group-legend rows, which don't bind a mouseenter/leave handler. */
.group-legend:hover { background: rgba(255, 255, 255, 0.06); border-radius: 4px; }

/* Filter bar (compare groups, range trip list, range trip overview — see
 * app/services/group_filters.py + app/static/js/filters.js). One row per
 * category, each a set of toggleable chips; a category's row is only
 * rendered when it has options. */
.filter-bar { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-3) 0; }
.filter-row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.filter-row-label { color: var(--muted); font-size: var(--text-sm); min-width: 5.5rem; }
.filter-chip { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 0.2rem var(--space-3); font-size: var(--text-sm); cursor: pointer; }
.filter-chip:hover { background: var(--bg); }
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-chip.disabled { color: var(--muted); cursor: not-allowed; opacity: 0.5; }
.filter-chip.disabled:hover { background: var(--panel); }

.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr); gap: var(--space-5); align-items: start; }
@media (max-width: 720px) {
  .two-col { grid-template-columns: 1fr; }
}

/* My Account and its sub pages (settings, rifles, ammunition) — a fixed
   vertical menu on the left instead of the card-grid hub the account
   section used to have, so navigating between sub pages doesn't mean going
   back to a hub page first. Reuses the same 720px breakpoint as .two-col;
   the nav flips to a horizontal row of links on narrow screens rather than
   disappearing. */
.account-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--space-6); align-items: start; }
.account-nav { display: flex; flex-direction: column; gap: 0.15rem; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: var(--space-2); }
.account-nav a { display: block; padding: var(--space-2) var(--space-3); border-radius: 6px; color: var(--text); text-decoration: none; font-weight: 500; }
.account-nav a:hover { background: var(--bg); }
.account-nav a.active { background: var(--accent); color: #fff; }
@media (max-width: 720px) {
  .account-layout { grid-template-columns: 1fr; }
  .account-nav { flex-direction: row; flex-wrap: wrap; }
}

/* Trip/target timelines — interleaved Target|Group rows and Note cards,
 * reordered via plain move-up/move-down form buttons (no drag-and-drop). */
.timeline-row { display: flex; align-items: flex-start; gap: var(--space-2); margin-bottom: var(--space-4); }
.move-buttons { display: flex; flex-direction: column; gap: 0.15rem; flex-shrink: 0; padding-top: 0.1rem; }
.move-buttons button { padding: 0.1rem var(--space-2); line-height: 1.4; }
.move-buttons button:disabled { opacity: 0.3; cursor: default; }
.timeline-row-body { flex: 1; min-width: 0; }

.note-card { background: #fbf8ee; border: 1px solid #e6dcb0; border-radius: 8px; padding: var(--space-3) var(--space-4); }
.note-card .note-body { white-space: pre-wrap; margin: 0 0 var(--space-2); }
.note-card .toolbar { margin: var(--space-2) 0 0; }

/* One line per category (location name; lat/lon+elevation; temp/wind/sky;
   humidity/pressure) rather than one run-on paragraph — each <p> row's own
   items are still " · "-joined via .meta-line. */
.trip-meta { color: var(--muted); margin-bottom: var(--space-4); }
.trip-meta p { margin: 0 0 0.2rem; }
.trip-meta p:last-child { margin-bottom: 0; }
.trip-meta span:not(:last-child)::after { content: " · "; }

fieldset { border: none; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: var(--text-base); padding: 0; margin-bottom: var(--space-2); }
