:root {
  --bg: #16181d;
  --surface: #1e2128;
  --surface-2: #262a33;
  --border: #333844;
  --text: #e8eaed;
  --muted: #9aa1ad;
  --green: #5ed19b;
  --red: #f3776b;
  --yellow: #e8c468;
  --blue: #7fb2f0;
  --tap: 48px;                   /* minimum touch target height */
  --gutter: .9rem;               /* page margin left and right */
  --sticker-width: 3.9rem;       /* sticker number column, identical in every card */
  --gutter-l: max(var(--gutter), env(safe-area-inset-left));
  --gutter-r: max(var(--gutter), env(safe-area-inset-right));
}

@media (max-width: 340px) {
  :root { --gutter: .7rem; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Our own display rules would otherwise win over the hidden attribute. */
[hidden] { display: none !important; }

a { color: inherit; text-decoration: none; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
  overflow-wrap: anywhere;
}

h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); font-size: .85rem; font-weight: 400; }
.error { color: var(--red); }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; }

/* Sticker number: the same typeface everywhere, so the eye learns it. */
.sticker {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem; font-weight: 650; letter-spacing: .02em;
  line-height: 1.2; overflow-wrap: normal;
}
.sticker small { display: block; font-size: .68rem; font-weight: 500; color: var(--muted);
                 letter-spacing: 0; margin-top: .1rem; white-space: nowrap; }
.sticker.none { font-family: inherit; font-size: .75rem; font-weight: 500; line-height: 1.25;
                color: var(--muted); letter-spacing: 0; overflow-wrap: normal; }
@media (max-width: 340px) { .sticker { font-size: 1rem; } }

/* --- login page --- */
.centered { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh;
            padding: 1rem var(--gutter-r) 1rem var(--gutter-l); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
        padding: 1.5rem; width: 100%; max-width: 22rem; }
.card label { display: block; margin: 1rem 0 0; font-size: .9rem; color: var(--muted); }
.card input { width: 100%; margin-top: .35rem; }
@media (max-width: 340px) { .card { padding: 1.15rem; } }

input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem;
  min-height: var(--tap);
}
textarea { resize: vertical; line-height: 1.35; display: block; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible,
a:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
button { cursor: pointer; }
button.primary { background: var(--green); color: #10221a; border-color: transparent;
                 font-weight: 600; width: 100%; margin-top: 1.25rem; }
button.primary:disabled { opacity: .5; }

/* --- header with progress --- */
header {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: max(.5rem, env(safe-area-inset-top)) var(--gutter-r) .6rem var(--gutter-l);
}
.header-row { display: flex; align-items: center; gap: .5rem; min-height: 44px; }
.header-row h1 {
  flex: 1; min-width: 0; margin: 0; font-size: 1.05rem; line-height: 1.25;
  /* Location names are long ("Directie PitCrew/Grayhams R"). Two lines beat
     a truncated name: this is where you are standing. */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.back {
  background: none; border: none; color: var(--blue); font-size: 1.35rem; line-height: 1;
  min-width: 44px; min-height: 44px; padding: 0; margin-left: -.6rem; flex: none;
}
.header-row .pill { flex: none; font-size: .8rem; color: var(--muted);
                    font-variant-numeric: tabular-nums; }
.bar { height: 5px; background: var(--surface-2); border-radius: 3px; margin-top: .45rem; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--green); transition: width .25s; }
.tally { font-size: .78rem; color: var(--muted); margin-top: .35rem;
         display: flex; flex-wrap: wrap; column-gap: .75rem; }

main {
  padding: .75rem var(--gutter-r) calc(5.5rem + env(safe-area-inset-bottom)) var(--gutter-l);
}

.hint { color: var(--muted); font-size: .82rem; line-height: 1.4; margin: 0 0 .25rem; }

/* --- lists --- */
.list { display: flex; flex-direction: column; gap: .45rem; }
.row {
  display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  padding: .7rem .8rem; min-height: var(--tap); color: inherit;
}
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 550; line-height: 1.3; }
.row .sub { font-size: .78rem; color: var(--muted); margin-top: .1rem; line-height: 1.35; }
.pill { font-size: .72rem; padding: .18rem .5rem; border-radius: 999px;
        background: var(--surface-2); color: var(--muted); white-space: nowrap; flex: none; }
.row > .sticker { width: var(--sticker-width); flex: none; }
/* Rows with a number: keep the number level with the title, even for long text. */
.row:has(> .sticker) { align-items: flex-start; }
.row.done { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); }
.row.done .tick { color: var(--green); }
.row.attention { border-color: color-mix(in srgb, var(--yellow) 45%, var(--border)); }
.row.attention .tick { color: var(--yellow); }
.tick { font-size: 1.05rem; width: 1.2rem; text-align: center; color: var(--muted); flex: none; }
.section-label { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
                 color: var(--muted); margin: 1.1rem 0 .4rem; }
.section-label:first-child { margin-top: .25rem; }

/* --- item at a location ---
   Row 1: number | description | toggle
   Row 2: deviation, flags and counter, below the description across the
   remaining width, so a long note doesn't stretch the card. */
.item {
  display: grid;
  /* Fixed number column, so descriptions start on the same line in every
     card, also for "geen sticker" or a range. */
  grid-template-columns: var(--sticker-width) minmax(0, 1fr) var(--tap);
  column-gap: .7rem; row-gap: .5rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  padding: .6rem .6rem .6rem .75rem; cursor: pointer;
}
@media (max-width: 340px) { .item { column-gap: .55rem; } }
.item .text { min-width: 0; }
.item .desc { line-height: 1.3; }
.item .brand { font-size: .76rem; color: var(--muted); margin-top: .15rem; line-height: 1.3; }
.item .extra { grid-column: 2 / -1; display: flex; flex-direction: column; gap: .35rem;
               min-width: 0; }
/* On narrow screens the counter doesn't fit under the description; the bottom
   row then gets the full card width. */
@media (max-width: 360px) { .item .extra { grid-column: 1 / -1; } }
.item .flag { font-size: .74rem; color: var(--yellow); line-height: 1.35; }
/* No name in the sheet: stand out, because then you don't know where to look. */
.item.nameless .desc { color: var(--yellow); font-style: italic; }
.warning { font-size: .82rem; line-height: 1.4; margin: .75rem 0 0; padding: .6rem .75rem;
           border-radius: 10px; color: var(--yellow);
           background: color-mix(in srgb, var(--yellow) 10%, transparent);
           border: 1px solid color-mix(in srgb, var(--yellow) 35%, transparent); }
.item .status-line { font-size: .8rem; line-height: 1.35; }
.item .status-line b { font-weight: 600; }

.item.present { border-color: color-mix(in srgb, var(--green) 50%, var(--border));
                background: color-mix(in srgb, var(--green) 7%, var(--surface)); }
.item.missing { border-color: var(--red); background: color-mix(in srgb, var(--red) 10%, var(--surface)); }
.item.unreadable, .item.elsewhere { border-color: var(--yellow);
                background: color-mix(in srgb, var(--yellow) 9%, var(--surface)); }

.toggle { width: var(--tap); height: var(--tap); padding: 0; border-radius: 10px;
          background: var(--surface-2); display: grid; place-items: center;
          font-size: 1.2rem; line-height: 1; }
.item.present .toggle { background: var(--green); color: #10221a; border-color: transparent; }
.item.missing .toggle { background: var(--red); color: #2a0f0c; border-color: transparent; }
.item.unreadable .toggle, .item.elsewhere .toggle { background: var(--yellow); color: #2a220c;
                                                    border-color: transparent; }

.counter { display: flex; align-items: center; gap: .4rem; }
.counter .muted { font-size: .8rem; margin-right: .15rem; white-space: nowrap; }
.counter button { width: 44px; min-height: 40px; padding: 0; font-size: 1.1rem; }
.counter output { min-width: 3.2rem; text-align: center; font-size: .9rem;
                  font-variant-numeric: tabular-nums; }

/* Found something that is not on the list: at the bottom, after walking the list. */
.add-unlisted {
  width: 100%; margin-top: 1.1rem; background: transparent; color: var(--muted);
  border: 1px dashed var(--border); text-align: center; font-size: .92rem;
}

/* --- bottom bar --- */
.bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: .55rem var(--gutter-r) calc(.55rem + env(safe-area-inset-bottom)) var(--gutter-l);
  display: flex; gap: .5rem;
}
.bottom-bar button { flex: 1; min-width: 0; padding-left: .5rem; padding-right: .5rem; }
.bottom-bar .primary { margin-top: 0; }

/* --- dialog: sheet sliding in from the bottom --- */
dialog {
  border: 1px solid var(--border); border-bottom: 0; background: var(--surface); color: var(--text);
  border-radius: 16px 16px 0 0; padding: 1.1rem var(--gutter-r) 0 var(--gutter-l);
  width: 100%; max-width: 32rem; max-height: 90vh; max-height: 90dvh;
  margin: auto auto 0; position: fixed; inset: 0; overflow-y: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 .2rem; line-height: 1.3; outline: none; }
dialog h2 .sticker { font-size: 1rem; margin-right: .35rem; }
dialog .muted { margin: 0; }
dialog label { display: block; margin: 1rem 0 0; font-size: .85rem; color: var(--muted); }
dialog input:not([type=file]), dialog select, dialog textarea { width: 100%; margin-top: .35rem; }

.choices { display: flex; flex-direction: column; gap: .45rem; margin-top: 1rem; }
.option { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
          background: var(--surface-2); }
.option .icon { width: 1.3rem; text-align: center; flex: none; color: var(--muted); }
.option[aria-pressed="true"] { border-color: var(--blue);
                               background: color-mix(in srgb, var(--blue) 16%, var(--surface-2));
                               font-weight: 600; }
.option[aria-pressed="true"] .icon { color: var(--text); }

/* Custom camera buttons; the native file control is ugly and not localised. */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden;
                   clip: rect(0 0 0 0); white-space: nowrap; }
.field { margin-top: 1rem; }
.field-label { font-size: .85rem; color: var(--muted); }
.photo-buttons { display: flex; gap: .5rem; margin-top: .35rem; }
dialog label.photo-button {
  flex: 2; display: flex; align-items: center; justify-content: center; gap: .5rem;
  margin: 0; min-height: var(--tap); padding: .6rem .8rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: .95rem; font-weight: 550; cursor: pointer;
}
dialog label.photo-button.secondary { flex: 1; font-weight: 400; color: var(--muted); }
.photo-button svg { flex: none; }
.photo-button:focus-within { outline: 2px solid var(--blue); outline-offset: 1px; }
.photo-button:active { background: var(--border); }

.preview { position: relative; margin-top: .6rem; }
.preview img { display: block; width: 100%; max-height: 220px; object-fit: cover;
               border-radius: 10px; border: 1px solid var(--border); }
.preview button { position: absolute; top: .4rem; right: .4rem; width: 40px; height: 40px;
                  min-height: 0; padding: 0; border-radius: 999px; font-size: 1.4rem;
                  line-height: 1; background: #000b; border-color: transparent; }

.thumbnails { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }
.thumbnails img { display: block; width: 52px; height: 52px; object-fit: cover;
                  border-radius: 8px; border: 1px solid var(--border); }
.thumbnails .muted { font-size: .78rem; margin-left: .2rem; }
dialog .error { font-size: .85rem; margin: .75rem 0 0; }

/* Save stays in view, even on a small screen with a long form. */
.actions {
  position: sticky; bottom: 0; display: flex; gap: .5rem;
  margin-top: 1rem; padding: .75rem 0 calc(1rem + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.actions button { flex: 1; margin-top: 0; }

/* --- overview --- */
.summary { background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
           padding: .8rem; }
.summary .muted { margin-top: .2rem; }

.empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%);
         bottom: calc(5rem + env(safe-area-inset-bottom));
         max-width: calc(100% - 2 * var(--gutter)); width: max-content; text-align: center;
         background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
         padding: .5rem 1rem; font-size: .85rem; z-index: 30; }
.offline { background: var(--yellow); color: #2a220c; border-color: transparent; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
