/* Colours, type and component styles follow the Sketch Gatherer and deepcheck_API. */
:root {
  --ink: #001439;
  --muted: #52627a;
  --line: #d9e6f5;
  --navy: #001439;
  --blue: #00309c;
  --cyan: #00b3fe;
  --soft: #eaf6ff;
  --card-border: rgba(198, 215, 238, 0.95);
  --gap: 20px;
  /* Query and results are always this same square: as big as fits two side by
     side with the header, task bar and toolbars still on screen. */
  --box: clamp(300px, min(calc((100vw - 3 * var(--gap)) / 2), calc(100vh - 252px)), 860px);
}

@supports (height: 100dvh) {
  :root {
    --box: clamp(300px, min(calc((100vw - 3 * var(--gap)) / 2), calc(100dvh - 252px)), 860px);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f7fbff;
  color: var(--ink);
  font-family: "Inter", Arial, sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 0 var(--gap);
  border-bottom: 1px solid rgba(217, 230, 245, 0.86);
  background: rgba(247, 251, 255, 0.9);
}

.brand {
  color: var(--navy);
  font-size: 1.12rem;
  font-weight: 800;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
}

.catalogue-info {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalogue-info strong {
  color: var(--navy);
  font-weight: 800;
}

.lab-logo {
  display: block;
  height: 30px;
  width: auto;
}

/* ------------------------------------------------------------- workspace */

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px var(--gap) 10px;
}

.task-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  width: calc(2 * var(--box) + var(--gap));
  max-width: 100%;
}

.task-title {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--navy);
  font-size: 1.9rem;
  line-height: 1.1;
  white-space: nowrap;
}

.helper-text {
  flex: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* segmented control */
.mode-switch {
  display: inline-flex;
  flex-shrink: 0;
  gap: 4px;
  border: 1px solid #c6d7ee;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
}

.mode-tab {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 7px;
  background: none;
  padding: 0 16px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 700;
}

.mode-tab svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.mode-tab:hover {
  color: var(--blue);
}

.mode-tab[aria-selected="true"] {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 48, 156, 0.22);
}

.panels {
  display: grid;
  grid-template-columns: repeat(2, var(--box));
  gap: var(--gap);
  justify-content: center;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.box {
  position: relative;
  width: var(--box);
  height: var(--box);
  overflow: hidden;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 20px 58px rgba(0, 20, 57, 0.11);
}

/* ------------------------------------------------------------ query side */

.query-box {
  border-color: #93cdec;
}

.query-box canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: #9fb1c9;
  font-size: 1.15rem;
  font-weight: 600;
  pointer-events: none;
}

.photo-pane {
  position: absolute;
  inset: 0;
  background: #fff;
}

.photo-pane img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.dropzone {
  position: absolute;
  inset: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px dashed #b9d4ef;
  border-radius: 10px;
  background: #fbfdff;
  padding: 20px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.dropzone:hover {
  border-color: var(--cyan);
  background: var(--soft);
}

.dropzone svg {
  width: 54px;
  height: 54px;
  margin-bottom: 6px;
  fill: none;
  stroke: #7fa3cc;
  stroke-width: 2;
  stroke-linejoin: round;
}

.dropzone strong {
  color: var(--navy);
  font-size: 1.05rem;
}

.dropzone span {
  font-size: 0.88rem;
}

.photo-caption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  margin: 0;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(0, 20, 57, 0.78);
  padding: 4px 12px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  border: 3px dashed var(--cyan);
  border-radius: 10px;
  background: rgba(234, 246, 255, 0.92);
  color: var(--blue);
  font-size: 1.15rem;
  font-weight: 800;
  pointer-events: none;
}

/* ----------------------------------------------------------- result side */

.results-box {
  overflow-y: auto;
}

.progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  height: 3px;
  overflow: hidden;
  background: var(--soft);
}

.progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  background: var(--cyan);
  animation: slide 0.9s ease-in-out infinite;
}

@keyframes slide {
  from {
    left: -35%;
  }
  to {
    left: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress::after {
    left: 0;
    width: 100%;
    animation: none;
    opacity: 0.6;
  }
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 0;
  padding: 10px;
  list-style: none;
}

.results-grid.is-stale {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.result {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}

.result:hover {
  transform: translateY(-2px);
  border-color: #93cdec;
  box-shadow: 0 10px 24px rgba(0, 20, 57, 0.14);
}

.result img {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  object-fit: contain;
}

.result .rank,
.result .score {
  position: absolute;
  z-index: 1;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
}

.result .rank {
  top: 5px;
  left: 5px;
  min-width: 20px;
  background: var(--navy);
  padding: 4px 6px;
  color: #fff;
}

.result .score {
  right: 5px;
  bottom: 5px;
  background: rgba(234, 246, 255, 0.94);
  padding: 4px 7px;
  color: var(--blue);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 28px;
  text-align: center;
}

.empty-title {
  margin: 0;
  color: var(--navy);
  font-size: 1.15rem;
  font-weight: 800;
}

.empty-text {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.examples {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(56px, 92px));
  justify-content: center;
  gap: 10px;
}

.example {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 600;
}

.example img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}

.example:hover img {
  transform: translateY(-2px);
  border-color: var(--cyan);
}

.example:hover {
  color: var(--blue);
}

.results-toolbar {
  min-height: 40px;
}

.model-input {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

.result-meta {
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.result-meta strong {
  color: var(--navy);
}

.model-chip {
  border-radius: 999px;
  background: var(--soft);
  padding: 6px 12px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.model-chip:empty {
  display: none;
}

/* --------------------------------------------------------------- buttons */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-note {
  color: var(--muted);
  font-size: 0.82rem;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.primary-button {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 12px 26px rgba(0, 48, 156, 0.24);
}

.secondary-button {
  border: 1px solid #c6d7ee;
  background: #fff;
  color: var(--ink);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- footer */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 8px var(--gap) 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 30;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  border-radius: 8px;
  background: var(--navy);
  padding: 12px 18px;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 16px 40px rgba(0, 20, 57, 0.3);
}

.toast.is-error {
  background: #aa2630;
}

/* ---------------------------------------------------------------- dialog */

.item-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 20, 57, 0.25);
}

.item-dialog::backdrop {
  background: rgba(0, 20, 57, 0.5);
}

.item-dialog form {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
}

.item-image {
  display: grid;
  place-items: center;
  min-height: 300px;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 16px;
}

.item-image img {
  display: block;
  max-width: 100%;
  max-height: min(60vh, 460px);
  object-fit: contain;
}

.item-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 24px;
  background: #f7fbff;
}

.item-body h2 {
  margin: 0;
  color: var(--navy);
  font-size: 1.35rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.item-meta {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.item-meta code {
  border-radius: 6px;
  background: var(--soft);
  padding: 1px 6px;
  color: var(--blue);
  font-size: 0.86em;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

/* -------------------------------------------------------------- narrow */

@media (max-width: 1100px) {
  .helper-text {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --gap: 16px;
    --box: min(calc(100vw - 2 * var(--gap)), 560px);
  }

  .panels {
    grid-template-columns: var(--box);
  }

  .task-bar {
    flex-wrap: wrap;
    gap: 10px 16px;
    width: var(--box);
  }

  h1 {
    font-size: 1.5rem;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-tab {
    flex: 1;
    justify-content: center;
  }

  .results-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
  }

  .lab-logo,
  .catalogue-label {
    display: none;
  }

  .item-dialog form {
    grid-template-columns: 1fr;
  }

  .item-image {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .item-image img {
    max-height: 42vh;
  }
}
