/* MOT Checker
 *
 * One stylesheet, no build step, no framework. The whole page is server
 * rendered and the only JavaScript is htmx's SSE extension, so anything that
 * can be done in CSS is done in CSS — including the photo carousel, which is
 * a scroll-snap strip with anchor links for dots.
 */

:root {
  /* Tells the browser to render native widgets — number-input spinners,
   * scrollbars, the date picker — to match. Without it those stay light and
   * glare out of an otherwise dark page. */
  color-scheme: light dark;

  --green: #15803d;
  --green-bg: #f0fdf4;
  --green-line: #bbf7d0;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --amber-line: #fde68a;
  --red: #b91c1c;
  --red-bg: #fef2f2;
  --red-line: #fecaca;

  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-2: #f1f5f9;
  --line-strong: #cbd5e1;
  --surface: #ffffff;
  --surface-2: #fcfdfe;               /* the MOT panel, a shade off the card */
  --bg: #f8fafc;
  --accent: #1d4ed8;
  --accent-ring: rgb(29 78 216 / 12%);

  --masthead: rgb(255 255 255 / 85%);
  --field-bg: #ffffff;
  --btn-bg: #0f172a;
  --btn-bg-hover: #1e293b;
  --btn-fg: #ffffff;
  --warn-ink: #78350f;

  /* Behind a letterboxed photo. Neutral rather than white so the bars read
   * as a frame instead of as part of the picture. */
  --photo-bg: #eef2f6;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 4%);
  --shadow-lift: 0 4px 12px rgb(15 23 42 / 8%), 0 2px 4px rgb(15 23 42 / 4%);
}

/* Dark mode follows the operating system. Everything below is a variable
 * override — no layout or component rule is duplicated, so the two themes
 * cannot drift apart.
 *
 * The status colours are not simply darkened: on a dark surface the light
 * tints (#f0fdf4 and friends) are near-white and would glare, and the deep
 * text colours (#15803d) fall below readable contrast. Each becomes a light
 * foreground over a translucent wash of itself, which keeps the green /
 * amber / red meaning while sitting properly in the page.
 *
 * The registration plate is deliberately NOT themed. A UK numberplate is
 * black on yellow in the world, and that is what makes it recognisable at a
 * glance as the car's actual registration rather than another badge. */
@media (prefers-color-scheme: dark) {
  :root {
    --green: #4ade80;
    --green-bg: rgb(34 197 94 / 14%);
    --green-line: rgb(74 222 128 / 30%);
    --amber: #fbbf24;
    --amber-bg: rgb(245 158 11 / 14%);
    --amber-line: rgb(251 191 36 / 30%);
    --red: #f87171;
    --red-bg: rgb(239 68 68 / 14%);
    --red-line: rgb(248 113 113 / 30%);

    --ink: #e2e8f0;
    --ink-2: #cbd5e1;
    --muted: #94a3b8;
    --line: #1e293b;
    --line-2: #172033;
    --line-strong: #334155;
    --surface: #0f172a;
    --surface-2: #131e35;
    --bg: #020617;
    --accent: #93b4fc;                /* lightened: #1d4ed8 is unreadable here */
    --accent-ring: rgb(147 180 252 / 18%);

    --masthead: rgb(2 6 23 / 80%);
    --field-bg: #0b1220;
    --btn-bg: #e2e8f0;                /* inverted, so the button stays the
                                       * strongest thing in the header */
    --btn-bg-hover: #ffffff;
    --btn-fg: #0f172a;
    --warn-ink: #fcd34d;

    --photo-bg: #0b1220;

    /* Shadows do almost nothing against a near-black page; depth comes from
     * the borders instead, so these are darker and tighter rather than the
     * soft light-mode spread. */
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lift: 0 4px 14px rgb(0 0 0 / 55%);
  }
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* Visible keyboard focus everywhere. The default outline disappears against
 * the card surfaces, and the dots and gallery frames are all links. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ----------------------------------------------------------- page header */

.masthead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--masthead);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.masthead .inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
}

h1 {
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin: 0 0 .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

h1 .mark {
  display: inline-grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: .7rem;
  font-weight: 700;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ------------------------------------------------------------ search form */

form.search {
  display: grid;
  grid-template-columns: minmax(12rem, 2fr) repeat(4, minmax(6rem, 1fr)) auto;
  gap: .6rem;
  align-items: end;
}

form.search label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--muted);
}

form.search input {
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--field-bg);
}

form.search input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

form.search button {
  padding: .55rem 1.4rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: .875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

form.search button:hover { background: var(--btn-bg-hover); }

@media (max-width: 780px) {
  form.search { grid-template-columns: 1fr 1fr; }
  form.search button { grid-column: 1 / -1; }
}

/* -------------------------------------------------------------- messages */

.warnings {
  padding: .7rem .9rem;
  background: var(--amber-bg);
  border: 1px solid var(--amber-line);
  color: var(--warn-ink);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .85rem;
}

.warnings div + div { margin-top: .3rem; }

.result-count {
  font-size: .85rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------ grid */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 1.1rem;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .15s ease, border-color .15s ease;
}

/* Deliberately NOT a transform. A transformed ancestor becomes the
 * containing block for position:fixed descendants, which would trap each
 * card's lightbox inside the card instead of covering the viewport. */
.card:hover {
  box-shadow: var(--shadow-lift);
  border-color: var(--line-strong);
}

/* --------------------------------------------------------------- gallery */

.gallery {
  position: relative;
  background: var(--line-2);
}

/* The scroll strip. scroll-snap gives trackpad and touch swiping for free;
 * the dots below are anchors into it. */
.frames {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* old Edge */
}

.frames::-webkit-scrollbar { display: none; }

.frame {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  aspect-ratio: 4 / 3;
  display: block;
  /* Anchor links scroll the page as well as this strip; without this the
   * jump lands under the sticky masthead. */
  scroll-margin-top: 6rem;
}

/* contain, not cover. Sellers photograph cars in both orientations —
 * Facebook serves a lot of 720x960 portraits — and cropping those to a
 * landscape box cut the bottom off the car, which is exactly the part a
 * buyer wants to see. Letterboxing shows the whole photo; the neutral
 * backdrop makes the bars read as deliberate. */
.frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: var(--photo-bg);
}

.frame.no-photo {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: .8rem;
}

/* The dots and the photo-count pill sit over the photograph itself, which can
 * be any colour in either theme, so they are intentionally not themed: white
 * on a dark scrim reads against both. */
.dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: .5rem;
  display: flex;
  justify-content: center;
  gap: .3rem;
  pointer-events: none;
}

/* The tap target is deliberately larger than the visible dot. */
.dots a {
  pointer-events: auto;
  padding: .35rem .2rem;
  line-height: 0;
}

.dots a span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgb(255 255 255 / 70%);
  box-shadow: 0 0 0 1px rgb(15 23 42 / 25%);
}

.dots a:hover span { background: #fff; }

.shot-count {
  position: absolute;
  top: .5rem;
  right: .5rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: rgb(15 23 42 / 65%);
  color: #fff;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .01em;
}

/* ------------------------------------------------------------- card body */

.card .body { padding: .9rem 1rem; }

.card h2 {
  font-size: .98rem;
  line-height: 1.35;
  margin: 0 0 .35rem;
  letter-spacing: -0.005em;
}

.card h2 a {
  color: var(--ink);
  text-decoration: none;
}

.card h2 a:hover { text-decoration: underline; }

.card .price {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card .price .unpriced {
  font-size: .85rem;
  font-weight: 500;
  color: var(--muted);
}

.card .meta {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .5rem;
  margin: .45rem 0 0;
  padding: 0;
  font-size: .78rem;
  color: var(--muted);
}

.card .meta li + li::before {
  content: "·";
  margin-right: .5rem;
  color: var(--line);
}

.card .meta .src {
  margin-left: auto;
  text-transform: capitalize;
}

.card .meta .src::before { content: none; }

/* ----------------------------------------------------------- description */

.desc {
  margin-top: .7rem;
  padding-top: .7rem;
  border-top: 1px solid var(--line-2);
  font-size: .84rem;
  color: var(--ink-2);
}

.desc p { margin: 0 0 .5rem; }
.desc > p:last-child { margin-bottom: 0; }

/* Only the first paragraph shows by default; the rest sits behind the
 * details toggle below it. Three lines is enough to tell whether it is worth
 * opening, without any two cards ending up wildly different heights. */
.desc > p:first-child {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.desc summary {
  cursor: pointer;
  color: var(--accent);
  font-size: .8rem;
  font-weight: 600;
  margin-top: .35rem;
  list-style: none;
}

.desc summary::-webkit-details-marker { display: none; }
.desc summary::after { content: " ▾"; }
.desc details[open] summary::after { content: " ▴"; }
.desc details[open] summary { margin-bottom: .5rem; }

ul.spec {
  list-style: none;
  margin: .4rem 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: .15rem .6rem;
}

ul.spec li {
  position: relative;
  padding-left: .8rem;
  font-size: .8rem;
}

ul.spec li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--muted);
}

/* ------------------------------------------------------------- MOT panel */

.mot {
  border-top: 1px solid var(--line);
  padding: .8rem 1rem;
  font-size: .84rem;
  background: var(--surface-2);
}

.verdict {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .01em;
}

.badge::before {
  content: "";
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: currentColor;
}

.badge.green { color: var(--green); background: var(--green-bg); box-shadow: inset 0 0 0 1px var(--green-line); }
.badge.amber { color: var(--amber); background: var(--amber-bg); box-shadow: inset 0 0 0 1px var(--amber-line); }
.badge.red   { color: var(--red);   background: var(--red-bg);   box-shadow: inset 0 0 0 1px var(--red-line); }

/* A registration, set the way a numberplate is — and deliberately identical
 * in both themes. Black on yellow is what a UK plate looks like in the world,
 * and that is what makes it read at a glance as the car's actual
 * registration rather than as another status badge. */
.vrm {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 700;
  letter-spacing: .04em;
  background: #fdc82f;
  color: #111;
  padding: .12rem .4rem;
  border-radius: 4px;
  font-size: .78rem;
  border: 1px solid #d9a908;
}

ul.flag {
  margin: .55rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: .3rem;
}

ul.flag li {
  position: relative;
  padding-left: 1.1rem;
  color: var(--ink-2);
  font-size: .82rem;
}

ul.flag li::before {
  content: "!";
  position: absolute;
  left: 0;
  top: .05rem;
  display: grid;
  place-items: center;
  width: .85rem;
  height: .85rem;
  border-radius: 50%;
  background: var(--amber-bg);
  color: var(--amber);
  font-size: .6rem;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px var(--amber-line);
}

p.clean {
  margin: .55rem 0 0;
  color: var(--green);
  font-size: .82rem;
}

.status { color: var(--muted); }

.status.pending {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
}

.spinner {
  width: .8rem;
  height: .8rem;
  border: 2px solid var(--line);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- test history */

.mot details { margin-top: .6rem; }

.mot summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 600;
}

table.tests {
  width: 100%;
  border-collapse: collapse;
  margin-top: .5rem;
  font-size: .75rem;
}

table.tests th {
  text-align: left;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: .3rem .35rem;
  border-bottom: 1px solid var(--line);
}

table.tests td {
  padding: .35rem;
  border-bottom: 1px solid var(--line-2);
  vertical-align: top;
}

table.tests tr:last-child td { border-bottom: 0; }

.res {
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.res.pass { color: var(--green); }
.res.fail { color: var(--red); }

td .defect { color: var(--ink-2); }
td .defect + .defect { margin-top: .2rem; }

/* -------------------------------------------------------------- lightbox */

/* A :target overlay. Hidden until the URL fragment names it, which is what
 * clicking a photo does. No JavaScript is involved, so there is nothing to
 * initialise and nothing to fail. */
.lightbox { display: none; }

.lightbox:target {
  display: grid;
  position: fixed;
  inset: 0;
  z-index: 100;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
  background: rgb(2 6 23 / 88%);
  overscroll-behavior: contain;
}

/* A full-bleed link behind the photo, so clicking anywhere outside it
 * closes. It sits below the figure in the stacking order. */
.lb-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.lightbox figure {
  position: relative;
  margin: 0;
  max-width: min(1100px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.lightbox img {
  max-width: 100%;
  /* Leave room for the caption; without the subtraction a tall photo pushes
   * the caption off the bottom of the viewport. */
  max-height: calc(100vh - 9rem);
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #0b1220;
}

.lightbox figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem 1rem;
  color: #e2e8f0;
  font-size: .84rem;
}

.lb-out {
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgb(255 255 255 / 45%);
}

.lb-out:hover { border-bottom-color: #fff; }

.lb-nav,
.lb-close {
  position: absolute;
  z-index: 1;
  display: grid;
  place-items: center;
  color: #fff;
  text-decoration: none;
  background: rgb(15 23 42 / 55%);
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 50%;
  line-height: 1;
}

.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.7rem;
  padding-bottom: .18em; /* optical centring of the chevron glyph */
}

.lb-nav.prev { left: clamp(.5rem, 2vw, 2rem); }
.lb-nav.next { right: clamp(.5rem, 2vw, 2rem); }

.lb-close {
  top: clamp(.5rem, 2vw, 1.5rem);
  right: clamp(.5rem, 2vw, 1.5rem);
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.4rem;
}

.lb-nav:hover,
.lb-close:hover { background: rgb(15 23 42 / 85%); }

/* ---------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
