/*
 * The activate host (app/views/layouts/activate.html.erb): the clerks' activation app.
 * The prototype's layout (header, steps row, cards, the tag spaces, notes) on the
 * tokens of tokens.css, so light and dark follow the device. Every rule is scoped
 * under body.activate, so the public and docs pages never see one. Touch targets
 * are --button-height (48px).
 */

body.activate {
  display: flex;
  flex-direction: column;
}

body.activate > main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-4);
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
}

/* Header: the brand on the left, the signed-in email and Sign out on the right; they wrap under it on a phone. */
body.activate .activate-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-3);
  padding: var(--space-1) var(--space-4);
  padding-top: max(var(--space-1), env(safe-area-inset-top));
  padding-left: max(var(--space-4), env(safe-area-inset-left));
  padding-right: max(var(--space-4), env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

body.activate .activate-brand {
  display: inline-flex;
  align-items: center;
  min-height: var(--button-height);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

body.activate .activate-account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 var(--space-2);
  min-width: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

body.activate .activate-email {
  min-width: 0;
}

body.activate .activate-sign-out {
  margin: 0;
}

/* A button that reads as a link (Sign out, later Start over): a form control, so it stays a button. */
body.activate .activate-link-button {
  display: inline-flex;
  align-items: center;
  min-height: var(--button-height);
  margin: 0;
  padding: 0 var(--space-2);
  border: 0;
  background: none;
  color: var(--accent);
  font-size: var(--text-sm);
  text-decoration: underline;
  cursor: pointer;
}

body.activate .activate-link-button:active {
  color: var(--accent-pressed);
}

@media (max-width: 719px) {
  body.activate .activate-email {
    flex-basis: 100%;
  }

  body.activate .activate-email + .activate-sign-out {
    margin-left: calc(-1 * var(--space-2));
  }
}

body.activate h1 {
  margin: var(--space-1) 0 var(--space-3);
  font-size: var(--text-xl);
}

body.activate h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
}

/* The steps row: Label, Shipment, Tags, Review; the current one aria-current="step", the done ones ticked green. */
body.activate .steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-1);
  max-width: 520px;
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

body.activate .steps li {
  min-width: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

body.activate .steps .step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: var(--button-height);
  padding: 2px 0;
  color: inherit;
  text-decoration: none;
}

body.activate .steps .stepno {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  line-height: 26px;
}

body.activate .steps .stepname {
  overflow-wrap: anywhere;
}

body.activate .steps .done .stepno {
  border-color: var(--success);
  background: var(--success);
  color: var(--on-accent);
}

body.activate .steps a.step .stepname {
  color: var(--accent);
  text-decoration: underline;
}

body.activate .steps [aria-current] {
  color: var(--text);
  font-weight: 700;
}

body.activate .steps [aria-current] .stepno {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

/* Cards and the two layouts that hold them: .grid (two columns from 720px), .split (the scanner first on a phone). */
body.activate .card {
  min-width: 0;
  margin-bottom: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
}

body.activate .actions {
  margin-top: var(--space-4);
}

body.activate .grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}

body.activate .grid .card {
  margin-bottom: 0;
}

body.activate .split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

body.activate .split .scanner {
  order: -1;
}

@media (min-width: 720px) {
  body.activate .grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  body.activate .split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  body.activate .split .scanner {
    order: 0;
  }
}

/* The tag spaces: one numbered row per unit. */
body.activate .spacelist {
  margin: 0;
  padding: 0;
  list-style: none;
}

body.activate .space {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--button-height);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

body.activate .space.over {
  border-left: var(--space-1) solid var(--danger);
  padding-left: var(--space-2);
}

body.activate .spaceno {
  flex: none;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--bg);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 24px;
  text-align: center;
}

body.activate .spaceid {
  flex: 1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

body.activate .space form {
  margin: 0;
}

body.activate .spaceform {
  display: flex;
  flex: 1;
  gap: var(--space-2);
  min-width: 0;
}

body.activate .spaceform input {
  flex: 1;
  min-width: 0;
  min-height: var(--button-height);
}

body.activate .space input[disabled] {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text-muted);
}

/* The Tags step (the prototype's tag.erb styles): a space wraps its check's sentence onto a row of its own, under
   the id; the space the last add filled is tinted; an empty space reads lighter; Remove and the add button keep
   their width. */
body.activate .space {
  flex-wrap: wrap;
}

body.activate .space.added {
  box-shadow: inset var(--space-1) 0 0 var(--success);
  padding-left: var(--space-2);
}

body.activate .space.empty .spaceid {
  color: var(--text-muted);
  font-weight: 400;
}

body.activate .space .remove,
body.activate .spaceform .button {
  flex: none;
  width: auto;
  margin: 0;
  padding: 0 var(--space-4);
}

body.activate .space .help,
body.activate .space .field-error {
  flex-basis: calc(100% - 26px - var(--space-3));
  margin: 0 0 0 calc(26px + var(--space-3));
}

body.activate .space-unknown .spaceid,
body.activate .space-linked .spaceid,
body.activate .space-failed .spaceid {
  color: var(--danger);
}

body.activate .split .scanner .card:last-child {
  margin-bottom: 0;
}

body.activate .tag-photo {
  margin-top: var(--space-4);
}

body.activate .tag-photo .button {
  margin-top: var(--space-2);
}

/* The Shipment step: the unit choices are a fieldset without a frame. */
body.activate .units {
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

body.activate .shipment-form .button {
  margin-top: var(--space-6);
}

/* Radio choices (packages or pallets): the whole label is the 48px target. */
body.activate .choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

body.activate .choices label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--button-height);
  margin: 0;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-input);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

body.activate .choices label:has(input:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

body.activate .choices input {
  width: 20px;
  height: 20px;
  min-height: 0;
  margin: 0;
}

/* Notes, errors and confirmations: a colored edge on the page ground, the text in --text. */
body.activate .note,
body.activate .error,
body.activate .ok {
  margin: var(--space-2) 0;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-left-width: var(--space-1);
  border-radius: var(--radius-input);
  background: var(--bg);
  color: var(--text);
}

body.activate .note {
  border-left-color: var(--accent);
}

body.activate .error {
  border-left-color: var(--danger);
}

body.activate .ok {
  border-left-color: var(--success);
}

/* The read and typed values of a card: label beside value. */
body.activate dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  margin: 0;
}

body.activate dt {
  color: var(--text-muted);
}

body.activate dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* The camera preview: shown by the scanner once the stream starts. */
body.activate #cam {
  display: none;
  width: 100%;
  max-height: 60vh;
  border-radius: var(--radius-input);
  background: var(--surface);
}

body.activate #cam.live {
  display: block;
}

/* The camera block of the Label step, above the photo or PDF input. */
body.activate .label-camera {
  margin-bottom: var(--space-4);
}

/* Start over sits between the email and Sign out; on a phone it starts the row under the email. */
@media (max-width: 719px) {
  body.activate .activate-email + .activate-start-over {
    margin-left: calc(-1 * var(--space-2));
  }
}

body.activate .activate-start-over {
  margin: 0;
}

/* Secondary text: the step's lead sentence and a field's help. */
body.activate .muted {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

body.activate .help {
  margin: var(--space-1) 0 0;
}

/* The Label step's choices: the photo or PDF input, its fallback button and the typed path below the card. */
body.activate .label-photo {
  margin-top: var(--space-4);
}

body.activate .field-file {
  display: block;
  width: 100%;
  min-height: var(--button-height);
  padding: var(--space-2);
  font-size: var(--text-md);
}

body.activate .field-file[aria-invalid="true"] {
  border-color: var(--danger);
}

body.activate .label-photo .button {
  margin-top: var(--space-4);
}

body.activate .activate-type-form {
  margin: 0 0 var(--space-4);
}

body.activate .activate-type-instead {
  padding: 0;
  font-size: var(--text-md);
}

/* Check the label: the sections of the form and, under a field, the value the reader returned. */
body.activate .label-form h2 {
  margin-top: var(--space-6);
}

body.activate .label-form h2:first-of-type {
  margin-top: 0;
}

body.activate .label-form .field + .field {
  margin-top: var(--space-3);
}

body.activate .label-form .button {
  margin-top: var(--space-6);
}

body.activate .read-hint {
  margin: var(--space-1) 0 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* The waiting state while the document is read. */
body.activate .reading {
  border-left: var(--space-1) solid var(--accent);
}

body.activate .ok p {
  margin: 0;
}

body.activate .ok p + p {
  margin-top: var(--space-1);
}

/* The review and the outcome: a refusal's two sentences, the waiting state after the Activate tap, the tag rows of
   the review (the spaces' number and id), and the buttons that stand on the page ground. */
body.activate .error p {
  margin: 0;
}

body.activate .error p + p {
  margin-top: var(--space-1);
}

body.activate .waiting {
  border-left: var(--space-1) solid var(--accent);
}

body.activate .tag-rows {
  margin: 0;
  padding: 0;
  list-style: none;
}

body.activate .tag-rows li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}

body.activate .tag-rows .spaceid {
  flex: 1 1 auto;
}

body.activate .review-tags {
  margin-top: var(--space-4);
}

body.activate .another {
  margin: var(--space-4) 0;
}

/* A display rule beats the hidden attribute, so hidden wins on this host. */
body.activate [hidden] {
  display: none !important;
}
