.dlux-form,
.archive-document-form {
    --archive-form-surface: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 249, 250, 0.96));
    --archive-form-border: rgba(var(--primal-rgb, 13, 110, 253), 0.14);
    --archive-form-border-strong: rgba(var(--primal-rgb, 13, 110, 253), 0.32);
    --archive-form-focus-ring: rgba(var(--primal-rgb, 13, 110, 253), 0.10);
    --archive-form-muted: color-mix(in srgb, var(--bs-secondary-color, #6c757d) 88%, white);
}

/* Form density (layout_config.default_form_density, per-user overridable via
   Options) — applied via the `data-dlux-form-density` body attribute, independent
   of table density. Balanced is the fallback (no attribute / value="balanced").
   Density drives row spacing, the gap between rows, label spacing, input height,
   and input vertical padding so the three levels are clearly distinct. */
body[data-dlux-form-density="dense"] {
    --dlux-form-gutter-y: 0.1rem;
    --dlux-form-row-mb: 0.4rem;
    --dlux-form-label-mb: 0.15rem;
    --dlux-form-input-h: 2.3rem;
    --dlux-form-input-py: 0.25rem;
    --dlux-form-textarea-h: 5.5rem;
}

body[data-dlux-form-density="roomy"] {
    --dlux-form-gutter-y: 0.6rem;
    --dlux-form-row-mb: 1.5rem;
    --dlux-form-label-mb: 0.7rem;
    --dlux-form-input-h: 3.6rem;
    --dlux-form-input-py: 0.75rem;
    --dlux-form-textarea-h: 9rem;
}

.dlux-form .row,
.archive-document-form .row {
    --bs-gutter-y: var(--dlux-form-gutter-y, 0.25rem);
}

/* Density-driven bottom margin for stacked form rows/groups. Scoped to dlux forms
   so it overrides crispy's fixed `mb-3` (1rem) without leaking into other layout. */
.dlux-form .row.mb-3,
.dlux-form .mb-3.dlux-form-group,
.archive-document-form .row.mb-3 {
    margin-bottom: var(--dlux-form-row-mb, 1rem) !important;
}

.dlux-filter .form-group,
.dlux-filter [class*="col-"] {
    min-width: 0;
}

.dlux-filter .form-control,
.dlux-filter .form-select,
.dlux-filter textarea {
    min-height: 2.95rem;
}

.dlux-filter .form-control,
.dlux-filter .form-select {
    font-size: 0.96rem;
}

.dlux-filter .form-select {
    padding-inline-end: 2.35rem;
}

.dlux-filter .invalid-feedback,
.dlux-filter .form-text {
    padding-inline: 0.2rem;
}

.dlux-form label:not(.form-check-label):not(.visually-hidden),
.archive-document-form label:not(.form-check-label):not(.visually-hidden) {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: var(--dlux-form-label-mb, 0.45rem);
    color: var(--archive-form-muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.dlux-form .form-control,
.dlux-form .form-select,
.dlux-form textarea,
.dlux-form input[type="text"],
.dlux-form input[type="number"],
.dlux-form input[type="date"],
.archive-document-form .form-control,
.archive-document-form .form-select,
.archive-document-form textarea,
.archive-document-form input[type="text"],
.archive-document-form input[type="number"],
.archive-document-form input[type="date"] {
    min-height: var(--dlux-form-input-h, 3.05rem);
    padding-block: var(--dlux-form-input-py, 0.5rem);
    border: 1px solid var(--archive-form-border);
    border-radius: 1rem;
    background:
        radial-gradient(circle at top, rgba(var(--primal-rgb, 13, 110, 253), 0.032), transparent 64%),
        var(--archive-form-surface);
    color: var(--bs-body-color, #212529);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 3px 10px rgba(15, 23, 42, 0.028);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.dlux-form textarea,
.archive-document-form textarea {
    min-height: var(--dlux-form-textarea-h, 7.25rem);
    resize: vertical;
}

.dlux-form .form-control::placeholder,
.dlux-form textarea::placeholder,
.archive-document-form .form-control::placeholder,
.archive-document-form textarea::placeholder {
    color: color-mix(in srgb, var(--bs-secondary-color, #6c757d) 78%, white);
}

.dlux-form .form-control:hover,
.dlux-form .form-select:hover,
.dlux-form textarea:hover,
.archive-document-form .form-control:hover,
.archive-document-form .form-select:hover,
.archive-document-form textarea:hover {
    border-color: rgba(var(--primal-rgb, 13, 110, 253), 0.22);
}

.dlux-form .form-control:focus,
.dlux-form .form-select:focus,
.dlux-form textarea:focus,
.dlux-form .form-check-input:focus,
.archive-document-form .form-control:focus,
.archive-document-form .form-select:focus,
.archive-document-form textarea:focus,
.archive-document-form .form-check-input:focus {
    border-color: var(--archive-form-border-strong);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.92),
        0 0 0 0.22rem var(--archive-form-focus-ring);
    background-color: rgba(255, 255, 255, 0.99);
}

.dlux-form .form-check-input,
.archive-document-form .form-check-input {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 0.42rem;
    border-color: rgba(var(--primal-rgb, 13, 110, 253), 0.24);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.025);
}

.dlux-form .form-check-label,
.archive-document-form .form-check-label {
    font-weight: 600;
    color: var(--bs-body-color, #212529);
}

.dlux-form .archive-checkbox-field,
.archive-document-form .archive-checkbox-field {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 3.05rem;
    padding: 0.55rem 0.95rem;
    border: 1px solid var(--archive-form-border);
    border-radius: 1rem;
    background:
        radial-gradient(circle at top, rgba(var(--primal-rgb, 13, 110, 253), 0.028), transparent 64%),
        var(--archive-form-surface);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.88),
        0 3px 10px rgba(15, 23, 42, 0.02);
}

.dlux-form .archive-checkbox-field .form-check-input,
.archive-document-form .archive-checkbox-field .form-check-input {
    margin: 0;
}

.dlux-form .archive-checkbox-field .form-check-label,
.archive-document-form .archive-checkbox-field .form-check-label {
    display: inline-flex;
    align-items: center;
    min-height: 1.15rem;
    margin: 0;
    white-space: nowrap;
}

.dlux-form hr,
.archive-document-form hr {
    margin: 1rem 0 1.1rem;
    border: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(var(--primal-rgb, 13, 110, 253), 0.18), transparent);
    opacity: 1;
}

.dlux-form .alert,
.archive-document-form .alert {
    border-radius: 1rem;
    border-color: rgba(255, 193, 7, 0.28);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.028);
}

.dlux-form .invalid-feedback,
.dlux-form .form-text,
.archive-document-form .invalid-feedback,
.archive-document-form .form-text {
    padding-inline: 0.2rem;
}

.dlux-form .select2-container .select2-selection,
.dlux-form .ts-control,
.archive-document-form .select2-container .select2-selection,
.archive-document-form .ts-control {
    border-radius: 1rem !important;
}

.dlux-form .form-check-input {
    float: none;
    margin-inline-start: 0;
}

/* Restore Bootstrap 5 switch toggle styling */
.dlux-form .form-switch .form-check-input {
    width: 2em !important;
    height: 1em !important;
    border-radius: 2rem !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba%280, 0, 0, 0.25%29'/%3e%3c/svg%3e") !important;
    background-position: left center !important;
    background-repeat: no-repeat !important;
    background-size: contain !important;
    transition: background-position 0.15s ease-in-out !important;
}

.dlux-form .form-switch .form-check-input:checked {
    background-position: right center !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e") !important;
}
