/* ============================================================
   Components — reusable building blocks. Built ONLY from tokens.
   Every screen composes these; screens never define raw colors,
   spacing or sizes. This guarantees consistent look everywhere.

   Mobile-first: defaults are the phone sizing, wider screens
   refine them at the bottom of each block.
   ============================================================ */

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  padding: var(--space-3) var(--space-5);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  background: none;
  transition: opacity var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease);
}
.btn-accent  { background: var(--color-brand); color: #fff; }
.btn-accent:hover { background: var(--color-brand-dark); }
.btn-start   { background: var(--color-accent); color: #fff; }
.btn-start:hover { background: var(--color-accent-dark); }
.btn-outline { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-outline:hover { border-color: var(--color-muted); }
.btn-ghost   { background: transparent; color: var(--color-muted); border-color: var(--color-border); }
.btn-ghost:hover { border-color: var(--color-muted); color: var(--color-text-2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------- Fields ---------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.field-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--color-muted);
}
.field-input,
.field-select,
.field-textarea {
  display: block;
  width: 100%;
  min-height: var(--tap-target);
  /* 16px stops iOS Safari from zooming in when the field gets focus */
  font-size: 16px;
  /* Pinned, not `normal`: a field's height is padding + border + one line box,
     and `normal` resolves differently for a plain text input than for the
     shadow DOM inside <input type="date">, which made the date field ~2px
     taller than its neighbours. An explicit value keeps every field identical. */
  line-height: var(--lh-tight);
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--color-accent);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, .10);
}
.field-input[readonly] {
  background: var(--color-surface-2);
  color: var(--color-muted);
  cursor: default;
}
.field-input[readonly]:focus { border-color: var(--color-border); box-shadow: none; }
.field-textarea { resize: vertical; min-height: 72px; line-height: var(--lh-base); }
.field-select {
  appearance: none;
  cursor: pointer;
  padding-right: var(--space-6);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236a7888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
}
.field.invalid .field-input,
.field.invalid .field-select,
.field.invalid .field-textarea {
  border-color: var(--color-accent);
  background: var(--color-accent-soft);
}
/* validation message pinned inside the input */
.input-wrap { position: relative; }
.field-msg {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--color-accent);
  background: var(--color-surface);
  padding-left: var(--space-2);
  display: none;
  pointer-events: none;
}
.field-msg.show { display: inline; }

@media (min-width: 768px) {
  .field-input,
  .field-select,
  .field-textarea { font-size: var(--fs-md); }
}

/* ---------------- Cards & badges ---------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  padding: 3px 12px;
  border-radius: var(--radius-pill);
  background: #eef1f6;
  color: var(--color-brand);
}
.badge-pass    { background: var(--color-success-soft); color: var(--color-success); }
.badge-fail    { background: var(--color-accent-soft);  color: var(--color-accent); }
.badge-pending { background: var(--color-warning-soft); color: var(--color-warning); }

/* ---------------- Toggle switch ----------------
   Off = nothing found (neutral), on = problem found (red). */
.switch {
  width: 42px;
  height: 22px;
  flex: none;
  border: none;
  padding: 0;
  border-radius: var(--radius-pill);
  background: var(--color-border-light);
  position: relative;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(26, 40, 64, .3);
  transition: transform var(--dur-fast) var(--ease);
}
.switch.on { background: var(--color-accent); }
.switch.on::after { transform: translateX(20px); }

/* ---------------- Status lamp ----------------
   green = details saved, amber blinking = flagged but not described.
   Rendered as a <span> while the row is unflagged and as a <button>
   once it is clickable (so it can be reached by keyboard) — hence the
   button reset here, otherwise the browser's default border and padding
   would make the lit lamp a small grey box. */
.lamp {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: transparent;
  padding: 0;
  border: none;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
}
.lamp.ok {
  background: var(--color-success);
  cursor: pointer;
}
.lamp.pending {
  background: var(--color-warning);
  cursor: pointer;
  animation: lampBlink 1s steps(1, end) infinite;
}
/* the dot is only 10px, so give the focus ring room to be visible */
.lamp:focus-visible { outline-offset: 3px; }
@keyframes lampBlink { 0%, 49.9% { opacity: 1; } 50%, 100% { opacity: .25; } }

/* ---------------- Spinner ---------------- */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Modal ----------------
   Full-screen sheet on phones, centred dialog on wider screens. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 26, .6);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 1100;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-height: 92vh;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-light);
  flex: none;
}
.modal__title { font-size: var(--fs-md); font-weight: var(--fw-bold); }
.modal__close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface-2);
  color: var(--color-muted);
  font-size: 18px;
  display: grid;
  place-items: center;
  flex: none;
}
.modal__close:hover { background: var(--color-border-light); color: var(--color-text); }
.modal__body {
  flex: 1;
  min-height: 0;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow-y: auto;
}
.modal__foot {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: 1px solid var(--color-border-light);
}
.modal__foot .btn { flex: 1; }

@media (min-width: 768px) {
  .modal-backdrop { align-items: center; }
  .modal {
    width: 900px;
    max-width: 94vw;
    height: 560px;
    border-radius: var(--radius-lg);
  }
  .modal__head, .modal__body, .modal__foot { padding: var(--space-4) var(--space-5); }
  .modal__body { padding: var(--space-5); }
  .modal__foot .btn { flex: none; }
}

/* ---------------- Lightbox (device photo) ---------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 26, .82);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 90%;
  max-height: 85%;
  object-fit: contain;
  cursor: default;
  background: #fff;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
