/* ==========================================================================
   RBB Form — Frontend styles
   ========================================================================== */

/* -------------------------------------------------------------------------
   CSS Custom Properties
   Override per Form (via css_class) oder global:
     .rbb-form.mein-formular { --rbb-accent: #e83a59; --rbb-radius: 8px; }
     .rbb-form { --rbb-accent: #brand-color; }
   ------------------------------------------------------------------------- */

.rbb-form {
    --rbb-accent:        #2271b1;
    --rbb-border:        #c8ccd0;
    --rbb-radius:        4px;
    --rbb-input-padding: 10px 12px;
    --rbb-field-gap:     20px;
    --rbb-col-gap:       16px;
    --rbb-focus-shadow:  0 0 0 2px rgba(34, 113, 177, 0.2);

    max-width: 720px;
    width: 100%;
    box-sizing: border-box;
}

/* -------------------------------------------------------------------------
   Fields grid
   ------------------------------------------------------------------------- */

.rbb-form-fields {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    column-gap: var(--rbb-col-gap);
    row-gap: var(--rbb-field-gap);
}

.rbb-field {
    grid-column: span 6;
}

.rbb-col-half {
    grid-column: span 3;
}

.rbb-col-third {
    grid-column: span 2;
}

/* -------------------------------------------------------------------------
   Divider (horizontal rule)
   ------------------------------------------------------------------------- */

.rbb-field--divider {
    grid-column: 1 / -1;
}

.rbb-divider-line {
    border: none;
    border-top: 1px solid var(--rbb-border);
    margin: 4px 0;
}

/* -------------------------------------------------------------------------
   Textblock (static content)
   ------------------------------------------------------------------------- */

.rbb-field--textblock {
    line-height: 1.6;
    font-size: 0.9375em;
    color: #2c3338;
}

.rbb-field--textblock > * {
    margin-top: 0;
    margin-bottom: 0.75em;
}

.rbb-field--textblock > *:last-child {
    margin-bottom: 0;
}

/* -------------------------------------------------------------------------
   Section (heading + optional description)
   ------------------------------------------------------------------------- */

.rbb-field--section {
    grid-column: 1 / -1;
}

/* Stacked cell: multiple fields inside one grid column */
.rbb-field--stack {
    display: flex;
    flex-direction: column;
    gap: var(--rbb-field-gap);
}

.rbb-section-title {
    margin: 0 0 4px;
    font-size: 1em;
    font-weight: 700;
    color: #1d2327;
}

.rbb-section-desc {
    margin: 0;
    font-size: 0.875em;
    color: #646970;
    line-height: 1.5;
}

/* -------------------------------------------------------------------------
   Fields (legacy — kept for context outside .rbb-form-fields)
   ------------------------------------------------------------------------- */

.rbb-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 0.9375em;
}

.rbb-required {
    color: #c0392b;
}

.rbb-input,
.rbb-select,
.rbb-textarea {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: var(--rbb-input-padding);
    border: 1px solid var(--rbb-border);
    border-radius: var(--rbb-radius);
    font-size: 1em;
    line-height: 1.5;
    background: #fff;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.rbb-input:focus,
.rbb-select:focus,
.rbb-textarea:focus {
    border-color: var(--rbb-accent);
    box-shadow: var(--rbb-focus-shadow);
    outline: none;
}

.rbb-textarea {
    min-height: 120px;
    resize: vertical;
}

.rbb-textarea--sm {
    min-height: 60px;
}

.rbb-select {
    cursor: pointer;
}

/* -------------------------------------------------------------------------
   Checkboxes
   ------------------------------------------------------------------------- */

.rbb-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.rbb-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9375em;
    cursor: pointer;
}

.rbb-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--rbb-accent);
}

/* -------------------------------------------------------------------------
   Radio buttons
   ------------------------------------------------------------------------- */

.rbb-radios {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
}

.rbb-radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9375em;
    cursor: pointer;
}

.rbb-radio-label input[type="radio"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--rbb-accent);
}

/* -------------------------------------------------------------------------
   WYSIWYG
   ------------------------------------------------------------------------- */

.rbb-field--wysiwyg .wp-editor-container {
    border: 1px solid var(--rbb-border);
    border-radius: var(--rbb-radius);
    overflow: hidden;
}

/* -------------------------------------------------------------------------
   Media field
   ------------------------------------------------------------------------- */

.rbb-media-preview {
    margin-bottom: 10px;
    min-height: 0;
}

.rbb-media-preview--empty {
    display: none;
}

.rbb-media-thumb {
    display: block;
    max-width: 160px;
    max-height: 160px;
    border: 1px solid var(--rbb-border);
    border-radius: var(--rbb-radius);
    object-fit: cover;
}

.rbb-media-filename {
    display: inline-block;
    padding: 6px 10px;
    background: #f0f6fc;
    border: 1px solid #c5d9ed;
    border-radius: var(--rbb-radius);
    font-size: 0.875em;
    color: #2c3338;
}

.rbb-media-input {
    display: block;
    margin-top: 6px;
    font-size: 0.875em;
}

.rbb-media-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--rbb-border);
    border-top-color: var(--rbb-accent);
    border-radius: 50%;
    animation: rbb-spin 0.7s linear infinite;
    vertical-align: middle;
}

@keyframes rbb-spin {
    to { transform: rotate(360deg); }
}

.rbb-media-error {
    margin-top: 6px;
    font-size: 0.875em;
    color: #6e2020;
    background: #fdf0ef;
    border: 1px solid #e0a8a8;
    border-radius: var(--rbb-radius);
    padding: 6px 10px;
    line-height: 1.4;
}

.rbb-media-errors {
    margin-bottom: 10px;
    font-size: 0.875em;
    color: #6e2020;
    background: #fdf0ef;
    border: 1px solid #e0a8a8;
    border-radius: var(--rbb-radius);
    padding: 8px 12px;
    line-height: 1.5;
}

.rbb-media-errors__item {
    display: block;
}

.rbb-media-errors__item + .rbb-media-errors__item {
    margin-top: 4px;
}

/* -------------------------------------------------------------------------
   Repeater
   ------------------------------------------------------------------------- */

.rbb-repeater {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rbb-repeater-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border: 1px solid var(--rbb-border);
    border-radius: var(--rbb-radius);
    background: #fafafa;
}

.rbb-repeater-fields {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.rbb-rep-sub {
    flex: 1 1 180px;
    min-width: 0;
}

.rbb-rep-label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8125em;
    font-weight: 600;
    color: #50575e;
}

.rbb-repeater-remove {
    flex-shrink: 0;
    margin-top: 24px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: 1px solid #b32d2e;
    border-radius: var(--rbb-radius);
    color: #b32d2e;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.rbb-repeater-remove:hover {
    background: #b32d2e;
    color: #fff;
}

.rbb-repeater-add {
    align-self: flex-start;
    margin-top: 6px;
}

/* -------------------------------------------------------------------------
   Conditional blocks
   ------------------------------------------------------------------------- */

.rbb-conditional {
    border-left: 3px solid #e0e4e8;
    padding-left: 16px;
    margin-left: 4px;
}

/* -------------------------------------------------------------------------
   Submit row
   ------------------------------------------------------------------------- */

.rbb-form-footer {
    margin-top: 24px;
}

.rbb-form-submit {
    display: inline-block;
    padding: 10px 24px;
    background: var(--rbb-accent);
    color: #fff;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: var(--rbb-radius);
    cursor: pointer;
    transition: background 0.15s;
}

.rbb-form-submit:hover {
    background: #135e96;
}

.rbb-form-submit:disabled {
    background: #8eafcf;
    cursor: not-allowed;
}

/* -------------------------------------------------------------------------
   Feedback messages
   ------------------------------------------------------------------------- */

.rbb-form-message {
    margin-top: 16px;
    padding: 10px 14px;
    border-radius: var(--rbb-radius);
    font-size: 0.9375em;
    line-height: 1.5;
}

.rbb-form-message:empty {
    display: none;
}

.rbb-form-success {
    background: #f0faf0;
    border: 1px solid #a8d5a8;
    color: #1e4620;
}

.rbb-form-error {
    background: #fdf0ef;
    border: 1px solid #e0a8a8;
    color: #6e2020;
}

/* -------------------------------------------------------------------------
   Notice (not logged in etc.)
   ------------------------------------------------------------------------- */

.rbb-form-notice {
    padding: 12px 16px;
    background: #f0f6fc;
    border: 1px solid #c5d9ed;
    border-radius: var(--rbb-radius);
    font-size: 0.9375em;
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

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

    .rbb-repeater-row {
        flex-direction: column;
    }

    .rbb-repeater-remove {
        margin-top: 0;
        align-self: flex-end;
    }

    .rbb-rep-sub {
        flex-basis: 100%;
    }
}

/* -------------------------------------------------------------------------
   Tom Select — overrides to match rbb-form look
   Scoped to .rbb-form so we don't affect other selects on the page.
   ------------------------------------------------------------------------- */

.rbb-form .ts-control,
.rbb-form .ts-control input,
.rbb-form .ts-dropdown {
    font-size: 1em;
    line-height: 1.5;
    color: #2c3338;
    font-family: inherit;
}

.rbb-form .ts-control {
    border: 1px solid var(--rbb-border);
    border-radius: var(--rbb-radius);
    box-shadow: none;
    background: #fff;
    padding: 6px 10px;
    min-height: 40px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

/* Remove gradient on single select */
.rbb-form .ts-wrapper.single .ts-control {
    background-color: #fff;
    background-image: none;
    box-shadow: none;
    border-color: var(--rbb-border);
}

/* Focus ring */
.rbb-form .ts-wrapper.focus .ts-control {
    border-color: var(--rbb-accent);
    box-shadow: var(--rbb-focus-shadow);
    outline: none;
}

/* Selected item chips (multi + remove_button plugin) */
.rbb-form .ts-wrapper.multi .ts-control .item,
.rbb-form .ts-wrapper.plugin-remove_button .item {
    background: #e8f0fe;
    background-image: none;
    border: 1px solid #c5d9ed;
    border-radius: 3px;
    color: #2c3338;
    text-shadow: none;
    box-shadow: none;
    padding: 1px 4px;
    font-size: 0.875em;
}

.rbb-form .ts-wrapper.plugin-remove_button .item .remove {
    border-left-color: #c5d9ed;
    color: #646970;
}

.rbb-form .ts-wrapper.plugin-remove_button .item .remove:hover {
    background: rgba(179, 45, 46, 0.08);
    color: #b32d2e;
}

/* Dropdown */
.rbb-form .ts-dropdown {
    border-color: var(--rbb-border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-radius: 0 0 var(--rbb-radius) var(--rbb-radius);
    font-size: 1em;
}

.rbb-form .ts-dropdown .option,
.rbb-form .ts-dropdown .no-results {
    padding: 7px 10px;
}

.rbb-form .ts-dropdown .active {
    background-color: #f0f6fc;
    color: #135e96;
}

/* Keep already-selected options visible in dropdown (multi) */
.rbb-form .ts-dropdown .option.selected {
    color: #646970;
    font-style: italic;
}

/* Dropdown open: keep top border-radius */
.rbb-form .dropdown-active .ts-control {
    border-radius: var(--rbb-radius) var(--rbb-radius) 0 0;
}
