/*
 * The site's form modal (shared/_modal, dialog_controller.js): the page stays
 * behind, dimmed and out of focus; in front, a sheet a little see-through
 * with its head (a drawn box, what it is, close), then the form: its fields
 * scroll (.form-fields) above its buttons (.form-actions), which stay at the
 * bottom. The same forms work as pages, where they look like any card. Under
 * 600px the sheet rises from the bottom.
 */
.app {
  /* A page wrapped in a dialog controller keeps the page's spacing */
  .page > [data-controller~="dialog"] { display: grid; gap: inherit; min-width: 0; }

  .form-fields, .modal-content { display: grid; gap: 14px; min-width: 0; }

  dialog.modal { width: min(620px, calc(100vw - 32px)); max-width: none; max-height: min(860px, calc(100dvh - 48px)); padding: 0; overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--line) 80%, transparent); border-radius: calc(var(--radius) + 6px);
    background: color-mix(in srgb, var(--paper) 95%, transparent); color: var(--ink); box-shadow: 0 40px 80px -30px rgba(0, 0, 0, .45); }
  dialog.modal[open] { display: flex; flex-direction: column; animation: modal-in .45s cubic-bezier(.3, 1.35, .5, 1) both; }
  dialog.modal::backdrop { background: rgba(15, 18, 24, .3); backdrop-filter: blur(7px) saturate(1.15); animation: modal-veil .25s ease both; }

  .modal-head { flex: none; display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 20px 20px 16px 22px;
    border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
  .modal-box { width: 56px; height: 56px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent) 10%, var(--paper)); display: grid; place-items: center; }
  .modal-box .tag-box { position: static; width: 84%; height: auto; aspect-ratio: 1; animation: none; background: none; }
  .modal-titles { display: grid; gap: 2px; min-width: 0; }
  .modal-titles .eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); overflow-wrap: anywhere; }
  .modal-titles h2 { font-size: 24px; line-height: 1.15; overflow-wrap: anywhere; }
  .modal-close { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--paper); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); cursor: pointer; }
  .modal-close:hover { background: var(--paper); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
  .modal-close svg.icon { width: 18px; height: 18px; }
  .modal-loading { padding: 22px; }

  /* The content: a frame or a form; the fields scroll above the buttons */
  .modal > turbo-frame { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
  .modal :is(form, .modal-content):has(> .form-fields) { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; gap: 0; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
  .modal .form-fields { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; gap: 16px; align-content: start; padding: 18px 22px 22px; }
  .modal .form-actions { flex: none; flex-direction: row-reverse; justify-content: flex-start; gap: 10px; margin: 0; padding: 14px 20px 16px 22px;
    border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); background: color-mix(in srgb, var(--paper) 55%, transparent); }

  /* "Adicionar presente" away from a list: first the list (quick_gifts/new) */
  .list-choices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
  .list-choice { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 12px 8px 8px; border-radius: var(--radius-sm);
    background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--line); color: var(--ink); text-decoration: none; transition: transform .3s cubic-bezier(.3, 1.35, .5, 1), box-shadow .2s; }
  .list-choice:hover { text-decoration: none; transform: translateX(3px); box-shadow: inset 0 0 0 1.5px var(--accent); }
  .list-choice .mini-shelf { width: 54px; height: 54px; border-radius: 8px; display: flex; justify-content: center; align-items: flex-end; gap: 2px; padding: 6px 3px 0;
    background: color-mix(in srgb, var(--c) 12%, var(--paper)); }
  .list-choice .mini-shelf .gift-picture { width: 21px; height: 25px; aspect-ratio: auto; border-radius: 4px; margin-bottom: 4px; }
  .list-choice .text { display: grid; gap: 3px; min-width: 0; }
  .list-choice b { font-size: 16px; overflow-wrap: anywhere; }
  .list-choice .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; font-weight: 600; color: var(--muted); }
  .list-choice .go { color: var(--muted); display: grid; }
  .list-choice .go svg.icon { width: 20px; height: 20px; }
  .create-instead { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 10px; border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 700; color: var(--muted); text-decoration: none; }
  .create-instead:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
  .create-instead svg.icon { width: 16px; height: 16px; }
  /* Then the form, saying where the gift goes */
  .chosen-list { flex: none; display: flex; align-items: center; gap: 10px; margin: 14px 22px 0; padding: 8px 8px 8px 12px; border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--c) 10%, var(--paper)); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--c) 35%, var(--line)); font-size: 14px; font-weight: 600; color: var(--muted); }
  .chosen-list .dot { flex: none; width: 12px; height: 12px; border-radius: 4px; background: var(--c); }
  .chosen-list > span:not(.dot) { margin-right: auto; overflow-wrap: anywhere; }
  .chosen-list b { color: var(--ink); }

  /* Editing a gift: deleting it sits above the form */
  .gift-delete { display: flex; justify-content: flex-end; }
  .modal .gift-delete { flex: none; padding: 12px 22px 0; }
  .modal .gift-delete + form .form-fields { padding-top: 4px; }

  /* A saved list's form says who sees it (that changes on its page) */
  .audience-note { display: flex; gap: 8px; align-items: center; }
  .audience-note svg.icon { flex: none; width: 16px; height: 16px; }
}

@media (max-width: 600px) {
  .app {
    dialog.modal { width: 100%; max-height: calc(100dvh - 40px); margin: auto 0 0; border-bottom: 0; border-radius: calc(var(--radius) + 8px) calc(var(--radius) + 8px) 0 0; }
    dialog.modal[open] { animation-name: modal-up; }
    .modal-head { position: relative; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; padding: 22px 16px 12px; }
    .modal-head::before { content: ""; position: absolute; top: 8px; left: 50%; translate: -50% 0; width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
    .modal-box { width: 44px; height: 44px; }
    .modal-titles h2 { font-size: 21px; }
    .modal .form-fields { padding: 16px 16px 20px; }
    .modal .form-actions { padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px)); }
    .modal .form-actions .btn { flex: 1; }
    .chosen-list { margin: 12px 16px 0; }
    .modal .gift-delete { padding: 10px 16px 0; }
  }
}

@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(.97); } }
@keyframes modal-up { from { transform: translateY(100%); } }
@keyframes modal-veil { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .app dialog.modal[open], .app dialog.modal::backdrop { animation: none; }
  .app .list-choice { transition: none; }
}
