/*!
 * FormFabricator — Frontend Styles
 * @copyright 2026 Alexander Jorek
 * @license   GPL-3.0-or-later
 */

/* ── Design tokens ────────────────────────────────────────────────────────────
 * --fabricator-accent (Settings → Appearance) arrives as an inline <style>; every component uses it.
 * ──────────────────────────────────────────────────────────────────────────── */
:root {
    --fabricator-accent:        #f59e0b;
    --fabricator-accent-dark:   #d97706;
    --fabricator-accent-light:  #fffbeb;

    --fabricator-text:          #1d2327;
    --fabricator-text-muted:    #50575e;
    --fabricator-text-subtle:   #787c82;

    --fabricator-border:        #dcdcde;
    --fabricator-border-input:  #c9cdd4;

    --fabricator-bg:            #ffffff;
    --fabricator-bg-subtle:     #f6f7f7;
    --fabricator-bg-muted:      #f0f0f1;

    --fabricator-error:         #b32d2e;
    --fabricator-error-bg:      #fce8e8;
    --fabricator-success:       #00a32a;
    --fabricator-success-bg:    #d6f5df;

    --fabricator-radius:        5px;
    --fabricator-radius-sm:     3px;
    --fabricator-input-height:  40px;
    --fabricator-font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --fabricator-font-size:     15px;
    --fabricator-gap:           20px;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
.fabricator-form-wrap {
    width: 100%;
    font-family: var(--fabricator-font);
    font-size: var(--fabricator-font-size);
    color: var(--fabricator-text);
}

/* ── Messages ─────────────────────────────────────────────────────────────── */
.fabricator-form-messages {
    /* The success message is a multi-line setting shown via textContent; keep its line breaks. */
    white-space: pre-line;
    padding: 12px 16px;
    border-radius: var(--fabricator-radius);
    margin-bottom: var(--fabricator-gap);
    font-size: 14px;
    border: 1px solid transparent;
}
.fabricator-form-messages.success {
    background: var(--fabricator-success-bg);
    border-color: var(--fabricator-success);
    color: #006400;
}
.fabricator-form-messages.error {
    background: var(--fabricator-error-bg);
    border-color: var(--fabricator-error);
    color: var(--fabricator-error);
}

/* ── Field wrapper ────────────────────────────────────────────────────────── */
.fabricator-field {
    margin-bottom: var(--fabricator-gap);
}

.fabricator-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .01em;
    color: var(--fabricator-text);
    margin-bottom: 6px;
}

.fabricator-required {
    color: var(--fabricator-error);
    margin-left: 2px;
}

.fabricator-field-description {
    font-size: 12px;
    color: var(--fabricator-text-muted);
    margin: 0 0 6px;
    line-height: 1.5;
}

.fabricator-field-hint {
    font-size: 12px;
    color: var(--fabricator-text-subtle);
    margin: 5px 0 0;
    line-height: 1.5;
}

.fabricator-field-error {
    font-size: 12px;
    color: var(--fabricator-error);
    margin-top: 4px;
    line-height: 1.4;
}
.fabricator-field-error:empty {
    display: none;
}

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.fabricator-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    height: var(--fabricator-input-height);
    padding: 0 12px;
    border: 1px solid var(--fabricator-border-input) !important;
    border-radius: var(--fabricator-radius);
    font-size: 14px;
    font-family: var(--fabricator-font);
    color: var(--fabricator-text);
    background: var(--fabricator-bg) !important;
    transition: border-color .15s, box-shadow .15s;
    appearance: none !important;
    -webkit-appearance: none !important;
    outline: 0 !important;
    box-shadow: none !important;
}
/* Scope with .fabricator-form to beat theme stylesheets that load after ours */
.fabricator-form .fabricator-input:focus,
.fabricator-form .fabricator-input:focus-visible {
    border-color: var(--fabricator-accent) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--fabricator-accent) 15%, transparent) !important;
}
.fabricator-input::placeholder {
    color: var(--fabricator-text-subtle);
}

textarea.fabricator-input {
    height: auto;
    padding: 10px 12px;
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

/* Visible native selects (e.g. NameField prefix) — restore the chevron that
   appearance:none strips, and ensure the same fabricator focus ring as text inputs. */
select.fabricator-input:not(.fabricator-select-native) {
    padding-right: 32px;
    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' stroke='%238c8f94' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
}

/* Native select is hidden — JS replaces it with .fabricator-select-custom */
select.fabricator-input.fabricator-select-native {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

/* ── Submit ───────────────────────────────────────────────────────────────── */
.fabricator-form-footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--fabricator-border);
    display: flex;
    justify-content: flex-end;
}
/* Set by the page navigation on every page but the last. The submit-button conditions use inline display instead,
   so the two never overwrite each other and the footer shows only when both allow it (front.js: applyPage). */
.fabricator-form-footer.fabricator-footer-off-page {
    display: none;
}
/* Scoped to the form, at a fixed height shared with the page-break buttons (PageBreakField.css): themes give buttons
   their own capitals, letter spacing, shadow, line height and padding with selectors that would win otherwise. */
.fabricator-form .fabricator-submit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
    height: 30px;
    padding: 0 20px;
    background: var(--fabricator-accent);
    color: #fff;
    border: none;
    border-radius: var(--fabricator-radius);
    box-shadow: none;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--fabricator-font);
    line-height: 1.2;
    letter-spacing: normal;
    text-transform: none;
    cursor: pointer;
    transition: background .15s;
}
@keyframes fabricator-btn-spin {
    to { transform: rotate(360deg); }
}
.fabricator-submit-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fabricator-btn-spin .7s linear infinite;
    flex-shrink: 0;
}
.fabricator-form .fabricator-submit-btn:hover {
    background: var(--fabricator-accent-dark);
}
.fabricator-form .fabricator-submit-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ── Multi-column row layout ──────────────────────────────────────────────── */
.fabricator-row {
    display: flex;
    gap: 16px;
    margin-bottom: 0;
}
.fabricator-col {
    min-width: 0;
}
.fabricator-col-12 {
    flex: 0 0 100%;
    width: 100%;
}
.fabricator-col-6 {
    flex: 0 0 calc(50% - 8px);
    width: calc(50% - 8px);
}
.fabricator-row--pair .fabricator-col-6[style*="display: none"] + .fabricator-col-6,
.fabricator-row--pair .fabricator-col-6:has(+ .fabricator-col-6[style*="display: none"]) {
    flex: 0 0 100%;
    width: 100%;
}

.fabricator-noscript-notice {
    color: var(--fabricator-text-muted, #666);
    font-size: 0.9em;
    margin-top: 8px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .fabricator-row   { flex-direction: column; gap: 0; }
    .fabricator-col-6 { flex: 0 0 100%; width: 100%; }
}
