/**
 * ProfileModal (pm- prefix) — in-place editor for quiz profile + business
 * fields + notification preferences. Opened from the dashboard Quiz Profile
 * card's "Edit profile →" button.
 *
 * Design goals:
 *   - Scannable: accordion sections collapsed by default (except Location)
 *   - Polished: form controls match the site's warm/editorial aesthetic
 *   - Accessible: 44px min touch targets, focus-visible rings, reduced-motion
 *   - Mobile: stacks to full-screen on narrow viewports
 */

.pm-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(26, 24, 20, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    padding: 20px;
}
.pm-modal-overlay.open {
    display: flex;
    animation: pmFadeIn 200ms ease-out;
}
@keyframes pmFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

body.pm-modal-open {
    overflow: hidden;
}

.pm-modal {
    background: #FFFDFA;
    border-radius: 14px;
    max-width: 620px;
    width: 100%;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow:
        0 18px 48px rgba(26, 24, 20, 0.24),
        0 2px 8px rgba(26, 24, 20, 0.08);
    animation: pmSlideIn 260ms cubic-bezier(0.16, 1, 0.3, 1);
    outline: none;
}
@keyframes pmSlideIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

.pm-modal__header {
    padding: 20px 28px 16px;
    border-bottom: 1px solid #F0EBE0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.pm-modal__title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 22px;
    font-weight: 500;
    letter-spacing: -0.015em;
    color: #1A1814;
    margin: 0;
}

.pm-modal__close {
    background: transparent;
    border: none;
    color: #6B6458;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 120ms ease, color 120ms ease;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.pm-modal__close:hover,
.pm-modal__close:focus-visible {
    background: #F4EEDF;
    color: #1A1814;
    outline: none;
}
.pm-modal__close:focus-visible {
    box-shadow: 0 0 0 2px #C4532B;
}

.pm-modal__body {
    padding: 8px 28px 0;
    overflow-y: auto;
    flex: 1;
}

/* ── Sections (collapsible accordions) ─────────────────────────────── */

.pm-section {
    border-bottom: 1px solid #F0EBE0;
    padding: 14px 0;
}
.pm-section:last-of-type {
    border-bottom: none;
}

.pm-section__toggle {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    border: none;
    padding: 4px 0;
    cursor: pointer;
    min-height: 44px;
    gap: 12px;
}
.pm-section__toggle:focus-visible {
    outline: 2px solid #C4532B;
    outline-offset: 2px;
    border-radius: 4px;
}

.pm-section__title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 17px;
    font-weight: 500;
    color: #1A1814;
    margin: 0;
}

.pm-section__chevron {
    color: #6B6458;
    font-size: 14px;
    transition: transform 150ms ease;
}
.pm-section--open .pm-section__chevron {
    transform: rotate(180deg);
}

/* First section (Location) is open by default — title renders as plain text. */
.pm-section[data-section="location"] .pm-section__title {
    padding: 4px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.pm-section__body {
    display: none;
    padding-top: 12px;
}
.pm-section--open .pm-section__body {
    display: block;
}

/* ── Fields ────────────────────────────────────────────────────────── */

.pm-field {
    display: block;
    margin-bottom: 14px;
}
.pm-field:last-child {
    margin-bottom: 0;
}

.pm-field__label {
    display: block;
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #1A1814;
    margin-bottom: 6px;
    letter-spacing: 0;
}

.pm-field__optional {
    font-weight: 400;
    color: #8A8378;
}

.pm-input {
    width: 100%;
    padding: 10px 12px;
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 14px;
    color: #1A1814;
    background: #FFFDFA;
    border: 1px solid #D9D1C0;
    border-radius: 6px;
    min-height: 44px;
    box-sizing: border-box;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.pm-input:focus {
    outline: none;
    border-color: #1F4A37;
    box-shadow: 0 0 0 2px rgba(31, 74, 55, 0.2);
}
select.pm-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 9L2 5h8z' fill='%236B6458'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── Radio / Checkbox groups ──────────────────────────────────────── */

.pm-field--radio,
.pm-field--checkbox {
    border: none;
    padding: 0;
    margin: 0 0 16px;
}

.pm-radio-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.pm-radio,
.pm-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    min-height: 44px;
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 14px;
    color: #3A362E;
    padding: 4px 0;
}
.pm-radio input,
.pm-checkbox input {
    width: 18px;
    height: 18px;
    accent-color: #1F4A37;
    cursor: pointer;
}
.pm-radio:hover span,
.pm-checkbox:hover span {
    color: #1A1814;
}

.pm-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 20px;
    margin-top: 4px;
}

/* ── Notification switches ────────────────────────────────────────── */

.pm-switch {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    cursor: pointer;
    min-height: 44px;
    border-bottom: 1px solid #F5F1E8;
}
.pm-switch:last-child {
    border-bottom: none;
}
.pm-switch input {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    accent-color: #1F4A37;
    cursor: pointer;
    flex-shrink: 0;
}
.pm-switch__body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pm-switch__label {
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #1A1814;
}
.pm-switch__desc {
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 13px;
    color: #57534E;
    line-height: 1.45;
}

/* ── Save bar + footer ────────────────────────────────────────────── */

.pm-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(255, 253, 250, 0) 0%, #FFFDFA 20%);
    padding: 24px 0 16px;
    margin: 16px -28px 0;
    padding-left: 28px;
    padding-right: 28px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    border-top: 1px solid #F0EBE0;
}

.pm-save-btn {
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.005em;
    color: #FFFDFA;
    background: #1F4A37;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    cursor: pointer;
    min-height: 44px;
    min-width: 160px;
    transition: background 150ms ease;
}
.pm-save-btn:hover,
.pm-save-btn:focus-visible {
    background: #143229;
    outline: none;
}
.pm-save-btn:focus-visible {
    box-shadow: 0 0 0 2px #C4532B;
}
.pm-save-btn[data-busy="1"] {
    background: #5F7566;
    cursor: wait;
}

.pm-actions__status {
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 13px;
    color: #1F4A37;
    font-weight: 500;
}

.pm-footer {
    padding: 18px 0 6px;
    text-align: center;
    font-family: 'DM Sans', -apple-system, sans-serif;
    font-size: 13px;
    color: #6B6458;
    line-height: 1.5;
}
.pm-footer__link {
    color: #1F4A37;
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: #B5AD9C;
    text-underline-offset: 2px;
}
.pm-footer__link:hover,
.pm-footer__link:focus-visible {
    text-decoration-color: #1F4A37;
    outline: none;
}

/* ── Mobile — full-screen, simpler accordion look ─────────────────── */

@media (max-width: 600px) {
    .pm-modal-overlay {
        padding: 0;
    }
    .pm-modal {
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }
    .pm-modal__header {
        padding: 16px 20px 12px;
    }
    .pm-modal__title {
        font-size: 19px;
    }
    .pm-modal__body {
        padding: 8px 20px 0;
    }
    .pm-checkbox-grid {
        grid-template-columns: 1fr;
    }
    .pm-radio-row {
        gap: 16px;
    }
    .pm-actions {
        margin-left: -20px;
        margin-right: -20px;
        padding-left: 20px;
        padding-right: 20px;
    }
    .pm-save-btn {
        flex: 1;
        min-width: 0;
    }
}

/* ── Reduced motion ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .pm-modal-overlay.open { animation: none; }
    .pm-modal { animation: none; }
    .pm-section__chevron { transition: none; }
}
