/* Interactive QR decoder (/tools/qr-decoder/). */

.qr-decoder {
  display: grid;
  gap: 1.5rem;
  margin: 1.5rem 0;
}

@media (min-width: 60rem) {
  .qr-decoder {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
}

.qr-panel {
  border: 1px solid var(--color-border, #d4d4d8);
  border-radius: 0.5rem;
  padding: 1rem;
  background: var(--color-surface, #ffffff);
  min-width: 0;
}

.qr-panel__title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 700;
}

.qr-field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.qr-field > label,
.qr-field__label {
  font-size: 0.875rem;
  font-weight: 600;
}

.qr-field select,
.qr-field input[type="file"] {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid var(--color-border, #d4d4d8);
  border-radius: 0.25rem;
  background: #fff;
  color: inherit;
  font: inherit;
}

.qr-field input[type="range"] {
  width: 100%;
}

.qr-field__hint {
  font-size: 0.8125rem;
  color: var(--color-text-muted, #52525b);
}

.qr-field--inline {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.qr-drop {
  border: 2px dashed var(--color-border, #d4d4d8);
  border-radius: 0.5rem;
  padding: 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-muted, #52525b);
}

.qr-drop[data-active] {
  border-color: var(--color-accent, #2563eb);
  background: rgba(37, 99, 235, 0.06);
}

.qr-preview {
  display: grid;
  gap: 0.5rem;
  justify-items: center;
}

/* The canvas is the decoder's actual input, so it is shown at whatever size the
   scale control produced, capped to the panel rather than stretched. */
.qr-preview canvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--color-border, #d4d4d8);
  image-rendering: pixelated;
}

.qr-preview__info {
  font-size: 0.8125rem;
  color: var(--color-text-muted, #52525b);
}

.qr-run {
  width: 100%;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--color-accent, #2563eb);
  border: 0;
  border-radius: 0.25rem;
  cursor: pointer;
}

.qr-run:disabled {
  opacity: 0.6;
  cursor: progress;
}

.qr-status {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  min-height: 1.4em;
}

.qr-status[data-tone="ok"] { color: #15803d; }
.qr-status[data-tone="warn"] { color: #b45309; }
.qr-status[data-tone="error"] { color: #b91c1c; }
.qr-status[data-tone="busy"] { color: var(--color-text-muted, #52525b); }

.qr-result__section + .qr-result__section {
  margin-top: 1rem;
}

.qr-result__heading {
  margin: 0 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-muted, #52525b);
}

/* Decoded values are arbitrary bytes: wrap hard so a long payload cannot push
   the panel wider than the page. */
.qr-result__value {
  margin: 0;
  padding: 0.6rem;
  background: var(--color-surface-alt, #f4f4f5);
  border-radius: 0.25rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.qr-result__kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0;
  font-size: 0.875rem;
}

.qr-result__kv dt { font-weight: 600; }
.qr-result__kv dd { margin: 0; overflow-wrap: anywhere; }

.qr-result__list {
  margin: 0;
  padding-left: 1.25rem;
  display: grid;
  gap: 0.4rem;
}

.qr-result__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.qr-result__table th,
.qr-result__table td {
  border: 1px solid var(--color-border, #d4d4d8);
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.qr-result__table td:first-child {
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.qr-result__note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted, #52525b);
}

/* Which decoding stage the image got to. The marker colour is the quickest read,
   so it carries no meaning on its own — every row also states 成功 / 失敗. */
.qr-result__stages {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.875rem;
  line-height: 1.7;
}

.qr-result__stages li[data-state="ok"]::marker {
  color: var(--color-success, #15803d);
}

.qr-result__stages li[data-state="fail"]::marker {
  color: var(--color-danger, #b91c1c);
}

.qr-result__stages li[data-state="partial"]::marker {
  color: var(--color-warning, #b45309);
}

.qr-result__stages li[data-state="skip"] {
  color: var(--color-text-muted, #52525b);
}

.qr-result__stages strong {
  font-weight: 600;
}

.qr-result__grids {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.qr-result__grid {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--color-border, #d4d4d8);
  background: #ffffff;
  image-rendering: pixelated;
}

@media (prefers-color-scheme: dark) {
  .qr-panel { background: rgba(255, 255, 255, 0.03); }
  .qr-field select,
  .qr-field input[type="file"] { background: rgba(255, 255, 255, 0.06); }
  .qr-result__value { background: rgba(255, 255, 255, 0.06); }
  .qr-result__stages li[data-state="ok"]::marker { color: #4ade80; }
  .qr-result__stages li[data-state="fail"]::marker { color: #f87171; }
  .qr-result__stages li[data-state="partial"]::marker { color: #fbbf24; }
}
