/* Public forms: forms from the form builder and the feedback pop-up
   (form-kit.js). Uses the site's own colours and fonts from portfolio.css:
   hover and focus states, inline validation, counters, styled checkboxes,
   radio buttons, drop-downs and date fields, and the submit button states. */

.fk-form {
    --fk-ok: var(--accent-bright);
    --fk-warn: var(--warning);
    --fk-bad: #ff6b61;
    --fk-glow: rgba(var(--accent-bright-rgb), 0.28);
}

/* --- Text fields, drop-downs, dates: hover and focus ----------------------- */

.fk-form input[type="text"],
.fk-form input[type="number"],
.fk-form input[type="url"],
.fk-form input[type="date"],
.fk-form input[type="search"],
.fk-form textarea,
.fk-form select {
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.fk-form input[type="text"]:hover,
.fk-form input[type="number"]:hover,
.fk-form input[type="url"]:hover,
.fk-form input[type="date"]:hover,
.fk-form input[type="search"]:hover,
.fk-form textarea:hover,
.fk-form select:hover {
    border-color: #2c5a5c;
}

.fk-form input[type="text"]:focus,
.fk-form input[type="number"]:focus,
.fk-form input[type="url"]:focus,
.fk-form input[type="date"]:focus,
.fk-form input[type="search"]:focus,
.fk-form textarea:focus,
.fk-form select:focus {
    outline: none;
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 3px var(--fk-glow);
}

/* Keyboard focus stays clearly visible everywhere. */
.fk-form :focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 2px;
}

.fk-form input[type="text"]:focus-visible,
.fk-form input[type="number"]:focus-visible,
.fk-form input[type="url"]:focus-visible,
.fk-form input[type="date"]:focus-visible,
.fk-form input[type="search"]:focus-visible,
.fk-form textarea:focus-visible,
.fk-form select:focus-visible {
    outline: none;
}

/* Drop-downs: the site's arrow instead of the browser's. */
.fk-form select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: calc(40px * var(--space-scale));
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238fa8a7' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    cursor: pointer;
}

.fk-form select option {
    background: var(--surface);
    color: var(--text);
}

/* Dates: dark calendar, the site's accent on the picker icon. */
.fk-form input[type="date"] {
    color-scheme: dark;
}

.fk-form input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.75;
    filter: invert(62%) sepia(55%) saturate(560%) hue-rotate(126deg);
}

.fk-form input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

/* --- Checkboxes and radio buttons ------------------------------------------- */

.fk-form input[type="checkbox"],
.fk-form input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    min-width: 20px;
    margin: 0;
    padding: 0;
    border: 2px solid #3a6a6c;
    background: var(--surface);
    border-radius: calc(5px * var(--radius-scale));
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    flex: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    vertical-align: middle;
}

.fk-form input[type="radio"] {
    border-radius: 50%;
}

.fk-form input[type="checkbox"]:hover,
.fk-form input[type="radio"]:hover {
    border-color: var(--accent-bright);
}

.fk-form input[type="checkbox"]:focus-visible,
.fk-form input[type="radio"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--fk-glow);
    border-color: var(--accent-bright);
}

.fk-form input[type="checkbox"]:checked {
    background: var(--accent-bright) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='10' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3.5 3.5L11 1.5' fill='none' stroke='%2306201e' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center no-repeat;
    border-color: var(--accent-bright);
}

.fk-form input[type="radio"]:checked {
    border-color: var(--accent-bright);
    background: radial-gradient(circle, var(--accent-bright) 0 4px, var(--surface) 5px);
}

/* The pop-up's own "Contact me" / "Bug" boxes keep their look. */
.fk-form .checkbox-container input[type="checkbox"] {
    appearance: auto;
    -webkit-appearance: checkbox;
}

.fk-form .site-form-check {
    display: flex;
    gap: calc(10px * var(--space-scale));
    align-items: center;
    padding: calc(4px * var(--space-scale)) 0;
}

/* The pop-up styles every label and input as a block field. */
.popup.fk-form .site-form-check {
    color: var(--text);
    font-weight: 400;
    margin-bottom: calc(6px * var(--space-scale));
}

.popup.fk-form .site-form-field {
    margin: 0 0 calc(20px * var(--space-scale));
    padding: 0;
    border: 0;
}

/* Anything the script hides (search results, closed panels) stays hidden,
   whatever display the element normally has. */
.fk-form [hidden] {
    display: none !important;
}

/* --- Validation ------------------------------------------------------------------- */

/* Element + class: must beat the field styles of forms.css and feedback.css. */
.fk-form input.fk-invalid,
.fk-form textarea.fk-invalid,
.fk-form select.fk-invalid,
.fk-form input.fk-invalid:hover,
.fk-form textarea.fk-invalid:hover,
.fk-form select.fk-invalid:hover {
    border-color: var(--fk-bad);
}

.fk-form input.fk-invalid:focus,
.fk-form textarea.fk-invalid:focus,
.fk-form select.fk-invalid:focus {
    border-color: var(--fk-bad);
    box-shadow: 0 0 0 3px rgba(255, 107, 97, 0.25);
}

/* A small tick inside valid fields. */
.fk-form input.fk-valid,
.fk-form textarea.fk-valid {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='11' viewBox='0 0 14 11'%3E%3Cpath d='M1.5 5.5l4 4L12.5 1.5' fill='none' stroke='%2317a398' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 15px;
    padding-right: calc(36px * var(--space-scale));
}

.fk-form input[type="date"].fk-valid {
    background-image: none;
    padding-right: calc(14px * var(--space-scale));
}

.fk-form fieldset.fk-valid > legend::after {
    content: " ✓";
    color: var(--fk-ok);
}

.fk-form fieldset.fk-invalid {
    border: 0;
}

.fk-error {
    color: var(--fk-bad);
    font-size: 0.88em;
    margin: calc(6px * var(--space-scale)) 0 0;
}

.fk-error::before {
    content: "! ";
    font-weight: 700;
}

/* The pop-up's fields have 20px below them: the message tucks in. */
.popup.fk-form > .fk-error,
.popup.fk-form > .fk-counter {
    margin: calc(-14px * var(--space-scale)) 0 calc(16px * var(--space-scale));
    text-align: left;
}

/* --- Counters ------------------------------------------------------------------------ */

.fk-counter {
    margin: calc(4px * var(--space-scale)) 0 0;
    text-align: right;
    font-size: 0.82em;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    transition: color 0.15s ease;
}

.fk-counter.fk-near {
    color: var(--fk-warn);
}

.fk-counter.fk-full {
    color: var(--fk-bad);
    font-weight: 600;
}

/* --- Long drop-downs: search ------------------------------------------------------- */

.fk-form .fk-search {
    width: 100%;
    margin-bottom: calc(8px * var(--space-scale));
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: calc(8px * var(--radius-scale));
    padding: calc(9px * var(--space-scale)) calc(12px * var(--space-scale));
    font: inherit;
    font-size: 0.95em;
}

.fk-none {
    color: var(--text-muted);
    font-size: 0.88em;
    margin: calc(4px * var(--space-scale)) 0;
}

/* --- Drop-downs with several choices --------------------------------------------- */

.fk-form .fk-multi-toggle {
    width: 100%;
    text-align: left;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%238fa8a7' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: calc(8px * var(--radius-scale));
    padding: calc(12px * var(--space-scale)) calc(40px * var(--space-scale)) calc(12px * var(--space-scale)) calc(14px * var(--space-scale));
    font: inherit;
    font-weight: 400;
    cursor: pointer;
    box-shadow: none;
    transform: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fk-form .fk-multi-toggle:hover {
    border-color: #2c5a5c;
    transform: none;
    box-shadow: none;
}

.fk-form .fk-multi-toggle:focus-visible,
.fk-form .fk-open .fk-multi-toggle {
    outline: none;
    border-color: var(--accent-bright);
    box-shadow: 0 0 0 3px var(--fk-glow);
}

.fk-form .fk-multi-toggle.fk-placeholder {
    color: var(--text-muted);
}

.fk-form .fk-invalid .fk-multi-toggle {
    border-color: var(--fk-bad);
}

.fk-multi-panel {
    margin-top: calc(6px * var(--space-scale));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(8px * var(--radius-scale));
    padding: calc(8px * var(--space-scale)) calc(12px * var(--space-scale));
    max-height: 260px;
    overflow-y: auto;
}

.fk-multi-list .site-form-check {
    padding: calc(6px * var(--space-scale)) 0;
}

.site-form-limits {
    font-weight: 400;
    color: var(--text-muted);
}

/* --- Submit button -------------------------------------------------------------------- */

.fk-form button.fk-loading {
    position: relative;
    cursor: progress;
    opacity: 0.85;
    padding-left: calc(48px * var(--space-scale));
}

.fk-form button.fk-loading::before {
    content: "";
    position: absolute;
    left: 20px;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-top: calc(-8px * var(--space-scale));
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: var(--text-strong);
    border-radius: 50%;
    animation: fk-spin 0.7s linear infinite;
}

.fk-form button.fk-success {
    background: var(--accent-bright);
    color: #06201e;
}

.fk-form button.fk-error {
    background: #8c2a22;
    color: var(--text-strong);
    animation: fk-shake 0.35s ease;
}

@keyframes fk-spin {
    to { transform: rotate(360deg); }
}

@keyframes fk-shake {
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

@media (prefers-reduced-motion: reduce) {
    .fk-form *,
    .fk-form button.fk-loading::before {
        transition: none !important;
        animation-duration: 0s !important;
    }
}

/* --- Spam check note -------------------------------------------------------------- */

.site-form-captcha {
    margin: calc(-6px * var(--space-scale)) 0 0;
    color: var(--text-muted);
    font-size: 0.82em;
    display: flex;
    align-items: center;
    gap: calc(6px * var(--space-scale));
}

.site-form-captcha::before {
    content: "";
    width: 12px;
    height: 14px;
    flex: none;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='14' viewBox='0 0 12 14'%3E%3Cpath d='M6 1l5 2v4c0 3-2.2 5.3-5 6-2.8-.7-5-3-5-6V3z' fill='none' stroke='%2317a398' stroke-width='1.5'/%3E%3C/svg%3E") center no-repeat;
}
