:root {
    --primary: #1c91e0;
    --primary-dark: #00b8cc;
    --bg-dark: #5ba9e903;
    /*#0f172a;*/
    --card-bg: rgba(222, 235, 246, 0.617);
    --text-main: #2a50c1;
    --text-muted: #5b87c5;
    --border-color: rgba(255, 255, 255, 0.1);
    --success: #22c55e;
    --error: #cb74df;
}

@keyframes highlight {
    0% { background-color: rgba(59, 130, 246, 0.4); transform: scale(1.02); }
    100% { background-color: transparent; transform: scale(1); }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(0, 229, 255, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(124, 58, 237, 0.05) 0%, transparent 40%);
}

.container {
    width: 100%;
    max-width: 1400px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

header {
    margin-bottom: 2rem;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #fff, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
}

.section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.section:last-child {
    border-bottom: none;
}

h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-left: 4px solid var(--primary);
    padding-left: 0.75rem;
}

.form-group {
    margin-bottom: 1.25rem;
    position: relative; /* Ajouté pour le positionnement absolute du select is-expanded */
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

input,
textarea {
    width: 100%;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 229, 255, 0.1);
}

.h2-row-left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1.5rem;
}

.h2-row-left h2 {
    margin-bottom: 0 !important;
    white-space: nowrap;
}

.select-profile {
    width: auto !important;
    min-width: 250px;
    padding: 0.3rem 0.5rem !important;
    font-weight: 600;
}

.info-inline {
    font-size: 0.95rem;
    color: var(--primary);
    font-weight: 700;
    padding: 0.4rem 0.75rem;
    background: rgba(0, 229, 255, 0.08);
    border-radius: 8px;
    border-right: 3px solid var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80%;
}

.grid-cols-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Params List */
.params-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.param-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.btn-remove {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.2);
    width: 42px;
    height: 42px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-remove:hover {
    background: var(--error);
    color: white;
}

.btn-add {
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
    width: 100%;
    padding: 0.75rem;
    border-radius: 12px;
    cursor: pointer;
    margin-top: 1rem;
    transition: all 0.2s;
}

.btn-add:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: var(--primary);
}

.btn-send {
    background: var(--primary);
    color: #ffffff;
    border: none;
    width: 100%;
    padding: 1.25rem;
    border-radius: 16px;
    font-size: 1.125rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.btn-send:hover {
    background: #00b8cc;
    color: #000000;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 229, 255, 0.3);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Status Log */
#status-log {
    margin-top: 2rem;
    max-height: 200px;
    overflow-y: auto;
    background: #f1f5f9;
    color: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
}

.log-entry {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-entry.success {
    color: var(--success);
}

.log-entry.error {
    color: var(--error);
}

.log-entry.info {
    color: var(--primary);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===== TEMPLATE ID SECTION (COMPACT) ===== */

.template-id-wrapper {
    display: flex;
    align-items: stretch;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s;
    width: fit-content;
}

.template-id-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 229, 255, 0.1);
}

#template-id {
    background: transparent;
    border: none;
    padding: 0.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
    width: 80px;
    box-shadow: none;
    height: auto;
}

.btn-inc {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    font-weight: 300;
    width: 36px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-inc:hover {
    background: rgba(0, 229, 255, 0.1);
    color: var(--primary);
}

.btn-inc:active {
    background: var(--primary);
    color: var(--bg-dark);
}

#template-id:focus {
    box-shadow: none;
}

/* Chrome, Safari, Edge, Opera */
#template-id::-webkit-outer-spin-button,
#template-id::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Firefox */
#template-id[type=number] {
    -moz-appearance: textfield;
}

/* ===== SELECT LISTS (fond blanc, 4 lignes, ascenseur) ===== */

select {
    width: 100%;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    font-size: 1rem;
    cursor: pointer;
}

.select-full {
    width: 100%;
    display: block;
}

.select-white {
    background: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 10px;
    padding: 0.4rem;
    font-family: 'JetBrains Mono', monospace !important;
}

.select-white option {
    color: #1e293b;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 1px;
}

.select-white option:checked {
    background: var(--primary) !important;
    color: #0f172a;
    font-weight: 600;
}

/* Ascenseur visible sur fond blanc */
.select-white::-webkit-scrollbar-thumb {
    background: #94a3b8;
}

.select-white::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.select-white::-webkit-scrollbar-track {
    background: #f1f5f9;
}

/* Comportement étendu (is-expanded) */
.select-white.is-expanded {
    position: absolute;
    z-index: 1000;
    width: 100%;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
    border-color: var(--primary) !important;
}


/* ===== INPUTS FOND BLANC ===== */

.input-white {
    background: #ffffff !important;
    color: #1e293b !important;
    border: 1px solid #cbd5e1 !important;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.95rem;
}

textarea.input-white {
    resize: none;
    height: 120px;
    display: block;
    width: 100%;
}

.input-white::placeholder {
    color: #94a3b8;
}

.input-white::-webkit-scrollbar-thumb {
    background: #94a3b8;
}

.input-white::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.input-white::-webkit-scrollbar-track {
    background: #f1f5f9;
}

/* ===== BOUTONS ===== */

.btn-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(0, 229, 255, 0.1);
    color: var(--primary);
    border: 1px solid rgba(0, 229, 255, 0.3);
    padding: 0.2rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    vertical-align: middle;
    margin-left: 0.5rem;
}

.btn-inline:hover {
    background: rgba(0, 229, 255, 0.2);
    border-color: var(--primary);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--primary);
}

.btn-full {
    width: 100%;
    display: block;
    text-align: center;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
        background-color: #f8fafc; /* Fond beaucoup plus clair sur mobile */
        background-image: none; /* Supprimer les gradients sombres */
    }

    .container {
        padding: 1rem;
        border-radius: 16px;
        background: #ffffff !important; /* Fond blanc pour le contenu sur mobile */
    }

    h1 {
        font-size: 1.8rem;
    }

    header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .btn-inline[style*="position: absolute"] {
        position: static !important;
        transform: none !important;
        margin: 0 !important;
        order: -1; /* Place le bouton au-dessus du titre sur mobile */
    }

    .grid-cols-2, .config-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .full-width {
        grid-column: span 1 !important;
    }

    .h2-row-left {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .h2-row-left h2 {
        border-left: none;
        border-bottom: 3px solid var(--primary);
        padding-left: 0;
        padding-bottom: 0.25rem;
    }

    .select-profile {
        width: 100% !important;
        min-width: 0 !important;
    }

    .info-inline {
        max-width: 100%;
        white-space: normal;
        word-break: break-all;
    }

    .param-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
        padding: 0.75rem !important;
        position: relative;
    }

    .param-row .drag-handle {
        position: absolute;
        right: 0.5rem;
        top: 0.5rem;
    }

    .param-row .btn-remove {
        width: 100%;
        height: 36px;
    }

    /* Fix pour les boutons en ligne (33.33%) */
    button[style*="width: 33.33%"] {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    div[style*="display: flex; gap: 1rem"] {
        flex-direction: column;
        gap: 0.5rem !important;
    }

    #datePickerContainer {
        flex-direction: column;
        align-items: stretch !important;
    }

    #scheduledDate {
        max-width: 100% !important;
    }

    /* Template Editor Specifics */
    .header-actions {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch !important;
    }

    .formatting-toolbar {
        position: static !important;
        padding: 4px !important;
    }

    .formatting-toolbar > div {
        flex-wrap: wrap;
        border: none !important;
        padding: 2px !important;
        margin: 0 !important;
    }

    #brevo-visual-editor, #brevo-code-editor {
        min-height: 400px !important;
        padding: 1rem !important;
    }

    div[style*="display: flex; align-items: center; gap: 2rem"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    div[style*="display: flex; align-items: flex-start; gap: 1rem"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }

    .btn-param {
        width: 100%;
        justify-content: center;
    }
}

/* ===== ATTACHMENTS ===== */
.attachments-container-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.5rem;
    margin-left: 0.5rem;
    max-width: calc(100% - 0.5rem);
}

.attachment-item {
    background: rgba(0, 153, 255, 0.1);
    border: 1px solid rgba(0, 153, 255, 0.2);
    padding: 0.3rem 0.6rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 500;
    flex: 1 1 min(240px, 100%);
    max-width: calc(50% - 0.5rem);
    min-width: 160px;
    overflow-wrap: anywhere;
}

.attachment-item .attachment-name {
    display: inline-block;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}

.attachment-item .icon {
    font-size: 1.1rem;
}

/* Drag and Drop Params */
.param-row {
    transition: transform 0.2s, opacity 0.2s;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 0.2rem;
    border: 1px solid transparent;
}

.param-row.dragging {
    opacity: 0.5;
    background: rgba(0, 153, 255, 0.05);
    border: 2px dashed var(--primary);
    transform: scale(0.98);
}

.drag-handle {
    cursor: grab;
    padding: 0 0.75rem;
    color: #94a3b8;
    font-size: 1.2rem;
    user-select: none;
    display: flex;
    align-items: center;
}

.drag-handle:active {
    cursor: grabbing;
}