/* Pop-ups. Every one is a <dialog class="modal"> opened with showModal()
   (atlantis.js wires the buttons), so the browser centres it, dims the page
   behind with ::backdrop, keeps focus inside and closes it on Escape. The
   dialog itself is only a shell the size of its .modal-panel; how the panel
   looks belongs to the page it's on (paper.css, shop.css, admin.css). */

dialog.modal {
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    /* The panel scrolls itself; the shell mustn't add a second bar. */
    overflow: visible;
}

dialog.modal::backdrop {
    background: rgba(24, 15, 5, 0.5);
}

/* The admin theme dresses every dialog as a panel; this one's panel is
   inside it, so the shell stays bare there too. */
.root-page dialog.modal {
    background: transparent;
    box-shadow: none;
}

dialog.modal[open] {
    animation: modal-in 0.18s ease-out;
}

dialog.modal[open]::backdrop {
    animation: modal-backdrop-in 0.18s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; translate: 0 10px; scale: 0.98; }
}

@keyframes modal-backdrop-in {
    from { opacity: 0; }
}

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

dialog.modal .modal-panel {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(92vw, 520px);
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

dialog#editUserPopup,
dialog#editProjectPopup {
    width: min(92vw, 520px);
    border: none;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

dialog#editUserPopup::backdrop,
dialog#editProjectPopup::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.modal-panel form,
dialog#editUserPopup form,
dialog#editProjectPopup form {
    display: grid;
    gap: 16px;
}

.modal-panel label,
dialog#editUserPopup label,
dialog#editProjectPopup label {
    display: grid;
    gap: 8px;
}

.modal-panel input,
.modal-panel textarea,
dialog#editUserPopup input,
dialog#editProjectPopup input {
    width: 100%;
    box-sizing: border-box;
}

dialog#editProjectPopup label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

dialog#editProjectPopup label.checkbox-label input {
    width: auto;
}

.group-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border: none;
    padding: 0;
    margin: 0;
}

.group-selector legend {
    padding: 0;
    margin-bottom: 8px;
    font-weight: 600;
}

.group-chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 999px;
    cursor: pointer;
    font-size: 14px;
    user-select: none;
}

.group-chip input {
    display: none;
}

.group-chip:has(input:checked) {
    background: #0066cc;
    border-color: #0066cc;
    color: #fff;
}
