/**
 * Doctiva RDV Express Modal Styles
 * Modal rapide pour conversion Google Ads
 * 
 * @version 1.0.0
 */

/* === VARIABLES === */
:root {
    --dre-primary: #00A0DC;
    --dre-primary-hover: #0090C8;
    --dre-success: #10B981;
    --dre-error: #EF4444;
    --dre-warning: #F59E0B;
    --dre-text: #0F172A;
    --dre-text-secondary: #64748B;
    --dre-bg: #FFFFFF;
    --dre-border: #E2E8F0;
    --dre-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --dre-radius: 16px;
    --dre-radius-sm: 10px;
    --dre-whatsapp: #25D366;
}

/* === BODY STATE === */
body.dre-modal-open {
    overflow: hidden;
}

/* === MODAL CONTAINER === */
.dre-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

@media (min-width: 640px) {
    .dre-modal {
        align-items: center;
        padding: 20px;
    }
}

/* === BACKDROP === */
.dre-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    animation: dreBackdropIn 0.2s ease;
}

@keyframes dreBackdropIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* === MODAL CONTAINER === */
.dre-modal__container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    max-height: 90dvh;
    display: flex;
    flex-direction: column;
    animation: dreSlideUp 0.3s ease;
}

@keyframes dreSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 639px) {
    .dre-modal__container {
        max-height: 95vh;
        max-height: 95dvh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* === CONTENT === */
.dre-modal__content {
    background: var(--dre-bg);
    border-radius: var(--dre-radius);
    box-shadow: var(--dre-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: inherit;
}

@media (max-width: 639px) {
    .dre-modal__content {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* === HEADER === */
.dre-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--dre-border);
    flex-shrink: 0;
}

.dre-modal__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--dre-text);
}

.dre-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: #F1F5F9;
    border-radius: 50%;
    cursor: pointer;
    color: #1E293B;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.dre-modal__close:hover {
    background: #E2E8F0;
    color: #0F172A;
}

.dre-modal__close:active {
    background: #CBD5E1;
    transform: scale(0.95);
}

.dre-modal__close-icon {
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
    display: block;
    margin-top: -2px;
}

/* === FORM VIEW === */
.dre-modal__form-view {
    overflow-y: auto;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    flex: 1;
    overscroll-behavior: contain;
}

/* === FORM === */
.dre-modal__form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* === REASSURANCE === */
.dre-modal__reassurance {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #F0FDFA 0%, #E0F7FA 100%);
    border-radius: var(--dre-radius-sm);
    font-size: 13px;
    color: #0F766E;
    line-height: 1.5;
}

.dre-modal__reassurance svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* === FIELDS === */
.dre-modal__fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.dre-modal__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dre-modal__field label {
    font-size: 14px;
    font-weight: 600;
    color: var(--dre-text);
}

.dre-modal__field label .required {
    color: var(--dre-error);
}

.dre-modal__field input,
.dre-modal__field select,
.dre-modal__field textarea {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    border: 1.5px solid var(--dre-border);
    border-radius: var(--dre-radius-sm);
    background: var(--dre-bg);
    color: var(--dre-text);
    transition: all 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.dre-modal__field input:focus,
.dre-modal__field select:focus,
.dre-modal__field textarea:focus {
    outline: none;
    border-color: var(--dre-primary);
    box-shadow: 0 0 0 3px rgba(0, 160, 220, 0.1);
}

.dre-modal__field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

.dre-modal__field textarea {
    resize: vertical;
    min-height: 70px;
}

/* Field error state */
.dre-modal__field.has-error input,
.dre-modal__field.has-error select,
.dre-modal__field.has-error textarea {
    border-color: var(--dre-error);
}

.dre-modal__field-error {
    font-size: 12px;
    color: var(--dre-error);
    min-height: 16px;
}

/* === PREFERENCES TOGGLE === */
.dre-modal__preferences {
    border-top: 1px solid var(--dre-border);
    padding-top: 14px;
    margin-top: 4px;
}

.dre-modal__preferences-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: 1px dashed var(--dre-border);
    border-radius: var(--dre-radius-sm);
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--dre-text-secondary);
    transition: all 0.15s ease;
}

.dre-modal__preferences-toggle:hover {
    border-color: var(--dre-primary);
    color: var(--dre-primary);
}

.dre-modal__preferences-icon {
    width: 18px;
    height: 18px;
    transition: transform 0.2s ease;
}

.dre-modal__preferences-icon.is-rotated {
    transform: rotate(45deg);
}

.dre-modal__preferences-hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--dre-text-secondary);
    opacity: 0.7;
}

.dre-modal__preferences-micro-hint {
    margin: 6px 0 0;
    padding: 0;
    font-size: 12px;
    color: #94A3B8;
    text-align: center;
}

.dre-modal__preferences-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 14px;
}

/* === PRIVACY NOTE === */
.dre-modal__privacy-note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    background: #FEF3C7;
    border-radius: var(--dre-radius-sm);
    font-size: 12px;
    color: #92400E;
    line-height: 1.4;
}

.dre-modal__privacy-note svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* === ERRORS CONTAINER === */
.dre-modal__errors {
    padding: 12px 14px;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--dre-radius-sm);
}

.dre-modal__error-message {
    font-size: 14px;
    font-weight: 500;
    color: var(--dre-error);
}

.dre-modal__error-list {
    margin: 8px 0 0;
    padding-left: 20px;
    font-size: 13px;
    color: #991B1B;
}

/* === SUBMIT BUTTON === */
.dre-modal__submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    color: white;
    background: var(--dre-primary);
    border: none;
    border-radius: var(--dre-radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.dre-modal__submit:hover:not(:disabled) {
    background: var(--dre-primary-hover);
    transform: translateY(-1px);
}

.dre-modal__submit:active:not(:disabled) {
    transform: translateY(0);
}

.dre-modal__submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.dre-modal__submit-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Spinner animation */
.dre-spinner {
    width: 20px;
    height: 20px;
    animation: dreSpin 1s linear infinite;
}

@keyframes dreSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* === SUCCESS VIEW === */
.dre-modal__success-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 24px;
    text-align: center;
}

.dre-modal__success-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #D1FAE5 0%, #A7F3D0 100%);
    border-radius: 50%;
    margin-bottom: 16px;
    animation: dreSuccessIconIn 0.4s ease;
}

@keyframes dreSuccessIconIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.dre-modal__success-icon svg {
    width: 36px;
    height: 36px;
    color: var(--dre-success);
}

.dre-modal__success-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 700;
    color: var(--dre-text);
}

.dre-modal__success-message {
    margin: 0 0 24px;
    font-size: 15px;
    color: var(--dre-text-secondary);
    line-height: 1.5;
}

/* === SUCCESS ACTIONS === */
.dre-modal__success-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.dre-modal__action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border-radius: var(--dre-radius-sm);
    transition: all 0.15s ease;
    cursor: pointer;
    border: none;
}

/* Primary action (Fermer) - prominent */
.dre-modal__action--primary {
    background: var(--dre-primary);
    color: white;
}

.dre-modal__action--primary:hover {
    background: var(--dre-primary-hover);
}

/* Secondary actions (Appeler, WhatsApp) - subtle */
.dre-modal__action--secondary {
    background: transparent;
    border: 1.5px solid var(--dre-border);
    color: var(--dre-text-secondary);
}

.dre-modal__action--secondary:hover {
    background: #F8FAFC;
    border-color: #CBD5E1;
    color: var(--dre-text);
}

.dre-modal__action--secondary svg {
    width: 16px;
    height: 16px;
}

/* Call button secondary style */
.dre-modal__action--call.dre-modal__action--secondary {
    color: var(--dre-primary);
    border-color: var(--dre-primary);
}

.dre-modal__action--call.dre-modal__action--secondary:hover {
    background: rgba(0, 160, 220, 0.08);
}

/* WhatsApp button secondary style */
.dre-modal__action--whatsapp.dre-modal__action--secondary {
    color: var(--dre-whatsapp);
    border-color: var(--dre-whatsapp);
}

.dre-modal__action--whatsapp.dre-modal__action--secondary:hover {
    background: rgba(37, 211, 102, 0.08);
}

/* === FLATPICKR INSIDE MODAL === */
#doctiva-rdv-express-modal .flatpickr-calendar {
    z-index: 100000 !important;
}

/* === MOBILE OPTIMIZATIONS === */
@media (max-width: 480px) {
    .dre-modal__form-view {
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    
    .dre-modal__header {
        padding: 14px 16px;
    }
    
    .dre-modal__field input,
    .dre-modal__field select,
    .dre-modal__field textarea {
        padding: 14px;
        font-size: 16px; /* Prevents iOS zoom */
    }
    
    .dre-modal__submit {
        padding: 16px 20px;
        /* Ensure submit button is always visible above keyboard */
        position: sticky;
        bottom: env(safe-area-inset-bottom, 0px);
        margin-top: 8px;
        z-index: 1;
    }
    
    .dre-modal__success-view {
        padding: 32px 20px;
        padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
    }
}

/* === ACCESSIBILITY === */
@media (prefers-reduced-motion: reduce) {
    .dre-modal__backdrop,
    .dre-modal__container,
    .dre-modal__success-icon,
    .dre-spinner {
        animation: none;
    }
    
    .dre-modal__preferences-icon {
        transition: none;
    }
}

/* Focus visible states */
.dre-modal__close:focus-visible,
.dre-modal__preferences-toggle:focus-visible,
.dre-modal__submit:focus-visible,
.dre-modal__action:focus-visible {
    outline: 2px solid var(--dre-primary);
    outline-offset: 2px;
}

/* High contrast mode */
@media (forced-colors: active) {
    .dre-modal__content {
        border: 2px solid CanvasText;
    }
    
    .dre-modal__submit {
        border: 2px solid ButtonText;
    }
}

