/* ══════════════════════════════════════════════════
   CTM Form Logic — Frontend Styles
   Column layout + conditional field transitions
   + base form element styles
   ══════════════════════════════════════════════════ */

/* ── Theme custom properties (light defaults) ── */
.ctm-form-wrap {
    --ctm-bg: #ffffff;
    --ctm-text: #1d2327;
    --ctm-label: #1d2327;
    --ctm-input-bg: #ffffff;
    --ctm-input-border: #c3c4c7;
    --ctm-input-text: #1d2327;
    --ctm-focus: #2271b1;
    --ctm-btn-bg: #2271b1;
    --ctm-btn-hover: color-mix(in srgb, var(--ctm-btn-bg) 80%, #000);
    --ctm-btn-text: #ffffff;
    --ctm-muted: #666666;
    --ctm-divider: #dddddd;
    --ctm-score-bg: #f8f9fa;
    --ctm-score-border: #e2e4e7;
    --ctm-float-label: #888888;
}

/* ── Dark scheme ── */
.ctm-form-wrap.ctm-scheme-dark {
    --ctm-bg: #1e1e2e;
    --ctm-text: #e0e0e0;
    --ctm-label: #cccccc;
    --ctm-input-bg: #2a2a3c;
    --ctm-input-border: #444466;
    --ctm-input-text: #e0e0e0;
    --ctm-focus: var(--ctm-btn-bg);
    --ctm-muted: #999999;
    --ctm-divider: #3a3a4c;
    --ctm-score-bg: #2a2a3c;
    --ctm-score-border: #444466;
    --ctm-float-label: #888888;
}

/* ── Column layout ── */
.ctm-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.ctm-col-full   { width: 100%; }
.ctm-col-half   { width: calc(50% - 8px); }
.ctm-col-third  { width: calc(33.333% - 11px); }
.ctm-col-quarter { width: calc(25% - 12px); }

/* ── Conditional field transitions ── */
[data-conditions] {
    transition: opacity .25s ease, max-height .3s ease;
}

/* ══════════════════════════════════════════════════
   Base Form Element Styles
   Scoped to .ctm-form-wrap to avoid leaking.
   ══════════════════════════════════════════════════ */

/* ── Form layout ── */
.ctm-form-wrap {
    background: var(--ctm-bg);
    color: var(--ctm-text);
    border-radius: 6px;
}

.ctm-form-wrap form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Field wrapper spacing (for non-column fields) ── */
.ctm-form-wrap .ctm-col-full {
    margin-bottom: 4px;
}

/* ── Labels ── */
.ctm-form-wrap label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--ctm-label);
}

/* ── Inputs, textarea, select ── */
.ctm-form-wrap input[type="text"],
.ctm-form-wrap input[type="email"],
.ctm-form-wrap input[type="tel"],
.ctm-form-wrap input[type="number"],
.ctm-form-wrap input[type="url"],
.ctm-form-wrap textarea,
.ctm-form-wrap select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--ctm-input-border);
    border-radius: 4px;
    font-size: 15px;
    line-height: 1.5;
    box-sizing: border-box;
    background: var(--ctm-input-bg);
    color: var(--ctm-input-text);
    font-family: inherit;
}

.ctm-form-wrap textarea {
    min-height: 100px;
    resize: vertical;
}

.ctm-form-wrap input:focus,
.ctm-form-wrap textarea:focus,
.ctm-form-wrap select:focus {
    border-color: var(--ctm-focus);
    box-shadow: 0 0 0 1px var(--ctm-focus);
    outline: none;
}

/* ── Submit button ── */
.ctm-form-wrap button[type="submit"],
.ctm-form-wrap input[type="submit"] {
    display: inline-block;
    padding: 12px 28px;
    background: var(--ctm-btn-bg);
    color: var(--ctm-btn-text);
    border: none;
    border-radius: 4px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.5;
    transition: background .2s;
}

.ctm-form-wrap button[type="submit"]:hover,
.ctm-form-wrap input[type="submit"]:hover {
    background: var(--ctm-btn-hover);
}

/* ── Fieldset / legend ── */
.ctm-form-wrap fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

.ctm-form-wrap legend {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
    color: var(--ctm-label);
}

/* ── Checkbox / radio labels ── */
.ctm-form-wrap input[type="checkbox"] + label,
.ctm-form-wrap input[type="radio"] + label {
    display: inline;
    font-weight: 400;
}

.ctm-form-wrap .ctm-check-label,
.ctm-form-wrap .ctm-radio-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
    margin-bottom: 4px;
    cursor: pointer;
}

/* ── Floating label wrapper ── */
.ctm-form-wrap .input {
    position: relative;
}

.ctm-form-wrap .input .input-label {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 14px;
    font-weight: 400;
    color: var(--ctm-float-label);
    pointer-events: none;
    transition: all .2s ease;
}

.ctm-form-wrap .input .input-field:focus ~ .input-label,
.ctm-form-wrap .input .input-field:not(:placeholder-shown) ~ .input-label,
.ctm-form-wrap .input .input-field.has-value ~ .input-label {
    top: -8px;
    left: 8px;
    font-size: 11px;
    color: var(--ctm-focus);
    background: var(--ctm-input-bg);
    padding: 0 4px;
}

/* ── Headings in form ── */
.ctm-form-wrap h3 {
    font-size: 18px;
    margin: 8px 0 4px;
    color: var(--ctm-text);
}

/* ── Dividers ── */
.ctm-form-wrap hr {
    border: none;
    border-top: 1px solid var(--ctm-divider);
    margin: 8px 0;
}

/* ── Help text ── */
.ctm-help-text {
    display: block;
    font-size: 12px;
    color: var(--ctm-muted);
    margin-top: 4px;
}

/* ── Score display ── */
.ctm-score-wrap {
    padding: 12px 16px;
    margin: 12px 0;
    background: var(--ctm-score-bg);
    border: 1px solid var(--ctm-score-border);
    border-radius: 6px;
    text-align: center;
}

.ctm-score-label {
    font-size: 14px;
    color: var(--ctm-muted);
    margin-right: 8px;
}

.ctm-score-display {
    font-size: 24px;
    font-weight: 700;
    color: var(--ctm-text);
}

/* ── Responsive: stack columns on mobile ── */
@media (max-width: 600px) {
    .ctm-col-half,
    .ctm-col-third,
    .ctm-col-quarter {
        width: 100%;
    }
}
