/* style.css — venaison design system: tokens up top, components below.
   Dark-only starter (leon shape); swap the tokens for the app's own voice.
   The update/liveness chrome (pull-to-refresh, sheet, toast, unreach)
   is part of the app standard — keep those selectors when restyling. */

:root {
  --bg: #1f1f1f;
  --card: #2a2a2a;
  --ink: #f2efe9;
  --muted: #9a958c;
  --accent: #d8b26e;
  --danger: #e07b6a;
  --hairline: #3a3a3a;
  --tap: 48px;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overscroll-behavior: none; touch-action: manipulation; } /* no native rubber-band fighting pull-to-refresh; no double-tap-to-zoom on fast repeated taps (pinch-zoom stays available) */
html { height: 100%; overflow: hidden; }
/* no UA focus ring on tap/programmatic focus (touch-action:manipulation makes
   taps commit as click+focus); keyboard focus keeps the ring via :focus-visible */
:focus:not(:focus-visible) { outline: none; }
body {
  /* The contained PWA viewport already excludes iOS-owned unsafe regions. */
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
#topbar { flex: none; }
#view {
  flex: 1 1 auto;
  min-width: 0; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
button { min-height: var(--tap); font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.pad { padding: 16px; }
.muted { color: var(--muted); }

/* ---- top bar + wordmark (opens the About sheet) */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.wordmark { font-weight: 700; letter-spacing: .02em; font-size: 20px; }
#brand { padding: 4px 0; flex: none; }
/* current chasse (v1.3), next to the wordmark; opens the chasse picker */
.brand-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chasse-btn { min-width: 0; padding: 4px 0; color: var(--accent); font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chasse-btn[hidden] { display: none; }
.status-pills { display: flex; gap: 6px; flex: none; }
.pill { padding: 5px 9px; border: 1px solid var(--hairline); border-radius: 999px; color: var(--muted); font-size: 12px; }

/* ---- login + unreachable */
.login-wrap, .unreach {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 10px;
}
.login { display: flex; flex-direction: column; gap: 14px; width: min(320px, 100%); }
.login h1, .unreach h1 { font-size: 22px; margin: 6px 0 2px; }
.login label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
.login input {
  font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--hairline); border-radius: 10px;
  padding: 12px; min-height: var(--tap);
}
.primary {
  min-height: var(--tap);
  background: var(--accent); color: #1a1a1a; font-weight: 600;
  border-radius: var(--radius); padding: 12px 18px;
}
.err { color: var(--danger); font-size: 14px; }

/* ---- bottom sheet (About) */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding-top: var(--modal-keyboard-top, 0px);
  padding-bottom: var(--modal-keyboard-bottom, 0px);
  opacity: 0; transition: opacity .18s ease;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; min-width: 0; max-width: 560px;
  max-height: min(90dvh, 100%); overflow-y: auto; overscroll-behavior: contain;
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
  transform: translateY(12px); transition: transform .18s ease;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-title { font-weight: 700; font-size: 18px; margin-bottom: 12px; }
.about-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--hairline);
  font-size: 15px;
}
.a-k { color: var(--muted); }
.a-v { text-align: right; }
.a-sub { display: block; color: var(--accent); font-size: 13px; }
.about-status { min-height: 22px; padding: 10px 0 2px; color: var(--muted); font-size: 14px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.sheet-btn {
  min-height: var(--tap);
  border: 1px solid var(--hairline); border-radius: var(--radius); padding: 12px;
}

/* ---- application */
h1 { margin: 4px 0 18px; font-size: 25px; line-height: 1.2; }
h2 { margin: 24px 0 10px; font-size: 18px; }
h3 { margin: 18px 0 8px; font-size: 16px; }
label { color: var(--muted); }
input, select, textarea {
  color: var(--ink); background: var(--bg); border: 1px solid var(--hairline);
  border-radius: 10px; min-height: var(--tap); padding: 10px 12px;
}
button:disabled { opacity: .45; cursor: default; }
.full { width: 100%; }
.compact { padding: 8px 14px; }
.field, .form-grid label, .offset-grid label, .sheet form > label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.title-row > div { display: flex; gap: 8px; }
.title-row button, .row-actions button, .button-row button, .triple-actions button { min-height: var(--tap); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--hairline); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.triple-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 22px; }
.row-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.notice { padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--card); border-radius: 6px; }
.empty { margin: 24px 0; padding: 24px; text-align: center; color: var(--muted); background: var(--card); border-radius: var(--radius); }
.wizard { padding-bottom: 28px; }
.wizard-steps { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px 18px; padding: 0 16px 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.wizard-steps .active { color: var(--accent); }
.wizard-steps .wizard-chasse { color: var(--ink); }
.counter-chasse { font-weight: 600; }
.animal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--hairline); }
.stepper > div { display: flex; align-items: center; }
.stepper button { width: var(--tap); height: var(--tap); border: 1px solid var(--hairline); border-radius: 10px; font-size: 22px; }
.stepper output { min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }
.check-list { display: flex; flex-direction: column; }
.check-list label { min-height: var(--tap); display: flex; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--hairline); color: var(--ink); }
.check-list input { width: 24px; min-height: 24px; }
.check-list span, .list-row span { display: flex; flex-direction: column; min-width: 0; text-align: left; }
small { color: var(--muted); font-size: 13px; }
.summary-card { display: flex; flex-direction: column; gap: 6px; padding: 20px; background: var(--card); border-radius: var(--radius); }
.reveal-grid { display: grid; gap: 8px; }
.reveal-card { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; min-height: 66px; border: 1px solid var(--hairline); border-radius: 12px; background: var(--card); transition: border-color .18s ease, transform .18s ease; }
.reveal-card.settled { border-color: var(--accent); transform: scale(1.015); }
.reveal-card strong { font-size: 17px; }
.reveal-fade { animation: reveal-fade .4s ease; }
@keyframes reveal-fade { from { opacity: 0; } to { opacity: 1; } }
.result-list, .card-list { display: flex; flex-direction: column; }
.result-row { display: grid; gap: 3px; padding: 13px 0; border-bottom: 1px solid var(--hairline); }
.result-row span { color: var(--muted); }
.reste { padding: 2px 14px; margin: 14px 0; border: 1px solid var(--danger); border-radius: var(--radius); }
details { margin: 14px 0; }
summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; color: var(--accent); }
.journal { padding-left: 20px; color: var(--muted); font-size: 14px; }
.list-row { width: 100%; min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--hairline); }
.list-row > button { min-height: var(--tap); padding: 8px; color: var(--danger); }
.deleted { text-decoration: line-through; opacity: .58; }
.archived { opacity: .62; }
.switch-label { min-height: var(--tap); display: flex; align-items: center; gap: 8px; font-size: 13px; }
.switch-label input { min-height: 22px; width: 22px; }
.offset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.danger, .danger-text { color: var(--danger); }
.counter-tools { display: grid; gap: 12px; }
.counter-tools label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden; }
.segmented button { min-height: var(--tap); padding: 8px; }
.segmented .sel { background: var(--accent); color: #171717; }
.table-wrap { overflow: auto; margin: 14px -20px; }
table { border-collapse: collapse; min-width: 720px; font-size: 13px; }
th, td { padding: 8px; border: 1px solid var(--hairline); text-align: center; }
th:first-child { position: sticky; left: 0; background: var(--card); text-align: left; }
#tabs { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--hairline); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
#tabs[hidden] { display: none; }
#tabs button { min-height: 56px; color: var(--muted); }
#tabs button.active { color: var(--accent); box-shadow: inset 0 2px var(--accent); }
.about-row { width: 100%; min-height: var(--tap); align-items: center; text-align: left; }
.about-row > :last-child { text-align: right; }

/* ---- toast */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 18px); z-index: 60; pointer-events: none; }
.toast {
  pointer-events: auto;
  margin: 0 auto; width: max-content; max-width: 88vw;
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--hairline); border-radius: 999px;
  padding: 10px 16px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
}
.toast.error { border-color: var(--danger); }
.toast-act { color: var(--accent); font-weight: 600; }

/* ---- pull-to-refresh (leon/marcel reveal-pane pattern; JS drives transform +
   classes). The whole page — #topbar and #view — slides down under a full-width
   pane parked just above the viewport, so the gesture telegraphs itself instead
   of nudging a pill behind the status bar. */
.ptr-pane {
  position: fixed; left: 0; right: 0; z-index: 50;
  top: calc(-1 * (72px + env(safe-area-inset-top)));
  height: calc(72px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 13px; font-weight: 600; letter-spacing: .01em; color: var(--muted);
  background: linear-gradient(to bottom, var(--card) 55%, transparent);
  pointer-events: none; will-change: transform;
}
.ptr-icon {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--hairline); background: var(--bg); color: var(--muted);
  transition: transform .18s ease, color .12s ease, border-color .12s ease;
}
.ptr-pane.ready .ptr-icon { transform: rotate(180deg); color: var(--accent); border-color: var(--accent); }
.ptr-pane.spin .ptr-icon { color: var(--accent); border-color: var(--accent); animation: ptr-rot .8s linear infinite; }
/* content + pane track the drag with no transition, then snap back with one */
#topbar.ptr-drag, #view.ptr-drag, .ptr-pane.ptr-drag { transition: none; }
#topbar.ptr-snap, #view.ptr-snap, .ptr-pane.ptr-snap { transition: transform .22s ease; }
#topbar.ptr-drag, #topbar.ptr-snap, #view.ptr-drag, #view.ptr-snap { will-change: transform; }
@keyframes ptr-rot { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .ptr-pane .ptr-icon { animation: none; transition: none; }
  #topbar.ptr-snap, #view.ptr-snap, .ptr-pane.ptr-snap { transition: none; }
}

/* Shared form bounds retain the native picker without its intrinsic overflow. */
input, select, textarea { min-width: 0; max-width: 100%; font: inherit; }
input[type=date], input[type=datetime-local] {
  display: block; width: 100%; -webkit-appearance: none; appearance: none;
}
.sheet input:not([type=checkbox]):not([type=radio]), .sheet select, .sheet textarea { width: 100%; }
.sheet-title, .about-row > * { min-width: 0; overflow-wrap: anywhere; }
#view > .pad { width: 100%; max-width: 840px; margin: 0 auto; }

/* Rotation changes layout only. Keep the same nodes, values, and scroll owner. */
@media (orientation: landscape) and (min-width: 560px) {
  .sheet-backdrop {
    align-items: center;
    padding: calc(8px + var(--modal-keyboard-top, 0px)) max(12px, env(safe-area-inset-right))
             calc(8px + var(--modal-keyboard-bottom, 0px)) max(12px, env(safe-area-inset-left));
  }
  .sheet { max-width: 840px; max-height: 100%; border-radius: var(--radius); padding: 16px 20px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #topbar { padding-top: 4px; padding-bottom: 4px; }
  .login-wrap, .unreach { justify-content: flex-start; padding: 12px 24px; }
}

@media (max-width: 420px) {
  .form-grid, .animal-grid { grid-template-columns: 1fr; }
  .triple-actions { grid-template-columns: 1fr; }
  .title-row { align-items: flex-start; }
  .title-row > div { flex-direction: column; }
}

@media print {
  :root { --bg: #fff; --card: #fff; --ink: #000; --muted: #444; --hairline: #bbb; }
  body { height: auto; overflow: visible; color: #000; background: #fff; }
  #topbar, #view, #tabs, #toast-root, .sheet-backdrop::before, .sheet > :not(.counter-tools):not(#table-compteurs) { display: none !important; }
  #sheet-root, .sheet-backdrop, .sheet { position: static; display: block; opacity: 1; transform: none; max-width: none; max-height: none; overflow: visible; padding: 0; background: #fff; }
  .counter-tools .segmented { display: none; }
  .table-wrap { overflow: visible; margin: 0; }
  table { min-width: 100%; }
}
