/* Shared components: buttons, fields, tags, panels, the plot sheet, dialog and toasts. */

/* ---------- labels ---------- */
.label {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--ink-soft);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-5);
  border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 600; font-size: var(--t-sm); white-space: nowrap; text-decoration: none;
  transition: background-color var(--fast) var(--ease-out), border-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out), transform var(--fast) var(--ease-out);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--t-xs); }

.btn--primary { background: var(--survey); color: var(--survey-ink); }
.btn--primary:hover:not(:disabled) { background: var(--survey-deep); }

.btn--quiet { background: var(--paper-raised); border-color: var(--rule-strong); color: var(--ink); }
.btn--quiet:hover:not(:disabled) { border-color: var(--ink); }

.btn--danger { background: transparent; border-color: var(--rule); color: var(--survey-deep); }
.btn--danger:hover:not(:disabled) { border-color: var(--survey); background: var(--survey-tint); }


/* ---------- tags (yield class) ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px;
  font-size: var(--t-xs); font-weight: 650;
  border-radius: 999px;
}
.tag--good { color: var(--good); background: var(--good-bg); }
.tag--fair { color: var(--fair); background: var(--fair-bg); }
.tag--poor { color: var(--poor); background: var(--poor-bg); }

/* ---------- panels ---------- */
.panel {
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--e1);
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); flex-wrap: wrap;
  padding: var(--s-4) var(--s-6);
  border-bottom: 1px solid var(--rule);
}
.panel__title { font-size: var(--t-md); }
.panel__sub { color: var(--ink-soft); font-size: var(--t-sm); margin-top: 2px; }
.panel__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------- fields ---------- */
.field { display: grid; gap: 6px; align-content: start; }
.field__label { font-size: var(--t-xs); font-weight: 650; color: var(--ink-soft); }
.field input, .field select, select[data-pref] {
  width: 100%; min-height: 40px; padding: 0 var(--s-3);
  background: var(--paper-raised); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  transition: border-color var(--fast) var(--ease-out), box-shadow var(--fast) var(--ease-out);
}
.field input:hover:not(:disabled), .field select:hover:not(:disabled), select[data-pref]:hover { border-color: var(--ink); }
.field input:focus-visible, .field select:focus-visible, select[data-pref]:focus-visible { border-color: var(--survey); box-shadow: 0 0 0 3px rgb(194 70 46 / 0.18); }
.field input:disabled, .field select:disabled { background: var(--paper-sunk); border-color: var(--rule); color: var(--ink-soft); cursor: not-allowed; }
.field input::placeholder { color: var(--ink-faint); }
select[data-pref] { width: auto; min-width: 240px; }

/* switch */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--rule-strong); border-radius: 12px; transition: background-color var(--base) var(--ease-out); }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  background: var(--paper-raised); border-radius: 50%; box-shadow: 0 1px 2px rgb(28 36 32 / 0.3);
  transition: transform var(--base) var(--ease-out);
}
.switch input:checked + span { background: var(--survey); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- plot sheet ---------- */
.sheet { background: var(--paper-raised); border: 1px solid var(--rule); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--e2); }
.sheet__head {
  display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: var(--s-4);
  padding: var(--s-4) var(--s-6); border-bottom: 1px solid var(--rule);
}
.sheet__code { font-size: var(--t-lg); font-weight: 700; }
.sheet__file { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sheet__time { color: var(--ink-soft); font-size: var(--t-sm); }
.sheet__body { display: grid; grid-template-columns: minmax(240px, 5fr) 7fr; }
.sheet__media { padding: var(--s-6); border-right: 1px solid var(--rule); display: grid; gap: var(--s-4); align-content: start; }
.sheet__frame { position: relative; aspect-ratio: 1; background: var(--paper-sunk); overflow: hidden; border-radius: var(--radius); }
.sheet__frame img, .sheet__frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sheet__frame canvas { opacity: 0; transition: opacity var(--base) var(--ease-out); }
.sheet__mapnote { position: absolute; left: var(--s-3); bottom: var(--s-3); padding: 4px 8px; background: var(--paper-raised); font-size: var(--t-xs); display: none; }
.sheet__media:has(.viewswitch input[value="map"]:checked) canvas { opacity: 1; }
.sheet__media.is-map-unavailable:has(.viewswitch input[value="map"]:checked) .sheet__mapnote { display: block; }
.sheet__noimg { aspect-ratio: 1; display: grid; place-items: center; background: var(--paper-sunk); color: var(--ink-soft); font-size: var(--t-sm); }
.sheet__data { display: grid; grid-template-columns: 1fr 1fr; align-content: start; }
.sheet__yield { grid-column: 1 / -1; padding: var(--s-6); border-bottom: 1px solid var(--rule); display: grid; gap: var(--s-2); justify-items: start; }
.sheet__value { font-family: var(--font-display); font-size: var(--t-md); font-weight: 600; color: var(--ink-soft); }
.sheet__value span { font-size: var(--t-2xl); font-weight: 700; color: var(--ink); letter-spacing: -0.02em; line-height: 1; margin-right: 4px; }
.sheet__block { padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--rule); display: grid; gap: var(--s-3); align-content: start; }
.sheet__block + .sheet__block:not(.sheet__block--wide) { border-left: 1px solid var(--rule); }
.sheet__block--wide { grid-column: 1 / -1; border-bottom: 0; }
.sheet__empty { color: var(--ink-soft); font-size: var(--t-sm); }

.viewswitch { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 999px; padding: 2px; justify-self: start; }
.viewswitch input { position: absolute; opacity: 0; pointer-events: none; }
.viewswitch label { padding: 4px 12px; border-radius: 999px; font-size: var(--t-xs); font-weight: 650; cursor: pointer; color: var(--ink-soft); transition: background-color var(--fast) var(--ease-out), color var(--fast) var(--ease-out); }
.viewswitch input:checked + label { background: var(--ink); color: var(--paper); }
.viewswitch input:focus-visible + label { box-shadow: var(--focus); }

.ramp { display: grid; gap: 6px; }
.ramp__bar { position: relative; height: 10px; background: var(--ramp); }
.ramp__mark { position: absolute; left: var(--at); top: -5px; bottom: -5px; width: 2px; background: var(--ink); transform: translateX(-1px); }
.ramp__mark::after { content: ""; position: absolute; top: -4px; left: -4px; border: 5px solid transparent; border-top-color: var(--ink); }
.ramp figcaption { display: flex; justify-content: space-between; font-size: var(--t-xs); color: var(--ink-soft); }
.ramp figcaption span:nth-child(2) { color: var(--ink); font-weight: 650; }

.features { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.features th { text-align: left; font-weight: 500; color: var(--ink-soft); padding: 6px 0; }
.features td { text-align: right; font-weight: 650; padding: 6px 0; }
.features th, .features td { padding: 5px 0; }

.crops { list-style: none; padding: 0; counter-reset: crop; display: grid; gap: var(--s-2); }
.crop { counter-increment: crop; display: grid; grid-template-columns: 22px 1fr auto; gap: var(--s-2); align-items: baseline; font-size: var(--t-sm); }
.crop::before { content: counter(crop) "."; color: var(--ink-faint); }
.crop__name { font-weight: 600; }
.crop__name i { font-weight: 400; color: var(--ink-soft); margin-left: 4px; }
.crop__share { font-weight: 650; }
.crop--warning .crop__name { color: var(--survey-deep); }
.crop__note { display: block; font-weight: 400; color: var(--ink-soft); font-size: var(--t-xs); }

.env { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-5); }
.env div { display: grid; gap: 2px; align-content: start; justify-items: start; }
.env dt { font-size: var(--t-xs); color: var(--ink-soft); font-weight: 600; }
.env dd { font-weight: 650; }
.env__sub { font-size: var(--t-xs); color: var(--ink-soft); }
.env .btn { margin-top: var(--s-2); }

/* ---------- dialog ---------- */
.dialog {
  /* the global margin reset removes the browser's centring, so restore it */
  margin: auto; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--rule); border-radius: var(--radius-lg);
  background: var(--paper-raised); color: var(--ink); box-shadow: var(--e3);
}
.dialog::backdrop { background: rgb(28 36 32 / 0.45); }
.dialog form { display: grid; gap: var(--s-4); padding: var(--s-6); }
.dialog__head { display: grid; gap: var(--s-1); }
.dialog__title { font-size: var(--t-lg); }
.dialog__sub { color: var(--ink-soft); font-size: var(--t-sm); }
.dialog__row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.dialog input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.dialog input[type="number"]::-webkit-inner-spin-button, .dialog input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.dialog__locate { justify-self: start; display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--t-sm); font-weight: 600; color: var(--ink); text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 0.25em; }
.dialog__locate svg { width: 16px; height: 16px; color: var(--survey); }
.dialog__locate:hover { text-decoration-color: var(--survey); }
.dialog__locate:disabled { opacity: 0.6; cursor: progress; }
.dialog__error { color: var(--survey-deep); font-size: var(--t-sm); font-weight: 600; }
.dialog__error:empty { display: none; }
.dialog__actions { display: flex; justify-content: flex-end; gap: var(--s-2); padding-top: var(--s-2); }
.dialog[open] { animation: dialog-in var(--base) var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (max-width: 560px) {
  /* phones: a bottom sheet within thumb reach */
  .dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0; }
  .dialog form { padding: var(--s-5) var(--s-4) calc(var(--s-5) + env(safe-area-inset-bottom)); }
  .dialog__actions .btn { flex: 1; }
}

/* ---------- toasts ---------- */
.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 50; display: grid; gap: var(--s-2); width: min(360px, calc(100vw - 2 * var(--s-4))); pointer-events: none; }
@media (max-width: 560px) { .toasts { right: var(--s-4); left: var(--s-4); width: auto; bottom: var(--s-4); } }
.toast {
  padding: var(--s-3) var(--s-4);
  background: var(--ink); color: var(--paper); font-size: var(--t-sm); font-weight: 550;
  border-radius: var(--radius); box-shadow: var(--e3);
  animation: toast-in var(--base) var(--ease-out);
  transition: opacity var(--base) var(--ease-out), transform var(--base) var(--ease-out);
}
.toast--error { background: var(--survey-deep); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .sheet__body { grid-template-columns: 1fr; }
  .sheet__media { border-right: 0; border-bottom: 1px solid var(--rule); }
  .sheet__head { grid-template-columns: auto 1fr; }
  .sheet__time { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .sheet__data { grid-template-columns: 1fr; }
  .sheet__block + .sheet__block:not(.sheet__block--wide) { border-left: 0; }
  .env { grid-template-columns: 1fr; }
  .sheet__head, .sheet__media, .sheet__yield, .sheet__block { padding-inline: var(--s-4); }
}

@media print {
  .site-header, .site-footer, .tool, .viewswitch, .env .btn, .toasts { display: none !important; }
  .sheet { box-shadow: none; break-inside: avoid; }
}
