/* =============================================================
   Communities Surveys — styling for:
     • CustomFieldFormRenderer (shared renderer, edit + read-only)
     • CreateSurveyWizard + WizardStep* + WizardListOptionsEditor
     • SurveyPost feed card (with PreviewMode) — includes the answered-state
       expander panel (compact badge + collapse/expand + skeleton shimmer)
     • SurveyResponseModal (fill-in)

   All colors respect the Communities CSS-variable contract:
     --community-primary, --community-accent  (per-community branding)
     --text-primary (#1f2937), --text-secondary (#4B5563)  (WCAG AA fixed)

   Touch targets ≥ 44px where interactive. Focus outlines preserved.
   ============================================================= */

/* --------- shared field renderer --------- */
.cf-field-group {
    margin: 0 0 1.25rem 0;
    padding: 0;
}

.cf-field-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.cf-required {
    color: #dc2626;
    margin-left: 0.25rem;
}

.cf-field-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0 0 0.5rem 0;
}

.cf-input,
.cf-textarea,
.cf-select {
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    color: var(--text-primary);
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-sizing: border-box;
}

.cf-textarea {
    min-height: 88px;
    resize: vertical;
    font-family: inherit;
}

.cf-input:focus,
.cf-textarea:focus,
.cf-select:focus {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
    border-color: var(--community-primary, #2563eb);
}

.cf-input.has-error,
.cf-textarea.has-error,
.cf-select.has-error {
    border-color: #dc2626;
}

.cf-field-error {
    color: #dc2626;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.cf-radio-group,
.cf-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cf-radio-option,
.cf-checkbox-option,
.cf-toggle-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.25rem;
    min-height: 44px;
    cursor: pointer;
    color: var(--text-primary);
}

.cf-radio-option input,
.cf-checkbox-option input,
.cf-toggle-option input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.cf-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cf-chip {
    padding: 0.5rem 1rem;
    min-height: 44px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    color: var(--text-primary);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.9375rem;
}

.cf-chip.selected {
    background: var(--community-primary, #2563eb);
    color: #ffffff;
    border-color: var(--community-primary, #2563eb);
}

.cf-chip:focus {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

.cf-rating {
    display: flex;
    gap: 0.25rem;
}

.cf-star {
    background: none;
    border: 0;
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.5rem;
    color: #d1d5db;
    cursor: pointer;
}

.cf-star.filled {
    color: var(--community-accent, #f59e0b);
}

.cf-star:focus {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

.cf-file-placeholder {
    color: var(--text-secondary);
    font-style: italic;
    padding: 0.75rem;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    background: #f9fafb;
}

/* Read-only variants */
.cf-readonly .cf-readonly-value {
    color: var(--text-primary);
    background: #f9fafb;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    min-height: 2.25rem;
}

.cf-readonly-longtext {
    white-space: pre-wrap;
}

.cf-readonly-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.cf-readonly-pill {
    padding: 0.25rem 0.75rem;
    background: var(--community-primary, #2563eb);
    color: #ffffff;
    border-radius: 999px;
    font-size: 0.875rem;
}

/* --------- wizard shell --------- */
/* Namespaced on .srv-modal-overlay to avoid colliding with the global modals.css
   .modal-overlay class (which is display:none by default and only visible when
   a .active class is toggled on). */
.srv-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.survey-wizard-modal,
.survey-fill-modal {
    background: #ffffff;
    border-radius: 12px;
    width: min(640px, 100%);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.survey-wizard-modal .srv-modal-header,
.survey-fill-modal .srv-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}

.survey-wizard-modal .srv-modal-header h2,
.survey-fill-modal .srv-modal-header h2 {
    margin: 0;
    font-size: 1.125rem;
    color: var(--text-primary);
}

.srv-modal-close-btn {
    background: none;
    border: 0;
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
}

.srv-modal-close-btn:hover,
.srv-modal-close-btn:focus {
    background: #f3f4f6;
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

.survey-wizard-modal .srv-modal-body,
.survey-fill-modal .srv-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    flex: 1 1 auto;
}

.survey-wizard-modal .srv-modal-actions,
.survey-fill-modal .srv-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1rem 1.25rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.wizard-error,
.srv-modal-error {
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 0.75rem;
    border-radius: 6px;
    margin-top: 1rem;
}

/* wizard steps */
.wizard-step {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.wizard-step-heading {
    font-size: 1rem;
    color: var(--text-primary);
    margin: 0;
}

.wizard-step-subtitle {
    color: var(--text-secondary);
    margin: 0;
    font-size: 0.9375rem;
}

.wizard-field-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.wizard-field-label {
    font-weight: 600;
    color: var(--text-primary);
}

.wizard-input,
.wizard-textarea,
.wizard-select {
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-sizing: border-box;
    color: var(--text-primary);
}

.wizard-textarea {
    min-height: 66px;
    resize: vertical;
    font-family: inherit;
}

.wizard-input:focus,
.wizard-textarea:focus,
.wizard-select:focus {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
    border-color: var(--community-primary, #2563eb);
}

.wizard-field-toggle {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.wizard-toggle-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    cursor: pointer;
    color: var(--text-primary);
}

.wizard-helper {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

/* Options editor (list types) */
.wizard-options-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.wizard-options-heading {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.wizard-option-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.wizard-option-remove {
    background: none;
    border: 0;
    width: 44px;
    height: 44px;
    color: #dc2626;
    cursor: pointer;
    border-radius: 6px;
}

.wizard-option-remove:hover:not(:disabled),
.wizard-option-remove:focus {
    background: #fef2f2;
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

.wizard-option-remove:disabled {
    color: #d1d5db;
    cursor: not-allowed;
}

.wizard-option-add {
    align-self: flex-start;
    background: transparent;
    border: 1px dashed var(--community-primary, #2563eb);
    color: var(--community-primary, #2563eb);
    padding: 0.5rem 1rem;
    min-height: 44px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.wizard-option-add:hover,
.wizard-option-add:focus {
    background: var(--community-primary, #2563eb);
    color: #ffffff;
    outline: none;
}

.wizard-validation {
    color: #dc2626;
    font-size: 0.875rem;
    margin: 0;
}

.wizard-preview-container {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    background: #f9fafb;
}

/* --------- survey post (feed card) --------- */
.post.survey-post {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.survey-post .post-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.survey-post .post-author {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.survey-post .post-author-info {
    display: flex;
    flex-direction: column;
}

.survey-post .post-author-name {
    font-weight: 600;
    color: var(--text-primary);
}

.survey-post .post-timeago {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

.survey-post .post-delete-btn {
    background: none;
    border: 0;
    width: 44px;
    height: 44px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
}

.survey-post .post-delete-btn:hover,
.survey-post .post-delete-btn:focus {
    background: #f3f4f6;
    color: #dc2626;
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

.survey-post-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.survey-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: color-mix(in srgb, var(--community-primary, #2563eb) 15%, #ffffff);
    color: var(--community-primary, #2563eb);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    align-self: flex-start;
}

.survey-card-title {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.125rem;
}

.survey-card-meta {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.survey-take-cta {
    align-self: flex-start;
}

/* --------- shared button base (in case the project doesn't already have one) --------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    min-height: 44px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    border: 1px solid transparent;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--community-primary, #2563eb);
    color: #ffffff;
    border-color: var(--community-primary, #2563eb);
}

.btn-primary:hover:not(:disabled),
.btn-primary:focus {
    filter: brightness(0.9);
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

.btn-secondary {
    background: #ffffff;
    color: var(--text-primary);
    border-color: #d1d5db;
}

.btn-secondary:hover:not(:disabled),
.btn-secondary:focus {
    background: #f3f4f6;
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

/* --------- comment-input poll icon --------- */
.comment-poll-btn {
    background: none;
    border: 0;
    width: 44px;
    height: 44px;
    color: var(--community-primary, #2563eb);
    cursor: pointer;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
}

.comment-poll-btn:hover:not(:disabled),
.comment-poll-btn:focus {
    background: color-mix(in srgb, var(--community-primary, #2563eb) 10%, #ffffff);
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: 2px;
}

.comment-poll-btn:disabled {
    color: #d1d5db;
    cursor: not-allowed;
}

/* --------- survey own-answers card --------- */
.survey-own-answers {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.survey-own-answers-heading {
    margin: 0;
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 600;
}

.survey-own-answers-empty {
    color: var(--text-secondary);
    font-style: italic;
    margin: 0;
}

.survey-answers-loading,
.srv-modal-loading {
    display: flex;
    justify-content: center;
    padding: 1.5rem;
    color: var(--community-primary, #2563eb);
    font-size: 1.25rem;
}

/* --------- visually-hidden (repeats project-wide pattern, scoped-safe) --------- */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =============================================================
   Survey answered panel (compact badge + collapse/expand)
   Renders inside SurveyPost when the user has already submitted.
   Auto-expanded once on just-submitted (one-shot pulse animation),
   collapsed-by-default on subsequent feed loads.
   ============================================================= */

.survey-answered-panel {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: linear-gradient(180deg, #ffffff 0%, #f9fafb 100%);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.survey-answered-panel:hover,
.survey-answered-panel:focus-within {
    border-color: var(--community-primary, #2563eb);
}

.survey-answered-panel.is-just-submitted {
    border-color: var(--community-primary, #2563eb);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--community-primary, #2563eb) 20%, transparent);
    animation: survey-answered-pulse 1.6s ease-out 1;
}

@keyframes survey-answered-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--community-primary, #2563eb) 45%, transparent); }
    70%  { box-shadow: 0 0 0 14px color-mix(in srgb, var(--community-primary, #2563eb) 0%, transparent); }
    100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--community-primary, #2563eb) 20%, transparent); }
}

.survey-answered-toggle {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    min-height: 48px;
    padding: 0.5rem 0.875rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    text-align: left;
    color: var(--text-primary, #1f2937);
    font-size: 0.9375rem;
    font-weight: 500;
}

.survey-answered-toggle:hover,
.survey-answered-toggle:focus-visible {
    background: color-mix(in srgb, var(--community-primary, #2563eb) 8%, transparent);
    outline: none;
}

.survey-answered-toggle:focus-visible {
    outline: 2px solid var(--community-primary, #2563eb);
    outline-offset: -2px;
}

.survey-answered-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--community-primary, #2563eb) 15%, #ffffff);
    color: var(--community-primary, #2563eb);
    font-size: 1rem;
    flex: 0 0 auto;
}

.survey-answered-panel.is-just-submitted .survey-answered-check {
    background: var(--community-primary, #2563eb);
    color: #ffffff;
    animation: survey-answered-check-pop 0.5s cubic-bezier(0.22, 1, 0.36, 1) 1;
}

@keyframes survey-answered-check-pop {
    0%   { transform: scale(0.6); }
    60%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.survey-answered-label {
    flex: 1 1 auto;
    font-weight: 600;
}

.survey-answered-cta {
    color: var(--community-primary, #2563eb);
    font-weight: 600;
    font-size: 0.875rem;
    flex: 0 0 auto;
}

.survey-answered-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    color: var(--text-secondary, #4B5563);
    transition: transform 0.2s ease;
    flex: 0 0 auto;
}

.survey-answered-chevron.rotated {
    transform: rotate(180deg);
}

.survey-answered-details {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    padding: 0 0.875rem;
}

.survey-answered-details.open {
    /* NOTE: 4000px is a soft ceiling that accommodates a typical poll (1–20 questions).
       Animating to "max-height: auto" is not possible in CSS, hence the fixed cap. If a future
       survey author posts a poll with so many questions that the content exceeds 4000px, the
       panel will silently clip. Bump this cap (or switch to the display:grid-template-rows
       0fr/1fr trick) if that ever happens. */
    max-height: 4000px;
    opacity: 1;
    padding: 0.5rem 0.875rem 0.875rem 0.875rem;
    border-top: 1px solid #e5e7eb;
}

/* Override CustomFieldFormRenderer field spacing inside the panel for tighter read-out layout */
.survey-answered-details .cf-field-group {
    margin: 0.75rem 0;
}

.survey-answered-details .cf-field-group:first-child {
    margin-top: 0.5rem;
}

.survey-answered-details .cf-field-group:last-child {
    margin-bottom: 0;
}

/* Skeleton shimmer while lazy-loading answers on first expand */
.survey-answered-skeleton {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    padding: 0.75rem 0;
}

.survey-answered-skeleton-row {
    height: 14px;
    border-radius: 4px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 37%, #f3f4f6 63%);
    background-size: 200% 100%;
    animation: survey-skeleton-shimmer 1.4s ease-in-out infinite;
}

.survey-answered-skeleton-row:nth-child(1) { width: 72%; }
.survey-answered-skeleton-row:nth-child(2) { width: 94%; }
.survey-answered-skeleton-row:nth-child(3) { width: 60%; }

@keyframes survey-skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.survey-answered-error {
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin: 0.5rem 0 0 0;
    font-size: 0.875rem;
}

/* --------- reduced motion --------- */
@media (prefers-reduced-motion: reduce) {
    .fa-spin {
        animation: none !important;
    }
    .survey-answered-panel,
    .survey-answered-chevron,
    .survey-answered-details,
    .survey-answered-toggle {
        transition: none !important;
    }
    .survey-answered-panel.is-just-submitted,
    .survey-answered-panel.is-just-submitted .survey-answered-check,
    .survey-answered-skeleton-row {
        animation: none !important;
    }
}
