/*
 * FlavorForms — Frontend Stylesheet
 * ────────────────────────────────────
 * HTML5-first, minimal-JavaScript form presentation.
 *
 * CSS techniques used (no JS needed):
 * • :valid / :invalid  — live field feedback
 * • :checked ~ label   — CSS-only star rating fill
 * • position:absolute + opacity:0 — honeypot hiding
 * • CSS grid           — responsive full/half/third columns
 * • <details>/<summary>— accessible accordion sections
 */

/* ── 1. Variables ──────────────────────────────────────────────────────────── */
:root {
    --ff-primary:        #2563eb;
    --ff-primary-hover:  #1d4ed8;
    --ff-danger:         #dc2626;
    --ff-success:        #16a34a;
    --ff-border:         #cbd5e1;
    --ff-border-focus:   #2563eb;
    --ff-bg:             #ffffff;
    --ff-bg-subtle:      #f8fafc;
    --ff-text:           #1e293b;
    --ff-muted:          #64748b;
    --ff-star-on:        #f59e0b;
    --ff-star-off:       #d1d5db;
    --ff-radius:         7px;
    --ff-focus-ring:     0 0 0 3px rgba(37,99,235,.22);
    --ff-transition:     150ms ease;
}

/* ── 2. Wrap & meta ─────────────────────────────────────────────────────────── */
.ff-form-wrap {
    color: var(--ff-text);
    max-width: 720px;
}

.ff-form-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 .4rem;
}

.ff-form-description {
    color: var(--ff-muted);
    margin: 0 0 1.5rem;
    line-height: 1.65;
}

/* ── 3. Multi-page progress bar ─────────────────────────────────────────────── */
.ff-page-nav {
    display: flex;
    gap: .5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.ff-page-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ff-border);
    display: inline-block;
    transition: background var(--ff-transition);
}

.ff-page-dot:first-child { background: var(--ff-primary); }

/* ── 4. Field layout grid ───────────────────────────────────────────────────── */
.ff-fields {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1.25rem 1rem;
    margin-bottom: 1.25rem;
}

.ff-field--full  { grid-column: span 6; }
.ff-field--half  { grid-column: span 3; }
.ff-field--third { grid-column: span 2; }

@media (max-width: 600px) {
    .ff-field--half,
    .ff-field--third { grid-column: span 6; }
}

/* ── 5. Labels & descriptions ───────────────────────────────────────────────── */
.ff-label {
    display: block;
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .35rem;
    cursor: pointer;
}

.ff-required { color: var(--ff-danger); }

.ff-description {
    font-size: .8125rem;
    color: var(--ff-muted);
    margin-top: .3rem;
    line-height: 1.5;
}

/* ── 6. Native inputs ───────────────────────────────────────────────────────── */
.ff-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: .55rem .75rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--ff-text);
    background: var(--ff-bg);
    border: 1.5px solid var(--ff-border);
    border-radius: var(--ff-radius);
    transition: border-color var(--ff-transition), box-shadow var(--ff-transition);
    -webkit-appearance: none;
    appearance: none;
}

.ff-input::placeholder { color: var(--ff-muted); }

.ff-input:focus {
    outline: none;
    border-color: var(--ff-border-focus);
    box-shadow: var(--ff-focus-ring);
}

/* HTML5 :valid/:invalid — only show after user interaction via :not(:placeholder-shown) */
.ff-input:not(:placeholder-shown):invalid {
    border-color: var(--ff-danger);
    box-shadow: 0 0 0 3px rgba(220,38,38,.15);
}

.ff-input:not(:placeholder-shown):valid {
    border-color: var(--ff-success);
}

/* Color picker — constrain height */
input[type="color"].ff-input {
    padding: .25rem;
    height: 2.5rem;
    cursor: pointer;
}

/* File input */
input[type="file"].ff-input {
    padding: .4rem .6rem;
    cursor: pointer;
}

/* Range — remove default and add custom track/thumb */
input[type="range"].ff-input {
    padding: .6rem 0;
    border: none;
    box-shadow: none;
    background: transparent;
    cursor: pointer;
}

input[type="range"].ff-input::-webkit-slider-runnable-track {
    height: 5px;
    background: var(--ff-border);
    border-radius: 3px;
}

input[type="range"].ff-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ff-primary);
    margin-top: -6.5px;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

input[type="range"].ff-input::-moz-range-track {
    height: 5px;
    background: var(--ff-border);
    border-radius: 3px;
}

input[type="range"].ff-input::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--ff-primary);
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

/* Range output bubble */
.ff-range-output {
    display: inline-block;
    background: var(--ff-primary);
    color: #fff;
    font-size: .75rem;
    font-weight: 600;
    padding: .15rem .4rem;
    border-radius: 4px;
    margin-top: .3rem;
}

/* ── 7. Textarea ────────────────────────────────────────────────────────────── */
.ff-textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: .55rem .75rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--ff-text);
    background: var(--ff-bg);
    border: 1.5px solid var(--ff-border);
    border-radius: var(--ff-radius);
    resize: vertical;
    min-height: 110px;
    transition: border-color var(--ff-transition), box-shadow var(--ff-transition);
}

.ff-textarea::placeholder { color: var(--ff-muted); }

.ff-textarea:focus {
    outline: none;
    border-color: var(--ff-border-focus);
    box-shadow: var(--ff-focus-ring);
}

.ff-textarea:not(:placeholder-shown):invalid { border-color: var(--ff-danger); }
.ff-textarea:not(:placeholder-shown):valid   { border-color: var(--ff-success); }

/* ── 8. Select ──────────────────────────────────────────────────────────────── */
.ff-select {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: .55rem 2.2rem .55rem .75rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--ff-text);
    background: var(--ff-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E") no-repeat right .75rem center;
    border: 1.5px solid var(--ff-border);
    border-radius: var(--ff-radius);
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border-color var(--ff-transition), box-shadow var(--ff-transition);
}

.ff-select:focus {
    outline: none;
    border-color: var(--ff-border-focus);
    box-shadow: var(--ff-focus-ring);
}

/* Multi-select */
select[multiple].ff-select {
    padding-right: .75rem;
    background-image: none;
    min-height: 120px;
}

/* ── 9. Radio & Checkbox groups ─────────────────────────────────────────────── */
.ff-radio-group,
.ff-checkbox-group {
    border: none;
    margin: 0;
    padding: 0;
}

.ff-radio-group legend,
.ff-checkbox-group legend,
.ff-field-label {
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: .5rem;
    display: block;
}

.ff-radio-label,
.ff-checkbox-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .6rem;
    border-radius: 5px;
    cursor: pointer;
    font-size: .9375rem;
    transition: background var(--ff-transition);
    margin-bottom: .2rem;
}

.ff-radio-label:hover,
.ff-checkbox-label:hover {
    background: var(--ff-bg-subtle, #f8fafc);
}

.ff-radio,
.ff-checkbox {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--ff-primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* ── 10. Star Rating (CSS-only) ─────────────────────────────────────────────── */
/*
 * Technique:
 *   Inputs are rendered in REVERSE order (5→1) then the labels follow.
 *   CSS uses :checked ~ .ff-rating__star to fill stars left of the selection,
 *   and :hover + sibling selectors for hover preview.
 *   Because inputs are in reverse order in the DOM but visually reversed by
 *   flex-direction:row-reverse, selecting star N fills all stars ≥ N.
 */

.ff-rating-group {
    border: none;
    margin: 0;
    padding: 0;
}

.ff-rating {
    display: inline-flex;
    flex-direction: row-reverse;
    gap: .15rem;
}

/* Hide the actual radio inputs */
.ff-rating__input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.ff-rating__star {
    font-size: 2rem;
    color: var(--ff-star-off);
    cursor: pointer;
    transition: color var(--ff-transition), transform var(--ff-transition);
    line-height: 1;
    -webkit-user-select: none;
    user-select: none;
}

/* Fill stars on hover — CSS sibling trick (inputs are reversed) */
.ff-rating__input:hover ~ .ff-rating__star,
.ff-rating__input:checked ~ .ff-rating__star {
    color: var(--ff-star-on);
}

/* Scale the selected star slightly */
.ff-rating__input:checked + .ff-rating__star {
    transform: scale(1.2);
}

.ff-rating__star:hover,
.ff-rating__star:hover ~ .ff-rating__star {
    color: var(--ff-star-on);
}

/* ── 11. Matrix table ───────────────────────────────────────────────────────── */
.ff-matrix {
    border: none;
    margin: 0;
    padding: 0;
}

.ff-matrix-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ff-matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.ff-matrix-table th,
.ff-matrix-table td {
    padding: .6rem .75rem;
    text-align: center;
    border: 1px solid var(--ff-border);
}

.ff-matrix-table thead th {
    background: var(--ff-bg-subtle, #f8fafc);
    font-weight: 600;
    font-size: .8125rem;
}

.ff-matrix-table tbody th {
    text-align: left;
    font-weight: 500;
    background: var(--ff-bg-subtle, #f8fafc);
}

.ff-matrix-table input[type="radio"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--ff-primary);
    cursor: pointer;
}

/* ── 12. Section header ─────────────────────────────────────────────────────── */
.ff-section {
    padding-bottom: .75rem;
    border-bottom: 2px solid var(--ff-border);
    margin-bottom: .25rem;
}

.ff-section-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 .3rem;
}

.ff-section-desc {
    color: var(--ff-muted);
    font-size: .875rem;
    line-height: 1.6;
}

/* ── 13. Navigation buttons ─────────────────────────────────────────────────── */
.ff-nav {
    display: flex;
    gap: .75rem;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--ff-border);
}

.ff-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .6rem 1.4rem;
    font-size: .9375rem;
    font-family: inherit;
    font-weight: 600;
    border-radius: var(--ff-radius);
    border: 2px solid transparent;
    cursor: pointer;
    transition: background var(--ff-transition), border-color var(--ff-transition), transform 80ms ease;
    text-decoration: none;
    white-space: nowrap;
}

.ff-btn:active { transform: scale(.98); }

.ff-btn--primary {
    background: var(--ff-primary);
    color: #fff;
    border-color: var(--ff-primary);
    margin-left: auto;
}

.ff-btn--primary:hover,
.ff-btn--primary:focus {
    background: var(--ff-primary-hover, #1d4ed8);
    border-color: var(--ff-primary-hover, #1d4ed8);
    outline: none;
    box-shadow: var(--ff-focus-ring);
}

.ff-btn--secondary {
    background: transparent;
    color: var(--ff-text);
    border-color: var(--ff-border);
}

.ff-btn--secondary:hover {
    background: var(--ff-bg-subtle, #f8fafc);
}

/* ── 14. Confirmation panel ─────────────────────────────────────────────────── */
.ff-confirmation {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    background: #f0fdf4;
    border: 2px solid #bbf7d0;
    border-radius: var(--ff-radius);
    padding: 1.5rem;
    color: #166534;
}

.ff-confirmation__icon {
    font-size: 2rem;
    line-height: 1;
    flex-shrink: 0;
    background: #dcfce7;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ff-confirmation__message {
    font-size: 1rem;
    line-height: 1.65;
}

/* ── 15. Notices ────────────────────────────────────────────────────────────── */
.ff-notice {
    padding: .85rem 1.1rem;
    border-radius: var(--ff-radius);
    font-size: .9375rem;
    margin-bottom: 1rem;
    border-left: 4px solid transparent;
}

.ff-notice--error {
    background: #fff1f2;
    border-color: var(--ff-danger);
    color: #9f1239;
}

.ff-notice--info {
    background: #eff6ff;
    border-color: var(--ff-primary);
    color: #1e40af;
}

/* Individual field error (via transient redirect) */
.ff-field--error .ff-input,
.ff-field--error .ff-textarea,
.ff-field--error .ff-select {
    border-color: var(--ff-danger);
}

.ff-field__error-msg {
    color: var(--ff-danger);
    font-size: .8125rem;
    margin-top: .3rem;
    display: block;
}

/* ── 16. Honeypot (invisible to real users) ─────────────────────────────────── */
.ff-hp {
    position: absolute;
    left: -9999px;
    opacity: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    pointer-events: none;
    tab-size: -1;
}

/* ── 17. Accessibility utilities ────────────────────────────────────────────── */
.ff-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Focus-visible for keyboard navigation */
.ff-btn:focus-visible,
.ff-input:focus-visible,
.ff-textarea:focus-visible,
.ff-select:focus-visible {
    outline: 2px solid var(--ff-primary);
    outline-offset: 2px;
}

/* ── 18. Fieldset / page container ──────────────────────────────────────────── */
.ff-page {
    border: none;
    margin: 0;
    padding: 0;
}

/* For multi-page forms, non-active pages are hidden server-side;
   no CSS toggling needed since PHP only renders the current page
   fieldset. The following keeps fieldset styling clean. */
.ff-form--paged .ff-page {
    display: block;
}
