/* ── Edit form and the side panel it opens in (task 044) ─────────────────────────────────────────────────
   One form (_EditForm.cshtml), two places: /MySets/Edit and .edit-panel over a list. Which fields show for which
   status, and a used copy's four boxes, are switched HERE with :has() on the checked radio — not in script — so
   the full page works without JavaScript. */

.content-section--edit { max-width: 560px; }

.edit-sheet { display: flex; flex-direction: column; min-height: 0; }

.edit-sheet__head {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 14px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.edit-sheet__image { width: 96px; height: 72px; padding: var(--photo-inset); object-fit: contain; border-radius: 6px; background: var(--photo-bg); }
.edit-sheet__heading { min-width: 0; }
.edit-sheet__meta { margin: 0; font-size: 0.78rem; color: var(--muted); }
.edit-sheet__title { margin: 2px 0 4px; font-size: 1.1rem; line-height: 1.25; overflow-wrap: anywhere; }
.edit-sheet__market { margin: 0 0 4px; font-size: 0.82rem; color: var(--muted); }
/* The market figure the record's copies are valued at (sealed, used, or both for a mixed holding). */
.edit-sheet__market-held { color: var(--text); font-weight: 600; }
.edit-sheet__details-link { font-size: 0.82rem; }
.edit-sheet__close {
  border: 0; background: none; font-size: 1.6rem; line-height: 1; padding: 0 4px; color: var(--muted); cursor: pointer;
}

.edit-form { display: flex; flex-direction: column; gap: 14px; padding: 14px 0; }
.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.edit-error { margin: 0; font-size: 0.8rem; color: var(--down); }
.edit-note { margin: 0; font-size: 0.82rem; color: var(--muted); }
[aria-invalid="true"] { border-color: #c53030; }

/* Status: four radio buttons drawn as one segmented row; the hint under it is the checked one's. */
.status-picker, .priority-picker { border: 0; margin: 0; padding: 0; min-width: 0; }
.status-picker__options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.status-picker__input, .copy-toggle__input { position: absolute; opacity: 0; pointer-events: none; }
.status-picker__btn, .copy-toggle__btn {
  display: block;
  padding: 7px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface);
}
.status-picker__btn--small { display: inline-block; padding: 4px 12px; font-size: 0.8rem; }
.status-picker__input:checked + .status-picker__btn,
.copy-toggle__input:checked + .copy-toggle__btn { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast); }
.status-picker__input:focus-visible:not([data-focus-quiet]) + .status-picker__btn,
.copy-toggle__input:focus-visible + .copy-toggle__btn { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.status-picker__hint { display: none; margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }
.status-picker:has(#edit-status-Wishlist:checked) .status-picker__hint[data-for="Wishlist"],
.status-picker:has(#edit-status-Purchased:checked) .status-picker__hint[data-for="Purchased"],
.status-picker:has(#edit-status-Sold:checked) .status-picker__hint[data-for="Sold"] { display: block; }

/* Fields by status: a wish has a target and a priority, nothing else does — an order is bought (task 166: it kept both,
   and a target for a set already paid for meant nothing); an order, a held and a sold set have purchase rows — an
   order's price, date and shop are the purchase-to-be, and stay as they are when it becomes «У колекції» (task 055;
   before it an order hid the rows and recorded nothing). The hidden inputs still post — the priority must survive a
   purchase (the refresh queue scores it for owned sets too), and switching back to «Хочу» shows what was there. */
.edit-form:has(#edit-status-Ordered:checked) .edit-when-wish,
.edit-form:has(#edit-status-Purchased:checked) .edit-when-wish,
.edit-form:has(#edit-status-Sold:checked) .edit-when-wish,
.edit-form:has(#edit-status-Wishlist:checked) .edit-when-owned { display: none; }
.edit-when-wish, .edit-when-owned { display: flex; flex-direction: column; gap: 10px; }
/* The rows' wording follows the status: «Замовлення / Дата замовлення / Де замовив» for an order,
   «Покупки / Дата покупки / Де купив» otherwise. */
.edit-label-ordered { display: none; }
.edit-form:has(#edit-status-Ordered:checked) .edit-label-ordered { display: inline; }
.edit-form:has(#edit-status-Ordered:checked) .edit-label-purchased { display: none; }

.edit-grid { display: grid; gap: 10px; }
.edit-grid--target { grid-template-columns: 1fr 90px; }
.edit-grid--price { grid-template-columns: 1fr 90px 70px; }
.edit-grid--when { grid-template-columns: 1fr 1fr; }

.edit-purchases__head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.edit-valuation { font-size: 0.85rem; font-weight: 600; }

.purchase-rows { display: grid; gap: 10px; }
.purchase-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.copy-toggle { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; }
.purchase-row__remove {
  border: 0; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; padding: 0 6px; cursor: pointer;
}
.purchase-row__used { display: none; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 0.85rem; }
.purchase-row:has(.copy-toggle__input[value="Used"]:checked) .purchase-row__used { display: grid; }
.purchase-row__fact { display: flex; align-items: center; gap: 6px; }
.purchase-row__note summary, .edit-notes summary { font-size: 0.82rem; color: var(--accent-text); cursor: pointer; }
.purchase-row__note[open] summary, .edit-notes[open] summary { margin-bottom: 4px; color: var(--muted); }

.edit-sheet__foot {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.edit-sheet__delete { margin-right: auto; }

/* ── The panel ── */
html.edit-panel-open { overflow: hidden; }
.edit-panel { position: fixed; inset: 0; z-index: 1000; }
.edit-panel[hidden] { display: none; }
.edit-panel__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.edit-panel__sheet {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  /* It mounts on <body>, so it states its own text colour rather than inherit the page's (task 044: a page that
     set body text to #f8fafc made the title, idle buttons and links white on white). */
  color: var(--text);
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.18);
  outline: none;
}
.edit-panel__sheet > .edit-sheet { height: 100%; }
.edit-panel__sheet .edit-sheet__head { padding: 16px 16px 12px; }
.edit-panel__sheet .edit-sheet__body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 16px; }
.edit-panel__sheet .edit-sheet__foot { padding: 12px 16px; background: var(--surface); }
.edit-panel__loading { padding: 24px 16px; color: var(--muted); }

@media (max-width: 480px) {
  .edit-panel__sheet { width: 100vw; }
  .edit-sheet__head { grid-template-columns: 64px 1fr auto; }
  .edit-sheet__image { width: 64px; height: 48px; }
  .status-picker__options { grid-template-columns: repeat(2, 1fr); }
  .edit-sheet__foot { flex-wrap: wrap; }
}

/* The phone (task 105): a status, a priority and a copy's state are pills a finger's 44 px tall; on the full page
   (/MySets/Edit, not the panel, whose foot is already the panel's last line) «Зберегти» is held at the bottom of the
   screen above the bottom bar, as .ui-sticky-action is. */
@media (max-width: 900px) {
  .status-picker__btn,
  .copy-toggle__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch);
  }

  .purchase-row__remove {
    min-width: var(--touch);
    min-height: var(--touch);
  }

  .content-section--edit .detail-back-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch);
  }

  .content-section--edit .edit-sheet__foot {
    position: sticky;
    bottom: var(--tabbar-space);
    z-index: 5;
    margin: 0 -16px -16px;
    padding: 12px 16px;
    background: color-mix(in srgb, var(--surface-1) 94%, transparent);
    box-shadow: 0 -1px 0 var(--border);
    backdrop-filter: blur(10px);
  }

  .content-section--edit .edit-sheet__foot .btn-primary {
    flex: 1 1 auto;
  }
}

/* ── The phone's form (task 119, _EditFormMobile): the phone components (.ui-m-*, 16-phone.css) on the hooks above, so the
   status and a copy's state switch the fields by the same :has() rules. What is left here is where it sits: on the
   page's --bg, so a purchase card (.ui-m-cells on .purchase-row) stands out — the panel's sheet too — and «Зберегти»
   the whole width of the foot. ── */
.edit-panel__sheet:has(> .edit-sheet--phone) {
  background: var(--bg);
}

.edit-panel__sheet > .edit-sheet--phone > .edit-sheet--phone__head {
  padding: var(--space-4) var(--space-4) 0;
}

.edit-sheet--phone .edit-sheet__foot {
  border-top: 0;
}

.edit-panel__sheet .edit-sheet--phone .edit-sheet__foot {
  background: var(--bg);
  box-shadow: 0 -1px 0 var(--border);
}

.edit-sheet--phone .edit-sheet__foot > .ui-btn {
  flex: 1 1 auto;
}

.edit-sheet--phone__purchases {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 var(--space-3);
}

.edit-sheet--phone__rows {
  display: grid;
  gap: var(--space-3);
}

/* The form's own gap (14 px) already parts its sections: a heading takes a smaller step of its own above it. */
.edit-sheet--phone .edit-form .ui-m-sheet__h {
  margin-top: var(--space-2);
}
