/* ==============================================
   PR4 - Template Forms
   Formulaires intelligents pour editer les modeles
   ============================================== */

/* Vue formulaire pleine page */
.tpl-form-view {
    padding: 0 4px;
}

/* Header avec bouton retour */
.tpl-form-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    margin-bottom: 8px;
}

.tpl-form-back {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--primary-color, #1260A8);
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.tpl-form-back:hover {
    background: rgba(18, 96, 168, 0.08);
}

.tpl-form-back svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.tpl-form-title {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #1A1A1A);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Formulaire */
.tpl-form {
    margin: 0;
}

/* Sections (fieldset) */
.tpl-form-section {
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius, 12px);
    padding: 16px;
    margin: 0 0 16px 0;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.tpl-form-section legend {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-color, #1260A8);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 0 8px;
}

/* Champs */
.tpl-form-fields {
    display: flex;
    flex-direction: column;
}

.tpl-form-field {
    margin-bottom: 14px;
}

.tpl-form-field:last-child {
    margin-bottom: 0;
}

.tpl-form-field label {
    display: block;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1A1A1A);
    margin-bottom: 6px;
}

.tpl-form-field input[type="text"],
.tpl-form-field input[type="number"],
.tpl-form-field input[type="date"],
.tpl-form-field textarea,
.tpl-form-field select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 15px;
    color: var(--text-primary, #1A1A1A);
    background: white;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.tpl-form-field textarea {
    resize: vertical;
    min-height: 60px;
}

.tpl-form-field input:focus,
.tpl-form-field textarea:focus,
.tpl-form-field select:focus {
    outline: none;
    border-color: var(--primary-color, #1260A8);
    box-shadow: 0 0 0 3px rgba(18, 96, 168, 0.1);
}

.tpl-form-field input::placeholder,
.tpl-form-field textarea::placeholder {
    color: var(--text-secondary, #666666);
    opacity: 0.5;
}

/* Champ avec suffix (ex: €) */
.tpl-form-field-with-suffix {
    position: relative;
}

.tpl-form-field-with-suffix input {
    padding-right: 36px;
}

.tpl-form-field-suffix {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary, #666666);
    pointer-events: none;
}

/* Champs en erreur */
.tpl-form-field.has-error input,
.tpl-form-field.has-error textarea,
.tpl-form-field.has-error select {
    border-color: var(--error-color, #CC2936);
    box-shadow: 0 0 0 3px rgba(204, 41, 54, 0.08);
}

.tpl-form-field.has-error label {
    color: var(--error-color, #CC2936);
}

.tpl-field-error {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 12px;
    color: var(--error-color, #CC2936);
    margin-top: 4px;
}

/* Row layout pour champs cote a cote */
.tpl-form-row {
    display: flex;
    gap: 12px;
}

.tpl-form-row .tpl-form-field {
    flex: 1;
}

/* Bouton generer */
.tpl-form-submit {
    width: 100%;
    padding: 14px 24px;
    margin-top: 8px;
    margin-bottom: 20px;
    background: var(--primary-color, #1260A8);
    color: white;
    border: none;
    border-radius: var(--radius, 12px);
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(18, 96, 168, 0.25);
}

.tpl-form-submit:hover {
    background: #0F4F8A;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(18, 96, 168, 0.3);
}

.tpl-form-submit:active {
    transform: translateY(0);
}

.tpl-form-submit:disabled {
    opacity: 0.6;
    pointer-events: none;
}

.tpl-form-submit svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Badge editable sur les cartes template */
.tpl-card-editable .tpl-card-dl {
    color: var(--primary-color, #1260A8);
}

.tpl-card-editable:hover .tpl-card-dl {
    color: white;
    background: var(--primary-color, #1260A8);
    border-radius: 6px;
}

.tpl-card-edit svg {
    width: 14px;
    height: 14px;
}

/* ── Image upload (logo) ── */

.tpl-form-image-upload {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tpl-form-image-preview {
    min-height: 0;
}

.tpl-form-image-preview img {
    max-width: 160px;
    max-height: 60px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 4px;
    background: #fafafa;
}

.tpl-form-image-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: white;
    border: 1px dashed rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #666666);
    cursor: pointer;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.tpl-form-image-btn:hover {
    border-color: var(--primary-color, #1260A8);
    color: var(--primary-color, #1260A8);
    background: rgba(18, 96, 168, 0.04);
}

/* ── Lignes du devis (tableau dynamique) ── */

.tpl-form-lines {
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    overflow: hidden;
}

.tpl-lines-header {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.tpl-lines-header span {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary, #666666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tpl-lines-desc { flex: 3; }
.tpl-lines-qty { flex: 0.8; text-align: center; }
.tpl-lines-pu { flex: 1; text-align: right; }
.tpl-lines-total { flex: 1; text-align: right; }
.tpl-lines-del { width: 28px; flex-shrink: 0; }

.tpl-lines-body {
    padding: 0;
}

.tpl-line-row {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    align-items: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.tpl-line-row:last-child {
    border-bottom: none;
}

.tpl-line-row input {
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 14px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    padding: 6px 8px;
    background: white;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.tpl-line-row input:focus {
    outline: none;
    border-color: var(--primary-color, #1260A8);
}

.tpl-line-desc {
    flex: 3;
    min-width: 0;
}

.tpl-line-qty {
    flex: 0.8;
    text-align: center;
    width: 50px;
}

.tpl-line-pu {
    flex: 1;
    text-align: right;
    width: 80px;
}

.tpl-line-total {
    flex: 1;
    text-align: right;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1A1A1A);
    white-space: nowrap;
}

.tpl-line-del {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tpl-line-del:hover {
    background: rgba(204, 41, 54, 0.08);
    color: var(--error-color, #CC2936);
}

.tpl-lines-add {
    display: block;
    width: 100%;
    padding: 10px;
    background: none;
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color, #1260A8);
    cursor: pointer;
    transition: background 0.2s ease;
}

.tpl-lines-add:hover {
    background: rgba(18, 96, 168, 0.04);
}

/* Totaux du devis */

.tpl-lines-totals {
    padding: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.02);
}

.tpl-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-family: 'Calibri', Arial, sans-serif;
    font-size: 13px;
    color: var(--text-secondary, #666666);
}

.tpl-totals-grand {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary, #1A1A1A);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 6px;
    margin-top: 4px;
}

/* Responsive mobile */
@media (max-width: 480px) {
    .tpl-form-view {
        padding: 0;
    }

    .tpl-form-header {
        padding: 8px 0;
        margin-bottom: 4px;
    }

    .tpl-form-title {
        font-size: 16px;
    }

    .tpl-form-section {
        padding: 14px;
        margin-bottom: 12px;
    }

    .tpl-form-row {
        flex-direction: column;
        gap: 0;
    }

    .tpl-form-submit {
        font-size: 15px;
        padding: 12px 20px;
    }

    .tpl-lines-header {
        display: none;
    }

    .tpl-line-row {
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px;
    }

    .tpl-line-desc {
        flex: 1 1 100%;
    }

    .tpl-line-qty,
    .tpl-line-pu {
        flex: 1;
    }

    .tpl-line-total {
        flex: 1;
    }
}
