/**
 * DSG Smart Forms — frontend styles.
 * Kept namespace-strict (.dsg-sf-*) to avoid theme collisions.
 */

.dsg-sf-form-wrap {
    /* Design tokens (overridable inline via settings). */
    --dsgsf-primary: #2271b1;
    --dsgsf-radius: 4px;
    --dsgsf-font: inherit;

    max-width: 680px;
    margin: 0 auto;
    font-family: var(--dsgsf-font);
    line-height: 1.5;
}

.dsg-sf-form {
    /* v0.12.3 — flex-wrap row para layout multi-columna.
       Fields con width<100 fluyen side-by-side; width=100 rompe línea. */
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
}

.dsg-sf-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* Default ocupa todo el ancho (se sobreescribe con .dsg-sf-field--w-XX) */
    flex: 1 1 100%;
    min-width: 0; /* permite encogerse dentro del flex-wrap */
}

/* v0.12.3 — Widths. Restamos gap a los % para que 2×50 quepan sin overflow.
   gap=18px → con 2 cols, cada una necesita calc(50% - 9px); con 3 cols, 33% - 12px; etc. */
.dsg-sf-field--w-100 { flex: 1 1 100%; }
.dsg-sf-field--w-66  { flex: 1 1 calc(66.6667% - 6px); max-width: calc(66.6667% - 6px); }
.dsg-sf-field--w-50  { flex: 1 1 calc(50% - 9px);      max-width: calc(50% - 9px); }
.dsg-sf-field--w-33  { flex: 1 1 calc(33.3333% - 12px); max-width: calc(33.3333% - 12px); }
.dsg-sf-field--w-25  { flex: 1 1 calc(25% - 14px);     max-width: calc(25% - 14px); }
/* Responsive — en pantallas angostas todo vuelve a 100% */
@media (max-width: 600px) {
    .dsg-sf-field--w-66, .dsg-sf-field--w-50,
    .dsg-sf-field--w-33, .dsg-sf-field--w-25 { flex: 1 1 100%; max-width: 100%; }
}

.dsg-sf-field--hidden { display: none; }

.dsg-sf-field__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

/* Label placement variants */
.dsg-sf-field--label-top    { flex-direction: column; }
.dsg-sf-field--label-bottom { flex-direction: column-reverse; }

.dsg-sf-field--label-left,
.dsg-sf-field--label-right {
    flex-direction: row;
    align-items: flex-start;
    gap: 14px;
}
.dsg-sf-field--label-right { flex-direction: row-reverse; }

.dsg-sf-field--label-left  .dsg-sf-label,
.dsg-sf-field--label-right .dsg-sf-label {
    flex: 0 0 140px;
    padding-top: 10px;
    margin: 0;
}
.dsg-sf-field--label-left  .dsg-sf-label { text-align: right; }
.dsg-sf-field--label-right .dsg-sf-label { text-align: left; }

.dsg-sf-field--label-hide .dsg-sf-label { display: none; }

/* Stack on small screens even if left/right placement is set */
@media (max-width: 600px) {
    .dsg-sf-field--label-left,
    .dsg-sf-field--label-right {
        flex-direction: column;
        gap: 6px;
    }
    .dsg-sf-field--label-left  .dsg-sf-label,
    .dsg-sf-field--label-right .dsg-sf-label {
        flex: none;
        padding-top: 0;
        text-align: left;
    }
}

.dsg-sf-label {
    font-weight: 600;
    color: inherit;
}

.dsg-sf-required {
    color: #dc3545;
    margin-left: 4px;
}

.dsg-sf-input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    border: 1px solid #ccd0d4;
    border-radius: var(--dsgsf-radius);
    background: #fff;
    color: inherit;
    box-sizing: border-box;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.dsg-sf-input:focus {
    outline: none;
    border-color: var(--dsgsf-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--dsgsf-primary) 18%, transparent);
}

.dsg-sf-input--textarea {
    resize: vertical;
    min-height: 96px;
    font-family: inherit;
}

.dsg-sf-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 0;
}

.dsg-sf-options--radio,
.dsg-sf-options--checkbox {
    padding-left: 2px;
}

.dsg-sf-option,
.dsg-sf-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-weight: 400;
}

.dsg-sf-option input,
.dsg-sf-consent input {
    margin-top: 3px;
    flex-shrink: 0;
}

.dsg-sf-help {
    font-size: 13px;
    color: #646970;
    margin: 0;
}

.dsg-sf-error {
    color: #dc3545;
    font-size: 13px;
    margin: 0;
    font-weight: 500;
}

.dsg-sf-field--has-error .dsg-sf-input {
    border-color: #dc3545;
}

.dsg-sf-field--has-error .dsg-sf-input:focus {
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.15);
}

.dsg-sf-actions {
    margin-top: 4px;
}

.dsg-sf-submit {
    display: inline-block;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: var(--dsgsf-primary);
    border: 1px solid var(--dsgsf-primary);
    border-radius: var(--dsgsf-radius);
    cursor: pointer;
    transition: filter .15s ease, transform .1s ease;
}

.dsg-sf-submit:hover,
.dsg-sf-submit:focus {
    filter: brightness(0.92);
}

/* Hidden by conditional logic — keep in DOM for re-showing but remove from flow */
.dsg-sf-field--cl-hidden { display: none !important; }

.dsg-sf-message {
    padding: 12px 16px;
    border-radius: 4px;
    margin-bottom: 16px;
    font-weight: 500;
}

.dsg-sf-message--success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.dsg-sf-message--error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.dsg-sf-message--unavailable {
    background: #fff3cd;
    color: #664d03;
    border: 1px solid #ffecb5;
    padding: 16px 20px;
    font-size: 15px;
    line-height: 1.55;
}

/* ---- Compound fields (name, address) ---- */
.dsg-sf-compound {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.dsg-sf-compound--name { grid-template-columns: 1fr 1fr; }
.dsg-sf-compound--address { grid-template-columns: 1fr 1fr; }

.dsg-sf-compound__full { grid-column: 1 / -1; }

.dsg-sf-sub { display: flex; flex-direction: column; gap: 4px; }
.dsg-sf-sub__label {
    font-size: 12px;
    color: #646970;
    font-weight: 500;
}

.dsg-sf-input--multi {
    min-height: 120px;
    padding: 8px;
}
.dsg-sf-input--multi option {
    padding: 6px 8px;
    border-radius: 2px;
}

@media (max-width: 480px) {
    .dsg-sf-compound { grid-template-columns: 1fr; }
}

/* v0.3.0 — Rating field */
.dsg-sf-rating {
    display: inline-flex;
    gap: 4px;
}
.dsg-sf-rating__star {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 28px;
    line-height: 1;
    padding: 2px 4px;
    color: rgba(0, 0, 0, 0.15);
    transition: color 80ms;
}
.dsg-sf-rating__star:hover,
.dsg-sf-rating__star.is-filled {
    color: #f59e0b;
}
.dsg-sf-rating:hover .dsg-sf-rating__star { color: rgba(0, 0, 0, 0.15); }
.dsg-sf-rating:hover .dsg-sf-rating__star:hover,
.dsg-sf-rating:hover .dsg-sf-rating__star:hover ~ .dsg-sf-rating__star {
    /* fill left-to-right on hover */
}

/* v0.4.0 — Multi-step forms */
.dsg-sf-form-wrap--multistep .dsg-sf-form { position: relative; }
.dsg-sf-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 0 4px;
}
.dsg-sf-progress {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    height: 8px;
    position: relative;
    overflow: visible;
}
.dsg-sf-progress__bar {
    background: var(--dsgsf-primary, #E53935);
    height: 100%;
    border-radius: 4px;
    transition: width 280ms cubic-bezier(.25, .8, .25, 1);
}
.dsg-sf-progress__label {
    position: absolute;
    right: 0;
    top: 14px;
    font-size: 11px;
    color: rgba(0, 0, 0, 0.5);
    font-weight: 600;
    letter-spacing: 0.4px;
}
.dsg-sf-step { animation: dsgsf-step-in 240ms ease-out; }
@keyframes dsgsf-step-in {
    from { opacity: 0; transform: translateX(8px); }
    to   { opacity: 1; transform: translateX(0); }
}
.dsg-sf-step-nav {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.dsg-sf-step-prev,
.dsg-sf-step-next {
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.15);
    color: inherit;
    padding: 10px 18px;
    border-radius: var(--dsgsf-radius, 6px);
    cursor: pointer;
    font-size: 14px;
    transition: all 120ms;
}
.dsg-sf-step-prev:hover,
.dsg-sf-step-next:hover {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.3);
}
.dsg-sf-step-next {
    margin-left: auto;
    background: var(--dsgsf-primary, #E53935);
    color: #fff;
    border-color: var(--dsgsf-primary, #E53935);
}
.dsg-sf-step-next:hover {
    background: var(--dsgsf-primary, #E53935);
    filter: brightness(1.05);
}
.dsg-sf-form--multistep .dsg-sf-submit { margin-left: auto; }

/* v0.4.1 — Fix: el atributo [hidden] del browser (display:none) era sobrescrito
   por reglas explícitas como `.dsg-sf-submit { display: inline-block }`.
   Forzamos display:none cuando hidden está presente en cualquier hijo del nav. */
.dsg-sf-step[hidden],
.dsg-sf-step-nav [hidden],
.dsg-sf-form [hidden] { display: none !important; }

/* v0.6.0 — Payment field (Stripe Elements) */
.dsg-sf-payment {
    padding: 14px 16px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: var(--dsgsf-radius, 6px);
}
.dsg-sf-payment__card {
    padding: 10px 12px;
    background: #fafafa;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    min-height: 40px;
}
.dsg-sf-payment__card.StripeElement--focus {
    border-color: #635bff;
    box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.15);
}
.dsg-sf-payment__errors {
    margin: 6px 0 0;
    font-size: 12px;
    color: #dc2626;
    min-height: 16px;
}
.dsg-sf-payment-missing {
    padding: 12px;
    border-radius: 4px;
    font-size: 13px;
}

/* v0.5.0 — Calc field (read-only display) */
.dsg-sf-calc {
    padding: 14px 18px;
    background: rgba(var(--dsgsf-primary-rgb, 229, 57, 53), 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--dsgsf-radius, 6px);
    text-align: right;
}
.dsg-sf-calc__display {
    font-size: 22px;
    font-weight: 700;
    color: var(--dsgsf-primary, #E53935);
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}

/* v0.4.2 — Mensaje inline cuando faltan campos required al avanzar */
.dsg-sf-step-error {
    margin: 14px 0 4px;
    padding: 10px 14px;
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 4px;
    font-size: 13px;
}

/* v0.4.0 — Save & Resume button */
.dsg-sf-save-resume {
    background: transparent;
    border: 1px dashed rgba(0, 0, 0, 0.25);
    color: inherit;
    padding: 8px 14px;
    margin-left: 8px;
    border-radius: var(--dsgsf-radius, 6px);
    cursor: pointer;
    font-size: 13px;
    opacity: 0.7;
    transition: opacity 120ms;
}
.dsg-sf-save-resume:hover {
    opacity: 1;
    border-color: rgba(0, 0, 0, 0.4);
    background: rgba(0, 0, 0, 0.03);
}
.dsg-sf-save-resume:disabled {
    opacity: 0.5;
    cursor: progress;
}

/* v0.3.0 — File upload field */
.dsg-sf-input--file {
    padding: 6px;
    cursor: pointer;
}
.dsg-sf-file-current {
    margin: 6px 0 0;
    font-size: 12px;
}
.dsg-sf-file-current a { text-decoration: none; }
