/**
 * @package     conwebia
 * @author      Frank Schumann
 * @copyright   Copyright © 2005 Frank Schumann / conwebia GmbH
 * @license     GNU General Public License version 2 or later; see conwebia-license.txt
 *
 * mod_cw_form – styles shared by all form layouts.
 */

.cw-form {
    --cw-form-border: #dee2e6;
    --cw-form-input-border: #ced4da;
    --cw-form-error: #b02a37;
    --cw-form-muted: #6c757d;
    --cw-form-disabled-bg: #f5f6f7;

    max-width: 1140px;
    margin-inline: auto;
}

/* Compact controls (Bootstrap default height instead of Cassiopeia's larger padding) */
.cw-form .form-control,
.cw-form .form-select,
.cw-form .input-group-text {
    padding-top: .375rem;
    padding-bottom: .375rem;
}

/* Same font weight as the page text (Bootstrap fixes controls at 400) */
.cw-form .form-control,
.cw-form .form-select,
.cw-form .input-group-text {
    font-weight: inherit;
}

/* Placeholders clearly lighter than entered values */
.cw-form .form-control::placeholder {
    color: #adb5bd;
    font-weight: inherit;
    opacity: 1;
}

/* Focus: no glow and no border colour change on fields; radios and buttons
   get a thin outline for keyboard users only */
.cw-form .form-control:focus,
.cw-form .form-select:focus,
.cw-form .form-check-input:focus,
.cw-form .btn:focus {
    box-shadow: none;
}

.cw-form .form-control:focus,
.cw-form .form-select:focus {
    border-color: var(--cw-form-input-border);
}

.cw-form .form-check-input:focus-visible,
.cw-form .btn:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Boxes */
.cw-form__box {
    margin: 0 0 1.5rem;
    padding: 1.25rem 1.5rem 1.5rem;
    border: 1px solid var(--cw-form-border);
    border-radius: .5rem;
}

.cw-form__box > legend {
    float: none;
    width: auto;
    margin: 0;
    padding: 0 .5rem;
    font-size: 1.25rem;
}

.cw-form__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75em;
    height: 1.75em;
    margin-right: .25em;
    border-radius: 50%;
    background: var(--cw-form-border);
    font-size: .8em;
    font-weight: 600;
}

/* Radio/checkbox groups */
/* Inline row: label, radios and fields side by side, wrapping on small screens */
.cw-form__inline {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline; /* radio labels and field labels on one text line */
    gap: .75rem 2rem;
    margin-top: .75rem;
}

.cw-form__group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1rem;
}

.cw-form__group--grow {
    flex: 1 1 16rem;
}

.cw-form__group--grow .form-control {
    flex: 1 1 10rem;
    width: auto;
    max-width: 22rem;
}

.cw-form__group .form-check-inline {
    margin: 0;
}

.cw-form .form-check-input,
.cw-form .form-check-label {
    cursor: pointer;
}

.cw-form__group > .cw-form__error {
    flex-basis: 100%;
    margin-top: 0;
}

/* Repeatable rows */
.cw-form__row + .cw-form__row {
    margin-top: .75rem;
}

.cw-form__row-actions {
    /* Push the remove button down to the input line (label height) */
    padding-top: calc(1.5em + .5rem);
    text-align: right;
}

/* Row amounts and total */
.cw-form__amount {
    white-space: nowrap;
}

.cw-form__sum-label {
    padding-top: .5rem;
}

.cw-form__sum-label label {
    font-weight: 600;
}

.cw-form__sum-label .cw-form__hint {
    margin: 0;
}

/* Line above the total (only as wide as the amount), as on an invoice */
.cw-form__sum output {
    display: inline-block;
    padding-top: .5rem;
    border-top: 2px solid var(--cw-form-input-border);
    font-size: 1.25rem;
    font-weight: 600;
    white-space: nowrap;
}

@media (max-width: 767.98px) {
    .cw-form__row + .cw-form__row {
        padding-top: .75rem;
        border-top: 1px solid var(--cw-form-border);
    }
}

/* Required marker and errors */
.cw-form__req {
    margin-left: .15em;
    color: var(--cw-form-error);
}

/* Disabled fields are not required at the moment (data-cw-enable-if) */
.cw-form__field--disabled .cw-form__req {
    display: none;
}

.cw-form__error {
    margin-top: .25rem;
    color: var(--cw-form-error);
    font-size: .875em;
}

.cw-form__error:empty {
    display: none;
}

/* Same specificity as the focus rule and defined later, so errors stay red while focused */
.cw-form .cw-form__field--invalid .form-control,
.cw-form .cw-form__field--invalid .form-select,
.cw-form .cw-form__field--invalid .form-check-input {
    border-color: var(--cw-form-error);
}

/* Disabled fields */
.cw-form .form-control:disabled {
    background-color: var(--cw-form-disabled-bg);
    cursor: not-allowed;
}

/* Read-only fields (data-cw-mirror) */
.cw-form .form-control[readonly] {
    background-color: var(--cw-form-disabled-bg);
}

/* Date fields set via the calendar only (class added by form.js) */
.cw-form__picker {
    cursor: pointer;
    caret-color: transparent;
}

/* Actions */
.cw-form__hint {
    color: var(--cw-form-muted);
    font-size: .875em;
}

@media print {
    .cw-form__actions {
        display: none;
    }
}

/* Print sheet ([data-cw-print-sheet], moved to <body> by form.js): on paper it replaces
   the whole page, everything else is hidden. Page margin 0 keeps the browser from
   printing date, title and URL; the margin is the sheet's padding instead */
.cw-print {
    --cw-print-accent: #333;
    --cw-print-tint: #f2f2f2;
    --cw-print-line: #ccc;

    display: none;
}

@page {
    size: A4;
    margin: 0;
}

@media print {
    body:has(> .cw-print) > :not(.cw-print) {
        display: none !important;
    }

    body:has(> .cw-print) {
        margin: 0;
        padding: 0;
        background: none;
    }

    .cw-print {
        display: block;
        padding: 10mm 15mm 8mm;
        color: #000;
        font-size: 10pt;
        line-height: 1.4;
        print-color-adjust: exact; /* print the tinted table rows */
        -webkit-print-color-adjust: exact;
    }

    .cw-print__head {
        padding-bottom: 3mm;
        border-bottom: 2px solid var(--cw-print-accent);
        text-align: center;
    }

    .cw-print__logo {
        width: auto;
        height: 14mm;
    }

    .cw-print__title {
        margin: 4mm 0 3mm;
        font-size: 20pt;
        font-weight: 600;
    }

    .cw-print__letter {
        display: flex;
        justify-content: space-between;
        gap: 10mm;
    }

    .cw-print__label {
        margin-bottom: 1mm;
        color: #555;
        font-size: 8pt;
        letter-spacing: .15em;
        text-transform: uppercase;
    }

    .cw-print__recipient {
        text-align: right;
    }

    .cw-print__recipient .cw-print__label {
        color: var(--cw-print-accent);
        font-weight: 600;
    }

    .cw-print__hint {
        margin: 3mm 0 0;
        color: var(--cw-print-accent);
        font-size: 9pt;
    }

    .cw-print__heading {
        margin: 4mm 0 2mm;
        padding-left: 2mm;
        border-left: 3px solid var(--cw-print-accent);
        font-size: 10pt;
        font-weight: 600;
        text-transform: uppercase;
    }

    .cw-print__table {
        width: 100%;
        margin-bottom: 3mm;
        border-collapse: collapse;
    }

    .cw-print__table th,
    .cw-print__table td {
        padding: 1.5mm 2mm;
        border: 1px solid var(--cw-print-line);
        text-align: left;
        vertical-align: top;
    }

    .cw-print__table th[scope="row"] {
        width: 45mm;
        font-weight: 600;
    }

    .cw-print__intro {
        margin: 3mm 0 2mm;
    }

    .cw-print__positions thead th,
    .cw-print__positions tfoot td {
        background: var(--cw-print-tint);
        font-weight: 600;
    }

    .cw-print__positions .text-end {
        white-space: nowrap;
    }

    .cw-print__declaration {
        margin: 4mm 0 0;
        padding: 3mm 4mm;
        border-left: 3px solid var(--cw-print-accent);
        background: var(--cw-print-tint);
        font-size: 9pt;
    }

    .cw-print__sign {
        display: flex;
        gap: 15mm;
        margin-top: 14mm; /* room for the handwritten signature */
    }

    .cw-print__sign > div {
        flex: 1;
        padding-top: 1mm;
        border-top: 1px solid #000;
        font-size: 9pt;
    }

    .cw-print__footer {
        margin-top: 4mm;
        padding-top: 2mm;
        border-top: 1px solid var(--cw-print-line);
        color: #555;
        font-size: 8pt;
        text-align: center;
    }
}
